1 /* $NetBSD: isc.c,v 1.3 2024/09/22 00:14:11 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 /*! \file */ 17 18 #include <inttypes.h> 19 #include <signal.h> 20 #include <stdbool.h> 21 #include <stdlib.h> 22 #include <time.h> 23 24 #include <isc/buffer.h> 25 #include <isc/hash.h> 26 #include <isc/managers.h> 27 #include <isc/mem.h> 28 #include <isc/os.h> 29 #include <isc/string.h> 30 #include <isc/task.h> 31 #include <isc/timer.h> 32 #include <isc/util.h> 33 34 #include "netmgr_p.h" 35 #include "task_p.h" 36 #include "timer_p.h" 37 38 #include <tests/isc.h> 39 40 isc_mem_t *mctx = NULL; 41 isc_taskmgr_t *taskmgr = NULL; 42 isc_timermgr_t *timermgr = NULL; 43 isc_nm_t *netmgr = NULL; 44 unsigned int workers = 0; 45 isc_task_t *maintask = NULL; 46 bool debug = false; 47 48 int 49 setup_managers(void **state) { 50 isc_result_t result; 51 52 UNUSED(state); 53 54 REQUIRE(mctx != NULL); 55 56 if (workers == 0) { 57 char *env_workers = getenv("ISC_TASK_WORKERS"); 58 if (env_workers != NULL) { 59 workers = atoi(env_workers); 60 } else { 61 workers = isc_os_ncpus(); 62 } 63 INSIST(workers > 0); 64 } 65 66 result = isc_managers_create(mctx, workers, 0, &netmgr, &taskmgr, 67 &timermgr); 68 if (result != ISC_R_SUCCESS) { 69 return (-1); 70 } 71 72 result = isc_task_create_bound(taskmgr, 0, &maintask, 0); 73 if (result != ISC_R_SUCCESS) { 74 return (-1); 75 } 76 77 isc_taskmgr_setexcltask(taskmgr, maintask); 78 79 return (0); 80 } 81 82 int 83 teardown_managers(void **state) { 84 UNUSED(state); 85 86 isc_task_detach(&maintask); 87 isc_managers_destroy(&netmgr, &taskmgr, &timermgr); 88 89 return (0); 90 } 91