blob: dc900fba0cc9373294bd3146f7d84c77a2127a16 [file] [log] [blame]
Gavin Howard7c715d62019-02-20 10:41:08 -07001#! /bin/sh
2#
3# Copyright 2018 Gavin D. Howard
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14# PERFORMANCE OF THIS SOFTWARE.
15#
16
17die() {
18
19 local d="$1"
20 shift
21
22 local msg="$1"
23 shift
24
25 local name="$1"
26 shift
27
28 local err="$1"
29 shift
30
31 printf '\n'
32 printf '%s %s on test:\n' "$d" "$msg"
33 printf '\n'
34 printf ' %s\n' "$name"
35 printf '\n'
36 printf 'exiting...\n'
37 exit "$err"
38}
39
40checkcrash() {
41
42 local error="$1"
43 shift
44
45 local name="$1"
46 shift
47
48 if [ "$error" -gt 127 ]; then
49 die "$d" "crashed" "$name" "$error"
50 fi
51}
52
53checktest()
54{
55 local error="$1"
56 shift
57
58 local name="$1"
59 shift
60
61 local out="$1"
62 shift
63
64 local exebase="$1"
65 shift
66
67 checkcrash "$error" "$name"
68
69 if [ "$error" -eq 0 ]; then
70 die "$d" "returned no error" "$name" 127
71 fi
72
73 if [ "$error" -eq 100 ]; then
74
75 output=$(cat "$out")
76 fatal_error="Fatal error"
77
78 if [ "${output##*$fatal_error*}" ]; then
79 printf "%s\n" "$output"
80 die "$d" "had memory errors on a non-fatal error" "$name" "$error"
81 fi
82 fi
83
84 if [ ! -s "$out" ]; then
85 die "$d" "produced no error message" "$name" "$error"
86 fi
87
88 # Display the error messages if not directly running exe.
89 # This allows the script to print valgrind output.
90 if [ "$exebase" != "bc" -a "$exebase" != "dc" ]; then
91 cat "$out"
92 fi
93}