diff --git a/test/apps/clone3/clone_files.c b/test/apps/clone3/clone_files.c new file mode 100644 index 00000000..bfbab342 --- /dev/null +++ b/test/apps/clone3/clone_files.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: MPL-2.0 + +#define _GNU_SOURCE + +#include "../network/test.h" + +#include +#include +#include +#include + +static char child_stack[4096]; +#define CHILD_STACK_TOP \ + (child_stack + sizeof(child_stack) / sizeof(child_stack[0])) + +static int fd1, fd2; + +static int child_close(void *arg) +{ + CHECK(close(fd2)); + + _exit(0); +} + +FN_TEST(clone_files_and_close) +{ + pid_t pid; + int status; + + fd1 = TEST_SUCC(open("/dev/null", O_RDONLY)); + fd2 = TEST_SUCC(open("/dev/null", O_RDONLY)); + + pid = TEST_SUCC(clone(&child_close, CHILD_STACK_TOP, + CLONE_FILES | SIGCHLD, NULL, NULL, NULL, NULL)); + + TEST_RES(wait(&status), + _ret == pid && WIFEXITED(status) && WEXITSTATUS(status) == 0); + + TEST_SUCC(close(fd1)); + TEST_ERRNO(close(fd2), EBADF); +} +END_TEST() diff --git a/test/apps/scripts/process.sh b/test/apps/scripts/process.sh index 25d71231..0de8608b 100755 --- a/test/apps/scripts/process.sh +++ b/test/apps/scripts/process.sh @@ -11,6 +11,7 @@ echo "Start process test......" # These test programs are sorted by name. tests=" clone3/clone_exit_signal +clone3/clone_files clone3/clone_no_exit_signal clone3/clone_process cpu_affinity/cpu_affinity