xref: /aosp_15_r20/external/bc/tests/error.sh (revision 5a6e848804d15c18a0125914844ee4eb0bda4fcf)
1*5a6e8488SAndroid Build Coastguard Worker#! /bin/sh
2*5a6e8488SAndroid Build Coastguard Worker#
3*5a6e8488SAndroid Build Coastguard Worker# SPDX-License-Identifier: BSD-2-Clause
4*5a6e8488SAndroid Build Coastguard Worker#
5*5a6e8488SAndroid Build Coastguard Worker# Copyright (c) 2018-2024 Gavin D. Howard and contributors.
6*5a6e8488SAndroid Build Coastguard Worker#
7*5a6e8488SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without
8*5a6e8488SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met:
9*5a6e8488SAndroid Build Coastguard Worker#
10*5a6e8488SAndroid Build Coastguard Worker# * Redistributions of source code must retain the above copyright notice, this
11*5a6e8488SAndroid Build Coastguard Worker#   list of conditions and the following disclaimer.
12*5a6e8488SAndroid Build Coastguard Worker#
13*5a6e8488SAndroid Build Coastguard Worker# * Redistributions in binary form must reproduce the above copyright notice,
14*5a6e8488SAndroid Build Coastguard Worker#   this list of conditions and the following disclaimer in the documentation
15*5a6e8488SAndroid Build Coastguard Worker#   and/or other materials provided with the distribution.
16*5a6e8488SAndroid Build Coastguard Worker#
17*5a6e8488SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*5a6e8488SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*5a6e8488SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*5a6e8488SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21*5a6e8488SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*5a6e8488SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*5a6e8488SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*5a6e8488SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*5a6e8488SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*5a6e8488SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*5a6e8488SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE.
28*5a6e8488SAndroid Build Coastguard Worker#
29*5a6e8488SAndroid Build Coastguard Worker
30*5a6e8488SAndroid Build Coastguard Workerscript="$0"
31*5a6e8488SAndroid Build Coastguard Workertestdir=$(dirname "$script")
32*5a6e8488SAndroid Build Coastguard Worker
33*5a6e8488SAndroid Build Coastguard Worker. "$testdir/../scripts/functions.sh"
34*5a6e8488SAndroid Build Coastguard Worker
35*5a6e8488SAndroid Build Coastguard Workeroutputdir=${BC_TEST_OUTPUT_DIR:-$testdir}
36*5a6e8488SAndroid Build Coastguard Worker
37*5a6e8488SAndroid Build Coastguard Worker# Just print the usage and exit with an error. This can receive a message to
38*5a6e8488SAndroid Build Coastguard Worker# print.
39*5a6e8488SAndroid Build Coastguard Worker# @param 1  A message to print.
40*5a6e8488SAndroid Build Coastguard Workerusage() {
41*5a6e8488SAndroid Build Coastguard Worker	if [ $# -eq 1 ]; then
42*5a6e8488SAndroid Build Coastguard Worker		printf '%s\n\n' "$1"
43*5a6e8488SAndroid Build Coastguard Worker	fi
44*5a6e8488SAndroid Build Coastguard Worker	printf 'usage: %s dir test problematic_tests [exec args...]\n' "$script"
45*5a6e8488SAndroid Build Coastguard Worker	exit 1
46*5a6e8488SAndroid Build Coastguard Worker}
47*5a6e8488SAndroid Build Coastguard Worker
48*5a6e8488SAndroid Build Coastguard Worker# Command-line processing.
49*5a6e8488SAndroid Build Coastguard Workerif [ "$#" -lt 3 ]; then
50*5a6e8488SAndroid Build Coastguard Worker	usage "Not enough arguments"
51*5a6e8488SAndroid Build Coastguard Workerelse
52*5a6e8488SAndroid Build Coastguard Worker
53*5a6e8488SAndroid Build Coastguard Worker	d="$1"
54*5a6e8488SAndroid Build Coastguard Worker	shift
55*5a6e8488SAndroid Build Coastguard Worker	check_d_arg "$d"
56*5a6e8488SAndroid Build Coastguard Worker
57*5a6e8488SAndroid Build Coastguard Worker	t="$1"
58*5a6e8488SAndroid Build Coastguard Worker	shift
59*5a6e8488SAndroid Build Coastguard Worker
60*5a6e8488SAndroid Build Coastguard Worker	problematic="$1"
61*5a6e8488SAndroid Build Coastguard Worker	shift
62*5a6e8488SAndroid Build Coastguard Worker	check_bool_arg "$problematic"
63*5a6e8488SAndroid Build Coastguard Worker
64*5a6e8488SAndroid Build Coastguard Workerfi
65*5a6e8488SAndroid Build Coastguard Worker
66*5a6e8488SAndroid Build Coastguard Workertestfile="$testdir/$d/errors/$t"
67*5a6e8488SAndroid Build Coastguard Workercheck_file_arg "$testfile"
68*5a6e8488SAndroid Build Coastguard Worker
69*5a6e8488SAndroid Build Coastguard Workerif [ "$#" -lt 1 ]; then
70*5a6e8488SAndroid Build Coastguard Worker	exe="$testdir/../bin/$d"
71*5a6e8488SAndroid Build Coastguard Workerelse
72*5a6e8488SAndroid Build Coastguard Worker	exe="$1"
73*5a6e8488SAndroid Build Coastguard Worker	shift
74*5a6e8488SAndroid Build Coastguard Workerfi
75*5a6e8488SAndroid Build Coastguard Worker
76*5a6e8488SAndroid Build Coastguard Worker# Just skip tests that are problematic on FreeBSD. These tests can cause FreeBSD
77*5a6e8488SAndroid Build Coastguard Worker# to kill bc from memory exhaustion because of overcommit.
78*5a6e8488SAndroid Build Coastguard Workerif [ "$d" = "bc" ] && [ "$problematic" -eq 0 ]; then
79*5a6e8488SAndroid Build Coastguard Worker	if [ "$t" = "33.txt" ]; then
80*5a6e8488SAndroid Build Coastguard Worker		printf 'Skipping problematic %s error file %s...\n' "$d" "$t"
81*5a6e8488SAndroid Build Coastguard Worker		exit 0
82*5a6e8488SAndroid Build Coastguard Worker	fi
83*5a6e8488SAndroid Build Coastguard Workerfi
84*5a6e8488SAndroid Build Coastguard Worker
85*5a6e8488SAndroid Build Coastguard Worker# I use these, so unset them to make the tests work.
86*5a6e8488SAndroid Build Coastguard Workerunset BC_ENV_ARGS
87*5a6e8488SAndroid Build Coastguard Workerunset BC_LINE_LENGTH
88*5a6e8488SAndroid Build Coastguard Workerunset DC_ENV_ARGS
89*5a6e8488SAndroid Build Coastguard Workerunset DC_LINE_LENGTH
90*5a6e8488SAndroid Build Coastguard Worker
91*5a6e8488SAndroid Build Coastguard Workerout="$outputdir/${d}_outputs/error_results_${t}"
92*5a6e8488SAndroid Build Coastguard Workeroutdir=$(dirname "$out")
93*5a6e8488SAndroid Build Coastguard Worker
94*5a6e8488SAndroid Build Coastguard Worker# Make sure the directory exists.
95*5a6e8488SAndroid Build Coastguard Workerif [ ! -d "$outdir" ]; then
96*5a6e8488SAndroid Build Coastguard Worker	mkdir -p "$outdir"
97*5a6e8488SAndroid Build Coastguard Workerfi
98*5a6e8488SAndroid Build Coastguard Worker
99*5a6e8488SAndroid Build Coastguard Worker# Set stuff for the correct calculator.
100*5a6e8488SAndroid Build Coastguard Workerif [ "$d" = "bc" ]; then
101*5a6e8488SAndroid Build Coastguard Worker	opts="-l"
102*5a6e8488SAndroid Build Coastguard Worker	halt="halt"
103*5a6e8488SAndroid Build Coastguard Worker	read_call="read()"
104*5a6e8488SAndroid Build Coastguard Worker	read_expr="${read_call}\n5+5;"
105*5a6e8488SAndroid Build Coastguard Workerelse
106*5a6e8488SAndroid Build Coastguard Worker	opts="-x"
107*5a6e8488SAndroid Build Coastguard Worker	halt="q"
108*5a6e8488SAndroid Build Coastguard Workerfi
109*5a6e8488SAndroid Build Coastguard Worker
110*5a6e8488SAndroid Build Coastguard Workerprintf 'Running %s error file %s with clamping...' "$d" "$t"
111*5a6e8488SAndroid Build Coastguard Worker
112*5a6e8488SAndroid Build Coastguard Workerprintf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $opts -c "$testfile" 2> "$out" > /dev/null
113*5a6e8488SAndroid Build Coastguard Workererr="$?"
114*5a6e8488SAndroid Build Coastguard Worker
115*5a6e8488SAndroid Build Coastguard Workercheckerrtest "$d" "$err" "$testfile" "$out" "$exebase" > /dev/null
116*5a6e8488SAndroid Build Coastguard Worker
117*5a6e8488SAndroid Build Coastguard Workerprintf 'pass\n'
118*5a6e8488SAndroid Build Coastguard Worker
119*5a6e8488SAndroid Build Coastguard Workerprintf 'Running %s error file %s without clamping...' "$d" "$t"
120*5a6e8488SAndroid Build Coastguard Worker
121*5a6e8488SAndroid Build Coastguard Workerprintf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $opts -C "$testfile" 2> "$out" > /dev/null
122*5a6e8488SAndroid Build Coastguard Workererr="$?"
123*5a6e8488SAndroid Build Coastguard Worker
124*5a6e8488SAndroid Build Coastguard Workercheckerrtest "$d" "$err" "$testfile" "$out" "$exebase" > /dev/null
125*5a6e8488SAndroid Build Coastguard Worker
126*5a6e8488SAndroid Build Coastguard Workerprintf 'pass\n'
127*5a6e8488SAndroid Build Coastguard Worker
128*5a6e8488SAndroid Build Coastguard Workerprintf 'Running %s error file %s through cat with clamping...' "$d" "$t"
129*5a6e8488SAndroid Build Coastguard Worker
130*5a6e8488SAndroid Build Coastguard Workercat "$testfile" 2> /dev/null | "$exe" "$@" $opts -c 2> "$out" > /dev/null
131*5a6e8488SAndroid Build Coastguard Workererr="$?"
132*5a6e8488SAndroid Build Coastguard Worker
133*5a6e8488SAndroid Build Coastguard Workercheckerrtest "$d" "$err" "$testfile" "$out" "$exebase"
134*5a6e8488SAndroid Build Coastguard Worker
135*5a6e8488SAndroid Build Coastguard Workerprintf 'pass\n'
136*5a6e8488SAndroid Build Coastguard Worker
137*5a6e8488SAndroid Build Coastguard Workerprintf 'Running %s error file %s through cat without clamping...' "$d" "$t"
138*5a6e8488SAndroid Build Coastguard Worker
139*5a6e8488SAndroid Build Coastguard Workercat "$testfile" 2> /dev/null | "$exe" "$@" $opts -C 2> "$out" > /dev/null
140*5a6e8488SAndroid Build Coastguard Workererr="$?"
141*5a6e8488SAndroid Build Coastguard Worker
142*5a6e8488SAndroid Build Coastguard Workercheckerrtest "$d" "$err" "$testfile" "$out" "$exebase"
143*5a6e8488SAndroid Build Coastguard Worker
144*5a6e8488SAndroid Build Coastguard Workerprintf 'pass\n'
145