Skip to content

Commit 41ca14e

Browse files
cvam0000shuahkh
authored andcommitted
selftests: tmpfs: Add Test-skip if not run as root
Add 'ksft_exit_skip()', if not run as root, with an appropriate Warning. Add 'ksft_print_header()' and 'ksft_set_plan()' to structure test outputs more effectively. Test logs: Before Change: - Without root error: unshare, errno 1 - With root No, output After change: - Without root TAP version 13 1..1 ok 2 # SKIP This test needs root to run! Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 - With root TAP version 13 1..1 Link: https://lore.kernel.org/r/20250105085255.124929-2-cvam0000@gmail.com Signed-off-by: Shivam Chaudhary <cvam0000@gmail.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 02bc220 commit 41ca14e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,22 @@
2323
#include <sys/mount.h>
2424
#include <unistd.h>
2525

26+
#include "../kselftest.h"
27+
2628
int main(void)
2729
{
2830
int fd;
2931

32+
// Setting up kselftest framework
33+
ksft_print_header();
34+
ksft_set_plan(1);
35+
36+
// Check if test is run as root
37+
if (geteuid()) {
38+
ksft_exit_skip("This test needs root to run!\n");
39+
return 1;
40+
}
41+
3042
if (unshare(CLONE_NEWNS) == -1) {
3143
if (errno == ENOSYS || errno == EPERM) {
3244
fprintf(stderr, "error: unshare, errno %d\n", errno);

0 commit comments

Comments
 (0)