1 #!/bin/sh
2 3 set -eux
4 5 export LC_ALL=C
6 7 # Print commit and relevant CI environment to allow reproducing the job outside of CI.
8 git show --no-patch
9 print_environment() {
10 # Turn off -x because it messes up the output
11 set +x
12 # There are many ways to print variable names and their content. This one
13 # does not rely on bash.
14 for var in WERROR_CFLAGS MAKEFLAGS BUILD \
15 ECMULTWINDOW ECMULTGENKB ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
16 EXPERIMENTAL ECDH RECOVERY EXTRAKEYS MUSIG SCHNORRSIG ELLSWIFT \
17 SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS SYMBOL_CHECK \
18 EXAMPLES \
19 HOST WRAPPER_CMD \
20 CC CFLAGS CPPFLAGS AR NM \
21 UBSAN_OPTIONS ASAN_OPTIONS LSAN_OPTIONS
22 do
23 eval "isset=\${$var+x}"
24 if [ -n "$isset" ]; then
25 eval "val=\${$var}"
26 # shellcheck disable=SC2154
27 printf '%s="%s" ' "$var" "$val"
28 fi
29 done
30 echo "$0"
31 set -x
32 }
33 print_environment
34 35 env >> test_env.log
36 37 # If gcc is requested, assert that it's in fact gcc (and not some symlinked Apple clang).
38 case "${CC:-undefined}" in
39 *gcc*)
40 $CC -v 2>&1 | grep -q "gcc version" || exit 1;
41 ;;
42 esac
43 44 if [ -n "${CC+x}" ]; then
45 # The MSVC compiler "cl" doesn't understand "-v"
46 $CC -v || true
47 fi
48 if [ "$WITH_VALGRIND" = "yes" ]; then
49 valgrind --version
50 fi
51 if [ -n "$WRAPPER_CMD" ]; then
52 $WRAPPER_CMD --version
53 fi
54 55 ./autogen.sh
56 57 ./configure \
58 --enable-experimental="$EXPERIMENTAL" \
59 --with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
60 --with-ecmult-window="$ECMULTWINDOW" \
61 --with-ecmult-gen-kb="$ECMULTGENKB" \
62 --enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
63 --enable-module-ellswift="$ELLSWIFT" \
64 --enable-module-extrakeys="$EXTRAKEYS" \
65 --enable-module-schnorrsig="$SCHNORRSIG" \
66 --enable-module-musig="$MUSIG" \
67 --enable-examples="$EXAMPLES" \
68 --enable-ctime-tests="$CTIMETESTS" \
69 --with-valgrind="$WITH_VALGRIND" \
70 --host="$HOST" $EXTRAFLAGS
71 72 # We have set "-j<n>" in MAKEFLAGS.
73 build_exit_code=0
74 make > make.log 2>&1 || build_exit_code=$?
75 cat make.log
76 if [ $build_exit_code -ne 0 ]; then
77 case "${CC:-undefined}" in
78 *snapshot*)
79 # Ignore internal compiler errors in gcc-snapshot and clang-snapshot
80 grep -e "internal compiler error:" -e "PLEASE submit a bug report" make.log
81 exit $?
82 ;;
83 *)
84 exit 1
85 ;;
86 esac
87 fi
88 89 # Print information about binaries so that we can see that the architecture is correct
90 file *tests* || true
91 file bench* || true
92 file .libs/* || true
93 94 if [ "$SYMBOL_CHECK" = "yes" ]
95 then
96 python3 --version
97 case "$HOST" in
98 *mingw*)
99 ls -l .libs
100 python3 ./tools/symbol-check.py .libs/libsecp256k1-*.dll
101 ;;
102 *)
103 python3 ./tools/symbol-check.py .libs/libsecp256k1.so
104 ;;
105 esac
106 fi
107 108 # This tells `make check` to wrap test invocations.
109 export LOG_COMPILER="$WRAPPER_CMD"
110 111 make "$BUILD"
112 113 # Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
114 EXEC='./libtool --mode=execute'
115 if [ -n "$WRAPPER_CMD" ]
116 then
117 EXEC="$EXEC $WRAPPER_CMD"
118 fi
119 120 if [ "$BENCH" = "yes" ]
121 then
122 {
123 $EXEC ./bench_ecmult
124 $EXEC ./bench_internal
125 $EXEC ./bench
126 } >> bench.log 2>&1
127 fi
128 129 if [ "$CTIMETESTS" = "yes" ]
130 then
131 if [ "$WITH_VALGRIND" = "yes" ]; then
132 ./libtool --mode=execute valgrind --error-exitcode=42 ./ctime_tests > ctime_tests.log 2>&1
133 else
134 $EXEC ./ctime_tests > ctime_tests.log 2>&1
135 fi
136 fi
137 138 # Rebuild precomputed files (if not cross-compiling).
139 if [ -z "$HOST" ]
140 then
141 make clean-precomp clean-testvectors
142 make precomp testvectors
143 fi
144 145 # Check that no repo files have been modified by the build.
146 # (This fails for example if the precomp files need to be updated in the repo.)
147 git diff --exit-code
148