-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.sh
executable file
·190 lines (168 loc) · 5.86 KB
/
test.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash
# author: Lefteris Karapetsas <[email protected]>
#
# A script to run tests for refu
# Get SCRIPT_DIR, the directory the script is located even if there are symlinks involved
FILE_SOURCE="${BASH_SOURCE[0]}"
# resolve $FILE_SOURCE until the file is no longer a symlink
while [ -h "$FILE_SOURCE" ]; do
SCRIPT_DIR="$( cd -P "$( dirname "$FILE_SOURCE" )" && pwd )"
FILE_SOURCE="$(readlink "$FILE_SOURCE")"
# if $FILE_SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $FILE_SOURCE != /* ]] && FILE_SOURCE="$SCRIPT_DIR/$FILE_SOURCE"
done
SCRIPT_DIR="$( cd -P "$( dirname "$FILE_SOURCE" )" && pwd )"
WORKING_DIR="./build/test"
TEST_CMD=" ./test_refu CK_VERBOSE False"
TEST_RFBASE=0
COVERAGE=0
IN_TRAVIS=0
TRAVIS_JOB_ID=0
REQUESTED_ARG=""
exists () {
local __result=$2
if type "$1" >/dev/null 2>/dev/null; then
local myresult=1
else
local myresult=0
fi
eval $__result="'$myresult'"
}
llvm_exists () {
local __result=$1
exists "llc" LLVM_EXISTS
exists "llc-3.9" LLVM39_EXISTS
exists "llc-3.8" LLVM38_EXISTS
exists "llc-3.7" LLVM37_EXISTS
local myresult=0
if [ $LLVM_EXISTS -eq 1 -o $LLVM39_EXISTS -eq 1 -o $LLVM38_EXISTS -eq 1 -o $LLVM37_EXISTS -eq 1 ]; then
local myresult=1
fi
eval $__result="'$myresult'"
}
llvm_exists LLVM_EXISTS
# Assert that llvm binaries are accessible in the path
if [[ $LLVM_EXISTS -eq 0 ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
export PATH="$PATH:/usr/local/opt/llvm/bin/"
exists "llvm-config" LLVM_EXISTS
if [[ $LLVM_EXISTS -eq 0 ]]; then
echo "test.sh - ERROR: llvm-config not found in the path. Have you installed llvm?"
echo " If you have, then have you added the proper directory in the path?"
exit 1
fi
else
echo "test.sh - ERROR: llvm-config not found in the path. Have you installed llvm?"
echo " If you have, then have you added the proper directory in the path?"
exit 1
fi
fi
function print_help {
echo "Usage: test.sh [extra-options]"
echo "Arguments:"
echo " --help Print this help message."
echo " --rfbase If given then also rfbase submodule tests are ran"
echo " --coverage If given then generate coverage report"
echo " --in-travis We are running tests in a travis instance"
echo " --travis-job-id NUMBER If running inside a travis instance this should contain the job ID"
}
function run_tests {
PREVIOUS_DIR=`pwd`
cd ${SCRIPT_DIR}
if [[ ! -d $WORKING_DIR ]]; then
echo "test.sh - ERROR: Could not find ${WORKING_DIR} directory"
exit 1
fi
TEST_EXEC=${WORKING_DIR}/${1}
if [[ ! -x $TEST_EXEC ]]; then
echo "test.sh - ERROR: Could not find ${TEST_EXEC}. Have you already built the tests?"
exit 1
fi
# Execute tests
cd $WORKING_DIR
# zero out previous lcov data
if [[ $COVERAGE -ne 0 ]]; then
lcov --zerocounters --directory .
fi
$TEST_CMD
if [[ $? -ne 0 ]]; then
echo "test.sh - ERROR: ${1} tests failed"
exit 1
fi
echo "test.sh - INFO: ${1} tests passed"
if [[ $COVERAGE -ne 0 && ${1} == "test_refu" ]]; then
echo "Generating coverage report for ${1} ..."
lcov --directory . --capture --output-file ${1}.info
lcov --remove ${1}.info \*.gperf -o ${1}.info
genhtml --output-directory coverage \
--demangle-cpp --num-spaces 4 --sort \
--title "Refu Test Coverage" \
--function-coverage --branch-coverage --legend \
${1}.info
echo "Coverage report generated!"
if [[ $IN_TRAVIS -eq 1 ]]; then
echo "Invoking coveralls-lcov to send report to coveralls.io with Travis Job ID: ${TRAVIS_JOB_ID}"
LCOV_OUT=`coveralls-lcov -nv ${1}.info`
if [[ $? -ne 0 ]]; then
echo "test.sh - ERROR: Failed to invoke coveralls-lcov"
exit 1
fi
REPLACE_NEW="\"service_job_id\": \"${TRAVIS_JOB_ID}\""
RESULT=${LCOV_OUT/\"service_job_id\":null/$REPLACE_NEW}
echo $RESULT > coveralls.json
curl -F '[email protected]' https://coveralls.io/api/v1/jobs
fi
fi
command -v valgrind >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "test.sh - INFO: Valgrind found. Running tests under valgrind"
valgrind --tool=memcheck --leak-check=yes --track-origins=yes --show-reachable=yes --num-callers=20 --track-fds=yes $TEST_CMD
echo "test.sh - INFO: ${1} VALGRIND tests passed"
else
echo "test.sh - INFO: Valgrind not found."
fi
cd ${PREVIOUS_DIR}
}
for arg in ${@:1}
do
if [[ ${REQUESTED_ARG} != "" ]]; then
case $REQUESTED_ARG in
"travis-job-id")
TRAVIS_JOB_ID=$arg
;;
*)
echo "ERROR: Unrecognized argument \"$arg\".";
print_help
exit 1
esac
REQUESTED_ARG=""
continue
fi
if [[ $arg == "--help" ]]; then
print_help
exit 1
fi
if [[ $arg == "--rfbase" ]]; then
TEST_RFBASE=1
continue
elif [[ $arg == "--coverage" ]]; then
COVERAGE=1
continue
elif [[ $arg == "--in-travis" ]]; then
IN_TRAVIS=1
continue
elif [[ $arg == "--travis-job-id" ]]; then
REQUESTED_ARG="travis-job-id"
continue
fi
# if we get here the argument is not recognized
echo "test.sh: Unrecognized argument ${arg}."
print_help
exit 1
done
run_tests test_refu
if [[ $TEST_RFBASE -eq 1 ]]; then
WORKING_DIR="./build/rfbase/test"
TEST_CMD="./test_rfbase CK_VERBOSE False"
run_tests test_rfbase
fi