Merge pull request #95 from libtom/improve/travis create a travis build matrix
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
diff --git a/.travis.yml b/.travis.yml
index c760245..37fe211 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,18 +1,35 @@
language: c
-compiler:
- - gcc
-script:
- - make travis_mtest
- - head -n 5 test.log
- - tail -n 2 test.log
- - ./testme.sh --with-cc=gcc --with-low-mp
+install:
+ - sudo apt-get update -qq
+ - sudo apt-get install gcc-multilib
+matrix:
+ fast_finish: true
branches:
only:
- master
- develop
- /^release\/.*$/
+compiler:
+ - gcc
+ - clang
+script:
+ - ./testme.sh --with-cc=$CC ${BUILDOPTIONS}
+env:
+ - |
+ BUILDOPTIONS="--test-vs-mtest=333333"
+ - |
+ BUILDOPTIONS="--test-vs-mtest=333333 --mtest-real-rand"
+ - |
+ BUILDOPTIONS="--with-low-mp"
+ - |
+ BUILDOPTIONS="--with-m64 --with-m32 --with-mx32"
+
+after_failure:
+ - cat test_*.log
+ - cat gcc_errors_*.log
+
notifications:
irc: "chat.freenode.net#libtom-notifications"
diff --git a/bn_mp_rand.c b/bn_mp_rand.c
index 83afe27..2ed665e 100644
--- a/bn_mp_rand.c
+++ b/bn_mp_rand.c
@@ -15,6 +15,9 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
+#if defined(MP_8BIT) || defined(MP_16BIT)
+#define MP_GEN_RANDOM_SHIFT DIGIT_BIT
+#else
#if MP_GEN_RANDOM_MAX == 0xffffffffu
#define MP_GEN_RANDOM_SHIFT 32
#elif MP_GEN_RANDOM_MAX == 32767
@@ -26,6 +29,7 @@
#elif !defined(MP_GEN_RANDOM_SHIFT)
#error Thou shalt define their own valid MP_GEN_RANDOM_SHIFT
#endif
+#endif
/* makes a pseudo-random int of a given size */
static mp_digit s_gen_random(void)
diff --git a/makefile b/makefile
index 64d8fcd..6642994 100644
--- a/makefile
+++ b/makefile
@@ -102,10 +102,6 @@ test_standalone: $(LIBNAME) demo/demo.o
mtest:
cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LFLAGS) -o mtest
-travis_mtest: test mtest
- @ for i in `seq 1 10` ; do sleep 500 && echo alive; done &
- ./mtest/mtest 666666 | ./test > test.log
-
timing: $(LIBNAME)
$(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o ltmtest
diff --git a/mtest/mtest.c b/mtest/mtest.c
index af86920..1e2da10 100644
--- a/mtest/mtest.c
+++ b/mtest/mtest.c
@@ -151,8 +151,9 @@ int main(int argc, char *argv[])
if (rng == NULL) {
rng = fopen("/dev/random", "rb");
if (rng == NULL) {
- fprintf(stderr, "\nWarning: stdin used as random source\n\n");
- rng = stdin;
+ fprintf(stderr, "\nWarning: no /dev/[u]random available\n\n");
+ printf("exit\n");
+ return 1;
}
}
#else
diff --git a/testme.sh b/testme.sh
index ee2e87c..5dce2d2 100755
--- a/testme.sh
+++ b/testme.sh
@@ -27,6 +27,9 @@ _help()
echo " --with-cc=* The compiler(s) to use for the tests"
echo " This is an option that will be iterated."
echo
+ echo " --test-vs-mtest=* Run test vs. mtest for '*' operations."
+ echo " Only the first of each options will be taken into account."
+ echo
echo "To be able to specify options a compiler has to be given."
echo "All options will be tested with all MP_xBIT configurations."
echo
@@ -45,6 +48,8 @@ _help()
echo
echo " --with-low-mp Also build&run tests with -DMP_{8,16,32}BIT."
echo
+ echo " --mtest-real-rand Use real random data when running mtest."
+ echo
echo "Godmode:"
echo
echo " --all Choose all architectures and gcc and clang as compilers"
@@ -65,22 +70,28 @@ _die()
fi
}
-_runtest()
+_make()
{
echo -ne " Compile $1 $2"
- make clean > /dev/null
suffix=$(echo ${1}${2} | tr ' ' '_')
- CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS test_standalone $MAKE_OPTIONS > /dev/null 2>gcc_errors_${suffix}.txt
- errcnt=$(wc -l < gcc_errors_${suffix}.txt)
+ CC="$1" CFLAGS="$2 $TEST_CFLAGS" make -j$MAKE_JOBS $3 $MAKE_OPTIONS > /dev/null 2>gcc_errors_${suffix}.log
+ errcnt=$(wc -l < gcc_errors_${suffix}.log)
if [[ ${errcnt} -gt 1 ]]; then
echo " failed"
- cat gcc_errors_${suffix}.txt
+ cat gcc_errors_${suffix}.log
exit 128
fi
- echo -e "\rRun test $1 $2"
+}
+
+
+_runtest()
+{
+ make clean > /dev/null
+ _make "$1" "$2" "test_standalone"
local _timeout=""
which timeout >/dev/null && _timeout="timeout --foreground 90"
- $_timeout ./test > test_${suffix}.txt || _die "running tests" $?
+ echo -e "\rRun test $1 $2"
+ $_timeout ./test > test_${suffix}.log || _die "running tests" $?
}
_banner()
@@ -105,6 +116,8 @@ ARCHFLAGS=""
COMPILERS=""
CFLAGS=""
WITH_LOW_MP=""
+TEST_VS_MTEST=""
+MTEST_RAND=""
while [ $# -gt 0 ];
do
@@ -124,6 +137,17 @@ do
--with-low-mp)
WITH_LOW_MP="1"
;;
+ --test-vs-mtest=*)
+ TEST_VS_MTEST="${1#*=}"
+ if ! [ "$TEST_VS_MTEST" -eq "$TEST_VS_MTEST" ] 2> /dev/null
+ then
+ echo "--test-vs-mtest Parameter has to be int"
+ exit -1
+ fi
+ ;;
+ --mtest-real-rand)
+ MTEST_RAND="-DLTM_MTEST_REAL_RAND"
+ ;;
--all)
COMPILERS="gcc clang"
ARCHFLAGS="-m64 -m32 -mx32"
@@ -161,6 +185,26 @@ fi
_banner
+if [[ "$TEST_VS_MTEST" != "" ]]
+then
+ make clean > /dev/null
+ _make "${compilers[0]} ${archflags[0]}" "$CFLAGS" "test"
+ echo
+ _make "gcc" "$MTEST_RAND" "mtest"
+ echo
+ echo "Run test vs. mtest for $TEST_VS_MTEST iterations"
+ for i in `seq 1 10` ; do sleep 500 && echo alive; done &
+ alive_pid=$!
+ _timeout=""
+ which timeout >/dev/null && _timeout="timeout --foreground 900"
+ $_TIMEOUT ./mtest/mtest $TEST_VS_MTEST | ./test > test.log
+ disown $alive_pid
+ kill $alive_pid 2>/dev/null
+ head -n 5 test.log
+ tail -n 2 test.log
+ exit 0
+fi
+
for i in "${compilers[@]}"
do
if [ -z "$(which $i)" ]