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.
This commit is contained in:
Ondřej Surý
2023-03-30 09:14:21 +02:00
parent bd94d8c98e
commit 32a8773ab3
2 changed files with 24 additions and 17 deletions

View File

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