Mercurial > dropbear
comparison libtommath/testme.sh @ 1692:1051e4eea25a
Update LibTomMath to 1.2.0 (#84)
* update C files
* update other files
* update headers
* update makefiles
* remove mp_set/get_double()
* use ltm 1.2.0 API
* update ltm_desc
* use bundled tommath if system-tommath is too old
* XMALLOC etc. were changed to MP_MALLOC etc.
author | Steffen Jaeckel <s@jaeckel.eu> |
---|---|
date | Tue, 26 May 2020 17:36:47 +0200 |
parents | f52919ffd3b1 |
children |
comparison
equal
deleted
inserted
replaced
1691:2d3745d58843 | 1692:1051e4eea25a |
---|---|
2 # | 2 # |
3 # return values of this script are: | 3 # return values of this script are: |
4 # 0 success | 4 # 0 success |
5 # 128 a test failed | 5 # 128 a test failed |
6 # >0 the number of timed-out tests | 6 # >0 the number of timed-out tests |
7 # 255 parsing of parameters failed | |
7 | 8 |
8 set -e | 9 set -e |
9 | 10 |
10 if [ -f /proc/cpuinfo ] | 11 if [ -f /proc/cpuinfo ] |
11 then | 12 then |
19 | 20 |
20 _help() | 21 _help() |
21 { | 22 { |
22 echo "Usage options for $(basename $0) [--with-cc=arg [other options]]" | 23 echo "Usage options for $(basename $0) [--with-cc=arg [other options]]" |
23 echo | 24 echo |
24 echo "Executing this script without any parameter will only run the default configuration" | 25 echo "Executing this script without any parameter will only run the default" |
25 echo "that has automatically been determined for the architecture you're running." | 26 echo "configuration that has automatically been determined for the" |
27 echo "architecture you're running." | |
26 echo | 28 echo |
27 echo " --with-cc=* The compiler(s) to use for the tests" | 29 echo " --with-cc=* The compiler(s) to use for the tests" |
28 echo " This is an option that will be iterated." | 30 echo " This is an option that will be iterated." |
29 echo | 31 echo |
30 echo " --test-vs-mtest=* Run test vs. mtest for '*' operations." | 32 echo " --test-vs-mtest=* Run test vs. mtest for '*' operations." |
31 echo " Only the first of each options will be taken into account." | 33 echo " Only the first of each options will be" |
32 echo | 34 echo " taken into account." |
33 echo "To be able to specify options a compiler has to be given." | 35 echo |
34 echo "All options will be tested with all MP_xBIT configurations." | 36 echo "To be able to specify options a compiler has to be given with" |
35 echo | 37 echo "the option --with-cc=compilername" |
36 echo " --with-{m64,m32,mx32} The architecture(s) to build and test for," | 38 echo "All other options will be tested with all MP_xBIT configurations." |
37 echo " e.g. --with-mx32." | 39 echo |
38 echo " This is an option that will be iterated, multiple selections are possible." | 40 echo " --with-{m64,m32,mx32} The architecture(s) to build and test" |
39 echo " The mx32 architecture is not supported by clang and will not be executed." | 41 echo " for, e.g. --with-mx32." |
42 echo " This is an option that will be iterated," | |
43 echo " multiple selections are possible." | |
44 echo " The mx32 architecture is not supported" | |
45 echo " by clang and will not be executed." | |
40 echo | 46 echo |
41 echo " --cflags=* Give an option to the compiler," | 47 echo " --cflags=* Give an option to the compiler," |
42 echo " e.g. --cflags=-g" | 48 echo " e.g. --cflags=-g" |
43 echo " This is an option that will always be passed as parameter to CC." | 49 echo " This is an option that will always be" |
50 echo " passed as parameter to CC." | |
44 echo | 51 echo |
45 echo " --make-option=* Give an option to make," | 52 echo " --make-option=* Give an option to make," |
46 echo " e.g. --make-option=\"-f makefile.shared\"" | 53 echo " e.g. --make-option=\"-f makefile.shared\"" |
47 echo " This is an option that will always be passed as parameter to make." | 54 echo " This is an option that will always be" |
55 echo " passed as parameter to make." | |
48 echo | 56 echo |
49 echo " --with-low-mp Also build&run tests with -DMP_{8,16,32}BIT." | 57 echo " --with-low-mp Also build&run tests with -DMP_{8,16,32}BIT." |
50 echo | 58 echo |
51 echo " --mtest-real-rand Use real random data when running mtest." | 59 echo " --mtest-real-rand Use real random data when running mtest." |
52 echo | 60 echo |
61 echo " --with-valgrind" | |
62 echo " --with-valgrind=* Run in valgrind (slow!)." | |
63 echo | |
64 echo " --with-travis-valgrind Run with valgrind on Travis on specific branches." | |
65 echo | |
66 echo " --valgrind-options Additional Valgrind options" | |
67 echo " Some of the options like e.g.:" | |
68 echo " --track-origins=yes add a lot of extra" | |
69 echo " runtime and may trigger the 30 minutes" | |
70 echo " timeout." | |
71 echo | |
53 echo "Godmode:" | 72 echo "Godmode:" |
54 echo | 73 echo |
55 echo " --all Choose all architectures and gcc and clang as compilers" | 74 echo " --all Choose all architectures and gcc and clang" |
56 echo | 75 echo " as compilers but does not run valgrind." |
76 echo | |
77 echo " --format Runs the various source-code formatters" | |
78 echo " and generators and checks if the sources" | |
79 echo " are clean." | |
80 echo | |
81 echo " -h" | |
57 echo " --help This message" | 82 echo " --help This message" |
83 echo | |
84 echo " -v" | |
85 echo " --version Prints the version. It is just the number" | |
86 echo " of git commits to this file, no deeper" | |
87 echo " meaning attached" | |
58 exit 0 | 88 exit 0 |
59 } | 89 } |
60 | 90 |
61 _die() | 91 _die() |
62 { | 92 { |
88 | 118 |
89 | 119 |
90 _runtest() | 120 _runtest() |
91 { | 121 { |
92 make clean > /dev/null | 122 make clean > /dev/null |
93 _make "$1" "$2" "test_standalone" | |
94 local _timeout="" | 123 local _timeout="" |
95 which timeout >/dev/null && _timeout="timeout --foreground 90" | 124 which timeout >/dev/null && _timeout="timeout --foreground 90" |
96 echo -e "\rRun test $1 $2" | 125 if [[ "$MAKE_OPTIONS" =~ "tune" ]] |
97 $_timeout ./test > test_${suffix}.log || _die "running tests" $? | 126 then |
98 } | 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 echo -e "\rRun autotune $1 $2" | |
130 _make "$1" "$2" "" | |
131 $_timeout $TUNE_CMD > test_${suffix}.log || _die "running autotune" $? | |
132 else | |
133 _make "$1" "$2" "test" | |
134 echo -e "\rRun test $1 $2" | |
135 $_timeout ./test > test_${suffix}.log || _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 _runvalgrind() | |
143 { | |
144 make clean > /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 which timeout >/dev/null && _timeout="timeout --foreground 1800" | |
149 echo "MAKE_OPTIONS = \"$MAKE_OPTIONS\"" | |
150 if [[ "$MAKE_OPTIONS" =~ "tune" ]] | |
151 then | |
152 echo "autotune branch" | |
153 _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 echo -e "\rRun etc/tune $1 $2 once inside valgrind" | |
157 $_timeout $VALGRIND_BIN $VALGRIND_OPTS $TUNE_CMD > test_${suffix}.log || _die "running etc/tune" $? | |
158 else | |
159 _make "$1" "$2" "test" | |
160 echo -e "\rRun test $1 $2 inside valgrind" | |
161 $_timeout $VALGRIND_BIN $VALGRIND_OPTS ./test > test_${suffix}.log || _die "running tests" $? | |
162 fi | |
163 } | |
164 | |
99 | 165 |
100 _banner() | 166 _banner() |
101 { | 167 { |
102 echo "uname="$(uname -a) | 168 echo "uname="$(uname -a) |
103 [[ "$#" != "0" ]] && (echo $1=$($1 -dumpversion)) || true | 169 [[ "$#" != "0" ]] && (echo $1=$($1 -dumpversion)) || true |
119 COMPILERS="" | 185 COMPILERS="" |
120 CFLAGS="" | 186 CFLAGS="" |
121 WITH_LOW_MP="" | 187 WITH_LOW_MP="" |
122 TEST_VS_MTEST="" | 188 TEST_VS_MTEST="" |
123 MTEST_RAND="" | 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_alive() { | |
203 disown $alive_pid || true | |
204 kill $alive_pid 2>/dev/null | |
205 } | |
206 | |
207 function start_alive_printing() { | |
208 [ "$alive_pid" == "0" ] || return 0; | |
209 for i in `seq 1 10` ; do sleep 300 && echo "Tests still in Progress..."; done & | |
210 alive_pid=$! | |
211 trap kill_alive EXIT | |
212 } | |
124 | 213 |
125 while [ $# -gt 0 ]; | 214 while [ $# -gt 0 ]; |
126 do | 215 do |
127 case $1 in | 216 case $1 in |
128 "--with-m64" | "--with-m32" | "--with-mx32") | 217 "--with-m64" | "--with-m32" | "--with-mx32") |
132 COMPILERS="$COMPILERS ${1#*=}" | 221 COMPILERS="$COMPILERS ${1#*=}" |
133 ;; | 222 ;; |
134 --cflags=*) | 223 --cflags=*) |
135 CFLAGS="$CFLAGS ${1#*=}" | 224 CFLAGS="$CFLAGS ${1#*=}" |
136 ;; | 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_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_printing | |
248 fi | |
249 ;; | |
137 --make-option=*) | 250 --make-option=*) |
138 MAKE_OPTIONS="$MAKE_OPTIONS ${1#*=}" | 251 MAKE_OPTIONS="$MAKE_OPTIONS ${1#*=}" |
139 ;; | 252 ;; |
140 --with-low-mp) | 253 --with-low-mp) |
141 WITH_LOW_MP="1" | 254 WITH_LOW_MP="1" |
143 --test-vs-mtest=*) | 256 --test-vs-mtest=*) |
144 TEST_VS_MTEST="${1#*=}" | 257 TEST_VS_MTEST="${1#*=}" |
145 if ! [ "$TEST_VS_MTEST" -eq "$TEST_VS_MTEST" ] 2> /dev/null | 258 if ! [ "$TEST_VS_MTEST" -eq "$TEST_VS_MTEST" ] 2> /dev/null |
146 then | 259 then |
147 echo "--test-vs-mtest Parameter has to be int" | 260 echo "--test-vs-mtest Parameter has to be int" |
148 exit -1 | 261 exit 255 |
149 fi | 262 fi |
263 start_alive_printing | |
150 ;; | 264 ;; |
151 --mtest-real-rand) | 265 --mtest-real-rand) |
152 MTEST_RAND="-DLTM_MTEST_REAL_RAND" | 266 MTEST_RAND="-DLTM_MTEST_REAL_RAND" |
267 ;; | |
268 --format) | |
269 CHECK_FORMAT="1" | |
153 ;; | 270 ;; |
154 --all) | 271 --all) |
155 COMPILERS="gcc clang" | 272 COMPILERS="gcc clang" |
156 ARCHFLAGS="-m64 -m32 -mx32" | 273 ARCHFLAGS="-m64 -m32 -mx32" |
157 ;; | 274 ;; |
158 --help | -h) | 275 --help | -h) |
159 _help | 276 _help |
160 ;; | 277 ;; |
278 --version | -v) | |
279 echo $(git rev-list HEAD --count -- testme.sh) || echo "Unknown. Please run in original libtommath git repository." | |
280 exit 0 | |
281 ;; | |
161 *) | 282 *) |
162 echo "Ignoring option ${1}" | 283 echo "Ignoring option ${1}" |
163 ;; | 284 ;; |
164 esac | 285 esac |
165 shift | 286 shift |
166 done | 287 done |
167 | 288 |
168 # default to gcc if no compiler is defined but some other options | 289 function _check_git() { |
290 git update-index --refresh >/dev/null || true | |
291 git diff-index --quiet HEAD -- . || ( echo "FAILURE: $*" && exit 1 ) | |
292 } | |
293 | |
294 if [[ "$CHECK_FORMAT" == "1" ]] | |
295 then | |
296 make astyle | |
297 _check_git "make astyle" | |
298 perl helper.pl --update-files | |
299 _check_git "helper.pl --update-files" | |
300 perl helper.pl --check-all | |
301 _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 | |
169 if [[ "$COMPILERS" == "" ]] && [[ "$ARCHFLAGS$MAKE_OPTIONS$CFLAGS" != "" ]] | 308 if [[ "$COMPILERS" == "" ]] && [[ "$ARCHFLAGS$MAKE_OPTIONS$CFLAGS" != "" ]] |
170 then | 309 then |
171 COMPILERS="gcc" | 310 COMPILERS="$CC" |
172 # default to gcc and run only default config if no option is given | 311 # default to CC environment variable and run only default config if no option is given |
173 elif [[ "$COMPILERS" == "" ]] | 312 elif [[ "$COMPILERS" == "" ]] |
174 then | 313 then |
175 _banner gcc | 314 _banner "$CC" |
176 _runtest "gcc" "" | 315 if [[ "$VALGRIND_BIN" != "" ]] |
316 then | |
317 _runvalgrind "$CC" "" | |
318 else | |
319 _runtest "$CC" "" | |
320 fi | |
177 _exit | 321 _exit |
178 fi | 322 fi |
323 | |
179 | 324 |
180 archflags=( $ARCHFLAGS ) | 325 archflags=( $ARCHFLAGS ) |
181 compilers=( $COMPILERS ) | 326 compilers=( $COMPILERS ) |
182 | 327 |
183 # choosing a compiler without specifying an architecture will use the default architecture | 328 # choosing a compiler without specifying an architecture will use the default architecture |
189 _banner | 334 _banner |
190 | 335 |
191 if [[ "$TEST_VS_MTEST" != "" ]] | 336 if [[ "$TEST_VS_MTEST" != "" ]] |
192 then | 337 then |
193 make clean > /dev/null | 338 make clean > /dev/null |
194 _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "test" | 339 _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "mtest_opponent" |
195 echo | 340 echo |
196 _make "gcc" "$MTEST_RAND" "mtest" | 341 _make "gcc" "$MTEST_RAND" "mtest" |
197 echo | 342 echo |
198 echo "Run test vs. mtest for $TEST_VS_MTEST iterations" | 343 echo "Run test vs. mtest for $TEST_VS_MTEST iterations" |
199 for i in `seq 1 10` ; do sleep 500 && echo alive; done & | |
200 alive_pid=$! | |
201 _timeout="" | 344 _timeout="" |
202 which timeout >/dev/null && _timeout="timeout --foreground 900" | 345 which timeout >/dev/null && _timeout="timeout --foreground 1800" |
203 $_TIMEOUT ./mtest/mtest $TEST_VS_MTEST | ./test > test.log | 346 $_timeout ./mtest/mtest $TEST_VS_MTEST | $VALGRIND_BIN $VALGRIND_OPTS ./mtest_opponent > valgrind_test.log 2> test_vs_mtest_err.log |
204 disown $alive_pid | 347 retval=$? |
205 kill $alive_pid 2>/dev/null | 348 head -n 5 valgrind_test.log |
206 head -n 5 test.log | 349 tail -n 2 valgrind_test.log |
207 tail -n 2 test.log | 350 exit $retval |
208 exit 0 | |
209 fi | 351 fi |
210 | 352 |
211 for i in "${compilers[@]}" | 353 for i in "${compilers[@]}" |
212 do | 354 do |
213 if [ -z "$(which $i)" ] | 355 if [ -z "$(which $i)" ] |
230 if [[ $(expr "$i" : "clang") -ne 0 && "$a" == "-mx32" ]] | 372 if [[ $(expr "$i" : "clang") -ne 0 && "$a" == "-mx32" ]] |
231 then | 373 then |
232 echo "clang -mx32 tests skipped" | 374 echo "clang -mx32 tests skipped" |
233 continue | 375 continue |
234 fi | 376 fi |
235 | 377 if [[ "$VALGRIND_BIN" != "" ]] |
236 _runtest "$i $a" "$CFLAGS" | 378 then |
237 [ "$WITH_LOW_MP" != "1" ] && continue | 379 _runvalgrind "$i $a" "$CFLAGS" |
238 _runtest "$i $a" "-DMP_8BIT $CFLAGS" | 380 [ "$WITH_LOW_MP" != "1" ] && continue |
239 _runtest "$i $a" "-DMP_16BIT $CFLAGS" | 381 _runvalgrind "$i $a" "-DMP_8BIT $CFLAGS" |
240 _runtest "$i $a" "-DMP_32BIT $CFLAGS" | 382 _runvalgrind "$i $a" "-DMP_16BIT $CFLAGS" |
383 _runvalgrind "$i $a" "-DMP_32BIT $CFLAGS" | |
384 else | |
385 _runtest "$i $a" "$CFLAGS" | |
386 [ "$WITH_LOW_MP" != "1" ] && continue | |
387 _runtest "$i $a" "-DMP_8BIT $CFLAGS" | |
388 _runtest "$i $a" "-DMP_16BIT $CFLAGS" | |
389 _runtest "$i $a" "-DMP_32BIT $CFLAGS" | |
390 fi | |
241 done | 391 done |
242 done | 392 done |
243 | 393 |
244 _exit | 394 _exit |