1#! /bin/sh 2# 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# Copyright (c) 2018-2023 Gavin D. Howard and contributors. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 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. 16# 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. 28# 29 30script="$0" 31 32testdir=$(dirname "$script") 33 34. "$testdir/../scripts/functions.sh" 35 36# usage: history.sh dir -a|idx [exe args...] 37 38# If Python does not exist, then just skip. 39py=$(command -v python3) 40err=$? 41 42if [ "$err" -ne 0 ]; then 43 44 py=$(command -v python) 45 err=$? 46 47 if [ "$err" -ne 0 ]; then 48 printf 'Could not find Python 3.\n' 49 printf 'Skipping %s history tests...\n' "$d" 50 exit 0 51 fi 52fi 53 54# d is "bc" or "dc" 55d="$1" 56shift 57 58# idx is either an index of the test to run or "-a". If it is "-a", then all 59# tests are run. 60idx="$1" 61shift 62 63if [ "$#" -gt 0 ]; then 64 65 # exe is the executable to run. 66 exe="$1" 67 shift 68 69else 70 exe="$testdir/../bin/$d" 71fi 72 73if [ "$d" = "bc" ]; then 74 flip="! %s" 75 addone="%s + 1" 76else 77 flip="%s Np" 78 addone="%s 1+p" 79fi 80 81# Set the test range correctly for all tests or one test. st is the start index. 82if [ "$idx" = "-a" ]; then 83 idx=$("$py" "$testdir/history.py" "$d" -a) 84 idx=$(printf '%s - 1\n' "$idx" | bc) 85 st=0 86else 87 st="$idx" 88fi 89 90# Run all of the tests. 91for i in $(seq "$st" "$idx"); do 92 93 printf 'Running %s history test %d...' "$d" "$i" 94 95 for j in $(seq 1 5); do 96 97 "$py" "$testdir/history.py" "$d" "$i" "$exe" "$@" 98 err="$?" 99 100 if [ "$err" -eq 0 ]; then 101 break 102 fi 103 104 done 105 106 checktest_retcode "$d" "$err" "$d history test $i" 107 108 printf 'pass\n' 109 110done 111