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