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