Skip to content

Commit 34d1c7c

Browse files
committed
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).
1 parent 1dc4a46 commit 34d1c7c

File tree

8 files changed

+115
-27
lines changed

8 files changed

+115
-27
lines changed

bin/tests/system/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ named.run
1414
/*.log
1515
/*.trs
1616
/resolve
17-
/run.sh
17+
/legacy.run.sh
1818
/run.log
1919
/start.sh
2020
/stop.sh

bin/tests/system/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ LOG_DRIVER_V_1 = --verbose yes
227227
LOG_DRIVER = $(srcdir)/custom-test-driver
228228
AM_LOG_DRIVER_FLAGS = $(LOG_DRIVER_V)
229229

230-
LOG_COMPILER = $(builddir)/run.sh
230+
LOG_COMPILER = $(builddir)/legacy.run.sh
231231
AM_LOG_FLAGS = -r
232232

233-
$(TESTS): run.sh
233+
$(TESTS): legacy.run.sh
234234

235235
test-local: check

bin/tests/system/README

+21-20
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ Running an Individual Test
119119
---
120120
The tests can be run individually using the following command:
121121

122-
sh run.sh [flags] <test-name> [<test-arguments>]
122+
sh legacy.run.sh [flags] <test-name> [<test-arguments>]
123123

124124
e.g.
125125

126-
sh run.sh [flags] notify
126+
sh legacy.run.sh [flags] notify
127127

128128
Optional flags are:
129129

@@ -241,9 +241,9 @@ Re-Running the Tests
241241
---
242242
If there is a requirement to re-run a test (or the entire test suite), the
243243
files produced by the tests should be deleted first. Normally, these files are
244-
deleted if the test succeeds but are retained on error. The run.sh script
245-
automatically calls a given test's clean.sh script before invoking its setup.sh
246-
script.
244+
deleted if the test succeeds but are retained on error. The legacy.run.sh
245+
script automatically calls a given test's clean.sh script before invoking its
246+
setup.sh script.
247247

248248
Deletion of the files produced by the set of tests (e.g. after the execution of
249249
make) can be carried out using the command:
@@ -283,8 +283,8 @@ tests.sh Runs the actual tests. This file is mandatory.
283283

284284
clean.sh Run at the end to clean up temporary files, but only if the test
285285
was completed successfully and its running was not inhibited by the
286-
"-n" switch being passed to "run.sh". Otherwise the temporary
287-
files are left in place for inspection.
286+
"-n" switch being passed to "legacy.run.sh". Otherwise the
287+
temporary files are left in place for inspection.
288288

289289
ns<N> These subdirectories contain test name servers that can be queried
290290
or can interact with each other. The value of N indicates the
@@ -303,8 +303,8 @@ ans<N> Like ns[X], but these are simple mock name servers implemented in
303303
Port Usage
304304
---
305305
In order for the tests to run in parallel, each test requires a unique set of
306-
ports. These are specified by the "-p" option passed to "run.sh", which sets
307-
environment variables that the scripts listed above can reference.
306+
ports. These are specified by the "-p" option passed to "legacy.run.sh", which
307+
sets environment variables that the scripts listed above can reference.
308308

309309
The convention used in the system tests is that the number passed is the start
310310
of a range of 100 ports. The test is free to use the ports as required,
@@ -356,10 +356,10 @@ General
356356
directory.
357357

358358
2. Arguments can be only passed to the script if the test is being run as a
359-
one-off with "run.sh". In this case, everything on the command line after the
360-
name of the test is passed to each script. For example, the command:
359+
one-off with "legacy.run.sh". In this case, everything on the command line
360+
after the name of the test is passed to each script. For example, the command:
361361

362-
sh run.sh -p 12300 mytest -D xyz
362+
sh legacy.run.sh -p 12300 mytest -D xyz
363363

364364
... will run "mytest" with a port range of 12300 to 12399. Each of the
365365
framework scripts provided by the test will be invoked using the remaining
@@ -530,8 +530,8 @@ Ideally, the directory numbers should start at 1 and work upwards.
530530
When running a test, the servers are started using "start.sh" (which is nothing
531531
more than a wrapper for start.pl). The options for "start.pl" are documented
532532
in the header for that file, so will not be repeated here. In summary, when
533-
invoked by "run.sh", start.pl looks for directories named "nsN" or "ansN" in
534-
the test directory and starts the servers it finds there.
533+
invoked by "legacy.run.sh", start.pl looks for directories named "nsN" or
534+
"ansN" in the test directory and starts the servers it finds there.
535535

536536

537537
"named" Command-Line Options
@@ -628,8 +628,8 @@ the options available are listed in the file's header and will not be repeated
628628
here.
629629

630630
In summary though, the nameservers for a given test, if left running by
631-
specifying the "-k" flag to "run.sh" when the test is started, can be stopped
632-
by the command:
631+
specifying the "-k" flag to "legacy.run.sh" when the test is started, can be
632+
stopped by the command:
633633

634634
sh stop.sh <test-name> [server]
635635

@@ -738,9 +738,10 @@ This section is aimed at developers maintaining BIND's system test framework.
738738

739739
Notes on Parallel Execution
740740
---
741-
Although execution of an individual test is controlled by "run.sh", which
742-
executes the above shell scripts (and starts the relevant servers) for each
743-
test, the running of all tests in the test suite is controlled by the Makefile.
741+
Although execution of an individual test is controlled by "legacy.run.sh",
742+
which executes the above shell scripts (and starts the relevant servers) for
743+
each test, the running of all tests in the test suite is controlled by the
744+
Makefile.
744745

745746
All system tests are capable of being run in parallel. For this to work, each
746747
test needs to use a unique set of ports. To avoid the need to define which
@@ -763,7 +764,7 @@ If the test fails, all these files are retained. But if the test succeeds,
763764
they are cleaned up at different times:
764765

765766
1. Files generated by the test itself are cleaned up by the test's own
766-
"clean.sh", which is called from "run.sh".
767+
"clean.sh", which is called from "legacy.run.sh".
767768

768769
2. Files that may not be cleaned up if named exits abnormally can be removed
769770
using the "cleanall.sh" script.

bin/tests/system/conf.sh.common

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ get_named_xfer_stats() {
695695
#
696696
# Convenience function to copy a configuration file, replacing the tokens
697697
# QUERYPORT, CONTROLPORT and EXTRAPORT[1-8] with the values of the equivalent
698-
# environment variables. (These values are set by "run.sh", which calls the
698+
# environment variables. (These values are set by test runner, which calls the
699699
# scripts invoking this function.)
700700
#
701701
# Usage:

bin/tests/system/get_algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def main():
230230
except Exception:
231231
# if anything goes wrong, the conf.sh ignores error codes, so make sure
232232
# we set an environment variable to an error value that can be checked
233-
# later by run.sh
233+
# later by the test runner and/or tests themselves
234234
print("export ALGORITHM_SET=error")
235235
raise
236236
for name, value in algs_env.items():
File renamed without changes.

bin/tests/system/run.sh

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/python3
2+
#
3+
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4+
#
5+
# SPDX-License-Identifier: MPL-2.0
6+
#
7+
# This Source Code Form is subject to the terms of the Mozilla Public
8+
# License, v. 2.0. If a copy of the MPL was not distributed with this
9+
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10+
#
11+
# See the COPYRIGHT file distributed with this work for additional
12+
# information regarding copyright ownership.
13+
14+
#
15+
# Run system test using the pytest runner. This is a simple wrapper around
16+
# pytest for convenience.
17+
#
18+
19+
import argparse
20+
import sys
21+
import time
22+
23+
import pytest
24+
25+
26+
def into_pytest_args(in_args):
27+
args = []
28+
if in_args.expression is None:
29+
# running all tests - execute in parallel
30+
args.extend(["-n", "auto"])
31+
args.extend(["--dist", "loadscope"])
32+
else:
33+
args.extend(["-k", in_args.expression])
34+
if in_args.noclean:
35+
args.append("--noclean")
36+
if in_args.keep:
37+
print(
38+
"ERROR -k / --keep option not implemented.\n"
39+
"Please contact QA with your use-case and use ./legacy.run.sh in the meantime."
40+
)
41+
sys.exit(1)
42+
return args
43+
44+
45+
def main():
46+
print(
47+
"----- WARNING -----\n"
48+
"Using pytest system test runner\n\n"
49+
'Please consider invoking "pytest" directly for more control:\n'
50+
" single test: pytest -k dns64\n"
51+
" parallel tests: pytest -n auto --dist loadscope\n\n"
52+
"Alternately, use ./legacy.run.sh for the legacy system test runner.\n"
53+
)
54+
55+
parser = argparse.ArgumentParser(
56+
description="Wrapper script for launching system tests"
57+
)
58+
parser.add_argument(
59+
"--noclean",
60+
action="store_true",
61+
help="don't clean tmpdir after test run",
62+
)
63+
parser.add_argument(
64+
"-k",
65+
"--keep",
66+
action="store_true",
67+
help="unused - not implemented",
68+
)
69+
parser.add_argument(
70+
"expression",
71+
type=str,
72+
nargs="?",
73+
help="select which test(s) to run",
74+
)
75+
76+
args = into_pytest_args(parser.parse_args())
77+
print(f"$ pytest {' '.join(args)}\n" "---------------------------\n")
78+
79+
time.sleep(2) # force the user to stare at the warning message
80+
81+
sys.exit(pytest.main(args))
82+
83+
84+
if __name__ == "__main__":
85+
main()
86+
87+
# vim: set filetype=python :

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -1598,8 +1598,8 @@ AC_CONFIG_FILES([bin/tests/Makefile
15981598

15991599
AC_CONFIG_FILES([bin/tests/system/ifconfig.sh],
16001600
[chmod +x bin/tests/system/ifconfig.sh])
1601-
AC_CONFIG_FILES([bin/tests/system/run.sh],
1602-
[chmod +x bin/tests/system/run.sh])
1601+
AC_CONFIG_FILES([bin/tests/system/legacy.run.sh],
1602+
[chmod +x bin/tests/system/legacy.run.sh])
16031603
AC_CONFIG_FILES([bin/tests/system/start.sh],
16041604
[chmod +x bin/tests/system/start.sh])
16051605
AC_CONFIG_FILES([bin/tests/system/stop.sh],

0 commit comments

Comments
 (0)