Commit Graph

37744 Commits

Author SHA1 Message Date
Tom Krizek
5b5210854d Capture log output during pytest runner setup
Instantiate a new logger that is used during pytest initialization /
configuration. This logging isn't handled by pytest itself, since it
happens outside of any tests or fixtures.

Root logger can't be reused for this purpose, because that would
duplicate the logs. Instead, create a conftest-specific logger for this
purpose.

Unfortunately, this introduces another log file,
pytest.conftest.log.txt, which contains only the logging from pytest
initialization. However, unless one is debugging the runner /
environment, there should be no need to investigate this file.

(cherry picked from commit 12c724ee07)
2023-05-23 17:41:34 +02:00
Tom Krizek
16eeb36432 Execute long running system tests first
In order to take the most advantage of parallel execution of tests,
ensure certain long running tests are scheduled first.

The list of tests considered long-running was created empirically. In
addition to the test run time, its position in the default
(alphabetical) ordering was also taken into account.

(cherry picked from commit 99e2e50c0e)
2023-05-23 17:41:34 +02:00
Tom Krizek
b9596d2107 Disable pylint check for too-few-public-methods
This check is overly aggressive and not really useful, especially for
non-Python codebase, where the primary use of Python is for testing.

(cherry picked from commit 6f134283eb)
2023-05-23 17:41:34 +02:00
Tom Krizek
1acb8a3f39 Add test specific logger for pytests
The logger fixture is provided as a test-level logging facility which
can be easily passed to tests to enable capturing and/or displaying
messages from tests written in Python.

While this works optimally with the pytest runner, messages on INFO
level or above will also be visible when using the legacy runner.

(cherry picked from commit 952776b61f)
2023-05-23 17:41:34 +02:00
Tom Krizek
862f6e043a Mark selected statschannel tests as xfail
The test_zone_timers_secondary_json() and
test_zone_timers_secondary_xml() tests are affected by issue #3983. Due
to the way tests are run, they are only affected when executing them
with the pytest runner.

Strict mode is set for pytest runner, as it always fails there. The
strict mode ensures we'll catch the change when the it starts passing
once the underlying issue is fixed. It can't be set for the legacy
runner, since the test (incorrectly) passes there.

Related #3983

(cherry picked from commit 087a9b3c97)
2023-05-23 17:41:34 +02:00
Tom Krizek
f0db1c27ba Ensure assertions and exceptions end up in system test log
If a test fails with an assertion failure or exception, its content
along with traceback is displayed in pytest output. This information
should be preserved in the test-specific logger for a given system test
to make it easier to debug test failures.

(cherry picked from commit 3a20e8d990)
2023-05-23 17:41:34 +02:00
Petr Špaček
0277c5098c Use raw byte format of env variables in pytest
In order to avoid issues with decoding/encoding env variables due to
different encodings on different systems, deal with the environment
variables directly as bytes.

(cherry picked from commit 37ed9ad2f8)
2023-05-23 17:41:33 +02:00
Tom Krizek
23b2777067 Display pytest failures for system:gcc:tarball
Since the tarball build&tests happen in a subdirectory, ensure the
after_script switches to it, so artifacts can be found properly.

(cherry picked from commit a6559176f1)
2023-05-23 17:41:33 +02:00
Tom Krizek
445b30b883 Handle missing test_results due to pytest runner interrupt
If pytest execution is interrupted, the hook that exposes test_results
to the pytest session is never called so the results can't be
interpreted.

(cherry picked from commit 0a063f51d3)
2023-05-23 17:41:33 +02:00
Tom Krizek
6103ee988e Run system tests sequentially if xdist is not available
(cherry picked from commit 1cc55d01c7)
2023-05-23 17:41:33 +02:00
Petr Špaček
8627d41d4d Include logs from failing tests in JUnit output
(cherry picked from commit 8952618262)
2023-05-23 17:41:33 +02:00
Petr Špaček
a802e84cd5 Enable live logging for non-parallel pytest runs
This provides incremental output when test is running _without xdist_,
just like the old runner did.

With xdist the live output is not available, I believe because of
https://github.com/pytest-dev/pytest-xdist/issues/402
https://github.com/pytest-dev/pytest-xdist/pull/883 might help with
that, but I'm not going to hold my breath until it is available on
distros we use.

(cherry picked from commit d0619c7a18)
2023-05-23 17:41:33 +02:00
Tom Krizek
a388a689cf Ensure --dist=loadscope is used when running pytest in parallel
The loadscope setting is required for parallel execution of our system
tests using pytest. The option ensure that all tests within a single
(module) scope will be assigned to the same worker.

This is neccessary because the worker sets up the nameservers for all
the tests within a module scope. If tests from the same module would be
assigned to different workers, then the setup could happen multiple
times, causing a race condition. This happens because each module uses
deterministic port numbers for the nameservers.

