Skip to content

Commit 86483f8

Browse files
musamaanjumshuahkh
authored andcommitted
selftests: add ksft_exit_fail_perror()
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. Resolved merge conflict found in next between the following commits: f7d5bcd ("selftests: kselftest: Mark functions that unconditionally call exit() as __noreturn") f07041728422 ("selftests: add ksft_exit_fail_perror()") Reported-by: Stephen Rothwell <[email protected]> Shuah Khan <[email protected]> Signed-off-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent b4970a8 commit 86483f8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* the program is aborting before finishing all tests):
4242
*
4343
* ksft_exit_fail_msg(fmt, ...);
44+
* ksft_exit_fail_perror(msg);
4445
*
4546
*/
4647
#ifndef __KSELFTEST_H
@@ -376,6 +377,19 @@ static inline __noreturn __printf(1, 2) int ksft_exit_fail_msg(const char *msg,
376377
exit(KSFT_FAIL);
377378
}
378379

380+
static inline void ksft_exit_fail_perror(const char *msg)
381+
{
382+
#ifndef NOLIBC
383+
ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
384+
#else
385+
/*
386+
* nolibc doesn't provide strerror() and it seems
387+
* inappropriate to add one, just print the errno.
388+
*/
389+
ksft_exit_fail_msg("%s: %d)\n", msg, errno);
390+
#endif
391+
}
392+
379393
static inline __noreturn int ksft_exit_xfail(void)
380394
{
381395
ksft_print_cnts();

0 commit comments

Comments
 (0)