aboutsummaryrefslogtreecommitdiff
path: root/tests/sys
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2024-02-24 01:49:53 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2024-02-24 01:49:53 +0000
commit4c6ceca9cc44fc9b02dc39e80713f2ad3ab8eeb6 (patch)
tree193119bd4983543a8372f3e22b4842da533f75f2 /tests/sys
parent98ef51d549064318c1cdc9cbea7cf499b9a1d34b (diff)
downloadsrc-4c6ceca9cc44fc9b02dc39e80713f2ad3ab8eeb6.tar.gz
src-4c6ceca9cc44fc9b02dc39e80713f2ad3ab8eeb6.zip
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.
Diffstat (limited to 'tests/sys')
-rw-r--r--tests/sys/kern/fdgrowtable_test.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/sys/kern/fdgrowtable_test.c b/tests/sys/kern/fdgrowtable_test.c
index 826599ecf836..ecab72ff09aa 100644
--- a/tests/sys/kern/fdgrowtable_test.c
+++ b/tests/sys/kern/fdgrowtable_test.c
@@ -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);
+
+ REQUIRE(pthread_cancel(thread) == 0);
+ REQUIRE(pthread_join(thread, NULL) == 0);
+#undef REQUIRE
- ATF_REQUIRE(pthread_cancel(thread) == 0);
- ATF_REQUIRE(pthread_join(thread, NULL) == 0);
+ exit(EXIT_SUCCESS);
}
/*