tests/fdgrowtable: perform the threaded test in a child process

The test needs to be performed in a new process that was forked with
RFCFDG flag.  The will guarantee that the table will start to grow from 20
file descriptors, no matter what kyua(1) or a bare shell was doing before
executing this test.  This should fix  repetitive test runs from a shell
as well as failures with kyua(1) in some environments.
This commit is contained in:
Gleb Smirnoff 2024-02-23 17:49:53 -08:00
parent 98ef51d549
commit 4c6ceca9cc

View file

@ -167,21 +167,43 @@ ATF_TC_HEAD(oldtables_shared_via_threads, tc)
ATF_TC_BODY(oldtables_shared_via_threads, tc)
{
pid_t child;
kvm_t *kd;
struct kinfo_proc *kp;
pthread_t thread;
ATF_REQUIRE((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) != NULL);
ATF_REQUIRE(pthread_create(&thread, NULL, exec_thread, NULL) == 0);
if ((child = rfork(RFPROC | RFCFDG)) > 0) {
pid_t wpid;
int status;
wpid = waitpid(child, &status, 0);
ATF_REQUIRE(wpid == child);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE(WEXITSTATUS(status) == EXIT_SUCCESS);
return;
}
#define REQUIRE(expression) do { \
if (!(expression)) \
exit(EXIT_FAILURE); \
} while (0)
REQUIRE(child == 0);
REQUIRE((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) != NULL);
REQUIRE(pthread_create(&thread, NULL, exec_thread, NULL) == 0);
openfiles(128);
kp = read_kinfo(kd);
ATF_CHECK(kp->ki_numthreads > 1);
ATF_CHECK(old_tables(kd,kp) > 1);
REQUIRE(kp->ki_numthreads > 1);
REQUIRE(old_tables(kd,kp) > 1);
ATF_REQUIRE(pthread_cancel(thread) == 0);
ATF_REQUIRE(pthread_join(thread, NULL) == 0);
REQUIRE(pthread_cancel(thread) == 0);
REQUIRE(pthread_join(thread, NULL) == 0);
#undef REQUIRE
exit(EXIT_SUCCESS);
}
/*