* [PATCH 0/2] selftests: add ksft_exit_fail_perror()
@ 2024-04-04 16:14 Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 1/2] " Muhammad Usama Anjum
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-04 16:14 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Shuah Khan, Muhammad Usama Anjum,
linux-mm, linux-kselftest, linux-kernel
Cc: kernel
In this series, ksft_exit_fail_perror() is being added which is helper
function on top of ksft_exit_fail_msg(). It prints errno and its string
form always. After writing and porting several kselftests, I've found
out that most of times ksft_exit_fail_msg() isn't useful if errno value
isn't printed. The ksft_exit_fail_perror() provides a convenient way to
always print errno when its used.
Muhammad Usama Anjum (2):
selftests: add ksft_exit_fail_perror()
selftests: exec: Use new ksft_exit_fail_perror() helper
tools/testing/selftests/exec/recursion-depth.c | 10 +++++-----
tools/testing/selftests/kselftest.h | 14 ++++++++++++++
2 files changed, 19 insertions(+), 5 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] selftests: add ksft_exit_fail_perror()
2024-04-04 16:14 [PATCH 0/2] selftests: add ksft_exit_fail_perror() Muhammad Usama Anjum
@ 2024-04-04 16:14 ` Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 2/2] selftests: exec: Use new ksft_exit_fail_perror() helper Muhammad Usama Anjum
2024-04-04 17:48 ` [PATCH 0/2] selftests: add ksft_exit_fail_perror() Shuah Khan
2 siblings, 0 replies; 4+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-04 16:14 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Shuah Khan, Muhammad Usama Anjum,
linux-mm, linux-kselftest, linux-kernel
Cc: kernel
Add a version of ksft_exit_fail_msg() which prints the errno and its
string form with ease. There is no benefit of exit message without
errno. Whenever some error occurs, instead of printing errno manually,
this function would be very helpful. In the next TAP ports or new tests,
this function will be used instead of ksft_exit_fail_msg() as it prints
errno.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/kselftest.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 159bf8e314fa3..2cd93d220f434 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -41,6 +41,7 @@
* the program is aborting before finishing all tests):
*
* ksft_exit_fail_msg(fmt, ...);
+ * ksft_exit_fail_perror(msg);
*
*/
#ifndef __KSELFTEST_H
@@ -370,6 +371,19 @@ static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
exit(KSFT_FAIL);
}
+static inline void ksft_exit_fail_perror(const char *msg)
+{
+#ifndef NOLIBC
+ ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
+#else
+ /*
+ * nolibc doesn't provide strerror() and it seems
+ * inappropriate to add one, just print the errno.
+ */
+ ksft_exit_fail_msg("%s: %d)\n", msg, errno);
+#endif
+}
+
static inline int ksft_exit_xfail(void)
{
ksft_print_cnts();
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] selftests: exec: Use new ksft_exit_fail_perror() helper
2024-04-04 16:14 [PATCH 0/2] selftests: add ksft_exit_fail_perror() Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 1/2] " Muhammad Usama Anjum
@ 2024-04-04 16:14 ` Muhammad Usama Anjum
2024-04-04 17:48 ` [PATCH 0/2] selftests: add ksft_exit_fail_perror() Shuah Khan
2 siblings, 0 replies; 4+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-04 16:14 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Shuah Khan, Muhammad Usama Anjum,
linux-mm, linux-kselftest, linux-kernel
Cc: kernel
Use ksft_exit_fail_perror() to print the value of errno and its string
form. This is the first user of the ksft_exit_fail_perror() and proves
the usefulness of this API.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/exec/recursion-depth.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/exec/recursion-depth.c b/tools/testing/selftests/exec/recursion-depth.c
index b2f37d86a5f62..438c8ff2fd260 100644
--- a/tools/testing/selftests/exec/recursion-depth.c
+++ b/tools/testing/selftests/exec/recursion-depth.c
@@ -37,25 +37,25 @@ int main(void)
ksft_test_result_skip("error: unshare, errno %d\n", errno);
ksft_finished();
}
- ksft_exit_fail_msg("error: unshare, errno %d\n", errno);
+ ksft_exit_fail_perror("error: unshare");
}
if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1)
- ksft_exit_fail_msg("error: mount '/', errno %d\n", errno);
+ ksft_exit_fail_perror("error: mount '/'");
/* Require "exec" filesystem. */
if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1)
- ksft_exit_fail_msg("error: mount ramfs, errno %d\n", errno);
+ ksft_exit_fail_perror("error: mount ramfs");
#define FILENAME "/tmp/1"
fd = creat(FILENAME, 0700);
if (fd == -1)
- ksft_exit_fail_msg("error: creat, errno %d\n", errno);
+ ksft_exit_fail_perror("error: creat");
#define S "#!" FILENAME "\n"
if (write(fd, S, strlen(S)) != strlen(S))
- ksft_exit_fail_msg("error: write, errno %d\n", errno);
+ ksft_exit_fail_perror("error: write");
close(fd);
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] selftests: add ksft_exit_fail_perror()
2024-04-04 16:14 [PATCH 0/2] selftests: add ksft_exit_fail_perror() Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 1/2] " Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 2/2] selftests: exec: Use new ksft_exit_fail_perror() helper Muhammad Usama Anjum
@ 2024-04-04 17:48 ` Shuah Khan
2 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2024-04-04 17:48 UTC (permalink / raw)
To: Muhammad Usama Anjum, Eric Biederman, Kees Cook, Shuah Khan,
linux-mm, linux-kselftest, linux-kernel, Shuah Khan
Cc: kernel
On 4/4/24 10:14, Muhammad Usama Anjum wrote:
> In this series, ksft_exit_fail_perror() is being added which is helper
> function on top of ksft_exit_fail_msg(). It prints errno and its string
> form always. After writing and porting several kselftests, I've found
> out that most of times ksft_exit_fail_msg() isn't useful if errno value
> isn't printed. The ksft_exit_fail_perror() provides a convenient way to
> always print errno when its used.
>
> Muhammad Usama Anjum (2):
> selftests: add ksft_exit_fail_perror()> selftests: exec: Use new ksft_exit_fail_perror() helper
>
> tools/testing/selftests/exec/recursion-depth.c | 10 +++++-----
> tools/testing/selftests/kselftest.h | 14 ++++++++++++++
> 2 files changed, 19 insertions(+), 5 deletions(-)
>
Applied the two patches to linux-kselftest next for Linux 6.10-rc1.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-04 17:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-04 16:14 [PATCH 0/2] selftests: add ksft_exit_fail_perror() Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 1/2] " Muhammad Usama Anjum
2024-04-04 16:14 ` [PATCH 2/2] selftests: exec: Use new ksft_exit_fail_perror() helper Muhammad Usama Anjum
2024-04-04 17:48 ` [PATCH 0/2] selftests: add ksft_exit_fail_perror() Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox