forked from signove/antidote
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·204 lines (158 loc) · 4.04 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/sh
####################################################################
# Copyright (C) 2010 Signove Tecnologia Corporation.
# All rights reserved.
# Contact: Signove Tecnologia Corporation ([email protected])
#
# $LICENSE_TEXT$
#
# test.sh
#
# Created on: Jun 16, 2010
# Author: fabricio.silva
####################################################################
BUILD_FOLDER=test_build
TEST_REPORT_DIR=$BUILD_FOLDER/test-reports
COVERAGE_REPORT_DIR=$BUILD_FOLDER/coverage-reports
TESTMODES=""
MEMCHECK=0
THREAD_ENABLED=0
RUNCMD=""
RUNCMD_STATUS=0
OPT_NO_BUILD=0
export HEALTHD_TMP=/tmp/hudson_healthd/
usage() {
USAGE="Usage: `basename $0` [-m <test modes>] [-c] \n\n\
-m \t Test mode (comma separated without spaces), values: auto, \
console, text. Default is text \n\
\t You can inform one test modes per time \n\n \
-c \t Execute the test with Memory Checking \n\n\
-b \t Use last build compilation to run tests \n\n\
-t \t Enable thread profiling support \n\n\
Usage example: \n\
\t test.sh -c \n
\t test.sh -m text -c \n
\t test.sh -c -t"
echo $USAGE >&2
exit $1
}
#################################### Functions ##################################
clean ()
{
echo "Cleaning auto generated files \n"
rm CUnitAutomated*
rm -rf $BUILD_FOLDER
}
build ()
{
clean
if [ "$OPT_NO_BUILD" -eq "0" ]; then
echo "Building project \n"
./autogen.sh
./configure --enable-coverage=yes --disable-shared
make clean
make
STATUS=$?
if [ "$STATUS" -eq "0" ]; then
echo "\n Build finshed! \n"
else
echo "\n Sorry, cannot build the project. \n"
exit 1;
fi
fi
mkdir -p $TEST_REPORT_DIR
mkdir -p $COVERAGE_REPORT_DIR
}
gen_test_reports()
{
CUNIT_RESULT=CUnitAutomated-Results.xml
INPUT=""
if [ -f $CUNIT_RESULT ]; then
mv $CUNIT_RESULT $TEST_REPORT_DIR
INPUT="$TEST_REPORT_DIR/$CUNIT_RESULT"
rm CUnitAutomated*
fi
OUTPUT=$TEST_REPORT_DIR/test_report_results.xml
if [ -f $INPUT ]; then
echo "Generating JUnit compatible xml report \n"
xsltproc --stringparam suitename TestAll \
--path tests/resources/cunit-report \
-o $OUTPUT \
tests/resources/cunit-report/cunit-to-junit.xsl \
$INPUT
fi
}
coverage_phase_pre_execution()
{
lcov -q --directory src --zerocounters
lcov -q --directory apps --zerocounters
}
gen_coverage_reports()
{
lcov -q --directory src --capture --output-file coverage.info
genhtml -q coverage.info -o $COVERAGE_REPORT_DIR
rm coverage.info
}
#################################### Execution Phases ##################################
run_phase_pre_execution()
{
build
coverage_phase_pre_execution
}
run_phase_execution()
{
VALGRIND_CMD=""
if [ "$TESTMODES" != "" ]; then
echo "Test Modes: $TESTMODES"
fi
RUNCMD="./tests/main_test_suite $TESTMODES"
if [ "$THREAD_ENABLED" -eq "1" ]; then
echo "Thread Check Activated"
VALGRIND_CMD="valgrind --error-exitcode=1 --tool=helgrind \
--read-var-info=yes "
elif [ "$MEMCHECK" -eq "1" ]; then
export G_SLICE=always-malloc
export G_DEBUG=gc-friendly
echo "Memory Check Activated"
VALGRIND_CMD="valgrind --suppressions=tests/resources/memcheck.supp \
--error-exitcode=1 --tool=memcheck --leak-check=full "
fi
RUNCMD="$VALGRIND_CMD $RUNCMD"
echo "Running: $RUNCMD \n\n"
$RUNCMD
RUNCMD_STATUS=$?
return $RUNCMD_STATUS;
}
run_phase_post_execution()
{
if [ "$RUNCMD_STATUS" -eq "0" ]; then
gen_test_reports
gen_coverage_reports
fi
}
################################## Main #######################################
# Get options
if [ $# -eq 0 ]; then
usage 1
fi
while getopts m:tcb option; do
case $option in
c) MEMCHECK=1
;;
m) TESTMODES=$(echo $OPTARG|sed 's/,/ /g')
;;
b) OPT_NO_BUILD=1
;;
t) THREAD_ENABLED=1
;;
\?) # getopts issues an error message
usage 1
;;
*) usage 0
;;
esac
done
run_phase_pre_execution
run_phase_execution
run_phase_post_execution
exit $RUNCMD_STATUS;