Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/bc/tests/history.sh
39536 views
1
#! /bin/sh
2
#
3
# SPDX-License-Identifier: BSD-2-Clause
4
#
5
# Copyright (c) 2018-2025 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
30
script="$0"
31
32
testdir=$(dirname "$script")
33
34
. "$testdir/../scripts/functions.sh"
35
36
# Just print the usage and exit with an error. This can receive a message to
37
# print.
38
# @param 1 A message to print.
39
usage() {
40
if [ $# -eq 1 ]; then
41
printf '%s\n\n' "$1"
42
fi
43
printf 'usage: %s dir -a|idx [exe args...]\n' "$script"
44
exit 1
45
}
46
47
# If Python does not exist, then just skip.
48
py=$(command -v python3)
49
err=$?
50
51
if [ "$err" -ne 0 ]; then
52
53
py=$(command -v python)
54
err=$?
55
56
if [ "$err" -ne 0 ]; then
57
printf 'Could not find Python 3.\n'
58
printf 'Skipping %s history tests...\n' "$d"
59
exit 0
60
fi
61
fi
62
63
if [ "$#" -lt 2 ]; then
64
usage "Not enough arguments; expect 2 arguments"
65
fi
66
67
# d is "bc" or "dc"
68
d="$1"
69
shift
70
check_d_arg "$d"
71
72
# idx is either an index of the test to run or "-a". If it is "-a", then all
73
# tests are run.
74
idx="$1"
75
shift
76
77
if [ "$#" -gt 0 ]; then
78
79
# exe is the executable to run.
80
exe="$1"
81
shift
82
check_exec_arg "$exe"
83
84
else
85
exe="$testdir/../bin/$d"
86
check_exec_arg "$exe"
87
fi
88
89
if [ "$d" = "bc" ]; then
90
flip="! %s"
91
addone="%s + 1"
92
else
93
flip="%s Np"
94
addone="%s 1+p"
95
fi
96
97
# Set the test range correctly for all tests or one test. st is the start index.
98
if [ "$idx" = "-a" ]; then
99
idx=$("$py" "$testdir/history.py" "$d" -a)
100
idx=$(printf '%s - 1\n' "$idx" | bc)
101
st=0
102
else
103
st="$idx"
104
fi
105
106
# Run all of the tests.
107
for i in $(seq "$st" "$idx"); do
108
109
printf 'Running %s history test %d...' "$d" "$i"
110
111
for j in $(seq 1 5); do
112
113
"$py" "$testdir/history.py" "$d" "$i" "$exe" "$@"
114
err="$?"
115
116
if [ "$err" -eq 0 ]; then
117
break
118
fi
119
120
done
121
122
checktest_retcode "$d" "$err" "$d history test $i"
123
124
printf 'pass\n'
125
126
done
127
128