Add a regression test

This commit is contained in:
Ruihan Li 2025-04-07 11:17:37 +08:00 committed by Tate, Hongliang Tian
parent 8600278a5f
commit f8429b2735
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,42 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include "../network/test.h"
#include <fcntl.h>
#include <sched.h>
#include <sys/wait.h>
#include <unistd.h>
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()

View File

@ -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