2011-09-02 17:15:39 -04:00
|
|
|
/*
|
2018-02-23 03:53:12 -05:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2011-09-02 17:15:39 -04:00
|
|
|
*
|
2021-06-03 02:37:05 -04:00
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*
|
2016-06-27 00:56:38 -04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 19:20:40 -04:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 03:53:12 -05:00
|
|
|
*
|
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
2011-09-02 17:15:39 -04:00
|
|
|
*/
|
|
|
|
|
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 15:08:40 -04:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
2020-02-12 07:59:18 -05:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
#include <stdarg.h>
|
2018-04-17 11:29:14 -04:00
|
|
|
#include <stdbool.h>
|
2020-02-12 07:59:18 -05:00
|
|
|
#include <stddef.h>
|
2018-02-28 02:01:14 -05:00
|
|
|
#include <stdlib.h>
|
2018-10-24 16:12:55 -04:00
|
|
|
#include <string.h>
|
Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations. In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.
Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>. However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>. Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.
Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation. We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true. The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code). Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code. Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.
Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.
All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk. While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.
2019-07-30 15:08:40 -04:00
|
|
|
#include <unistd.h>
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
#define UNIT_TESTING
|
|
|
|
|
|
2020-12-01 09:08:49 -05:00
|
|
|
#include <cmocka.h>
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
#include <isc/atomic.h>
|
2020-09-02 04:22:21 -04:00
|
|
|
#include <isc/cmocka.h>
|
2018-10-24 16:12:55 -04:00
|
|
|
#include <isc/commandline.h>
|
2018-02-28 02:01:14 -05:00
|
|
|
#include <isc/condition.h>
|
2021-04-26 18:07:43 -04:00
|
|
|
#include <isc/managers.h>
|
2018-02-28 02:01:14 -05:00
|
|
|
#include <isc/mem.h>
|
2018-03-09 19:55:21 -05:00
|
|
|
#include <isc/print.h>
|
2011-09-02 17:15:39 -04:00
|
|
|
#include <isc/task.h>
|
2018-02-28 02:01:14 -05:00
|
|
|
#include <isc/time.h>
|
|
|
|
|
#include <isc/timer.h>
|
2011-09-02 17:15:39 -04:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
2022-05-03 05:37:31 -04:00
|
|
|
#include "netmgr/uv-compat.h"
|
|
|
|
|
|
|
|
|
|
#include <tests/isc.h>
|
2018-10-03 19:11:10 -04:00
|
|
|
|
2018-11-16 03:19:06 -05:00
|
|
|
/* Set to true (or use -v option) for verbose output */
|
2018-10-24 16:12:55 -04:00
|
|
|
static bool verbose = false;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2020-02-13 17:44:37 -05:00
|
|
|
static isc_mutex_t lock;
|
2018-10-24 16:12:55 -04:00
|
|
|
static isc_condition_t cv;
|
|
|
|
|
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_int_fast32_t counter;
|
2020-02-13 17:44:37 -05:00
|
|
|
static int active[10];
|
2021-05-18 13:44:31 -04:00
|
|
|
static atomic_bool done;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
static int
|
2020-02-13 17:44:37 -05:00
|
|
|
_setup(void **state) {
|
2018-11-16 09:33:22 -05:00
|
|
|
isc_mutex_init(&lock);
|
2018-11-15 11:20:36 -05:00
|
|
|
isc_condition_init(&cv);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
workers = 0;
|
|
|
|
|
setup_managers(state);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2020-02-13 17:44:37 -05:00
|
|
|
_setup2(void **state) {
|
2018-11-16 09:33:22 -05:00
|
|
|
isc_mutex_init(&lock);
|
2018-11-15 11:20:36 -05:00
|
|
|
isc_condition_init(&cv);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
/* Two worker threads */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
workers = 2;
|
|
|
|
|
setup_managers(state);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2020-02-13 17:44:37 -05:00
|
|
|
_setup4(void **state) {
|
2018-11-16 09:33:22 -05:00
|
|
|
isc_mutex_init(&lock);
|
2018-11-15 11:20:36 -05:00
|
|
|
isc_condition_init(&cv);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
/* Four worker threads */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
workers = 4;
|
|
|
|
|
setup_managers(state);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2020-02-13 17:44:37 -05:00
|
|
|
_teardown(void **state) {
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
teardown_managers(state);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
isc_condition_destroy(&cv);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
isc_mutex_destroy(&lock);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
2018-03-10 13:33:45 -05:00
|
|
|
|
2011-09-02 17:15:39 -04:00
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
set(isc_task_t *task, isc_event_t *event) {
|
2020-02-12 07:59:18 -05:00
|
|
|
atomic_int_fast32_t *value = (atomic_int_fast32_t *)event->ev_arg;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(value, atomic_fetch_add(&counter, 1));
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
|
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
#include <isc/thread.h>
|
|
|
|
|
|
2011-09-02 17:15:39 -04:00
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
set_and_drop(isc_task_t *task, isc_event_t *event) {
|
2020-02-12 07:59:18 -05:00
|
|
|
atomic_int_fast32_t *value = (atomic_int_fast32_t *)event->ev_arg;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
2018-02-28 02:01:14 -05:00
|
|
|
LOCK(&lock);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
atomic_store(value, atomic_fetch_add(&counter, 1));
|
2018-02-28 02:01:14 -05:00
|
|
|
UNLOCK(&lock);
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create a task */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(create_task) {
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_result_t result;
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_task_t *task = NULL;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
isc_task_destroy(&task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_null(task);
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Process events */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(all_events) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_result_t result;
|
|
|
|
|
isc_task_t *task = NULL;
|
|
|
|
|
isc_event_t *event = NULL;
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_int_fast32_t a, b;
|
2020-02-13 17:44:37 -05:00
|
|
|
int i = 0;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&counter, 1);
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_init(&a, 0);
|
|
|
|
|
atomic_init(&b, 0);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* First event */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST, set, &a,
|
2020-02-12 07:59:18 -05:00
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&a), 0);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task, ISC_TASKEVENT_TEST, set, &b,
|
2020-02-12 07:59:18 -05:00
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&b), 0);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
while ((atomic_load(&a) == 0 || atomic_load(&b) == 0) && i++ < 5000) {
|
2022-05-03 05:37:31 -04:00
|
|
|
uv_sleep(1);
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_not_equal(atomic_load(&a), 0);
|
|
|
|
|
assert_int_not_equal(atomic_load(&b), 0);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
isc_task_destroy(&task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_null(task);
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Privileged events */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(privileged_events) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_result_t result;
|
|
|
|
|
isc_task_t *task1 = NULL, *task2 = NULL;
|
|
|
|
|
isc_event_t *event = NULL;
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_int_fast32_t a, b, c, d, e;
|
2020-02-13 17:44:37 -05:00
|
|
|
int i = 0;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&counter, 1);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
atomic_init(&a, -1);
|
|
|
|
|
atomic_init(&b, -1);
|
|
|
|
|
atomic_init(&c, -1);
|
|
|
|
|
atomic_init(&d, -1);
|
|
|
|
|
atomic_init(&e, -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/*
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
* Pause the net/task manager so we can fill up the work
|
|
|
|
|
* queue without things happening while we do it.
|
2011-09-02 17:15:39 -04:00
|
|
|
*/
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
isc_nm_pause(netmgr);
|
2021-05-06 22:41:49 -04:00
|
|
|
isc_taskmgr_setmode(taskmgr, isc_taskmgrmode_privileged);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task1);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_setname(task1, "privileged", NULL);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_false(isc_task_getprivilege(task1));
|
2018-04-17 11:29:14 -04:00
|
|
|
isc_task_setprivilege(task1, true);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_true(isc_task_getprivilege(task1));
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task2);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_setname(task2, "normal", NULL);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_false(isc_task_getprivilege(task2));
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* First event: privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST, set, &a,
|
|
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_int_equal(atomic_load(&a), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
|
|
|
|
|
/* Second event: not privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST, set, &b,
|
|
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_int_equal(atomic_load(&b), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task2, &event);
|
|
|
|
|
|
|
|
|
|
/* Third event: privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST, set, &c,
|
|
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_int_equal(atomic_load(&c), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
|
|
|
|
|
/* Fourth event: privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST, set, &d,
|
|
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_int_equal(atomic_load(&d), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
|
|
|
|
|
/* Fifth event: not privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST, set, &e,
|
|
|
|
|
sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_int_equal(atomic_load(&e), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task2, &event);
|
|
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
isc_nm_resume(netmgr);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* We're waiting for *all* variables to be set */
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
while ((atomic_load(&a) < 0 || atomic_load(&b) < 0 ||
|
|
|
|
|
atomic_load(&c) < 0 || atomic_load(&d) < 0 ||
|
|
|
|
|
atomic_load(&e) < 0) &&
|
2020-02-13 17:44:37 -05:00
|
|
|
i++ < 5000)
|
|
|
|
|
{
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_test_nap(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We can't guarantee what order the events fire, but
|
|
|
|
|
* we do know the privileged tasks that set a, c, and d
|
|
|
|
|
* would have fired first.
|
|
|
|
|
*/
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_true(atomic_load(&a) <= 3);
|
|
|
|
|
assert_true(atomic_load(&c) <= 3);
|
|
|
|
|
assert_true(atomic_load(&d) <= 3);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* ...and the non-privileged tasks that set b and e, last */
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_true(atomic_load(&b) > 3);
|
|
|
|
|
assert_true(atomic_load(&e) > 3);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&counter), 6);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-04-17 11:29:14 -04:00
|
|
|
isc_task_setprivilege(task1, false);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_false(isc_task_getprivilege(task1));
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
isc_task_destroy(&task1);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_null(task1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_destroy(&task2);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_null(task2);
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Edge case: this tests that the task manager behaves as expected when
|
|
|
|
|
* we explicitly set it into normal mode *while* running privileged.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(privilege_drop) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_result_t result;
|
|
|
|
|
isc_task_t *task1 = NULL, *task2 = NULL;
|
|
|
|
|
isc_event_t *event = NULL;
|
2020-02-12 07:59:18 -05:00
|
|
|
atomic_int_fast32_t a, b, c, d, e; /* non valid states */
|
2020-02-13 17:44:37 -05:00
|
|
|
int i = 0;
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&counter, 1);
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_init(&a, -1);
|
|
|
|
|
atomic_init(&b, -1);
|
|
|
|
|
atomic_init(&c, -1);
|
|
|
|
|
atomic_init(&d, -1);
|
|
|
|
|
atomic_init(&e, -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/*
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
* Pause the net/task manager so we can fill up the work queue
|
2011-09-02 17:15:39 -04:00
|
|
|
* without things happening while we do it.
|
|
|
|
|
*/
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
isc_nm_pause(netmgr);
|
2021-05-06 22:41:49 -04:00
|
|
|
isc_taskmgr_setmode(taskmgr, isc_taskmgrmode_privileged);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task1);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_setname(task1, "privileged", NULL);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_false(isc_task_getprivilege(task1));
|
2018-04-17 11:29:14 -04:00
|
|
|
isc_task_setprivilege(task1, true);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_true(isc_task_getprivilege(task1));
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task2);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_setname(task2, "normal", NULL);
|
2021-05-06 22:41:49 -04:00
|
|
|
assert_false(isc_task_getprivilege(task2));
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* First event: privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
|
2020-02-12 07:59:18 -05:00
|
|
|
set_and_drop, &a, sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&a), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
|
|
|
|
|
/* Second event: not privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
|
2020-02-12 07:59:18 -05:00
|
|
|
set_and_drop, &b, sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&b), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task2, &event);
|
|
|
|
|
|
|
|
|
|
/* Third event: privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
|
2020-02-12 07:59:18 -05:00
|
|
|
set_and_drop, &c, sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&c), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
|
|
|
|
|
/* Fourth event: privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task1, ISC_TASKEVENT_TEST,
|
2020-02-12 07:59:18 -05:00
|
|
|
set_and_drop, &d, sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&d), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
|
|
|
|
|
/* Fifth event: not privileged */
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, task2, ISC_TASKEVENT_TEST,
|
2020-02-12 07:59:18 -05:00
|
|
|
set_and_drop, &e, sizeof(isc_event_t));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&e), -1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_send(task2, &event);
|
|
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
isc_nm_resume(netmgr);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
2011-11-28 19:41:28 -05:00
|
|
|
/* We're waiting for all variables to be set. */
|
2020-02-12 07:59:18 -05:00
|
|
|
while ((atomic_load(&a) == -1 || atomic_load(&b) == -1 ||
|
|
|
|
|
atomic_load(&c) == -1 || atomic_load(&d) == -1 ||
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_load(&e) == -1) &&
|
2020-02-13 17:44:37 -05:00
|
|
|
i++ < 5000)
|
|
|
|
|
{
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_test_nap(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2018-10-22 07:18:45 -04:00
|
|
|
* We need to check that all privilege mode events were fired
|
|
|
|
|
* in privileged mode, and non privileged in non-privileged.
|
2011-09-02 17:15:39 -04:00
|
|
|
*/
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_true(atomic_load(&a) <= 3);
|
|
|
|
|
assert_true(atomic_load(&c) <= 3);
|
|
|
|
|
assert_true(atomic_load(&d) <= 3);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* ...and neither of the non-privileged tasks did... */
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
assert_true(atomic_load(&b) > 3);
|
|
|
|
|
assert_true(atomic_load(&e) > 3);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
/* ...but all five of them did run. */
|
2019-07-04 08:15:39 -04:00
|
|
|
assert_int_equal(atomic_load(&counter), 6);
|
2011-09-02 17:15:39 -04:00
|
|
|
|
|
|
|
|
isc_task_destroy(&task1);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_null(task1);
|
2011-09-02 17:15:39 -04:00
|
|
|
isc_task_destroy(&task2);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_null(task2);
|
2011-09-02 17:15:39 -04:00
|
|
|
}
|
2011-11-28 19:41:28 -05:00
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
/*
|
|
|
|
|
* Basic task functions:
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
basic_cb(isc_task_t *task, isc_event_t *event) {
|
2018-10-24 16:12:55 -04:00
|
|
|
int i, j;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
|
for (i = 0; i < 1000000; i++) {
|
|
|
|
|
j += 100;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 23:52:44 -04:00
|
|
|
UNUSED(j);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# task %s\n", (char *)event->ev_arg);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
basic_shutdown(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# shutdown %s\n", (char *)event->ev_arg);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
basic_tick(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# %s\n", (char *)event->ev_arg);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char one[] = "1";
|
|
|
|
|
static char two[] = "2";
|
|
|
|
|
static char three[] = "3";
|
|
|
|
|
static char four[] = "4";
|
|
|
|
|
static char tick[] = "tick";
|
|
|
|
|
static char tock[] = "tock";
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(basic) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_result_t result;
|
|
|
|
|
isc_task_t *task1 = NULL;
|
|
|
|
|
isc_task_t *task2 = NULL;
|
|
|
|
|
isc_task_t *task3 = NULL;
|
|
|
|
|
isc_task_t *task4 = NULL;
|
|
|
|
|
isc_event_t *event = NULL;
|
|
|
|
|
isc_timer_t *ti1 = NULL;
|
|
|
|
|
isc_timer_t *ti2 = NULL;
|
|
|
|
|
isc_time_t absolute;
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_interval_t interval;
|
2020-02-12 07:59:18 -05:00
|
|
|
char *testarray[] = { one, one, one, one, one, one, one, one,
|
|
|
|
|
one, two, three, four, two, three, four, NULL };
|
2020-02-13 17:44:37 -05:00
|
|
|
int i;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task1);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_task_create(taskmgr, 0, &task2);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_task_create(taskmgr, 0, &task3);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_task_create(taskmgr, 0, &task4);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_onshutdown(task1, basic_shutdown, one);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_task_onshutdown(task2, basic_shutdown, two);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_task_onshutdown(task3, basic_shutdown, three);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_task_onshutdown(task4, basic_shutdown, four);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_time_settoepoch(&absolute);
|
|
|
|
|
isc_interval_set(&interval, 1, 0);
|
2020-02-12 07:59:18 -05:00
|
|
|
result = isc_timer_create(timermgr, isc_timertype_ticker, &absolute,
|
|
|
|
|
&interval, task1, basic_tick, tick, &ti1);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
ti2 = NULL;
|
|
|
|
|
isc_time_settoepoch(&absolute);
|
|
|
|
|
isc_interval_set(&interval, 1, 0);
|
2020-02-12 07:59:18 -05:00
|
|
|
result = isc_timer_create(timermgr, isc_timertype_ticker, &absolute,
|
|
|
|
|
&interval, task2, basic_tick, tock, &ti2);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
|
|
for (i = 0; testarray[i] != NULL; i++) {
|
|
|
|
|
/*
|
|
|
|
|
* Note: (void *)1 is used as a sender here, since some
|
|
|
|
|
* compilers don't like casting a function pointer to a
|
|
|
|
|
* (void *).
|
|
|
|
|
*
|
|
|
|
|
* In a real use, it is more likely the sender would be a
|
|
|
|
|
* structure (socket, timer, task, etc) but this is just a
|
|
|
|
|
* test program.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, (void *)1, 1, basic_cb,
|
2018-02-28 02:01:14 -05:00
|
|
|
testarray[i], sizeof(*event));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_task_send(task1, &event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(void)isc_task_purge(task3, NULL, 0, 0);
|
|
|
|
|
|
|
|
|
|
isc_task_detach(&task1);
|
|
|
|
|
isc_task_detach(&task2);
|
|
|
|
|
isc_task_detach(&task3);
|
|
|
|
|
isc_task_detach(&task4);
|
|
|
|
|
|
|
|
|
|
sleep(10);
|
2022-04-01 18:42:20 -04:00
|
|
|
isc_timer_destroy(&ti1);
|
|
|
|
|
isc_timer_destroy(&ti2);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Exclusive mode test:
|
|
|
|
|
* When one task enters exclusive mode, all other active
|
|
|
|
|
* tasks complete first.
|
|
|
|
|
*/
|
2018-10-24 16:12:55 -04:00
|
|
|
static int
|
2020-02-13 17:44:37 -05:00
|
|
|
spin(int n) {
|
2018-02-28 02:01:14 -05:00
|
|
|
int i;
|
|
|
|
|
int r = 0;
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
|
r += i;
|
2018-10-24 16:12:55 -04:00
|
|
|
if (r > 1000000) {
|
2018-02-28 02:01:14 -05:00
|
|
|
r = 0;
|
2018-10-24 16:12:55 -04:00
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
return (r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
exclusive_cb(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
int taskno = *(int *)(event->ev_arg);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# task enter %d\n", taskno);
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/* task chosen from the middle of the range */
|
|
|
|
|
if (taskno == 6) {
|
|
|
|
|
isc_result_t result;
|
2020-02-13 17:44:37 -05:00
|
|
|
int i;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_beginexclusive(task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(active[i], 0);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isc_task_endexclusive(task);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&done, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
} else {
|
|
|
|
|
active[taskno]++;
|
2020-02-12 07:59:18 -05:00
|
|
|
(void)spin(10000000);
|
2018-02-28 02:01:14 -05:00
|
|
|
active[taskno]--;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# task exit %d\n", taskno);
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
if (atomic_load(&done)) {
|
2020-02-12 07:59:18 -05:00
|
|
|
isc_mem_put(event->ev_destroy_arg, event->ev_arg, sizeof(int));
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_event_free(&event);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
atomic_fetch_sub(&counter, 1);
|
2018-02-28 02:01:14 -05:00
|
|
|
} else {
|
|
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(task_exclusive) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_task_t *tasks[10];
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_result_t result;
|
2020-02-13 17:44:37 -05:00
|
|
|
int i;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
atomic_init(&counter, 0);
|
|
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
|
isc_event_t *event = NULL;
|
2020-02-13 17:44:37 -05:00
|
|
|
int *v;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
tasks[i] = NULL;
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (i == 6) {
|
2021-05-06 10:11:43 -04:00
|
|
|
/* task chosen from the middle of the range */
|
|
|
|
|
result = isc_task_create_bound(taskmgr, 0, &tasks[i],
|
|
|
|
|
0);
|
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
isc_taskmgr_setexcltask(taskmgr, tasks[6]);
|
2021-05-06 10:11:43 -04:00
|
|
|
} else {
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &tasks[i]);
|
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-10-24 16:12:55 -04:00
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
v = isc_mem_get(mctx, sizeof *v);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(v);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
*v = i;
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, NULL, 1, exclusive_cb, v,
|
2020-02-12 07:59:18 -05:00
|
|
|
sizeof(*event));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_task_send(tasks[i], &event);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
atomic_fetch_add(&counter, 1);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
|
isc_task_detach(&tasks[i]);
|
|
|
|
|
}
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
|
|
|
|
|
while (atomic_load(&counter) > 0) {
|
2022-05-03 05:37:31 -04:00
|
|
|
uv_sleep(1);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 05:31:19 -04:00
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Max tasks test:
|
|
|
|
|
* The task system can create and execute many tasks. Tests with 10000.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
maxtask_shutdown(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
if (event->ev_arg != NULL) {
|
2020-02-12 07:59:18 -05:00
|
|
|
isc_task_destroy((isc_task_t **)&event->ev_arg);
|
2018-02-28 02:01:14 -05:00
|
|
|
} else {
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&done, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
SIGNAL(&cv);
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
}
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
maxtask_cb(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
|
|
if (event->ev_arg != NULL) {
|
|
|
|
|
isc_task_t *newtask = NULL;
|
|
|
|
|
|
2020-02-12 07:59:18 -05:00
|
|
|
event->ev_arg = (void *)(((uintptr_t)event->ev_arg) - 1);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create a new task and forward the message.
|
|
|
|
|
*/
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &newtask);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_onshutdown(newtask, maxtask_shutdown,
|
2018-10-24 16:12:55 -04:00
|
|
|
(void *)task);
|
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_task_send(newtask, &event);
|
|
|
|
|
} else if (task != NULL) {
|
|
|
|
|
isc_task_destroy(&task);
|
2018-10-24 16:12:55 -04:00
|
|
|
isc_event_free(&event);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(manytasks) {
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_event_t *event = NULL;
|
2020-02-13 17:44:37 -05:00
|
|
|
uintptr_t ntasks = 10000;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# Testing with %lu tasks\n",
|
|
|
|
|
(unsigned long)ntasks);
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&done, false);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
event = isc_event_allocate(mctx, (void *)1, 1, maxtask_cb,
|
|
|
|
|
(void *)ntasks, sizeof(*event));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
LOCK(&lock);
|
|
|
|
|
maxtask_cb(NULL, event);
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&done)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
WAIT(&cv, &lock);
|
|
|
|
|
}
|
2019-07-04 08:15:39 -04:00
|
|
|
UNLOCK(&lock);
|
2018-10-24 16:12:55 -04:00
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Shutdown test:
|
|
|
|
|
* When isc_task_shutdown() is called, shutdown events are posted
|
|
|
|
|
* in LIFO order.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-13 17:44:37 -05:00
|
|
|
static int nevents = 0;
|
|
|
|
|
static int nsdevents = 0;
|
|
|
|
|
static int senders[4];
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_bool ready, all_done;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
sd_sde1(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(nevents, 256);
|
|
|
|
|
assert_int_equal(nsdevents, 1);
|
2018-02-28 02:01:14 -05:00
|
|
|
++nsdevents;
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# shutdown 1\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
2018-10-24 16:12:55 -04:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&all_done, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
sd_sde2(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(nevents, 256);
|
|
|
|
|
assert_int_equal(nsdevents, 0);
|
2018-02-28 02:01:14 -05:00
|
|
|
++nsdevents;
|
2018-10-24 16:12:55 -04:00
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# shutdown 2\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
sd_event1(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
LOCK(&lock);
|
2019-07-12 10:44:51 -04:00
|
|
|
while (!atomic_load(&ready)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
WAIT(&cv, &lock);
|
|
|
|
|
}
|
2018-10-24 16:12:55 -04:00
|
|
|
UNLOCK(&lock);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# event 1\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
sd_event2(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
++nevents;
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# event 2\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(task_shutdown) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_result_t result;
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_eventtype_t event_type;
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_event_t *event = NULL;
|
|
|
|
|
isc_task_t *task = NULL;
|
|
|
|
|
int i;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
nevents = nsdevents = 0;
|
2018-02-28 02:01:14 -05:00
|
|
|
event_type = 3;
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_init(&ready, false);
|
|
|
|
|
atomic_init(&all_done, false);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
LOCK(&lock);
|
|
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This event causes the task to wait on cv.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, &senders[1], event_type, sd_event1,
|
|
|
|
|
NULL, sizeof(*event));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now we fill up the task's event queue with some events.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < 256; ++i) {
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, &senders[1], event_type,
|
2018-02-28 02:01:14 -05:00
|
|
|
sd_event2, NULL, sizeof(*event));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now we register two shutdown events.
|
|
|
|
|
*/
|
|
|
|
|
result = isc_task_onshutdown(task, sd_sde1, NULL);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_onshutdown(task, sd_sde2, NULL);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
isc_task_shutdown(task);
|
2018-10-24 16:12:55 -04:00
|
|
|
isc_task_detach(&task);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now we free the task by signaling cv.
|
|
|
|
|
*/
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_store(&ready, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
SIGNAL(&cv);
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&all_done)) {
|
2018-10-24 16:12:55 -04:00
|
|
|
isc_test_nap(1000);
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(nsdevents, 2);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Post-shutdown test:
|
|
|
|
|
* After isc_task_shutdown() has been called, any call to
|
|
|
|
|
* isc_task_onshutdown() will return ISC_R_SHUTTINGDOWN.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
psd_event1(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
LOCK(&lock);
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&done)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
WAIT(&cv, &lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
psd_sde(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(post_shutdown) {
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_result_t result;
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_eventtype_t event_type;
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_event_t *event;
|
|
|
|
|
isc_task_t *task;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&done, false);
|
2018-02-28 02:01:14 -05:00
|
|
|
event_type = 4;
|
|
|
|
|
|
2018-11-15 11:20:36 -05:00
|
|
|
isc_condition_init(&cv);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
LOCK(&lock);
|
|
|
|
|
|
|
|
|
|
task = NULL;
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This event causes the task to wait on cv.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, &senders[1], event_type, psd_event1,
|
|
|
|
|
NULL, sizeof(*event));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
|
|
|
|
|
isc_task_shutdown(task);
|
|
|
|
|
|
|
|
|
|
result = isc_task_onshutdown(task, psd_sde, NULL);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SHUTTINGDOWN);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Release the task.
|
|
|
|
|
*/
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&done, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
SIGNAL(&cv);
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_task_detach(&task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Helper for the purge tests below:
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-12 07:59:18 -05:00
|
|
|
#define SENDERCNT 3
|
2020-02-13 17:44:37 -05:00
|
|
|
#define TYPECNT 4
|
|
|
|
|
#define TAGCNT 5
|
|
|
|
|
#define NEVENTS (SENDERCNT * TYPECNT * TAGCNT)
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2020-02-13 17:44:37 -05:00
|
|
|
static bool testrange;
|
|
|
|
|
static void *purge_sender;
|
2018-02-28 02:01:14 -05:00
|
|
|
static isc_eventtype_t purge_type_first;
|
|
|
|
|
static isc_eventtype_t purge_type_last;
|
2020-02-13 17:44:37 -05:00
|
|
|
static void *purge_tag;
|
|
|
|
|
static int eventcnt;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2019-07-12 10:44:51 -04:00
|
|
|
atomic_bool started;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
pg_event1(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&started)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
WAIT(&cv, &lock);
|
|
|
|
|
}
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
pg_event2(isc_task_t *task, isc_event_t *event) {
|
2018-04-17 11:29:14 -04:00
|
|
|
bool sender_match = false;
|
|
|
|
|
bool type_match = false;
|
|
|
|
|
bool tag_match = false;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
if ((purge_sender == NULL) || (purge_sender == event->ev_sender)) {
|
2018-04-17 11:29:14 -04:00
|
|
|
sender_match = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (testrange) {
|
|
|
|
|
if ((purge_type_first <= event->ev_type) &&
|
2022-11-29 03:14:07 -05:00
|
|
|
(event->ev_type <= purge_type_last))
|
|
|
|
|
{
|
2018-04-17 11:29:14 -04:00
|
|
|
type_match = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (purge_type_first == event->ev_type) {
|
2018-04-17 11:29:14 -04:00
|
|
|
type_match = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((purge_tag == NULL) || (purge_tag == event->ev_tag)) {
|
2018-04-17 11:29:14 -04:00
|
|
|
tag_match = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sender_match && type_match && tag_match) {
|
2018-10-11 05:57:57 -04:00
|
|
|
if ((event->ev_attributes & ISC_EVENTATTR_NOPURGE) != 0) {
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# event %p,%d,%p "
|
|
|
|
|
"matched but was not "
|
|
|
|
|
"purgeable\n",
|
|
|
|
|
event->ev_sender,
|
|
|
|
|
(int)event->ev_type,
|
|
|
|
|
event->ev_tag);
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
++eventcnt;
|
2018-10-24 16:12:55 -04:00
|
|
|
} else if (verbose) {
|
|
|
|
|
print_message("# event %p,%d,%p not purged\n",
|
|
|
|
|
event->ev_sender, (int)event->ev_type,
|
|
|
|
|
event->ev_tag);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
++eventcnt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
pg_sde(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&done, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
SIGNAL(&cv);
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
test_purge(int sender, int type, int tag, int exp_purged) {
|
|
|
|
|
isc_result_t result;
|
|
|
|
|
isc_task_t *task = NULL;
|
|
|
|
|
isc_event_t *eventtab[NEVENTS];
|
|
|
|
|
isc_event_t *event = NULL;
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_interval_t interval;
|
2020-02-13 17:44:37 -05:00
|
|
|
isc_time_t now;
|
|
|
|
|
int sender_cnt, type_cnt, tag_cnt, event_cnt, i;
|
|
|
|
|
int purged = 0;
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&started, false);
|
|
|
|
|
atomic_init(&done, false);
|
2018-02-28 02:01:14 -05:00
|
|
|
eventcnt = 0;
|
|
|
|
|
|
2018-11-15 11:20:36 -05:00
|
|
|
isc_condition_init(&cv);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_onshutdown(task, pg_sde, NULL);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Block the task on cv.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event = isc_event_allocate(mctx, (void *)1, 9999, pg_event1, NULL,
|
2020-02-12 07:59:18 -05:00
|
|
|
sizeof(*event));
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event);
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_task_send(task, &event);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Fill the task's queue with some messages with varying
|
|
|
|
|
* sender, type, tag, and purgeable attribute values.
|
|
|
|
|
*/
|
|
|
|
|
event_cnt = 0;
|
|
|
|
|
for (sender_cnt = 0; sender_cnt < SENDERCNT; ++sender_cnt) {
|
|
|
|
|
for (type_cnt = 0; type_cnt < TYPECNT; ++type_cnt) {
|
|
|
|
|
for (tag_cnt = 0; tag_cnt < TAGCNT; ++tag_cnt) {
|
2020-02-12 07:59:18 -05:00
|
|
|
eventtab[event_cnt] = isc_event_allocate(
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
mctx, &senders[sender + sender_cnt],
|
2020-02-12 07:59:18 -05:00
|
|
|
(isc_eventtype_t)(type + type_cnt),
|
|
|
|
|
pg_event2, NULL, sizeof(*event));
|
2018-02-28 02:01:14 -05:00
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(eventtab[event_cnt]);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
eventtab[event_cnt]->ev_tag =
|
|
|
|
|
(void *)((uintptr_t)tag + tag_cnt);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Mark events as non-purgeable if
|
|
|
|
|
* sender, type and tag are all
|
|
|
|
|
* odd-numbered. (There should be 4
|
|
|
|
|
* of these out of 60 events total.)
|
|
|
|
|
*/
|
|
|
|
|
if (((sender_cnt % 2) != 0) &&
|
|
|
|
|
((type_cnt % 2) != 0) &&
|
2022-11-29 03:14:07 -05:00
|
|
|
((tag_cnt % 2) != 0))
|
|
|
|
|
{
|
2018-02-28 02:01:14 -05:00
|
|
|
eventtab[event_cnt]->ev_attributes |=
|
|
|
|
|
ISC_EVENTATTR_NOPURGE;
|
|
|
|
|
}
|
|
|
|
|
++event_cnt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < event_cnt; ++i) {
|
|
|
|
|
isc_task_send(task, &eventtab[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (testrange) {
|
|
|
|
|
/*
|
|
|
|
|
* We're testing isc_task_purgerange.
|
|
|
|
|
*/
|
2020-02-12 07:59:18 -05:00
|
|
|
purged = isc_task_purgerange(
|
|
|
|
|
task, purge_sender, (isc_eventtype_t)purge_type_first,
|
|
|
|
|
(isc_eventtype_t)purge_type_last, purge_tag);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(purged, exp_purged);
|
2018-02-28 02:01:14 -05:00
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* We're testing isc_task_purge.
|
|
|
|
|
*/
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
2020-02-12 07:59:18 -05:00
|
|
|
print_message("# purge events %p,%u,%p\n", purge_sender,
|
|
|
|
|
purge_type_first, purge_tag);
|
2018-10-24 16:12:55 -04:00
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purged = isc_task_purge(task, purge_sender,
|
|
|
|
|
(isc_eventtype_t)purge_type_first,
|
|
|
|
|
purge_tag);
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
2020-02-12 07:59:18 -05:00
|
|
|
print_message("# purged %d expected %d\n", purged,
|
|
|
|
|
exp_purged);
|
2018-10-24 16:12:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert_int_equal(purged, exp_purged);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Unblock the task, allowing event processing.
|
|
|
|
|
*/
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&started, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
SIGNAL(&cv);
|
|
|
|
|
|
|
|
|
|
isc_task_shutdown(task);
|
|
|
|
|
|
|
|
|
|
isc_interval_set(&interval, 5, 0);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Wait for shutdown processing to complete.
|
|
|
|
|
*/
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&done)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_time_nowplusinterval(&now, &interval);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
WAITUNTIL(&cv, &lock, &now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_task_detach(&task);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(eventcnt, event_cnt - exp_purged);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Purge test:
|
|
|
|
|
* A call to isc_task_purge(task, sender, type, tag) purges all events of
|
|
|
|
|
* type 'type' and with tag 'tag' not marked as unpurgeable from sender
|
|
|
|
|
* from the task's " queue and returns the number of events purged.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(purge) {
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
/* Try purging on a specific sender. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 2,4,8 expecting 1\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = &senders[2];
|
|
|
|
|
purge_type_first = 4;
|
|
|
|
|
purge_type_last = 4;
|
|
|
|
|
purge_tag = (void *)8;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = false;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 1);
|
|
|
|
|
|
|
|
|
|
/* Try purging on all senders. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 0,4,8 expecting 3\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = NULL;
|
|
|
|
|
purge_type_first = 4;
|
|
|
|
|
purge_type_last = 4;
|
|
|
|
|
purge_tag = (void *)8;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = false;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 3);
|
|
|
|
|
|
|
|
|
|
/* Try purging on all senders, specified type, all tags. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 0,4,0 expecting 15\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = NULL;
|
|
|
|
|
purge_type_first = 4;
|
|
|
|
|
purge_type_last = 4;
|
|
|
|
|
purge_tag = NULL;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = false;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 15);
|
|
|
|
|
|
|
|
|
|
/* Try purging on a specified tag, no such type. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 0,99,8 expecting 0\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = NULL;
|
|
|
|
|
purge_type_first = 99;
|
|
|
|
|
purge_type_last = 99;
|
|
|
|
|
purge_tag = (void *)8;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = false;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 0);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
/* Try purging on specified sender, type, all tags. */
|
|
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 3,5,0 expecting 5\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = &senders[3];
|
|
|
|
|
purge_type_first = 5;
|
|
|
|
|
purge_type_last = 5;
|
|
|
|
|
purge_tag = NULL;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = false;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Purge range test:
|
|
|
|
|
* A call to isc_event_purgerange(task, sender, first, last, tag) purges
|
|
|
|
|
* all events not marked unpurgeable from sender 'sender' and of type within
|
|
|
|
|
* the range 'first' to 'last' inclusive from the task's event queue and
|
|
|
|
|
* returns the number of tasks purged.
|
|
|
|
|
*/
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(purgerange) {
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
2018-02-28 02:01:14 -05:00
|
|
|
/* Now let's try some ranges. */
|
2018-10-24 16:12:55 -04:00
|
|
|
/* testing purgerange on 2,4-5,8 expecting 1 */
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = &senders[2];
|
|
|
|
|
purge_type_first = 4;
|
|
|
|
|
purge_type_last = 5;
|
|
|
|
|
purge_tag = (void *)8;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 1);
|
|
|
|
|
|
|
|
|
|
/* Try purging on all senders. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 0,4-5,8 expecting 5\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = NULL;
|
|
|
|
|
purge_type_first = 4;
|
|
|
|
|
purge_type_last = 5;
|
|
|
|
|
purge_tag = (void *)8;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 5);
|
|
|
|
|
|
|
|
|
|
/* Try purging on all senders, specified type, all tags. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 0,5-6,0 expecting 28\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = NULL;
|
|
|
|
|
purge_type_first = 5;
|
|
|
|
|
purge_type_last = 6;
|
|
|
|
|
purge_tag = NULL;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 28);
|
|
|
|
|
|
|
|
|
|
/* Try purging on a specified tag, no such type. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 0,99-101,8 expecting 0\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = NULL;
|
|
|
|
|
purge_type_first = 99;
|
|
|
|
|
purge_type_last = 101;
|
|
|
|
|
purge_tag = (void *)8;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 0);
|
|
|
|
|
|
|
|
|
|
/* Try purging on specified sender, type, all tags. */
|
2018-10-24 16:12:55 -04:00
|
|
|
if (verbose) {
|
|
|
|
|
print_message("# testing purge on 3,5-6,0 expecting 10\n");
|
|
|
|
|
}
|
2018-02-28 02:01:14 -05:00
|
|
|
purge_sender = &senders[3];
|
|
|
|
|
purge_type_first = 5;
|
|
|
|
|
purge_type_last = 6;
|
|
|
|
|
purge_tag = NULL;
|
2018-04-17 11:29:14 -04:00
|
|
|
testrange = true;
|
2018-02-28 02:01:14 -05:00
|
|
|
test_purge(1, 4, 7, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Helpers for purge event tests
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
pge_event1(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&started)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
WAIT(&cv, &lock);
|
|
|
|
|
}
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
pge_event2(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
++eventcnt;
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
pge_sde(isc_task_t *task, isc_event_t *event) {
|
2018-02-28 02:01:14 -05:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&done, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
SIGNAL(&cv);
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-13 17:44:37 -05:00
|
|
|
try_purgeevent(bool purgeable) {
|
|
|
|
|
isc_result_t result;
|
|
|
|
|
isc_task_t *task = NULL;
|
|
|
|
|
bool purged;
|
|
|
|
|
isc_event_t *event1 = NULL;
|
|
|
|
|
isc_event_t *event2 = NULL;
|
|
|
|
|
isc_event_t *event2_clone = NULL;
|
|
|
|
|
isc_time_t now;
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_interval_t interval;
|
|
|
|
|
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_init(&started, false);
|
|
|
|
|
atomic_init(&done, false);
|
2018-02-28 02:01:14 -05:00
|
|
|
eventcnt = 0;
|
|
|
|
|
|
2018-11-15 11:20:36 -05:00
|
|
|
isc_condition_init(&cv);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_create(taskmgr, 0, &task);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
result = isc_task_onshutdown(task, pge_sde, NULL);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Block the task on cv.
|
|
|
|
|
*/
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event1 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
|
2018-02-28 02:01:14 -05:00
|
|
|
pge_event1, NULL, sizeof(*event1));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event1);
|
2018-02-28 02:01:14 -05:00
|
|
|
isc_task_send(task, &event1);
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
event2 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
|
2018-02-28 02:01:14 -05:00
|
|
|
pge_event2, NULL, sizeof(*event2));
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_non_null(event2);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
event2_clone = event2;
|
|
|
|
|
|
|
|
|
|
if (purgeable) {
|
|
|
|
|
event2->ev_attributes &= ~ISC_EVENTATTR_NOPURGE;
|
|
|
|
|
} else {
|
|
|
|
|
event2->ev_attributes |= ISC_EVENTATTR_NOPURGE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isc_task_send(task, &event2);
|
|
|
|
|
|
|
|
|
|
purged = isc_task_purgeevent(task, event2_clone);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(purgeable, purged);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Unblock the task, allowing event processing.
|
|
|
|
|
*/
|
|
|
|
|
LOCK(&lock);
|
2019-07-04 08:15:39 -04:00
|
|
|
atomic_store(&started, true);
|
2018-02-28 02:01:14 -05:00
|
|
|
SIGNAL(&cv);
|
|
|
|
|
|
|
|
|
|
isc_task_shutdown(task);
|
|
|
|
|
|
|
|
|
|
isc_interval_set(&interval, 5, 0);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Wait for shutdown processing to complete.
|
|
|
|
|
*/
|
2019-07-04 08:15:39 -04:00
|
|
|
while (!atomic_load(&done)) {
|
2018-02-28 02:01:14 -05:00
|
|
|
result = isc_time_nowplusinterval(&now, &interval);
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-02-28 02:01:14 -05:00
|
|
|
|
|
|
|
|
WAITUNTIL(&cv, &lock, &now);
|
|
|
|
|
}
|
|
|
|
|
UNLOCK(&lock);
|
|
|
|
|
|
|
|
|
|
isc_task_detach(&task);
|
|
|
|
|
|
2018-10-24 16:12:55 -04:00
|
|
|
assert_int_equal(eventcnt, (purgeable ? 0 : 1));
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Purge event test:
|
|
|
|
|
* When the event is marked as purgeable, a call to
|
|
|
|
|
* isc_task_purgeevent(task, event) purges the event 'event' from the
|
2018-04-17 11:29:14 -04:00
|
|
|
* task's queue and returns true.
|
2018-02-28 02:01:14 -05:00
|
|
|
*/
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_RUN_TEST_IMPL(purgeevent) {
|
2018-10-24 16:12:55 -04:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
2018-04-17 11:29:14 -04:00
|
|
|
try_purgeevent(true);
|
2018-02-28 02:01:14 -05:00
|
|
|
}
|
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_LIST_START
|
2018-10-24 16:12:55 -04:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_ENTRY_CUSTOM(manytasks, _setup4, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(all_events, _setup, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(basic, _setup2, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(create_task, _setup, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(post_shutdown, _setup2, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(privilege_drop, _setup, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(privileged_events, _setup, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(purge, _setup2, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(purgeevent, _setup2, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(task_shutdown, _setup4, _teardown)
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(task_exclusive, _setup4, _teardown)
|
2018-10-24 16:12:55 -04:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_LIST_END
|
2018-10-24 16:12:55 -04:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
(cherry picked from commit 63fe9312ff8f54bc79e399bdbd5aaa15cd3e5459)
2022-05-02 04:56:42 -04:00
|
|
|
ISC_TEST_MAIN
|