Commit Graph

39122 Commits

Author SHA1 Message Date
Tom Krizek
8a406b73c9 Ignore tempdirs during pytest collection phase 2023-05-22 14:11:38 +02:00
Tom Krizek
527ac6ad26 Ensure compatiblity with older pytest
Special care needs to be taken to support older pytest / xdist versions.
The target versions are what is available in EL8, since that seems to
have the oldest versions that can be reasonably supported.
2023-05-22 14:11:38 +02:00
Tom Krizek
247e90c382 Keep the tempdir in case test setup/teardown fails
When an issue occurs inside a fixture (e.g. servers fail to start/stop),
the test result won't be detected as failed, but rather an error will be
thrown.

To ensure the tempdir is kept even if the test itself passes but the
system_test() fixture throws an error, a different mechanism is needed.
At the start of the critical test setup section, note that the fixture
hasn't finished yet. When this is detected in the system_test_dir()
fixture, it is recognized as error in test setup/teardown and the temp
directory is kept.

This may seem cumbersome, because it is. It's basically a workaround for
the way pytest handles fixtures and test errors in general.
2023-05-22 14:11:38 +02:00
Tom Krizek
2d93ed8546 Ensure tempdir is kept for failed system tests
The temporary directory contains artifacts for the pytest module. That
module may contain multiple individual tests which were executed
sequentially. The artifacts should be kept if even one of these tests
failed.

Since pytest doesn't have any facility to expose test results to
fixtures, customize the pytest_runtest_makereport() hook to enable that.
It stores the test results into a session scope variable which is
available in all fixtures.

When deciding whether to remove the temporary directory, find the
relevant test results for this module and don't remove the tmpdir if any
one the tests failed.
2023-05-22 14:11:38 +02:00
Tom Krizek
8b1a906b39 Add --noclean option to pytest runner
Support the --noclean option to allow the user to keep the artifacts
from any test run.
2023-05-22 14:11:38 +02:00
Tom Krizek
c571af8c8f Run system tests inside temporary directories
For every pytest module, create a copy of its system test directory and
run the test from that directory. This makes it easier to clean up
afterwards and makes it less error-prone when re-running (failed) tests.

Configure the logger to capture the module's log output into a separate
file available from the temporary directory. This is quite convenient
for exploring failures.

Cases where temporary directory should be kept are handled in a
follow-up commits.
2023-05-22 14:11:38 +02:00
Tom Krizek
2b64618624 Execute the system test workflow in pytest runner
This is basically the pytest re-implementation of the run.sh script.

The fixture is applied to every module and ensures complete test
setup/teardown, such as starting/stopping servers, detecting coredumps
etc.

Note that the fixture system_test_dir is not defined yet. It is omitted
now for review readability and it's added in follow-up commits.
2023-05-22 14:11:37 +02:00
Tom Krizek
6886cc1826 Utility fixtures for pytest runner
Add fixtures for deriving system test name from the directory name and
for a module-specific logger.

Add fixtures to execute shell and perl scripts. Similar to how run.sh
calls commands, this functionality is also needed in pytest. The
fixtures take care of switching to a proper directory, logging
everything and handling errors.

Note that the fixture system_test_dir is not defined yet. It is omitted
now for review readability and it's added in follow-up commits.
2023-05-22 14:11:37 +02:00
Tom Krizek
0061758156 Assign unique ports to pytest modules
This is basically a pytest re-implementation of the get_ports.sh script.
The main difference is that ports are assigned on a module basis, rather
than a directory basis. Module is the new atomic unit for parallel
execution, therefore it needs to have unique ports to avoid collisions.

Each module gets its ports through the env fixture which is updated with
ports and other module-specific variables.
2023-05-22 14:11:37 +02:00
Tom Krizek
ee26066897 Ensure system test programs and deps are compiled
Some system tests require extra programs and/or dependencies to be
compiled first. This is done via `make check` with the automake
framework when using check_* variables such as check_PROGRAMS.

