]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bc/tests/scripts.sh
usr.bin/gh-bc, contrib/bc: update to version 5.0.0
[FreeBSD/FreeBSD.git] / contrib / bc / tests / scripts.sh
1 #! /bin/sh
2 #
3 # SPDX-License-Identifier: BSD-2-Clause
4 #
5 # Copyright (c) 2018-2021 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 pids=""
35
36 # We need to figure out if we should run stuff in parallel.
37 pll=1
38
39 while getopts "n" opt; do
40
41         case "$opt" in
42                 n) pll=0 ; shift ; set -e ;;
43                 ?) usage "Invalid option: $opt" ;;
44         esac
45
46 done
47
48 # Command-line processing.
49 if [ "$#" -eq 0 ]; then
50         printf 'usage: %s [-n] dir [run_extra_tests] [run_stack_tests] [generate_tests] [time_tests] [exec args...]\n' "$script"
51         exit 1
52 else
53         d="$1"
54         shift
55 fi
56
57 if [ "$#" -gt 0 ]; then
58         run_extra_tests="$1"
59         shift
60 else
61         run_extra_tests=1
62 fi
63
64 if [ "$#" -gt 0 ]; then
65         run_stack_tests="$1"
66         shift
67 else
68         run_stack_tests=1
69 fi
70
71 if [ "$#" -gt 0 ]; then
72         generate="$1"
73         shift
74 else
75         generate=1
76 fi
77
78 if [ "$#" -gt 0 ]; then
79         time_tests="$1"
80         shift
81 else
82         time_tests=0
83 fi
84
85 if [ "$#" -gt 0 ]; then
86         exe="$1"
87         shift
88 else
89         exe="$testdir/../bin/$d"
90 fi
91
92 scriptdir="$testdir/$d/scripts"
93
94 scripts=$(cat "$scriptdir/all.txt")
95
96 # Run each script test individually.
97 for s in $scripts; do
98
99         f=$(basename "$s")
100
101         if [ "$pll" -ne 0 ]; then
102                 sh "$testdir/script.sh" "$d" "$f" "$run_extra_tests" "$run_stack_tests" \
103                         "$generate" "$time_tests" "$exe" "$@" &
104                 pids="$pids $!"
105         else
106                 sh "$testdir/script.sh" "$d" "$f" "$run_extra_tests" "$run_stack_tests" \
107                         "$generate" "$time_tests" "$exe" "$@"
108         fi
109
110 done
111
112 if [ "$pll" -ne 0 ]; then
113
114         exit_err=0
115
116         for p in $pids; do
117
118                 wait "$p"
119                 err="$?"
120
121                 if [ "$err" -ne 0 ]; then
122                         printf 'A script failed!\n'
123                         exit_err=1
124                 fi
125
126         done
127
128         if [ "$exit_err" -ne 0 ]; then
129                 exit 1
130         fi
131
132 fi