comparison libtommath/testme.sh @ 1436:60fc6476e044

Update to libtommath v1.0
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 22:37:14 +0800
parents
children 8bba51a55704
comparison
equal deleted inserted replaced
1435:f849a5ca2efc 1436:60fc6476e044
1 #!/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
8 set -e
9
10 if [ -f /proc/cpuinfo ]
11 then
12 MAKE_JOBS=$(( ($(cat /proc/cpuinfo | grep -E '^processor[[:space:]]*:' | tail -n -1 | cut -d':' -f2) + 1) * 2 + 1 ))
13 else
14 MAKE_JOBS=8
15 fi
16
17 ret=0
18 TEST_CFLAGS=""
19
20 _help()
21 {
22 echo "Usage options for $(basename $0) [--with-cc=arg [other options]]"
23 echo
24 echo "Executing this script without any parameter will only run the default configuration"
25 echo "that has automatically been determined for the architecture you're running."
26 echo
27 echo " --with-cc=* The compiler(s) to use for the tests"
28 echo " This is an option that will be iterated."
29 echo
30 echo "To be able to specify options a compiler has to be given."
31 echo "All options will be tested with all MP_xBIT configurations."
32 echo
33 echo " --with-{m64,m32,mx32} The architecture(s) to build and test for,"
34 echo " e.g. --with-mx32."
35 echo " This is an option that will be iterated, multiple selections are possible."
36 echo " The mx32 architecture is not supported by clang and will not be executed."
37 echo
38 echo " --cflags=* Give an option to the compiler,"
39 echo " e.g. --cflags=-g"
40 echo " This is an option that will always be passed as parameter to CC."
41 echo
42 echo " --make-option=* Give an option to make,"
43 echo " e.g. --make-option=\"-f makefile.shared\""
44 echo " This is an option that will always be passed as parameter to make."
45 echo
46 echo "Godmode:"
47 echo
48 echo " --all Choose all architectures and gcc and clang as compilers"
49 echo
50 echo " --help This message"
51 exit 0
52 }
53
54 _die()
55 {
56 echo "error $2 while $1"
57 if [ "$2" != "124" ]
58 then
59 exit 128
60 else
61 echo "assuming timeout while running test - continue"
62 ret=$(( $ret + 1 ))
63 fi
64 }
65
66 _runtest()
67 {
68 echo -ne " Compile $1 $2"
69 make clean > /dev/null
70 CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS test_standalone $MAKE_OPTIONS > /dev/null 2>test_errors.txt
71 echo -e "\rRun test $1 $2"
72 timeout --foreground 90 ./test > test_$(echo ${1}${2} | tr ' ' '_').txt || _die "running tests" $?
73 }
74
75 _banner()
76 {
77 echo "uname="$(uname -a)
78 [[ "$#" != "0" ]] && (echo $1=$($1 -dumpversion)) || true
79 }
80
81 _exit()
82 {
83 if [ "$ret" == "0" ]
84 then
85 echo "Tests successful"
86 else
87 echo "$ret tests timed out"
88 fi
89
90 exit $ret
91 }
92
93 ARCHFLAGS=""
94 COMPILERS=""
95 CFLAGS=""
96
97 while [ $# -gt 0 ];
98 do
99 case $1 in
100 "--with-m64" | "--with-m32" | "--with-mx32")
101 ARCHFLAGS="$ARCHFLAGS ${1:6}"
102 ;;
103 --with-cc=*)
104 COMPILERS="$COMPILERS ${1#*=}"
105 ;;
106 --cflags=*)
107 CFLAGS="$CFLAGS ${1#*=}"
108 ;;
109 --make-option=*)
110 MAKE_OPTIONS="$MAKE_OPTIONS ${1#*=}"
111 ;;
112 --all)
113 COMPILERS="gcc clang"
114 ARCHFLAGS="-m64 -m32 -mx32"
115 ;;
116 --help)
117 _help
118 ;;
119 esac
120 shift
121 done
122
123 # default to gcc if nothing is given
124 if [[ "$COMPILERS" == "" ]]
125 then
126 _banner gcc
127 _runtest "gcc" ""
128 _exit
129 fi
130
131 archflags=( $ARCHFLAGS )
132 compilers=( $COMPILERS )
133
134 # choosing a compiler without specifying an architecture will use the default architecture
135 if [ "${#archflags[@]}" == "0" ]
136 then
137 archflags[0]=" "
138 fi
139
140 _banner
141
142 for i in "${compilers[@]}"
143 do
144 if [ -z "$(which $i)" ]
145 then
146 echo "Skipped compiler $i, file not found"
147 continue
148 fi
149 compiler_version=$(echo "$i="$($i -dumpversion))
150 if [ "$compiler_version" == "clang=4.2.1" ]
151 then
152 # one of my versions of clang complains about some stuff in stdio.h and stdarg.h ...
153 TEST_CFLAGS="-Wno-typedef-redefinition"
154 else
155 TEST_CFLAGS=""
156 fi
157 echo $compiler_version
158
159 for a in "${archflags[@]}"
160 do
161 if [[ $(expr "$i" : "clang") && "$a" == "-mx32" ]]
162 then
163 echo "clang -mx32 tests skipped"
164 continue
165 fi
166
167 _runtest "$i $a" ""
168 _runtest "$i $a" "-DMP_8BIT"
169 _runtest "$i $a" "-DMP_16BIT"
170 _runtest "$i $a" "-DMP_32BIT"
171 done
172 done
173
174 _exit