Skip to content

Commit ac1e7eb

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). (cherry picked from commit 4dbe8e5) (also manually added a additional run.sh -> legacy.run.sh renames)
1 parent 75a3155 commit ac1e7eb

11 files changed

+122
-35
lines changed

bin/tests/system/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ parallel.mk
1717
/*.log
1818
/*.trs
1919
/resolve
20-
/run.sh
20+
/legacy.run.sh
2121
/run.log
2222
/start.sh
2323
/stop.sh

bin/tests/system/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ LOG_DRIVER_V_1 = --verbose yes
247247
LOG_DRIVER = $(srcdir)/custom-test-driver
248248
AM_LOG_DRIVER_FLAGS = $(LOG_DRIVER_V)
249249

250-
LOG_COMPILER = $(builddir)/run.sh
250+
LOG_COMPILER = $(builddir)/legacy.run.sh
251251
AM_LOG_FLAGS = -r
252252

253-
$(TESTS): run.sh
253+
$(TESTS): legacy.run.sh
254254

255255
test-local: check

bin/tests/system/README

+25-25
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

@@ -165,10 +165,10 @@ To run all the system tests, enter the command:
165165
sh runall.sh [-c] [-n] [numproc]
166166

167167
The optional flag "-c" forces colored output (by default system test output is
168-
not printed in color due to run.sh being piped through "tee").
168+
not printed in color due to legacy.run.sh being piped through "tee").
169169

170-
The optional flag "-n" has the same effect as it does for "run.sh" - it causes
171-
the retention of all output files from all tests.
170+
The optional flag "-n" has the same effect as it does for "legacy.run.sh" - it
171+
causes the retention of all output files from all tests.
172172

173173
The optional "numproc" argument specifies the maximum number of tests that can
174174
run in parallel. The default is 1, which means that all of the tests run
@@ -288,9 +288,9 @@ Re-Running the Tests
288288
---
289289
If there is a requirement to re-run a test (or the entire test suite), the
290290
files produced by the tests should be deleted first. Normally, these files are
291-
deleted if the test succeeds but are retained on error. The run.sh script
292-
automatically calls a given test's clean.sh script before invoking its setup.sh
293-
script.
291+
deleted if the test succeeds but are retained on error. The legacy.run.sh
292+
script automatically calls a given test's clean.sh script before invoking its
293+
setup.sh script.
294294

295295
Deletion of the files produced by the set of tests (e.g. after the execution
296296
of "runall.sh") can be carried out using the command:
@@ -330,8 +330,8 @@ tests.sh Runs the actual tests. This file is mandatory.
330330

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

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

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

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

409-
sh run.sh -p 12300 mytest -D xyz
409+
sh legacy.run.sh -p 12300 mytest -D xyz
410410

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

583583

584584
"named" Command-Line Options
@@ -675,8 +675,8 @@ the options available are listed in the file's header and will not be repeated
675675
here.
676676

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

681681
sh stop.sh <test-name> [server]
682682

@@ -788,10 +788,10 @@ This section is aimed at developers maintaining BIND's system test framework.
788788

789789
Notes on Parallel Execution
790790
---
791-
Although execution of an individual test is controlled by "run.sh", which
792-
executes the above shell scripts (and starts the relevant servers) for each
793-
test, the running of all tests in the test suite is controlled by the Makefile.
794-
("runall.sh" does little more than invoke "make" on the Makefile.)
791+
Although execution of an individual test is controlled by "legacy.run.sh",
792+
which executes the above shell scripts (and starts the relevant servers) for
793+
each test, the running of all tests in the test suite is controlled by the
794+
Makefile. ("runall.sh" does little more than invoke "make" on the Makefile.)
795795

796796
All system tests are capable of being run in parallel. For this to work, each
797797
test needs to use a unique set of ports. To avoid the need to define which
@@ -801,7 +801,7 @@ the ports are assigned when the tests are run. This is achieved by having the
801801
when "make check" is run, and contains a target for each test of the form:
802802

803803
<test-name>:
804-
@$(SHELL) run.sh -p <baseport> <test-name>
804+
@$(SHELL) legacy.run.sh -p <baseport> <test-name>
805805

806806
The <baseport> is unique and the values of <baseport> for each test are
807807
separated by at least 100 ports.
@@ -825,7 +825,7 @@ If the test fails, all these files are retained. But if the test succeeds,
825825
they are cleaned up at different times:
826826

827827
1. Files generated by the test itself are cleaned up by the test's own
828-
"clean.sh", which is called from "run.sh".
828+
"clean.sh", which is called from "legacy.run.sh".
829829

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

bin/tests/system/conf.sh.common

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ get_named_xfer_stats() {
702702
#
703703
# Convenience function to copy a configuration file, replacing the tokens
704704
# QUERYPORT, CONTROLPORT and EXTRAPORT[1-8] with the values of the equivalent
705-
# environment variables. (These values are set by "run.sh", which calls the
705+
# environment variables. (These values are set by test runner, which calls the
706706
# scripts invoking this function.)
707707
#
708708
# 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/parallel.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ echo "test check: $PARALLELS"
3030
for directory in $PARALLELDIRS ; do
3131
echo
3232
echo "test-$(echo "$directory" | tr _ -): check_interfaces"
33-
echo " @${SHELL} ./run.sh -r $directory 2>&1 | tee test.output.$directory"
33+
echo " @${SHELL} ./legacy.run.sh -r $directory 2>&1 | tee test.output.$directory"
3434
done

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 :

bin/tests/system/runall.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ else
8888
(
8989
status=0
9090
for testdir in $SUBDIRS; do
91-
$SHELL run.sh -r "$testdir" || status=1
91+
$SHELL legacy.run.sh -r "$testdir" || status=1
9292
done
9393
echo "$status" > systests.status
9494
) 2>&1 | tee "systests.output"

bin/tests/system/runsequential.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222

2323
for d in $SEQUENTIALDIRS
2424
do
25-
$SHELL run.sh "${@}" "$d" 2>&1 | tee "test.output.$d"
25+
$SHELL legacy.run.sh "${@}" "$d" 2>&1 | tee "test.output.$d"
2626
done

configure.ac

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

15921592
AC_CONFIG_FILES([bin/tests/system/ifconfig.sh],
15931593
[chmod +x bin/tests/system/ifconfig.sh])
1594-
AC_CONFIG_FILES([bin/tests/system/run.sh],
1595-
[chmod +x bin/tests/system/run.sh])
1594+
AC_CONFIG_FILES([bin/tests/system/legacy.run.sh],
1595+
[chmod +x bin/tests/system/legacy.run.sh])
15961596
AC_CONFIG_FILES([bin/tests/system/start.sh],
15971597
[chmod +x bin/tests/system/start.sh])
15981598
AC_CONFIG_FILES([bin/tests/system/stop.sh],

0 commit comments

Comments
 (0)