From: Ondřej Surý Date: Thu, 30 Mar 2023 07:14:21 +0000 (+0200) Subject: Always initialize the workers in the libtest X-Git-Tag: v9.19.13~21^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=32a8773ab35ec7fb4c1c888c9ced59d0522ab10b;p=thirdparty%2Fbind9.git Always initialize the workers in the libtest The workers variable might be needed even to tests not using loopmgr. Split the workers initialization into setup_workers() function and always call it from the default main loop. --- diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h index 391a64454be..add574ffb31 100644 --- a/tests/include/tests/isc.h +++ b/tests/include/tests/isc.h @@ -42,6 +42,9 @@ setup_mctx(void **state); int teardown_mctx(void **state); +int +setup_workers(void **state); + int setup_loopmgr(void **state); int @@ -172,8 +175,8 @@ teardown_managers(void **state); \ signal(SIGPIPE, SIG_IGN); \ \ - isc_mem_debugging |= ISC_MEM_DEBUGRECORD; \ - isc_mem_create(&mctx); \ + setup_mctx(NULL); \ + setup_workers(NULL); \ \ r = cmocka_run_group_tests(tests, setup, teardown); \ \ diff --git a/tests/libtest/isc.c b/tests/libtest/isc.c index 777d2508eec..324fc1d7cf3 100644 --- a/tests/libtest/isc.c +++ b/tests/libtest/isc.c @@ -51,6 +51,24 @@ adjustnofile(void) { } } +int +setup_workers(void **state ISC_ATTR_UNUSED) { + char *env_workers = getenv("ISC_TASK_WORKERS"); + if (env_workers != NULL) { + workers = atoi(env_workers); + } else { + workers = isc_os_ncpus(); + + /* We always need at least two loops for some of the tests */ + if (workers < 2) { + workers = 2; + } + } + INSIST(workers != 0); + + return (0); +} + int setup_mctx(void **state ISC_ATTR_UNUSED) { isc_mem_debugging |= ISC_MEM_DEBUGRECORD; @@ -68,23 +86,9 @@ teardown_mctx(void **state ISC_ATTR_UNUSED) { int setup_loopmgr(void **state ISC_ATTR_UNUSED) { - char *env_workers = NULL; - REQUIRE(mctx != NULL); - env_workers = getenv("ISC_TASK_WORKERS"); - if (env_workers != NULL) { - workers = atoi(env_workers); - } - - if (workers == 0) { - workers = isc_os_ncpus(); - - /* We always need at least two loops for some of the tests */ - if (workers < 2) { - workers = 2; - } - } + setup_workers(state); isc_loopmgr_create(mctx, workers, &loopmgr); mainloop = isc_loop_main(loopmgr);