Skip to content

Commit e957bc4

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 46d45c9 commit e957bc4

File tree

9 files changed

+124
-36
lines changed

9 files changed

+124
-36
lines changed

bin/tests/system/.gitignore

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ LOG_DRIVER_V_1 = --verbose yes
230230
LOG_DRIVER = $(srcdir)/custom-test-driver
231231
AM_LOG_DRIVER_FLAGS = $(LOG_DRIVER_V)
232232

233-
LOG_COMPILER = $(builddir)/run.sh
233+
LOG_COMPILER = $(builddir)/legacy.run.sh
234234
AM_LOG_FLAGS = -r
235235

236-
$(TESTS): run.sh
236+
$(TESTS): legacy.run.sh
237237

238238
test-local: check

bin/tests/system/README

Lines changed: 21 additions & 20 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
else:
File renamed without changes.

bin/tests/system/run.sh

Lines changed: 87 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,8 +1624,8 @@ AC_CONFIG_FILES([bin/tests/Makefile
16241624

16251625
AC_CONFIG_FILES([bin/tests/system/ifconfig.sh],
16261626
[chmod +x bin/tests/system/ifconfig.sh])
1627-
AC_CONFIG_FILES([bin/tests/system/run.sh],
1628-
[chmod +x bin/tests/system/run.sh])
1627+
AC_CONFIG_FILES([bin/tests/system/legacy.run.sh],
1628+
[chmod +x bin/tests/system/legacy.run.sh])
16291629
AC_CONFIG_FILES([bin/tests/system/start.sh],
16301630
[chmod +x bin/tests/system/start.sh])
16311631
AC_CONFIG_FILES([bin/tests/system/stop.sh],

doc/dev/dev.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ into 'consumed' and 'remaining'.
432432

433433
When parsing a message, the message to be parsed in in the 'used'
434434
part of the buffer. As the message is parsed, the 'consumed'
435-
subregion grows and the 'remaining' subregion shrinks.
435+
subregion grows and the 'remaining' subregion shrinks.
436436

437437
When creating a message, data is written into the 'available'
438438
subregion, which then becomes part of 'used'.
@@ -533,7 +533,7 @@ memory context is freed before all references have been cleaned up.
533533
/* Populate other isc_foo members here */
534534

535535
foo->magic = ISC_FOO_MAGIC;
536-
536+
537537
*foop = foo;
538538
return (ISC_R_SUCCESS);
539539
}
@@ -649,7 +649,7 @@ More macros are provided for iterating the list:
649649

650650
isc_foo_t *foo;
651651
for (foo = ISC_LIST_HEAD(foolist);
652-
foo != NULL;
652+
foo != NULL;
653653
foo = ISC_LIST_NEXT(foo, link))
654654
{
655655
/* do things */
@@ -818,7 +818,7 @@ The return value may be:
818818
* `dns_name_commonancestor`: name1 and name2 share some labels
819819
* `dns_name_equal`: name1 and name2 are the same
820820

821-
Some simpler comparison functions are provided for convenience when
821+
Some simpler comparison functions are provided for convenience when
822822
not all of this information is required:
823823

824824
* `dns_name_compare()`: returns the sort order of two names but
@@ -889,7 +889,7 @@ sets have been defined:
889889

890890
Each of these has a `first()`, `next()` and `current()` function; for
891891
example, `dns_rdataset_first()`, `dns_rdataset_next()`, and
892-
`dns_rdataset_current()`.
892+
`dns_rdataset_current()`.
893893

894894
The `first()` and `next()` functions move the iterator's cursor and so that
895895
the data at a new location can be retrieved. (Most of these can only step
@@ -1038,7 +1038,7 @@ messages up to the current debugging level are written to the channel.
10381038

10391039
These objects -- the category, module, and channel -- direct hessages
10401040
to desired destinations. Each category/module pair can be associated
1041-
with a specific channel, and the correct destination will be used
1041+
with a specific channel, and the correct destination will be used
10421042
when a message is logged by `isc_log_write()`.
10431043

10441044
In `isc_log_write()`, the logging system first looks up a list that
@@ -1171,7 +1171,7 @@ to control the closing of log files.
11711171

11721172
void isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level);
11731173
unsigned int isc_log_getdebuglevel(isc_log_t *lctx);
1174-
1174+
11751175
These set and retrieve the current debugging level of the program.
11761176
`isc_log_getdebuglevel()` can be used so that you need not keep track of
11771177
the level yourself in another variable.
@@ -1417,7 +1417,7 @@ be triggered at that time.
14171417
result = isc_timer_reset(timermgr, isc_timertype_once, NULL,
14181418
interval, false);
14191419

1420-
An event can also be explicitly triggered via `isc_task_send()`.
1420+
An event can also be explicitly triggered via `isc_task_send()`.
14211421

14221422
static void
14231423
do_things(isc_task_t *task, isc_event_t *event) {
@@ -1427,7 +1427,7 @@ An event can also be explicitly triggered via `isc_task_send()`.
14271427
...
14281428

14291429
/*
1430-
* Allocate an event that calls 'do_things' with a
1430+
* Allocate an event that calls 'do_things' with a
14311431
* NULL argument, using 'myself' as ev_sender.
14321432
*
14331433
* DNS_EVENT_DOTHINGS must be defined in <dns/events.h>.

0 commit comments

Comments
 (0)