To avoid running any tests via the automake framework, set the TESTS
env variable to empty string and utilize `make -e check` to override
default Makefile variables with environment ones. This ensures automake
will only compile the needed dependencies without running any tests.

Additional consideration needs to be taken for xdist. The compilation
command should be called just once before any tests are executed. To
achieve that, use the pytest_configure() hook and check that the
PYTEST_XDIST_WORKER env variable isn't set -- if it is, it indicates
we're in the spawned xdist worker and the compilation was already done
by the main pytest process that spawned the workers.

This is mostly done to have on-par functionality with legacy test
framework. In the future, we should get rid of the need to run "empty"
make -e check and perhaps compile test-stuff by default.
2023-05-22 14:11:37 +02:00
Tom Krizek
2f7af791a1 Obtain env vars from conf.sh in pytest runner
The commands executed by pytest during a system test need to have the
same environment variables set as if they were executed by the run.sh
shell script.

It was decided that for the moment, legacy way of executing system tests
with run.sh should be kept, which complicates things a bit. In order to
avoid duplicating the required variables in both conf.sh and pytest, it
was decided to use the existing conf.sh as the only authoritative
place for the variables.

It is necessary to process the environment variables from conf.sh right
when conftest.py is loaded, since they might be needed right away (e.g.
to test for feature support during test collection).

This solution is a bit hacky and is only meant to be used during the
transitory phase when both pytest and the legacy run.sh are both
supported. In the future, a superior pytest-only solution should be
used.

For discussion of other options, refer to
https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/6809#note_318889
2023-05-22 14:11:37 +02:00
Tom Krizek
08c4e35bc0 Collect existing tests in pytest runner
Ensure pytest picks up our python test modules, since we're using
tests_*.py convention, which is different from the default.

Configure pytest logging to display the output from all tests (even the
ones that passed). This ensures we have sufficient amount of information
to debug test post-mortem just from the artifacts.
2023-05-22 14:11:37 +02:00
Tom Krizek
30cb9b7e28 Support both pytest and legacy system test runner
The legacy system test framework uses pytest to execute some tests.
Since it'd be quite difficult to convince pytest to decide whether to
include conftest.py (or which ones to include when launching from
subdir), it makes more sense to have a shared conftest.py which is used
by both the legacy test runner invocations of pytest and the new pytest
system test runner. It is ugly, but once we drop support for the legacy
runner, we'll get rid of it.

Properly scope the *port fixtures in order to ensure they'll work as
expected with the new pytest runner. Instead of using "session" (which
means the fixture is only evaluated once for the entire execution of
pytest), use "module" scope, which is evaluated separately for each
module. The legacy runner invoked pytest for each system test
separately, while the new pytest runner is invoked once for all system
tests -- therefore it requires the more fine-grained "module" scope to
for the fixtures to work properly.

Remove python shebang, as conftest.py isn't supposed to be an executable
script.
2023-05-22 14:11:35 +02:00
Tony Finch
845fa7a849 Merge branch '4070-tsan-qpmulti-destroy' into 'main'
Acquire qpmulti->mutex during destruction

Closes #4070 and #4073

See merge request isc-projects/bind9!7938
2023-05-20 07:27:44 +00:00
Tony Finch
b754c6628f Acquire qpmulti->mutex during destruction
Thread sanitizer warns that parts of the qp-trie are accessed
both with and without the mutex; the unlocked accesses happen during
destruction, so they should be benign, but there's no harm locking
anyway to convince tsan it is clean.

Also, ensure .tsan-suppress and .tsan-suppress-extra are in sync.
2023-05-20 07:26:21 +00:00
Michal Nowak
4203e1643a Merge branch 'mnowak/danger-test-pairwise-hint' into 'main'
Add a friendly Danger plea to run the pairwise CI job

