3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2021 Gavin D. Howard and contributors.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
32 testdir=$(dirname "$script")
34 . "$testdir/../scripts/functions.sh"
36 # usage: history.sh dir -a|idx [exe args...]
38 # If Python does not exist, then just skip.
39 py=$(command -v python3)
42 if [ "$err" -ne 0 ]; then
44 py=$(command -v python)
47 if [ "$err" -ne 0 ]; then
48 printf 'Could not find Python 3.\n'
49 printf 'Skipping %s history tests...\n' "$d"
58 # idx is either an index of the test to run or "-a". If it is "-a", then all
63 if [ "$#" -gt 0 ]; then
65 # exe is the executable to run.
70 exe="$testdir/../bin/$d"
73 if [ "$d" = "bc" ]; then
81 # Set the test range correctly for all tests or one test. st is the start index.
82 if [ "$idx" = "-a" ]; then
83 idx=$("$py" "$testdir/history.py" "$d" -a)
84 idx=$(printf '%s - 1\n' "$idx" | bc)
90 # Run all of the tests.
91 for i in $(seq "$st" "$idx"); do
93 printf 'Running %s history test %d...' "$d" "$i"
95 for j in $(seq 1 3); do
97 "$py" "$testdir/history.py" "$d" "$i" "$exe" "$@"
100 if [ "$err" -eq 0 ]; then
106 checktest_retcode "$d" "$err" "$d history test $i"