Skip to content

Commit 1d0e51b

Browse files
musamaanjumkees
authored andcommitted
selftests/exec: recursion-depth: conform test to TAP format output
Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. While at it, do minor cleanups like move the declarations of the variables on top of the function. Signed-off-by: Muhammad Usama Anjum <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent c409506 commit 1d0e51b

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

tools/testing/selftests/exec/recursion-depth.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,44 @@
2323
#include <fcntl.h>
2424
#include <sys/mount.h>
2525
#include <unistd.h>
26+
#include "../kselftest.h"
2627

2728
int main(void)
2829
{
30+
int fd, rv;
31+
32+
ksft_print_header();
33+
ksft_set_plan(1);
34+
2935
if (unshare(CLONE_NEWNS) == -1) {
3036
if (errno == ENOSYS || errno == EPERM) {
31-
fprintf(stderr, "error: unshare, errno %d\n", errno);
32-
return 4;
37+
ksft_test_result_skip("error: unshare, errno %d\n", errno);
38+
ksft_finished();
3339
}
34-
fprintf(stderr, "error: unshare, errno %d\n", errno);
35-
return 1;
36-
}
37-
if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
38-
fprintf(stderr, "error: mount '/', errno %d\n", errno);
39-
return 1;
40+
ksft_exit_fail_msg("error: unshare, errno %d\n", errno);
4041
}
42+
43+
if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1)
44+
ksft_exit_fail_msg("error: mount '/', errno %d\n", errno);
45+
4146
/* Require "exec" filesystem. */
42-
if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1) {
43-
fprintf(stderr, "error: mount ramfs, errno %d\n", errno);
44-
return 1;
45-
}
47+
if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1)
48+
ksft_exit_fail_msg("error: mount ramfs, errno %d\n", errno);
4649

4750
#define FILENAME "/tmp/1"
4851

49-
int fd = creat(FILENAME, 0700);
50-
if (fd == -1) {
51-
fprintf(stderr, "error: creat, errno %d\n", errno);
52-
return 1;
53-
}
52+
fd = creat(FILENAME, 0700);
53+
if (fd == -1)
54+
ksft_exit_fail_msg("error: creat, errno %d\n", errno);
55+
5456
#define S "#!" FILENAME "\n"
55-
if (write(fd, S, strlen(S)) != strlen(S)) {
56-
fprintf(stderr, "error: write, errno %d\n", errno);
57-
return 1;
58-
}
57+
if (write(fd, S, strlen(S)) != strlen(S))
58+
ksft_exit_fail_msg("error: write, errno %d\n", errno);
59+
5960
close(fd);
6061

61-
int rv = execve(FILENAME, NULL, NULL);
62-
if (rv == -1 && errno == ELOOP) {
63-
return 0;
64-
}
65-
fprintf(stderr, "error: execve, rv %d, errno %d\n", rv, errno);
66-
return 1;
62+
rv = execve(FILENAME, NULL, NULL);
63+
ksft_test_result(rv == -1 && errno == ELOOP,
64+
"execve failed as expected (ret %d, errno %d)\n", rv, errno);
65+
ksft_finished();
6766
}

0 commit comments

Comments
 (0)