-
Notifications
You must be signed in to change notification settings - Fork 8
/
regression-test-all.sh
executable file
·108 lines (96 loc) · 3.13 KB
/
regression-test-all.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
#!/bin/bash
# Functions
die(){ (echo "$USAGE"; echo "FATAL ERROR: $@")>&2; exit 1; }
warn(){ (echo "WARNING: $@")>&2; }
not(){ if eval "$@"; then return 1; else return 0; fi; }
newlines(){ awk '{for(i=1; i<=NF;i++)print $i}' "$@"; }
parse(){ awk "BEGIN{print $@}" </dev/null; }
TMP=/tmp/cpus.$$
trap "/bin/rm -rf $TMP $TMP.?" 0 1 2 3 15
cpus_output(){ [ -f $TMP ] && awk '{cpus=$1; av=(cpus); printf "%d\n", (av<0)?0:av}' $TMP | tee $MY_CPUS_USED && exit 0; }
cpus() {
# Most Linux machines:
lscpu >$TMP.2 2>/dev/null &&
awk '/^CPU[(s)]*:/{cpus=$NF}END{if(cpus)print cpus; else exit 1}' $TMP.2 > $TMP && cpus_output
# MacOS:
(arch;uname -a) | egrep 'Darwin|arm64' >/dev/null && sysctl -n hw.ncpu > $TMP && cpus_output
# Cygwin:
if (arch; uname -a) | grep CYGWIN >/dev/null; then
grep '^cpu cores[ ]*:' /proc/cpuinfo > $TMP || die "shouldn't get here since CYGWIN has /proc/cpuinfo"
cat $TMP | uniq | awk '{print $NF}'
elif [ -d /dev/cpu -a ! -f /dev/cpu/microcode ]; then
ls -F /dev/cpu | fgrep -c > $TMP && cpus_output
else
echo "couldn't figure out number of CPUs" >&2; exit 1
fi
}
# generally useful Variables
NL='
'
TAB=' '
case "$1" in
-use-git-at)
if [ -f git-at ] && [ `wc -l < git-at` -eq 2 -a `git log -1 --format=%at` -eq `tail -1 git-at` ]; then
echo -n "Repo unchanged; returning same status code as "
tail -1 git-at | xargs -I{} date -d @{} +%Y-%m-%d-%H:%M:%S
exit `head -1 git-at`
fi
shift
;;
esac
USAGE="USAGE: $0 [ -make ] [ -x SAHAP_EXE ] [ list of tests to run, defaults to regression-tests/*/*.sh ]"
PATH=`pwd`:`pwd`/scripts:$PATH
export PATH
EXE=./sahap
MAKE=false
while [ $# -gt -0 ]; do
case "$1" in
-make) MAKE=true; shift;;
-x) EXE="$2"; shift 2;;
-*) die "unknown option '$1";;
*) break;;
esac
done
CORES=${CORES:=`cpus | awk '{c2=int($1); if(c2>0)print c2; else print 1}'`}
[ "$CORES" -gt 0 ] || die "can't figure out how many cores this machine has"
MAKE_CORES=$CORES
[ `hostname` = Jenkins ] && MAKE_CORES=2 # only use 2 cores to make on Jenkins
echo "Using $MAKE_CORES cores to make and $CORES cores for regression tests"
export EXE CORES MAKE_CORES
NUM_FAILS=0
EXECS="parallel MEC Poisson"
$MAKE && make clean
for EXE in $EXECS; do
if $MAKE ; then
if not make -k -j$MAKE_CORES $EXE; then # "-k" mean "keep going even if some targets fail"
(( NUM_FAILS+=1000 ))
warn "make '$EXE' failed"
fi
[ $NUM_FAILS -gt 0 ] && warn "Cumulative NUM_FAILS is $NUM_FAILS"
fi
[ -x $EXE -o -x sahap.$EXE ] || warn "$EXE doesn't exist; did you forget to pass the '-make' option?"
done
STDBUF=''
if which stdbuf >/dev/null; then
STDBUF='stdbuf -oL -eL'
fi
if [ $# -eq 0 ]; then
set regression-tests/*/*.sh
fi
for r
do
REG_DIR=`dirname "$r"`
NEW_FAILS=0
export REG_DIR
echo --- running test $r ---
if eval time $STDBUF "$r"; then # force output and error to be line buffered
:
else
NEW_FAILS=$?
(( NUM_FAILS+=$NEW_FAILS ))
fi
echo --- test $r incurred $NEW_FAILS failures, cumulative failures is $NUM_FAILS ---
done
echo Total number of failures: $NUM_FAILS
(echo $NUM_FAILS; git log -1 --format=%at) > git-at
exit $NUM_FAILS