(cherry picked from commit 8f57bce7af)
2023-05-23 17:41:33 +02:00
Tom Krizek
ac1e7eb40d Invoke pytest runner from run.sh
Utilize developers' muscle memory to incentivize using the pytest runner
instead of the legacy one. The script also serves as basic examples of
how to run the pyest command to achieve the same results as the legacy
runner.

Invoking pytest directly should be the end goal, since it offers many
potentially useful options (refer to pytest --help).

(cherry picked from commit 4dbe8e5347)

(also manually added a additional run.sh -> legacy.run.sh renames)
2023-05-23 17:41:33 +02:00
Tom Krizek
75a31555bd Use pytest system test runner in CI
Replace the legacy system test runner by the pytest system test runner.
Since EL7 and OpenBSD have only ancient versions of pytest / xdist, keep
using the legacy test runner there for now.

Out of tree tests aren't supported by the pytest runner yet. Use the
legacy test runner for that purpose as well.

Use awk to display failures and errors at the end of the log for
convenience, since pytest displays them first, which makes them
difficult to find.

(cherry picked from commit 4bc2b3be48)
2023-05-23 17:41:31 +02:00
Tom Krizek
2c167bb35f Add developer docs for pytest system test runner
(cherry picked from commit d1ef51f589)
2023-05-23 16:55:28 +02:00
Tom Krizek
e9c15a5736 Update user docs with pytest system test runner
(cherry picked from commit dc84121004)
2023-05-23 16:55:27 +02:00
Tom Krizek
3b6ca76f46 Add pytest functions for shell system tests
In order to run the shell system tests, the pytest runner has to pick
them up somehow. Adding an extra python file with a single function
for the shell tests for each system test proved to be the most
compatible way of running the shell tests across older pytest/xdist
versions.

Modify the legacy run.sh script to ignore these pytest-runner specific
glue files when executing tests written in pytest.

(cherry picked from commit 2f5bf6d971)

(manually added host/tests_sh_host.py, tkey/tests_sh_tkey.py on top)
2023-05-23 16:55:26 +02:00
Tom Krizek
0df2ea8fab Ignore tempdirs during pytest collection phase
(cherry picked from commit 8a406b73c9)
2023-05-23 16:17:24 +02:00
Tom Krizek
b8d6434d5d 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.

(cherry picked from commit 527ac6ad26)
2023-05-23 16:17:24 +02:00
Tom Krizek
eaf64e93aa 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.

(cherry picked from commit 247e90c382)
2023-05-23 16:17:24 +02:00
Tom Krizek
cdbdbd9eaf 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.

(cherry picked from commit 2d93ed8546)
2023-05-23 16:17:24 +02:00
Tom Krizek
ba922ba774 Add --noclean option to pytest runner
Support the --noclean option to allow the user to keep the artifacts
from any test run.

(cherry picked from commit 8b1a906b39)
2023-05-23 16:17:24 +02:00
Tom Krizek
d1e6400d63 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.

(cherry picked from commit c571af8c8f)
2023-05-23 16:17:24 +02:00
Tom Krizek
0ed639010c 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.

(cherry picked from commit 2b64618624)
2023-05-23 16:17:24 +02:00
Tom Krizek
23cecd2190 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.

(cherry picked from commit 6886cc1826)
2023-05-23 16:17:23 +02:00
Tom Krizek
aa199e2726 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.

(cherry picked from commit 0061758156)
2023-05-23 16:17:23 +02:00
Tom Krizek
f23ce6a37f 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.

(cherry picked from commit ee26066897)
2023-05-23 16:17:23 +02:00
Tom Krizek
6000883f8d 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

(cherry picked from commit 2f7af791a1)
2023-05-23 16:17:23 +02:00
Tom Krizek
495216f81c 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.

(cherry picked from commit 08c4e35bc0)
2023-05-23 16:17:23 +02:00
Tom Krizek
9112b51bb9 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.

(cherry picked from commit 30cb9b7e28)
2023-05-23 16:17:20 +02:00
Michal Nowak
799a6d1941 Merge branch 'mnowak/danger-test-pairwise-hint-9.18' into 'bind-9.18'
[9.18] Add a friendly Danger plea to run the pairwise CI job

See merge request isc-projects/bind9!7953
2023-05-19 12:34:30 +00:00
Michal Nowak
b52d416cb0 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.

(cherry picked from commit 96563c6020)
2023-05-19 14:32:10 +02:00
Michal Nowak
7ade835795 Merge branch 'mnowak/fedora-38-9.18' into 'bind-9.18'
[9.18] Add Fedora 38

