diff --git a/bin/tests/system/.gitignore b/bin/tests/system/.gitignore index 588c6dc0e2..b9cda1a53a 100644 --- a/bin/tests/system/.gitignore +++ b/bin/tests/system/.gitignore @@ -17,7 +17,7 @@ parallel.mk /*.log /*.trs /resolve -/run.sh +/legacy.run.sh /run.log /start.sh /stop.sh diff --git a/bin/tests/system/Makefile.am b/bin/tests/system/Makefile.am index 937c50a382..f98be0b416 100644 --- a/bin/tests/system/Makefile.am +++ b/bin/tests/system/Makefile.am @@ -247,9 +247,9 @@ LOG_DRIVER_V_1 = --verbose yes LOG_DRIVER = $(srcdir)/custom-test-driver AM_LOG_DRIVER_FLAGS = $(LOG_DRIVER_V) -LOG_COMPILER = $(builddir)/run.sh +LOG_COMPILER = $(builddir)/legacy.run.sh AM_LOG_FLAGS = -r -$(TESTS): run.sh +$(TESTS): legacy.run.sh test-local: check diff --git a/bin/tests/system/README b/bin/tests/system/README index dea63308c1..6a84940966 100644 --- a/bin/tests/system/README +++ b/bin/tests/system/README @@ -119,11 +119,11 @@ Running an Individual Test --- The tests can be run individually using the following command: - sh run.sh [flags] [] + sh legacy.run.sh [flags] [] e.g. - sh run.sh [flags] notify + sh legacy.run.sh [flags] notify Optional flags are: @@ -165,10 +165,10 @@ To run all the system tests, enter the command: sh runall.sh [-c] [-n] [numproc] The optional flag "-c" forces colored output (by default system test output is -not printed in color due to run.sh being piped through "tee"). +not printed in color due to legacy.run.sh being piped through "tee"). -The optional flag "-n" has the same effect as it does for "run.sh" - it causes -the retention of all output files from all tests. +The optional flag "-n" has the same effect as it does for "legacy.run.sh" - it +causes the retention of all output files from all tests. The optional "numproc" argument specifies the maximum number of tests that can run in parallel. The default is 1, which means that all of the tests run @@ -288,9 +288,9 @@ Re-Running the Tests --- If there is a requirement to re-run a test (or the entire test suite), the files produced by the tests should be deleted first. Normally, these files are -deleted if the test succeeds but are retained on error. The run.sh script -automatically calls a given test's clean.sh script before invoking its setup.sh -script. +deleted if the test succeeds but are retained on error. The legacy.run.sh +script automatically calls a given test's clean.sh script before invoking its +setup.sh script. Deletion of the files produced by the set of tests (e.g. after the execution of "runall.sh") can be carried out using the command: @@ -330,8 +330,8 @@ tests.sh Runs the actual tests. This file is mandatory. clean.sh Run at the end to clean up temporary files, but only if the test was completed successfully and its running was not inhibited by the - "-n" switch being passed to "run.sh". Otherwise the temporary - files are left in place for inspection. + "-n" switch being passed to "legacy.run.sh". Otherwise the + temporary files are left in place for inspection. ns These subdirectories contain test name servers that can be queried or can interact with each other. The value of N indicates the @@ -350,8 +350,8 @@ ans Like ns[X], but these are simple mock name servers implemented in Port Usage --- In order for the tests to run in parallel, each test requires a unique set of -ports. These are specified by the "-p" option passed to "run.sh", which sets -environment variables that the scripts listed above can reference. +ports. These are specified by the "-p" option passed to "legacy.run.sh", which +sets environment variables that the scripts listed above can reference. The convention used in the system tests is that the number passed is the start of a range of 100 ports. The test is free to use the ports as required, @@ -403,10 +403,10 @@ General directory. 2. Arguments can be only passed to the script if the test is being run as a -one-off with "run.sh". In this case, everything on the command line after the -name of the test is passed to each script. For example, the command: +one-off with "legacy.run.sh". In this case, everything on the command line +after the name of the test is passed to each script. For example, the command: - sh run.sh -p 12300 mytest -D xyz + sh legacy.run.sh -p 12300 mytest -D xyz ... will run "mytest" with a port range of 12300 to 12399. Each of the 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. When running a test, the servers are started using "start.sh" (which is nothing more than a wrapper for start.pl). The options for "start.pl" are documented in the header for that file, so will not be repeated here. In summary, when -invoked by "run.sh", start.pl looks for directories named "nsN" or "ansN" in -the test directory and starts the servers it finds there. +invoked by "legacy.run.sh", start.pl looks for directories named "nsN" or +"ansN" in the test directory and starts the servers it finds there. "named" Command-Line Options @@ -675,8 +675,8 @@ the options available are listed in the file's header and will not be repeated here. In summary though, the nameservers for a given test, if left running by -specifying the "-k" flag to "run.sh" when the test is started, can be stopped -by the command: +specifying the "-k" flag to "legacy.run.sh" when the test is started, can be +stopped by the command: sh stop.sh [server] @@ -788,10 +788,10 @@ This section is aimed at developers maintaining BIND's system test framework. Notes on Parallel Execution --- -Although execution of an individual test is controlled by "run.sh", which -executes the above shell scripts (and starts the relevant servers) for each -test, the running of all tests in the test suite is controlled by the Makefile. -("runall.sh" does little more than invoke "make" on the Makefile.) +Although execution of an individual test is controlled by "legacy.run.sh", +which executes the above shell scripts (and starts the relevant servers) for +each test, the running of all tests in the test suite is controlled by the +Makefile. ("runall.sh" does little more than invoke "make" on the Makefile.) All system tests are capable of being run in parallel. For this to work, each 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 when "make check" is run, and contains a target for each test of the form: : - @$(SHELL) run.sh -p + @$(SHELL) legacy.run.sh -p The is unique and the values of for each test are separated by at least 100 ports. @@ -825,7 +825,7 @@ If the test fails, all these files are retained. But if the test succeeds, they are cleaned up at different times: 1. Files generated by the test itself are cleaned up by the test's own -"clean.sh", which is called from "run.sh". +"clean.sh", which is called from "legacy.run.sh". 2. Files that may not be cleaned up if named exits abnormally can be removed using the "cleanall.sh" script. diff --git a/bin/tests/system/conf.sh.common b/bin/tests/system/conf.sh.common index 1f3bb68d3e..1499de6f34 100644 --- a/bin/tests/system/conf.sh.common +++ b/bin/tests/system/conf.sh.common @@ -702,7 +702,7 @@ get_named_xfer_stats() { # # Convenience function to copy a configuration file, replacing the tokens # QUERYPORT, CONTROLPORT and EXTRAPORT[1-8] with the values of the equivalent -# environment variables. (These values are set by "run.sh", which calls the +# environment variables. (These values are set by test runner, which calls the # scripts invoking this function.) # # Usage: diff --git a/bin/tests/system/get_algorithms.py b/bin/tests/system/get_algorithms.py index e21e208ce9..b2a060df63 100755 --- a/bin/tests/system/get_algorithms.py +++ b/bin/tests/system/get_algorithms.py @@ -230,7 +230,7 @@ def main(): except Exception: # if anything goes wrong, the conf.sh ignores error codes, so make sure # we set an environment variable to an error value that can be checked - # later by run.sh + # later by the test runner and/or tests themselves print("export ALGORITHM_SET=error") raise for name, value in algs_env.items(): diff --git a/bin/tests/system/run.sh.in b/bin/tests/system/legacy.run.sh.in similarity index 100% rename from bin/tests/system/run.sh.in rename to bin/tests/system/legacy.run.sh.in diff --git a/bin/tests/system/parallel.sh b/bin/tests/system/parallel.sh index 16b0b49c94..11a424f9b1 100644 --- a/bin/tests/system/parallel.sh +++ b/bin/tests/system/parallel.sh @@ -30,5 +30,5 @@ echo "test check: $PARALLELS" for directory in $PARALLELDIRS ; do echo echo "test-$(echo "$directory" | tr _ -): check_interfaces" - echo " @${SHELL} ./run.sh -r $directory 2>&1 | tee test.output.$directory" + echo " @${SHELL} ./legacy.run.sh -r $directory 2>&1 | tee test.output.$directory" done diff --git a/bin/tests/system/run.sh b/bin/tests/system/run.sh new file mode 100755 index 0000000000..27d122857f --- /dev/null +++ b/bin/tests/system/run.sh @@ -0,0 +1,87 @@ +#!/usr/bin/python3 +# +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +# +# Run system test using the pytest runner. This is a simple wrapper around +# pytest for convenience. +# + +import argparse +import sys +import time + +import pytest + + +def into_pytest_args(in_args): + args = [] + if in_args.expression is None: + # running all tests - execute in parallel + args.extend(["-n", "auto"]) + args.extend(["--dist", "loadscope"]) + else: + args.extend(["-k", in_args.expression]) + if in_args.noclean: + args.append("--noclean") + if in_args.keep: + print( + "ERROR -k / --keep option not implemented.\n" + "Please contact QA with your use-case and use ./legacy.run.sh in the meantime." + ) + sys.exit(1) + return args + + +def main(): + print( + "----- WARNING -----\n" + "Using pytest system test runner\n\n" + 'Please consider invoking "pytest" directly for more control:\n' + " single test: pytest -k dns64\n" + " parallel tests: pytest -n auto --dist loadscope\n\n" + "Alternately, use ./legacy.run.sh for the legacy system test runner.\n" + ) + + parser = argparse.ArgumentParser( + description="Wrapper script for launching system tests" + ) + parser.add_argument( + "--noclean", + action="store_true", + help="don't clean tmpdir after test run", + ) + parser.add_argument( + "-k", + "--keep", + action="store_true", + help="unused - not implemented", + ) + parser.add_argument( + "expression", + type=str, + nargs="?", + help="select which test(s) to run", + ) + + args = into_pytest_args(parser.parse_args()) + print(f"$ pytest {' '.join(args)}\n" "---------------------------\n") + + time.sleep(2) # force the user to stare at the warning message + + sys.exit(pytest.main(args)) + + +if __name__ == "__main__": + main() + +# vim: set filetype=python : diff --git a/bin/tests/system/runall.sh b/bin/tests/system/runall.sh index a3bd54b26c..bbd072efc9 100755 --- a/bin/tests/system/runall.sh +++ b/bin/tests/system/runall.sh @@ -88,7 +88,7 @@ else ( status=0 for testdir in $SUBDIRS; do - $SHELL run.sh -r "$testdir" || status=1 + $SHELL legacy.run.sh -r "$testdir" || status=1 done echo "$status" > systests.status ) 2>&1 | tee "systests.output" diff --git a/bin/tests/system/runsequential.sh b/bin/tests/system/runsequential.sh index 4b99bd09b9..953bff0fac 100755 --- a/bin/tests/system/runsequential.sh +++ b/bin/tests/system/runsequential.sh @@ -22,5 +22,5 @@ for d in $SEQUENTIALDIRS do - $SHELL run.sh "${@}" "$d" 2>&1 | tee "test.output.$d" + $SHELL legacy.run.sh "${@}" "$d" 2>&1 | tee "test.output.$d" done diff --git a/configure.ac b/configure.ac index 7b6adec282..5aa4e6824c 100644 --- a/configure.ac +++ b/configure.ac @@ -1591,8 +1591,8 @@ AC_CONFIG_FILES([bin/tests/Makefile AC_CONFIG_FILES([bin/tests/system/ifconfig.sh], [chmod +x bin/tests/system/ifconfig.sh]) -AC_CONFIG_FILES([bin/tests/system/run.sh], - [chmod +x bin/tests/system/run.sh]) +AC_CONFIG_FILES([bin/tests/system/legacy.run.sh], + [chmod +x bin/tests/system/legacy.run.sh]) AC_CONFIG_FILES([bin/tests/system/start.sh], [chmod +x bin/tests/system/start.sh]) AC_CONFIG_FILES([bin/tests/system/stop.sh],