blob: ce672e80b0b685939d04657925851ceff578dc87 [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
Gavin Howard50080252019-02-20 15:27:43 -070017readlink() {
18
19 local exe="$1"
20 shift
21
22 L=$(ls -dl "$exe")
23
24 printf ${L#*-> }
25}
26
Gavin Howard7c715d62019-02-20 10:41:08 -070027die() {
28
29 local d="$1"
30 shift
31
32 local msg="$1"
33 shift
34
35 local name="$1"
36 shift
37
38 local err="$1"
39 shift
40
41 printf '\n'
42 printf '%s %s on test:\n' "$d" "$msg"
43 printf '\n'
44 printf ' %s\n' "$name"
45 printf '\n'
46 printf 'exiting...\n'
47 exit "$err"
48}
49
50checkcrash() {
51
52 local error="$1"
53 shift
54
55 local name="$1"
56 shift
57
58 if [ "$error" -gt 127 ]; then
59 die "$d" "crashed" "$name" "$error"
60 fi
61}
62
63checktest()
64{
65 local error="$1"
66 shift
67
68 local name="$1"
69 shift
70
71 local out="$1"
72 shift
73
74 local exebase="$1"
75 shift
76
77 checkcrash "$error" "$name"
78
79 if [ "$error" -eq 0 ]; then
80 die "$d" "returned no error" "$name" 127
81 fi
82
83 if [ "$error" -eq 100 ]; then
84
85 output=$(cat "$out")
86 fatal_error="Fatal error"
87
88 if [ "${output##*$fatal_error*}" ]; then
89 printf "%s\n" "$output"
90 die "$d" "had memory errors on a non-fatal error" "$name" "$error"
91 fi
92 fi
93
94 if [ ! -s "$out" ]; then
95 die "$d" "produced no error message" "$name" "$error"
96 fi
97
98 # Display the error messages if not directly running exe.
99 # This allows the script to print valgrind output.
100 if [ "$exebase" != "bc" -a "$exebase" != "dc" ]; then
101 cat "$out"
102 fi
103}