isc.c revision 1.2 1 /* $NetBSD: isc.c,v 1.2 2024/02/21 22:52:51 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
47 int
48 setup_managers(void **state) {
49 isc_result_t result;
50
51 UNUSED(state);
52
53 REQUIRE(mctx != NULL);
54
55 if (workers == 0) {
56 char *env_workers = getenv("ISC_TASK_WORKERS");
57 if (env_workers != NULL) {
58 workers = atoi(env_workers);
59 } else {
60 workers = isc_os_ncpus();
61 }
62 INSIST(workers > 0);
63 }
64
65 result = isc_managers_create(mctx, workers, 0, &netmgr, &taskmgr,
66 &timermgr);
67 if (result != ISC_R_SUCCESS) {
68 return (-1);
69 }
70
71 result = isc_task_create_bound(taskmgr, 0, &maintask, 0);
72 if (result != ISC_R_SUCCESS) {
73 return (-1);
74 }
75
76 isc_taskmgr_setexcltask(taskmgr, maintask);
77
78 return (0);
79 }
80
81 int
82 teardown_managers(void **state) {
83 UNUSED(state);
84
85 isc_task_detach(&maintask);
86 isc_managers_destroy(&netmgr, &taskmgr, &timermgr);
87
88 return (0);
89 }
90