Debian Codegraph @

third_party/heimdal/lib/hcrypto/libtommath/testme.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # return values of this script are:
4 # 0 success
5 # 128 a test failed
6 # >0 the number of timed-out tests
7 # 255 parsing of parameters failed
8
9 set -e
10
11 if [scip-shell system . . `[`. -f /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`. ]
12 then
13 MAKE_JOBS=$(( ($(catscip-shell system . . cat. /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`. | grepscip-shell system . . grep. -E '^processor[[:space:]]*:' | tailscip-shell system . . tail. -n -1 | cutscip-shell system . . cut. -d':' -f2) + 1) * 2 + 1 ))
14 else
15 MAKE_JOBS=8
16 fi
17
18 ret=0
19 TEST_CFLAGS=""
20
21 _helpscip-shell shell samba 2:4.24.3+dfsg-1 _help().()
22 {
23 echoscip-shell system . . echo. "Usage options for $(basenamescip-shell system . . basename. $0) [--with-cc=arg [other options]]"
24 echoscip-shell system . . echo.
25 echoscip-shell system . . echo. "Executing this script without any parameter will only run the default"
26 echoscip-shell system . . echo. "configuration that has automatically been determined for the"
27 echoscip-shell system . . echo. "architecture you're running."
28 echoscip-shell system . . echo.
29 echoscip-shell system . . echo. " --with-cc=* The compiler(s) to use for the tests"
30 echoscip-shell system . . echo. " This is an option that will be iterated."
31 echoscip-shell system . . echo.
32 echoscip-shell system . . echo. " --test-vs-mtest=* Run test vs. mtest for '*' operations."
33 echoscip-shell system . . echo. " Only the first of each options will be"
34 echoscip-shell system . . echo. " taken into account."
35 echoscip-shell system . . echo.
36 echoscip-shell system . . echo. "To be able to specify options a compiler has to be given with"
37 echoscip-shell system . . echo. "the option --with-cc=compilername"
38 echoscip-shell system . . echo. "All other options will be tested with all MP_xBIT configurations."
39 echoscip-shell system . . echo.
40 echoscip-shell system . . echo. " --with-{m64,m32,mx32} The architecture(s) to build and test"
41 echoscip-shell system . . echo. " for, e.g. --with-mx32."
42 echoscip-shell system . . echo. " This is an option that will be iterated,"
43 echoscip-shell system . . echo. " multiple selections are possible."
44 echoscip-shell system . . echo. " The mx32 architecture is not supported"
45 echoscip-shell system . . echo. " by clang and will not be executed."
46 echoscip-shell system . . echo.
47 echoscip-shell system . . echo. " --cflags=* Give an option to the compiler,"
48 echoscip-shell system . . echo. " e.g. --cflags=-g"
49 echoscip-shell system . . echo. " This is an option that will always be"
50 echoscip-shell system . . echo. " passed as parameter to CC."
51 echoscip-shell system . . echo.
52 echoscip-shell system . . echo. " --make-option=* Give an option to make,"
53 echoscip-shell system . . echo. " e.g. --make-option=\"-f makefile.shared\""
54 echoscip-shell system . . echo. " This is an option that will always be"
55 echoscip-shell system . . echo. " passed as parameter to make."
56 echoscip-shell system . . echo.
57 echoscip-shell system . . echo. " --with-low-mp Also build&run tests with -DMP_{8,16,32}BIT."
58 echoscip-shell system . . echo.
59 echoscip-shell system . . echo. " --mtest-real-rand Use real random data when running mtest."
60 echoscip-shell system . . echo.
61 echoscip-shell system . . echo. " --with-valgrind"
62 echoscip-shell system . . echo. " --with-valgrind=* Run in valgrind (slow!)."
63 echoscip-shell system . . echo.
64 echoscip-shell system . . echo. " --with-travis-valgrind Run with valgrind on Travis on specific branches."
65 echoscip-shell system . . echo.
66 echoscip-shell system . . echo. " --valgrind-options Additional Valgrind options"
67 echoscip-shell system . . echo. " Some of the options like e.g.:"
68 echoscip-shell system . . echo. " --track-origins=yes add a lot of extra"
69 echoscip-shell system . . echo. " runtime and may trigger the 30 minutes"
70 echoscip-shell system . . echo. " timeout."
71 echoscip-shell system . . echo.
72 echoscip-shell system . . echo. "Godmode:"
73 echoscip-shell system . . echo.
74 echoscip-shell system . . echo. " --all Choose all architectures and gcc and clang"
75 echoscip-shell system . . echo. " as compilers but does not run valgrind."
76 echoscip-shell system . . echo.
77 echoscip-shell system . . echo. " --format Runs the various source-code formatters"
78 echoscip-shell system . . echo. " and generators and checks if the sources"
79 echoscip-shell system . . echo. " are clean."
80 echoscip-shell system . . echo.
81 echoscip-shell system . . echo. " -h"
82 echoscip-shell system . . echo. " --help This message"
83 echoscip-shell system . . echo.
84 echoscip-shell system . . echo. " -v"
85 echoscip-shell system . . echo. " --version Prints the version. It is just the number"
86 echoscip-shell system . . echo. " of git commits to this file, no deeper"
87 echoscip-shell system . . echo. " meaning attached"
88 exit 0
89 }
90
91 _diescip-shell shell samba 2:4.24.3+dfsg-1 _die().()
92 {
93 echoscip-shell system . . echo. "error $2 while $1"
94 if [scip-shell system . . `[`. "$2" != "124" ]
95 then
96 exit 128
97 else
98 echoscip-shell system . . echo. "assuming timeout while running test - continue"
99 local _tail=""
100 whichscip-shell system . . which. tail >/dev/nullscip-shell filesystem . . `/dev/null`. && _tail="tail -n 1 test_${suffix}.log" && \
101 echo "last line of test_"${suffix}".log was:" && $_tail && echoscip-shell system . . echo. ""
102 ret=$(( $ret + 1 ))
103 fi
104 }
105
106 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make().()
107 {
108 echoscip-shell system . . echo. -ne " Compile $1 $2"
109 suffix=$(echoscip-shell system . . echo. ${1}${2} | trscip-shell system . . tr. ' ' '_')
110 CC="$1" CFLAGS="$2 $TEST_CFLAGS" makescip-shell system . . make. -j$MAKE_JOBS $3 $MAKE_OPTIONS > /dev/nullscip-shell filesystem . . `/dev/null`. 2>gcc_errors_${suffix}.log
111 errcnt=$(wcscip-shell system . . wc. -l < gcc_errors_${suffix}.log)
112 if [[ ${errcnt} -gt 1 ]]; then
113 echoscip-shell system . . echo. " failed"
114 catscip-shell system . . cat. gcc_errors_${suffix}.log
115 exit 128
116 fi
117 }
118
119
120 _runtestscip-shell shell samba 2:4.24.3+dfsg-1 _runtest().()
121 {
122 makescip-shell system . . make. clean > /dev/nullscip-shell filesystem . . `/dev/null`.
123 local _timeout=""
124 whichscip-shell system . . which. timeout >/dev/nullscip-shell filesystem . . `/dev/null`. && _timeout="timeout --foreground 90"
125 if [[ "$MAKE_OPTIONS" =~ "tune" ]]
126 then
127 # "make tune" will run "tune_it.sh" automatically, hence "autotune", but it cannot
128 # get switched off without some effort, so we just let it run twice for testing purposes
129 echoscip-shell system . . echo. -e "\rRun autotune $1 $2"
130 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make(). "$1" "$2" ""
131 $_timeout $TUNE_CMD > test_${suffix}.log || _diescip-shell shell samba 2:4.24.3+dfsg-1 _die(). "running autotune" $?
132 else
133 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make(). "$1" "$2" "test"
134 echoscip-shell system . . echo. -e "\rRun test $1 $2"
135 $_timeout ./test > test_${suffix}.log || _diescip-shell shell samba 2:4.24.3+dfsg-1 _die(). "running tests" $?
136 fi
137 }
138
139 # This is not much more of a C&P of _runtest with a different timeout
140 # and the additional valgrind call.
141 # TODO: merge
142 _runvalgrindscip-shell shell samba 2:4.24.3+dfsg-1 _runvalgrind().()
143 {
144 makescip-shell system . . make. clean > /dev/nullscip-shell filesystem . . `/dev/null`.
145 local _timeout=""
146 # 30 minutes? Yes. Had it at 20 minutes and the Valgrind run needed over 25 minutes.
147 # A bit too close for comfort.
148 whichscip-shell system . . which. timeout >/dev/nullscip-shell filesystem . . `/dev/null`. && _timeout="timeout --foreground 1800"
149 echoscip-shell system . . echo. "MAKE_OPTIONS = \"$MAKE_OPTIONS\""
150 if [[ "$MAKE_OPTIONS" =~ "tune" ]]
151 then
152 echoscip-shell system . . echo. "autotune branch"
153 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make(). "$1" "$2" ""
154 # The shell used for /bin/sh is DASH 0.5.7-4ubuntu1 on the author's machine which fails valgrind, so
155 # we just run on instance of etc/tune with the same options as in etc/tune_it.sh
156 echoscip-shell system . . echo. -e "\rRun etc/tune $1 $2 once inside valgrind"
157 $_timeout $VALGRIND_BIN $VALGRIND_OPTS $TUNE_CMD > test_${suffix}.log || _diescip-shell shell samba 2:4.24.3+dfsg-1 _die(). "running etc/tune" $?
158 else
159 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make(). "$1" "$2" "test"
160 echoscip-shell system . . echo. -e "\rRun test $1 $2 inside valgrind"
161 $_timeout $VALGRIND_BIN $VALGRIND_OPTS ./test > test_${suffix}.log || _diescip-shell shell samba 2:4.24.3+dfsg-1 _die(). "running tests" $?
162 fi
163 }
164
165
166 _bannerscip-shell shell samba 2:4.24.3+dfsg-1 _banner().()
167 {
168 echoscip-shell system . . echo. "uname="$(unamescip-shell system . . uname. -a)
169 [[ "$#" != "0" ]] && (echoscip-shell system . . echo. $1=$($1 -dumpversion)) || truescip-shell system . . true.
170 }
171
172 _exitscip-shell shell samba 2:4.24.3+dfsg-1 _exit().()
173 {
174 if [scip-shell system . . `[`. "$ret" == "0" ]
175 then
176 echoscip-shell system . . echo. "Tests successful"
177 else
178 echoscip-shell system . . echo. "$ret tests timed out"
179 fi
180
181 exit $ret
182 }
183
184 ARCHFLAGS=""
185 COMPILERS=""
186 CFLAGS=""
187 WITH_LOW_MP=""
188 TEST_VS_MTEST=""
189 MTEST_RAND=""
190 # timed with an AMD A8-6600K
191 # 25 minutes
192 #VALGRIND_OPTS=" --track-origins=yes --leak-check=full --show-leak-kinds=all --error-exitcode=1 "
193 # 9 minutes (14 minutes with --test-vs-mtest=333333 --mtest-real-rand)
194 VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 "
195 #VALGRIND_OPTS=""
196 VALGRIND_BIN=""
197 CHECK_FORMAT=""
198 TUNE_CMD="./etc/tune -t -r 10 -L 3"
199
200 alive_pid=0
201
202 function kill_alivescip-shell shell samba 2:4.24.3+dfsg-1 kill_alive().() {
203 disown $alive_pid || truescip-shell system . . true.
204 killscip-shell system . . kill. $alive_pid 2>/dev/nullscip-shell filesystem . . `/dev/null`.
205 }
206
207 function start_alive_printingscip-shell shell samba 2:4.24.3+dfsg-1 start_alive_printing().() {
208 [scip-shell system . . `[`. "$alive_pid" == "0" ] || return 0;
209 for i in `seqscip-shell system . . seq. 1 10` ; do sleepscip-shell system . . sleep. 300 && echoscip-shell system . . echo. "Tests still in Progress..."; done &
210 alive_pid=$!
211 trap kill_alive EXIT
212 }
213
214 while [scip-shell system . . `[`. $# -gt 0 ];
215 do
216 case $1 in
217 "--with-m64" | "--with-m32" | "--with-mx32")
218 ARCHFLAGS="$ARCHFLAGS ${1:6}"
219 ;;
220 --with-cc=*)
221 COMPILERS="$COMPILERS ${1#*=}"
222 ;;
223 --cflags=*)
224 CFLAGS="$CFLAGS ${1#*=}"
225 ;;
226 --valgrind-options=*)
227 VALGRIND_OPTS="$VALGRIND_OPTS ${1#*=}"
228 ;;
229 --with-valgrind*)
230 if [[ ${1#*d} != "" ]]
231 then
232 VALGRIND_BIN="${1#*=}"
233 else
234 VALGRIND_BIN="valgrind"
235 fi
236 start_alive_printingscip-shell shell samba 2:4.24.3+dfsg-1 start_alive_printing().
237 ;;
238 --with-travis-valgrind*)
239 if [[ ("$TRAVIS_BRANCH" == "develop" && "$TRAVIS_PULL_REQUEST" == "false") || "$TRAVIS_BRANCH" == *"valgrind"* || "$TRAVIS_COMMIT_MESSAGE" == *"valgrind"* ]]
240 then
241 if [[ ${1#*d} != "" ]]
242 then
243 VALGRIND_BIN="${1#*=}"
244 else
245 VALGRIND_BIN="valgrind"
246 fi
247 start_alive_printingscip-shell shell samba 2:4.24.3+dfsg-1 start_alive_printing().
248 fi
249 ;;
250 --make-option=*)
251 MAKE_OPTIONS="$MAKE_OPTIONS ${1#*=}"
252 ;;
253 --with-low-mp)
254 WITH_LOW_MP="1"
255 ;;
256 --test-vs-mtest=*)
257 TEST_VS_MTEST="${1#*=}"
258 if ! [scip-shell system . . `[`. "$TEST_VS_MTEST" -eq "$TEST_VS_MTEST" ] 2> /dev/nullscip-shell filesystem . . `/dev/null`.
259 then
260 echoscip-shell system . . echo. "--test-vs-mtest Parameter has to be int"
261 exit 255
262 fi
263 start_alive_printingscip-shell shell samba 2:4.24.3+dfsg-1 start_alive_printing().
264 ;;
265 --mtest-real-rand)
266 MTEST_RAND="-DLTM_MTEST_REAL_RAND"
267 ;;
268 --format)
269 CHECK_FORMAT="1"
270 ;;
271 --all)
272 COMPILERS="gcc clang"
273 ARCHFLAGS="-m64 -m32 -mx32"
274 ;;
275 --help | -h)
276 _helpscip-shell shell samba 2:4.24.3+dfsg-1 _help().
277 ;;
278 --version | -v)
279 echoscip-shell system . . echo. $(gitscip-shell system . . git. rev-list HEAD --count -- testme.sh) || echoscip-shell system . . echo. "Unknown. Please run in original libtommath git repository."
280 exit 0
281 ;;
282 *)
283 echoscip-shell system . . echo. "Ignoring option ${1}"
284 ;;
285 esac
286 shift
287 done
288
289 function _check_gitscip-shell shell samba 2:4.24.3+dfsg-1 _check_git().() {
290 gitscip-shell system . . git. update-index --refresh >/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
291 gitscip-shell system . . git. diff-index --quiet HEAD -- . || ( echoscip-shell system . . echo. "FAILURE: $*" && exit 1 )
292 }
293
294 if [[ "$CHECK_FORMAT" == "1" ]]
295 then
296 makescip-shell system . . make. astyle
297 _check_gitscip-shell shell samba 2:4.24.3+dfsg-1 _check_git(). "make astyle"
298 perlscip-shell system . . perl. helper.pl --update-files
299 _check_gitscip-shell shell samba 2:4.24.3+dfsg-1 _check_git(). "helper.pl --update-files"
300 perlscip-shell system . . perl. helper.pl --check-all
301 _check_gitscip-shell shell samba 2:4.24.3+dfsg-1 _check_git(). "helper.pl --check-all"
302 exit $?
303 fi
304
305 [[ "$VALGRIND_BIN" == "" ]] && VALGRIND_OPTS=""
306
307 # default to CC environment variable if no compiler is defined but some other options
308 if [[ "$COMPILERS" == "" ]] && [[ "$ARCHFLAGS$MAKE_OPTIONS$CFLAGS" != "" ]]
309 then
310 COMPILERS="$CC"
311 # default to CC environment variable and run only default config if no option is given
312 elif [[ "$COMPILERS" == "" ]]
313 then
314 _bannerscip-shell shell samba 2:4.24.3+dfsg-1 _banner(). "$CC"
315 if [[ "$VALGRIND_BIN" != "" ]]
316 then
317 _runvalgrindscip-shell shell samba 2:4.24.3+dfsg-1 _runvalgrind(). "$CC" ""
318 else
319 _runtestscip-shell shell samba 2:4.24.3+dfsg-1 _runtest(). "$CC" ""
320 fi
321 _exitscip-shell shell samba 2:4.24.3+dfsg-1 _exit().
322 fi
323
324
325 archflags=( $ARCHFLAGS )
326 compilers=( $COMPILERS )
327
328 # choosing a compiler without specifying an architecture will use the default architecture
329 if [scip-shell system . . `[`. "${#archflags[@]}" == "0" ]
330 then
331 archflags[0]=" "
332 fi
333
334 _bannerscip-shell shell samba 2:4.24.3+dfsg-1 _banner().
335
336 if [[ "$TEST_VS_MTEST" != "" ]]
337 then
338 makescip-shell system . . make. clean > /dev/nullscip-shell filesystem . . `/dev/null`.
339 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make(). "${compilers[0]} ${archflags[0]}" "$CFLAGS" "mtest_opponent"
340 echoscip-shell system . . echo.
341 _makescip-shell shell samba 2:4.24.3+dfsg-1 _make(). "gcc" "$MTEST_RAND" "mtest"
342 echoscip-shell system . . echo.
343 echoscip-shell system . . echo. "Run test vs. mtest for $TEST_VS_MTEST iterations"
344 _timeout=""
345 whichscip-shell system . . which. timeout >/dev/nullscip-shell filesystem . . `/dev/null`. && _timeout="timeout --foreground 1800"
346 $_timeout ./mtest/mtest $TEST_VS_MTEST | $VALGRIND_BIN $VALGRIND_OPTS ./mtest_opponent > valgrind_test.log 2> test_vs_mtest_err.log
347 retval=$?
348 headscip-shell system . . head. -n 5 valgrind_test.log
349 tailscip-shell system . . tail. -n 2 valgrind_test.log
350 exit $retval
351 fi
352
353 for i in "${compilers[@]}"
354 do
355 if [scip-shell system . . `[`. -z "$(whichscip-shell system . . which. $i)" ]
356 then
357 echoscip-shell system . . echo. "Skipped compiler $i, file not found"
358 continue
359 fi
360 compiler_version=$(echoscip-shell system . . echo. "$i="$($i -dumpversion))
361 if [scip-shell system . . `[`. "$compiler_version" == "clang=4.2.1" ]
362 then
363 # one of my versions of clang complains about some stuff in stdio.h and stdarg.h ...
364 TEST_CFLAGS="-Wno-typedef-redefinition"
365 else
366 TEST_CFLAGS=""
367 fi
368 echoscip-shell system . . echo. $compiler_version
369
370 for a in "${archflags[@]}"
371 do
372 if [[ $(expr "$i" : "clang") -ne 0 && "$a" == "-mx32" ]]
373 then
374 echoscip-shell system . . echo. "clang -mx32 tests skipped"
375 continue
376 fi
377 if [[ "$VALGRIND_BIN" != "" ]]
378 then
379 _runvalgrindscip-shell shell samba 2:4.24.3+dfsg-1 _runvalgrind(). "$i $a" "$CFLAGS"
380 [scip-shell system . . `[`. "$WITH_LOW_MP" != "1" ] && continue
381 _runvalgrindscip-shell shell samba 2:4.24.3+dfsg-1 _runvalgrind(). "$i $a" "-DMP_8BIT $CFLAGS"
382 _runvalgrindscip-shell shell samba 2:4.24.3+dfsg-1 _runvalgrind(). "$i $a" "-DMP_16BIT $CFLAGS"
383 _runvalgrindscip-shell shell samba 2:4.24.3+dfsg-1 _runvalgrind(). "$i $a" "-DMP_32BIT $CFLAGS"
384 else
385 _runtestscip-shell shell samba 2:4.24.3+dfsg-1 _runtest(). "$i $a" "$CFLAGS"
386 [scip-shell system . . `[`. "$WITH_LOW_MP" != "1" ] && continue
387 _runtestscip-shell shell samba 2:4.24.3+dfsg-1 _runtest(). "$i $a" "-DMP_8BIT $CFLAGS"
388 _runtestscip-shell shell samba 2:4.24.3+dfsg-1 _runtest(). "$i $a" "-DMP_16BIT $CFLAGS"
389 _runtestscip-shell shell samba 2:4.24.3+dfsg-1 _runtest(). "$i $a" "-DMP_32BIT $CFLAGS"
390 fi
391 done
392 done
393
394 _exitscip-shell shell samba 2:4.24.3+dfsg-1 _exit().