3 # SPDX-License-Identifier: GPL-2.0-only
5 # SPDX-FileCopyrightText: 2022 EfficiOS Inc.
8 # This file is meant to be sourced at the start of shell script-based tests.
11 # Error out when encountering an undefined variable
14 # If "readlink -f" is available, get a resolved absolute path to the
15 # tests source dir, otherwise make do with a relative path.
16 scriptdir
="$(dirname "${BASH_SOURCE[0]}")"
17 if readlink
-f "." >/dev
/null
2>&1; then
18 testsdir
=$
(readlink
-f "$scriptdir/..")
20 testsdir
="$scriptdir/.."
23 # The OS on which we are running. See [1] for possible values of 'uname -s'.
24 # We do a bit of translation to ease our life down the road for comparison.
25 # Export it so that called executables can use it.
26 # [1] https://en.wikipedia.org/wiki/Uname#Examples
27 if [ "x${URCU_TESTS_OS_TYPE:-}" = "x" ]; then
28 URCU_TESTS_OS_TYPE
="$(uname -s)"
29 case "$URCU_TESTS_OS_TYPE" in
31 URCU_TESTS_OS_TYPE
="mingw"
34 URCU_TESTS_OS_TYPE
="darwin"
37 URCU_TESTS_OS_TYPE
="linux"
40 URCU_TESTS_OS_TYPE
="cygwin"
43 URCU_TESTS_OS_TYPE
="unsupported"
47 export URCU_TESTS_OS_TYPE
49 # Allow overriding the source and build directories
50 if [ "x${URCU_TESTS_SRCDIR:-}" = "x" ]; then
51 URCU_TESTS_SRCDIR
="$testsdir"
53 export URCU_TESTS_SRCDIR
55 if [ "x${URCU_TESTS_BUILDDIR:-}" = "x" ]; then
56 URCU_TESTS_BUILDDIR
="$testsdir"
58 export URCU_TESTS_BUILDDIR
60 # Source the generated environment file if it's present.
61 if [ -f "${URCU_TESTS_BUILDDIR}/utils/env.sh" ]; then
62 # shellcheck source=./env.sh
63 .
"${URCU_TESTS_BUILDDIR}/utils/env.sh"
67 ### External Tools ###
69 if [ "x${URCU_TESTS_NPROC_BIN:-}" = "x" ]; then
70 URCU_TESTS_NPROC_BIN
="nproc"
72 export URCU_TESTS_NPROC_BIN
74 if [ "x${URCU_TESTS_GETCONF_BIN:-}" = "x" ]; then
75 URCU_TESTS_GETCONF_BIN
="getconf"
77 export URCU_TESTS_GETCONF_BIN
80 # By default, it will not source tap.sh. If you to tap output directly from
81 # the test script, define the 'SH_TAP' variable to '1' before sourcing this
83 if [ "x${SH_TAP:-}" = x1
]; then
84 # shellcheck source=./tap.sh
85 .
"${URCU_TESTS_SRCDIR}/utils/tap.sh"
91 # Print the number of online CPUs, fallback to '1' if no tools to count CPUs
92 # are found in the environment.
94 if command -v "${URCU_TESTS_NPROC_BIN}" >/dev
/null
2>&1; then
95 "${URCU_TESTS_NPROC_BIN}"
96 elif command -v "${URCU_TESTS_GETCONF_BIN}" >/dev
/null
2>&1; then
97 "${URCU_TESTS_GETCONF_BIN}" _NPROCESSORS_ONLN
104 # Shell implementation of the 'seq' command.
108 while [[ "$i" -le "$2" ]]; do
This page took 0.040639 seconds and 4 git commands to generate.