See merge request isc-projects/bind9!7951
2023-05-19 12:03:42 +00:00
Michal Nowak
465a797014 Add Fedora 38
(cherry picked from commit 2e0550970b)
2023-05-19 13:56:34 +02:00
Michal Nowak
3007bb18e2 Merge branch 'mnowak/get_core_dumps-fix-misplaced-tsan-line-9.18' into 'bind-9.18'
[9.18] TSAN summarising line was misplaced in get_core_dumps.sh

See merge request isc-projects/bind9!7949
2023-05-19 08:11:32 +00:00
Michal Nowak
1fa70a559c 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.

(cherry picked from commit 0c4c7ddec4)
2023-05-19 09:20:51 +02:00
Michał Kępień
66a8a0de23 Merge branch 'michal/cmocka-future-proofing-9.18' into 'bind-9.18'
[9.18] cmocka future-proofing

See merge request isc-projects/bind9!7947
2023-05-18 13:51:35 +00:00
Michał Kępień
b2b3899af7 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:69:45: warning: passing argument 2 of ‘_assert_ptr_equal’ makes pointer from integer without a cast [-Wint-conversion]
       69 |                 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:164:45: warning: passing argument 2 of ‘_assert_ptr_equal’ makes pointer from integer without a cast [-Wint-conversion]
      164 |                 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

(cherry picked from commit 8d36e68c7a)
2023-05-18 15:36:03 +02:00
Michał Kępień
78afc0bf04 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.

(cherry picked from commit c2dcd055fe)
2023-05-18 15:36:03 +02:00
Michał Kępień
c65a405827 Merge tag 'v9.18.15' into bind-9.18
BIND 9.18.15
2023-05-18 14:10:33 +02:00
Tony Finch
09c5244611 Merge branch 'fanf-noreturn-lossage-bind-9.18' into 'bind-9.18'
[9.18] Avoid lossage from <stdnoreturn.h>

See merge request isc-projects/bind9!7940
2023-05-17 15:23:18 +00:00
Tony Finch
3c1098715e Avoid lossage from <stdnoreturn.h>
A few of the source files in `tests/ns` included `<isc/util.h>`
before `<cmocka.h>`. This could cause compile failures because the
`CMOCKA_NORETURN` macro is defined as `__attribute__((noreturn))`
and `<stdnoreturn.h>` defines `noreturn` as `_Noreturn` which does
not work as a gcc-style attribute.

(cherry picked from commit 623f2fdb18)
2023-05-17 14:21:06 +01:00
Artem Boldariev
1e412d1bf5 Merge branch 'artem-9_18-fix_isc__nm_sockstop' into 'bind-9.18'
Fix isc__nmsocket_stop(): make sockstop netievent as a high priority event (similarly to other transports)

See merge request isc-projects/bind9!7935
2023-05-17 13:18:44 +00:00
Artem Boldariev
d7a60427b9 Update release notes [GL #4071]
Mention that BIND getting stuck during reconfiguration when
DoH-enabled listen statement is removed on re-configuration has been
fixed.
2023-05-17 14:25:31 +03:00
Artem Boldariev
8eeafbc6a7 Update CHANGES [GL #4071]
Mention that BIND getting stuck during reconfiguration when
DoH-enabled listen statement is removed on re-configuration has been
fixed.
2023-05-17 14:25:14 +03:00
Artem Boldariev
9ab6c3a5b1 Make sockstop netievent a high-priority one
Seemingly by omission, sockstop netievent used by multi-layer sockets
was not a high priority event, like it should be (similarly to other
socket types).

In particular, that could make BIND stuck on reconfiguration after a
DoH-listener is removed from the configuration.

This commit fixes that.
2023-05-17 13:06:41 +03:00
Artem Boldariev
18d662f4d2 Pass the right worker into isc__nm_async_sockstop()
The intention behind 'isc__nmsocket_stop()' was that the function
sends notifications on every worker thread, making them synchronise on
the barrier, then the initiating thread waits on it, too. This way we
ensure than no other operation will start when we shutting down the
listener.

However, it seems that due to mistake we have been passing the wrong
worker pointer into isc__nm_async_sockstop() from within the context
of an worker thread which has initiated shutting down. While
effectively we have not been using the pointer in this case, it could
cause maintenance issues later. This commit fixes that.
2023-05-17 12:56:25 +03:00
Mark Andrews
50c30d835c Merge branch '4066-resolv-conf-parsing-eats-lines-if-more-than-3-nameservers-set-bind-9.18' into 'bind-9.18'
[9.18] Resolve "resolv.conf parsing eats lines if more than 3 nameservers set"

See merge request isc-projects/bind9!7933
2023-05-16 04:05:58 +00:00
Mark Andrews
4e9d998180 Add CHANGES for [GL #4066]
(cherry picked from commit 36dab033dc)
2023-05-16 13:30:01 +10:00