forked from uos3/obc-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·235 lines (212 loc) · 5.29 KB
/
Copy pathtest
File metadata and controls
executable file
·235 lines (212 loc) · 5.29 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
## Cross-Platform Embedded Toolchain
## Copyright (c) 2016 Phil Crump <phil@philcrump.co.uk>
## Freely distributable under the MIT license.
source_dir="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
cd $source_dir
opt_flash=false
opt_quiet=false
opt_sound=false
opt_asm=false
opt_werror=false
opt_verbose=false
opt_osize=false
opt_testverbose=false
opt_testcoverage=true
COLOUR_GREEN='\033[0;32m'
COLOUR_YELLOW='\033[1;33m'
COLOUR_PURPLE='\033[0;35m'
COLOUR_RED='\033[0;31m'
COLOUR_OFF='\033[0;00m'
CLEAR_LINE='\033[2K'
_ERROR_="$COLOUR_RED[ERROR]$COLOUR_OFF"
_INFO_="$COLOUR_PURPLE[INFO]$COLOUR_OFF"
_DEBUG_="$COLOUR_YELLOW[DEBUG]$COLOUR_OFF"
stdin="/proc/$$/fd/0"
stdout="/proc/$$/fd/1"
stderr="/proc/$$/fd/2"
stdnull="/dev/null"
usage() {
echo "Usage: test [board]" >&2
}
print() {
if ! $opt_quiet
then
echo -e $@ >&$stdout
fi
}
print_err() {
if ! $opt_quiet
then
echo -e $@ >&$stderr
fi
}
flash() {
flash_args="";
if $opt_sound; then flash_args="-s"; fi
${source_dir}/flash ${flash_args} ${outdir}/${filename};
}
test_run() {
if [ ${board} == "gnulinux" ]
then
${source_dir}/${outdir}/${filename}
else
flash
fi
}
hyphenjoin() {
str=""
while [ $# -gt 0 ]
do
str="$str$1-"
shift
done
if [ ! -z "$str" ]
then
str="${str::-1}"
fi
echo "$str"
}
print_help() {
echo ""
echo " Usage: ./test [board]"
echo ""
echo " Options:"
echo ""
echo " -h Display this help and exit."
echo " -q Hide all messages apart from errors."
echo " -v Compile verbosely."
echo " -V Test verbosely."
echo " -m Also generate machine code output."
echo " -w Tell compiler to treat warnings as errors."
echo " -s Tell compiler to optimise for code size."
echo ""
}
## Read Flags
OPTIND=1
while getopts ":hmdsqvVw" opt; do
case "$opt" in
h) # Help
print_help
exit 0
;;
m) # ASM
opt_asm=true
;;
s) # Optimise for Size
opt_osize=true
;;
q) # Quiet
opt_quiet=true
;;
v) # Verbose
opt_verbose=true
;;
V) # Verbose Tests
opt_testverbose=true
;;
w) # Warnings as Errors
opt_werror=true
;;
?) # Illegal Option
print_err "$_ERROR_ Illegal option '$OPTARG'"
print_help
exit 3
;;
esac
done
for i in `seq 2 $OPTIND`; do shift; done
board=${1,,}
shift
## Check <program> argument
if [ -z "$board" ]; then
board="gnulinux" ## insert default option here
fi
## Set up Makefile Flags
githash="$(git describe --dirty --always)"
# Mark as dirty if untracked files exist
if [ -z "$(echo "$githash" | grep "dirty")" ] && [ ! -z "$(git status --porcelain | grep "^??")" ]; then
githash="$githash-dirty"
fi
outdir="builds"
filename="test-$(hyphenjoin $flags $githash)"
flags="BOARD=${board} RUNTESTS=true MAIN=../test OUTDIR=${outdir} OUTFILE=\"${filename}\""
cc="gcc-7"
gcov="gcov-7"
which ${cc} 1>/dev/null 2>&1
if [ $? != 0 ]; then
cc="gcc"
gcov="gcov"
print "$_INFO_$COLOUR_RED Warning: GCC 7.x not installed, using GCC $(${cc} -dumpversion).$COLOUR_OFF"
else
print "$_INFO_ Using GCC $(${cc} -dumpversion) $COLOUR_OFF"
fi
flags="${flags} CC=${cc}"
if $opt_osize; then
print "$_INFO_ Compiler optimise for size (-Os):$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} OSIZE_ON=true"
fi
if $opt_werror; then
print "$_INFO_ Compiler set Warnings as Errors:$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} WERROR_ON=true"
fi
if $opt_verbose; then
print "$_INFO_ Compiler Verbose:$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} VERBOSE_ON=true"
fi
if $opt_testverbose; then
print "$_INFO_ Tests Verbose:$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} TESTVERBOSE_ON=true"
fi
which lcov 1>/dev/null 2>&1
if [ $? != 0 ]; then
opt_testcoverage=false
print "$_INFO_$COLOUR_RED 'lcov' not installed, test coverage report disabled.$COLOUR_OFF"
else
flags="${flags} TESTCOVERAGE_ON=true"
fi
## Change to board directory, make clean, make, then print summary message.
cd "src/board/${board}"
make ${flags} clean \
&& print "$_INFO_ Compiling..$COLOUR_OFF" \
&& make ${flags} \
&& {
print "$_INFO_$COLOUR_GREEN Built: ${outdir}/${filename}$COLOUR_OFF"
} || {
print "$_ERROR_$COLOUR_RED There were errors in the build process$COLOUR_OFF" \
&& exit 1
} \
&& print "$_INFO_ Running Tests..$COLOUR_OFF" \
&& test_run \
&& {
print "$_INFO_$COLOUR_GREEN Tests Passed $COLOUR_OFF"
} || {
print "$_ERROR_$COLOUR_RED Tests Failed $COLOUR_OFF" \
&& exit 1
} \
&& {
if $opt_testcoverage; then
print "$_INFO_ Running Coverage Report..$COLOUR_OFF"
lcov -q --capture \
--gcov-tool ${gcov} \
--base-directory ${source_dir}/src/board/${board} \
--output-file ${source_dir}/${outdir}/${filename}-coverage.info \
--directory ${source_dir}/src/buffer/ \
--directory ${source_dir}/src/packet/ \
--directory ${source_dir}/src/configuration/ \
--directory ${source_dir}/src/mission/ \
--directory ${source_dir}/src/util/ \
--no-recursion
find ${source_dir}/src/ -name '*.gcno' -delete
find ${source_dir}/src/ -name '*.gcda' -delete
if $opt_testverbose; then
lcov -l \
${source_dir}/${outdir}/${filename}-coverage.info \
--gcov-tool ${gcov}
else
lcov --summary \
${source_dir}/${outdir}/${filename}-coverage.info \
--gcov-tool ${gcov}
fi
fi
}