| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 4 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
usage() { |
| 20 |
cat <<eof |
| 21 |
Usage: run-functional-tests [...] |
| 22 |
|
| 23 |
Run the Cylc test battery, in <CYLC_REPO_DIR>/tests. |
| 24 |
|
| 25 |
Options and arguments are appended to "prove -j \$NPROC -s -r \${@:-tests/f}". |
| 26 |
NPROC is the number of concurrent processes to run, which defaults to the |
| 27 |
global config "[scheduler]process pool size" setting. |
| 28 |
|
| 29 |
The tests ignore normal site/user global config and instead use: |
| 30 |
~/.cylc/flow/<cylc-version>/global-tests.cylc |
| 31 |
This should specify test platforms under the [platforms] section. Additional |
| 32 |
global config items can be added on the fly using the create_test_global_config |
| 33 |
shell function defined in the test_header. |
| 34 |
|
| 35 |
Workflow run directories are only cleaned up for passing tests on the workflow |
| 36 |
host. |
| 37 |
|
| 38 |
Set "export CYLC_TEST_DEBUG=true" to print failed-test stderr to the terminal. |
| 39 |
|
| 40 |
To change the test file comparison command from "diff -u" do (for example): |
| 41 |
export CYLC_TEST_DIFF_CMD='xxdiff -D' |
| 42 |
|
| 43 |
Some test workflows submit jobs to the 'at' so atd must be up on the test |
| 44 |
platforms. |
| 45 |
|
| 46 |
Commits or Pull Requests to cylc/cylc-flow on GitHub will trigger |
| 47 |
GitHub Actions to run tests, see .github/workflows for details. |
| 48 |
|
| 49 |
By default all tests are executed. To run just a subset of them: |
| 50 |
* list individual tests or test directories to run on the command line |
| 51 |
* list individual tests or test directories to skip in \$CYLC_TEST_SKIP |
| 52 |
List specific tests relative to \$CYLC_REPO_DIR (i.e. starting with "test/"). |
| 53 |
Some platform-specific tests are automatically skipped, depending on platform. |
| 54 |
|
| 55 |
|
| 56 |
Options: |
| 57 |
-h, --help Print this help message and exit. |
| 58 |
-p, --platform Specify one or more platforms to use for running the |
| 59 |
tests. |
| 60 |
|
| 61 |
Platforms should be configured in global-test.cylc. |
| 62 |
|
| 63 |
Tests will run on the first compatible platform. |
| 64 |
|
| 65 |
Defaults to: |
| 66 |
host: localhost |
| 67 |
job runner: background |
| 68 |
|
| 69 |
Can be set to a glob. e.g. '_local*' will match all |
| 70 |
configuted test platforms with local job submission. |
| 71 |
|
| 72 |
'*' will match all configured test platforms. |
| 73 |
|
| 74 |
Alternatively provide a space separated string of platforms |
| 75 |
using the CYLC_TEST_PLATFORMS environment variable. |
| 76 |
|
| 77 |
Examples: |
| 78 |
# Run the full test suite with the default options. |
| 79 |
$ run-functional-tests |
| 80 |
|
| 81 |
# Run the full test suite with 12 processes |
| 82 |
$ run-functional-tests -j 12 |
| 83 |
|
| 84 |
# Run only tests under "tests/f/cyclers/" |
| 85 |
$ run-functional-tests tests/f/cyclers |
| 86 |
|
| 87 |
# Run only "tests/f/cyclers/16-weekly.t" in verbose mode |
| 88 |
$ run-functional-tests -v tests/f/cyclers/16-weekly.t |
| 89 |
|
| 90 |
# Run only tests under "tests/f/cyclers/", and skip 00-daily.t |
| 91 |
$ export CYLC_TEST_SKIP=tests/f/cyclers/00-daily.t |
| 92 |
$ run-functional-tests tests/f/cyclers |
| 93 |
|
| 94 |
# Run the first quarter of the test battery |
| 95 |
$ CHUNK=1/4 run-functional-tests |
| 96 |
|
| 97 |
# Re-run failed tests |
| 98 |
$ run-functional-tests --state=save |
| 99 |
$ run-functional-tests --state=failed |
| 100 |
|
| 101 |
# run tests on a specified test platform |
| 102 |
$ run-functional-tests -p <test_platform> <path> |
| 103 |
|
| 104 |
# run tests using the first matching test platform from the test config |
| 105 |
# (test platforms have names beggining with an underscore) |
| 106 |
$ run-functional-tests -p all <path> |
| 107 |
eof |
| 108 |
} |
| 109 |
|
| 110 |
# parse args |
| 111 |
PROVE_ARGS=() |
| 112 |
TESTS=() |
| 113 |
# must use string as can't export arrays in bash |
| 114 |
PLATFORMS="${CYLC_TEST_PLATFORMS:-}" |
| 115 |
PROVIDE_TESTBASE=true |
| 116 |
while [[ $# -gt 0 ]]; do |
| 117 |
case "$1" in |
| 118 |
--help|-h) |
| 119 |
usage |
| 120 |
exit 0 |
| 121 |
;; |
| 122 |
-p|--platform) |
| 123 |
# note "all" logic is handled in the test_header |
| 124 |
PLATFORMS="$PLATFORMS $2" |
| 125 |
shift |
| 126 |
shift |
| 127 |
;; |
| 128 |
--state*) |
| 129 |
STATES=${1/--state=/} |
| 130 |
if [[ -n ${STATES/save/} ]]; then |
| 131 |
# run tests from a previous saved state, don't provide a list |
| 132 |
# of tests to run as prove does this for us |
| 133 |
PROVIDE_TESTBASE=false |
| 134 |
fi |
| 135 |
PROVE_ARGS+=("$1") |
| 136 |
shift |
| 137 |
;; |
| 138 |
-j|-a) |
| 139 |
PROVE_ARGS+=("$1" "$2") |
| 140 |
shift |
| 141 |
shift |
| 142 |
;; |
| 143 |
-*) |
| 144 |
PROVE_ARGS+=("$1") |
| 145 |
shift |
| 146 |
;; |
| 147 |
*) |
| 148 |
TESTS+=("$1") |
| 149 |
shift |
| 150 |
;; |
| 151 |
esac |
| 152 |
done |
| 153 |
|
| 154 |
# base dir |
| 155 |
cd "$(dirname "$0")/../.." || exit 1 |
| 156 |
export CYLC_REPO_DIR="${PWD}" |
| 157 |
|
| 158 |
export PLATFORMS |
| 159 |
|
| 160 |
# default test base |
| 161 |
if [[ ${#TESTS[@]} -eq 0 ]]; then |
| 162 |
TESTS=('tests/functional') |
| 163 |
fi |
| 164 |
|
| 165 |
# handle chunking |
| 166 |
if [[ -n "${CHUNK:-}" ]]; then |
| 167 |
TEMP=("${TESTS[@]}") |
| 168 |
TESTS=() |
| 169 |
# would be a lot nicer with mapfile but we should keep bash3 support |
| 170 |
while IFS='' read -r line; do TESTS+=("$line"); done < <( |
| 171 |
prove "${TEMP[@]}" --dry --recurse | sort | split -n "r/${CHUNK}" |
| 172 |
) |
| 173 |
fi |
| 174 |
|
| 175 |
if ! $PROVIDE_TESTBASE; then |
| 176 |
TESTS=() |
| 177 |
fi |
| 178 |
|
| 179 |
# ensure that TMPDIR is not a symlink |
| 180 |
# (we rely on path comparisons in many tests) |
| 181 |
TMPDIR="$(realpath "${TMPDIR:-/tmp}")" |
| 182 |
export TMPDIR |
| 183 |
|
| 184 |
# test environment |
| 185 |
export CYLC_TEST_SKIP=${CYLC_TEST_SKIP:-} |
| 186 |
CYLC_TEST_TIME_INIT="$(date -u +'%Y%m%dT%H%M%SZ')" |
| 187 |
CYLC_TEST_UID="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c4)" |
| 188 |
CYLC_TEST_REG_BASE="${CYLC_TEST_REG_BASE:-cylctb-${CYLC_TEST_TIME_INIT}-${CYLC_TEST_UID}}" |
| 189 |
export CYLC_TEST_REG_BASE |
| 190 |
export CYLC_TEST_TIME_INIT |
| 191 |
|
| 192 |
# get number of cores |
| 193 |
NPROC=$(python3 -c 'import multiprocessing as mp; print(mp.cpu_count())') |
| 194 |
|
| 195 |
# run tests run |
| 196 |
exec prove --timer -j "${NPROC}" -s -r "${PROVE_ARGS[@]}" "${TESTS[@]}" |