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