Skip to content

Commit 696bf15

Browse files
brooniet-8ch
authored andcommitted
selftests/nolibc: Add coverage of vfork()
Generalise the existing fork() test to also cover the newly added vfork() implementation. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Thomas Weißschuh <[email protected]>
1 parent fb476df commit 696bf15

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,12 @@ int test_file_stream(void)
877877
return 0;
878878
}
879879

880-
int test_fork(void)
880+
enum fork_type {
881+
FORK_STANDARD,
882+
FORK_VFORK,
883+
};
884+
885+
int test_fork(enum fork_type type)
881886
{
882887
int status;
883888
pid_t pid;
@@ -886,14 +891,23 @@ int test_fork(void)
886891
fflush(stdout);
887892
fflush(stderr);
888893

889-
pid = fork();
894+
switch (type) {
895+
case FORK_STANDARD:
896+
pid = fork();
897+
break;
898+
case FORK_VFORK:
899+
pid = vfork();
900+
break;
901+
default:
902+
return 1;
903+
}
890904

891905
switch (pid) {
892906
case -1:
893907
return 1;
894908

895909
case 0:
896-
exit(123);
910+
_exit(123);
897911

898912
default:
899913
pid = waitpid(pid, &status, 0);
@@ -1330,7 +1344,7 @@ int run_syscall(int min, int max)
13301344
CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break;
13311345
CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break;
13321346
CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break;
1333-
CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break;
1347+
CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD)); break;
13341348
CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break;
13351349
CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break;
13361350
CASE_TEST(directories); EXPECT_SYSZR(proc, test_dirent()); break;
@@ -1374,6 +1388,7 @@ int run_syscall(int min, int max)
13741388
CASE_TEST(uname_fault); EXPECT_SYSER(1, uname(NULL), -1, EFAULT); break;
13751389
CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); break;
13761390
CASE_TEST(unlink_blah); EXPECT_SYSER(1, unlink("/proc/self/blah"), -1, ENOENT); break;
1391+
CASE_TEST(vfork); EXPECT_SYSZR(1, test_fork(FORK_VFORK)); break;
13771392
CASE_TEST(wait_child); EXPECT_SYSER(1, wait(&tmp), -1, ECHILD); break;
13781393
CASE_TEST(waitpid_min); EXPECT_SYSER(1, waitpid(INT_MIN, &tmp, WNOHANG), -1, ESRCH); break;
13791394
CASE_TEST(waitpid_child); EXPECT_SYSER(1, waitpid(getpid(), &tmp, WNOHANG), -1, ECHILD); break;

0 commit comments

Comments
 (0)