-
Notifications
You must be signed in to change notification settings - Fork 85
/
pass_fail.sh
executable file
·119 lines (99 loc) · 2.98 KB
/
pass_fail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Compute absolute and relative diffs of gold norms using bc
#
# Returns a string that can be evaluated to be a bash array
# ( abs_diff, rel_diff)
#
compute_diffs() {
local currNorm=$1
local goldNorm=$2
bc -l <<EOF
c = $currNorm
g = $goldNorm
a = (c - g)
if (a < 0.0) a = -a
r = (c / g - 1.0)
if (r < 0.0) r = -r
print "( ", a, " ", r, " )"
EOF
}
determine_pass_fail() {
diffAnywhere=0
tolerance=$1
logFileName=$2
localNormFileName=$3
goldNormFileName=$4
# check for required files: log file and gold
if [ ! -f "$logFileName" ]; then
diffAnywhere=1
fi
# check for gold norm file
if [ ! -f "$goldNormFileName" ]; then
diffAnywhere=1
fi
grep "Mean System Norm:" "$logFileName" | awk '{print $4 " " $5 " " $6 }' > "$localNormFileName"
# make sure the grep worked
if [ ! -f "$localNormFileName" ]; then
diffAnywhere=1
fi
# read in gold norm values
goldCount=1
goldFileContent=( `cat "$goldNormFileName"`)
for gfc in "${goldFileContent[@]}" ; do
goldNorm[goldCount]=$gfc
((goldCount++))
done
# read in local norm values
localCount=1
localFileContent=( `cat "$localNormFileName"`)
for lfc in "${localFileContent[@]}" ; do
localNorm[localCount]=$lfc
((localCount++))
done
if [ $(echo " $goldCount - $localCount" | bc) -eq 0 ]; then
# the lengths the same... proceed
for ((i=1;i<$goldCount;i+=3)); do
modLocalNorm=$(printf "%1.32f" ${localNorm[i]})
modGoldNorm=$(printf "%1.32f" ${goldNorm[i]})
eval "diffs=$(compute_diffs $modLocalNorm $modGoldNorm)"
absDiff=${diffs[0]}
relDiff=${diffs[1]}
# test the difference
if [ $(echo " $absDiff > $tolerance" | bc) -eq 1 ]; then
diffAnywhere=1
fi
# find the max
if [ $(echo " $absDiff > $maxSolutionDiff " | bc) -eq 1 ]; then
maxSolutionDiff=$absDiff
maxRelDiff=$relDiff
fi
done
else
# length was not the same; fail
diffAnywhere=1
maxSolutionDiff=1000000.0
fi
# extract simulation time
return $diffAnywhere
}
# $1 is the test name
main() {
testName=$1
goldFile=$2
mytolerance=$3
maxSolutionDiff=-1000000000.0
maxRelDiff=-1000000000.0
determine_pass_fail ${mytolerance} "${testName}.log" "${testName}.norm" "${goldFile}"
passStatus="$?"
performanceTime=`grep "STKPERF: Total Time" ${testName}.log | awk '{print $4}'`
padding="........................................"
if [ ${passStatus} -eq 0 ]; then
printf "PASS: %s%s %10.4fs\n" ${testName} ${padding:${#testName}} ${performanceTime}
exit 0
else
printf "FAIL: %s%s %10.4fs %.4e %.4e\n" ${testName} ${padding:${#testName}} ${performanceTime} ${maxSolutionDiff} ${maxRelDiff}
exit 1
fi
}
# ./pass_fail.sh testName normFile tolerance
main "$@"