See merge request isc-projects/bind9!7876
2023-05-19 12:31:28 +00:00
Michal Nowak
96563c6020 Add a friendly Danger plea to run the pairwise CI job
Sometimes a pairwise definition for a new ./configure switch is added
but not tested in the CI.
2023-05-19 14:11:54 +02:00
Michal Nowak
07d2684af8 Merge branch 'mnowak/fedora-38' into 'main'
Add Fedora 38

See merge request isc-projects/bind9!7936
2023-05-19 11:53:40 +00:00
Michal Nowak
2e0550970b Add Fedora 38 2023-05-19 13:47:53 +02:00
Michal Nowak
55cec5d45d Merge branch '4077-add-RUNTIME_CHECK-around-wrap' into 'main'
Ensure "wrap" variable is non-NULL

Closes #4077

See merge request isc-projects/bind9!7948
2023-05-19 09:07:18 +00:00
Michal Nowak
1fe5c008d6 Ensure "wrap" variable is non-NULL
RUNTIME_CHECK on the "wrap" variable avoids possible NULL dereference:

    thread.c: In function 'thread_wrap':
    thread.c:60:15: error: dereference of possibly-NULL 'wrap' [CWE-690] [-Werror=analyzer-possible-null-dereference]
       60 |         *wrap = (struct thread_wrap){

The RUNTIME_CHECK was there before
7d1ceaf35d.
2023-05-19 11:02:59 +02:00
Michal Nowak
896cf6364a Merge branch 'mnowak/get_core_dumps-fix-misplaced-tsan-line' into 'main'
TSAN summarising line was misplaced in get_core_dumps.sh

See merge request isc-projects/bind9!7870
2023-05-19 07:18:11 +00:00
Michal Nowak
0c4c7ddec4 TSAN summarising line was misplaced in get_core_dumps.sh
The line summarising TSAN reports was misplaced in the ASAN territory
and thus never used.

I also made core dumps, assertion failures, and TSAN reports detection
independent of each other.
2023-05-19 08:57:36 +02:00
Michał Kępień
59ea45fc48 Merge branch 'michal/cmocka-future-proofing' into 'main'
cmocka future-proofing

See merge request isc-projects/bind9!7939
2023-05-18 13:30:48 +00:00
Michał Kępień
6029010dd2 Remove <isc/cmocka.h>
The last use of the cmocka_add_test_byname() helper macro was removed in
commit 63fe9312ff.  Remove the
<isc/cmocka.h> header that defines it.
2023-05-18 15:12:23 +02:00
Michał Kępień
8d36e68c7a Fix cmocka-related compiler warnings in ht_test
tests/isc/ht_test.c triggers the following compiler warnings when built
against development versions of cmocka:

    In file included from ht_test.c:24:
    ht_test.c: In function ‘test_ht_full’:
    ht_test.c:68:45: warning: passing argument 2 of ‘_assert_ptr_equal’ makes pointer from integer without a cast [-Wint-conversion]
       68 |                 assert_ptr_equal((void *)i, (uintptr_t)f);
    /usr/include/cmocka.h:1513:56: note: in definition of macro ‘assert_ptr_equal’
     1513 | #define assert_ptr_equal(a, b) _assert_ptr_equal((a), (b), __FILE__, __LINE__)
          |                                                        ^
    /usr/include/cmocka.h:2907:36: note: expected ‘const void *’ but argument is of type ‘long unsigned int’
     2907 |                        const void *b,
          |                        ~~~~~~~~~~~~^
    ht_test.c:163:45: warning: passing argument 2 of ‘_assert_ptr_equal’ makes pointer from integer without a cast [-Wint-conversion]
      163 |                 assert_ptr_equal((void *)i, (uintptr_t)f);
    /usr/include/cmocka.h:1513:56: note: in definition of macro ‘assert_ptr_equal’
     1513 | #define assert_ptr_equal(a, b) _assert_ptr_equal((a), (b), __FILE__, __LINE__)
          |                                                        ^
    /usr/include/cmocka.h:2907:36: note: expected ‘const void *’ but argument is of type ‘long unsigned int’
     2907 |                        const void *b,
          |                        ~~~~~~~~~~~~^

These are caused by a change to the definitions of pointer assert
functions in cmocka's development branch [1].  Fix by casting the
affected variables to (void *) instead of (uintptr_t).

[1] https://git.cryptomilk.org/projects/cmocka.git/commit/?id=09621179af67535788a67957a910d9f17c975b45
2023-05-18 15:12:23 +02:00
Michał Kępień
c2dcd055fe Include <inttypes.h> whenever including <cmocka.h>
Development versions of cmocka require the intmax_t and uintmax_t types
to be defined by the time the test code includes the <cmocka.h> header.
These types are defined in the <stdint.h> header, which is included by
the <inttypes.h> header, which in turn is already explicitly included by
some of the programs in the tests/ directory.  Ensure all programs in
that directory that include the <cmocka.h> header also include the
<inttypes.h> header to future-proof the code while keeping the change
set minimal and the resulting code consistent.  Also prevent explicitly
including the <stdint.h> header in those programs as it is included by
the <inttypes.h> header.
2023-05-18 15:12:23 +02:00
Michał Kępień
ddbbb8612d Merge tag 'v9.19.13'
BIND 9.19.13
2023-05-18 14:06:04 +02:00
Mark Andrews
1845e8bff3 Merge branch '4022-three-dnssec-failures-on-fedora-38' into 'main'
Resolve "Three "dnssec" failures on Fedora 38"

Closes #4022

See merge request isc-projects/bind9!7932
2023-05-18 00:42:17 +00:00
Mark Andrews
d360d8af8f Let RSASHA1 signing keys be ignored in FIPS mode
When the FIPS provider is available, RSASHA1 signing keys for zone
"example.com." are ignored if the zone is attempted to be signed with
the dnssec-signzone "-F" (FIPS mode) option:

    "fatal: No signing keys specified or found"
2023-05-17 23:51:39 +00:00
Michał Kępień
35094195cf Merge branch '4071-placeholder' into 'main'
Add placeholder for GL #4071

Closes #4071

See merge request isc-projects/bind9!7941
2023-05-17 14:28:22 +00:00
Michał Kępień
b95f85f4a9 Add placeholder for GL #4071 2023-05-17 16:26:39 +02:00
Tony Finch
55cc071547 Merge branch '4069-upforwd-wait' into 'main'
Fix the `upforwd` system test

Closes #4069

See merge request isc-projects/bind9!7931
2023-05-16 15:29:29 +00:00
Tony Finch
725c2b12e8 CHANGES for [GL #4069]
[test]		Fix the `upforwd` system test to be more reliable,
		especially when using thread sanitizer.
2023-05-16 13:38:05 +01:00
Evan Hunt
6bf35c2f19 Match UQ and UR stats to domain name
The upforwd test for forwarding updates to a dead primary can continue
running a little bit past its end, causing update replies to be
recorded during a subsequent test case. Correct this by only looking
for update requests and replies for the specific domain name being
tested at any given time.
2023-05-16 13:37:07 +01:00
Tony Finch
2e96d225ae Fix the upforwd system test
After the RCU changes were merged, the `upforwd` test started
consistenly failing when run under thread sanitizer. After some
investigation, it turned out that retry attempts were continuing after
the "update forwarding to dead primary" test. This caused mismatches
in the DNSTAP message counts for the subsequent tests, because they
were also counting retries.

Fix this problem by `wait`ing for the `nsupdate` processes to exit.

While investigating the bug, I replaced several fixed 15 second delays
with `wait_for_log`, so the test runs faster.
2023-05-16 13:37:02 +01:00
Mark Andrews
7d3cd47a7a Merge branch '4066-resolv-conf-parsing-eats-lines-if-more-than-3-nameservers-set' into 'main'
Resolve "resolv.conf parsing eats lines if more than 3 nameservers set"

Closes #4066

See merge request isc-projects/bind9!7922
2023-05-16 03:25:34 +00:00
Mark Andrews
36dab033dc Add CHANGES for [GL #4066] 2023-05-16 02:04:55 +00:00
Mark Andrews
864cd08052 Properly process extra nameserver lines in resolv.conf
The whole line needs to be read rather than just the token "nameserver"
otherwise the next line in resolv.conf is not properly processed.
2023-05-16 02:04:55 +00:00
Tony Finch
15eaf9d3f2 Merge branch 'fanf-urcu-qsbr-build' into 'main'
Fixes for liburcu-qsbr

Closes #4067

See merge request isc-projects/bind9!7925
2023-05-15 20:49:47 +00:00
Tony Finch
c319ccd4c9 Fixes for liburcu-qsbr
Move registration and deregistration of the main thread from
`isc_loopmgr_run()` into `isc__initialize()` / `isc__shutdown()`:
liburcu-qsbr fails an assertion if we try to use it from an
unregistered thread, and we need to be able to use it when the
event loops are not running.

Use `rcu_assign_pointer()` and `rcu_dereference()` in qp-trie
transactions so that they properly mark threads as online. The
RCU-protected pointer is no longer declared atomic because
liburcu does not (yet) use standard C atomics.

Fix the definition of `isc_qsbr_rcu_dereference()` to return
the referenced value, and to call the right function inside
liburcu.

Change the thread sanitizer suppressions to match any variant of
`rcu_*_barrier()`
2023-05-15 20:49:42 +00:00
Tony Finch
b4326572dd Merge branch '4068-coverity-uv_async_send' into 'main'
Check the return value from uv_async_send()

Closes #4068

See merge request isc-projects/bind9!7926
2023-05-15 20:49:23 +00:00
Tony Finch
afae41aa40 Check the return value from uv_async_send()
An omission pointed out by the following report from Coverity:

    /lib/isc/loop.c: 483 in isc_loopmgr_pause()
    >>>     CID 455002:  Error handling issues  (CHECKED_RETURN)
    >>>     Calling "uv_async_send" without checking return value (as is done elsewhere 5 out of 6 times).
    483     		uv_async_send(&loop->pause_trigger);
2023-05-15 18:52:04 +01:00
Michal Nowak
e047508cb4 Merge branch 'mnowak/openbsd-7.3' into 'main'
Add OpenBSD 7.3

See merge request isc-projects/bind9!7847
2023-05-15 17:46:44 +00:00
Michal Nowak
ff52cd9604 Add OpenBSD 7.3 2023-05-15 18:55:38 +02:00
Michal Nowak
b59c58702e Merge branch 'mnowak/freebsd-13.2' into 'main'
Add FreeBSD 13.2

See merge request isc-projects/bind9!7846
2023-05-15 16:31:38 +00:00
Michal Nowak
81ad645d7d Add FreeBSD 13.2 2023-05-15 18:31:07 +02:00
Evan Hunt
996819b0a3 Merge branch '4064-read-timeout-failure' into 'main'
allow streamdns read to resume after timeout

Closes #4064

See merge request isc-projects/bind9!7921
2023-05-15 16:25:45 +00:00
Evan Hunt
b4ac7faee9 allow streamdns read to resume after timeout
when reading on a streamdns socket failed due to timeout, but
the dispatch was still waiting for other responses, it would
resume reading by calling isc_nm_read() again. this caused
an assertion because the socket was already reading.

we now check that either the socket is reading, or that it was
already reading on the same handle.
2023-05-13 23:31:45 -07:00
Tony Finch
562697e703 Merge branch 'fanf-urcu-qp' into 'main'
Replace isc_qsbr with liburcu-qsbr

Closes #3936 and #4019

See merge request isc-projects/bind9!7668
2023-05-12 20:43:30 +00:00