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\
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 # Workaround for https://bugs.kde.org/show_bug.cgi?id=452758 (fixed in valgrind 3.20.0).
56 case "${CC:-undefined}" in
57 clang*)
58 if [ "$CTIMETESTS" = "yes" ] && [ "$WITH_VALGRIND" = "yes" ]
59 then
60 export CFLAGS="${CFLAGS:+$CFLAGS }-gdwarf-4"
61 else
62 case "$WRAPPER_CMD" in
63 valgrind*)
64 export CFLAGS="${CFLAGS:+$CFLAGS }-gdwarf-4"
65 ;;
66 esac
67 fi
68 ;;
69 esac
70 71 ./autogen.sh
72 73 ./configure \
74 --enable-experimental="$EXPERIMENTAL" \
75 --with-test-override-wide-multiply="$WIDEMUL" --with-asm="$ASM" \
76 --with-ecmult-window="$ECMULTWINDOW" \
77 --with-ecmult-gen-kb="$ECMULTGENKB" \
78 --enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
79 --enable-module-ellswift="$ELLSWIFT" \
80 --enable-module-extrakeys="$EXTRAKEYS" \
81 --enable-module-schnorrsig="$SCHNORRSIG" \
82 --enable-module-musig="$MUSIG" \
83 --enable-examples="$EXAMPLES" \
84 --enable-ctime-tests="$CTIMETESTS" \
85 --with-valgrind="$WITH_VALGRIND" \
86 --host="$HOST" $EXTRAFLAGS
87 88 # We have set "-j<n>" in MAKEFLAGS.
89 build_exit_code=0
90 make > make.log 2>&1 || build_exit_code=$?
91 cat make.log
92 if [ $build_exit_code -ne 0 ]; then
93 case "${CC:-undefined}" in
94 *snapshot*)
95 # Ignore internal compiler errors in gcc-snapshot and clang-snapshot
96 grep -e "internal compiler error:" -e "PLEASE submit a bug report" make.log
97 return $?;
98 ;;
99 *)
100 return 1;
101 ;;
102 esac
103 fi
104 105 # Print information about binaries so that we can see that the architecture is correct
106 file *tests* || true
107 file bench* || true
108 file .libs/* || true
109 110 # This tells `make check` to wrap test invocations.
111 export LOG_COMPILER="$WRAPPER_CMD"
112 113 make "$BUILD"
114 115 # Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
116 EXEC='./libtool --mode=execute'
117 if [ -n "$WRAPPER_CMD" ]
118 then
119 EXEC="$EXEC $WRAPPER_CMD"
120 fi
121 122 if [ "$BENCH" = "yes" ]
123 then
124 {
125 $EXEC ./bench_ecmult
126 $EXEC ./bench_internal
127 $EXEC ./bench
128 } >> bench.log 2>&1
129 fi
130 131 if [ "$CTIMETESTS" = "yes" ]
132 then
133 if [ "$WITH_VALGRIND" = "yes" ]; then
134 ./libtool --mode=execute valgrind --error-exitcode=42 ./ctime_tests > ctime_tests.log 2>&1
135 else
136 $EXEC ./ctime_tests > ctime_tests.log 2>&1
137 fi
138 fi
139 140 # Rebuild precomputed files (if not cross-compiling).
141 if [ -z "$HOST" ]
142 then
143 make clean-precomp clean-testvectors
144 make precomp testvectors
145 fi
146 147 # Check that no repo files have been modified by the build.
148 # (This fails for example if the precomp files need to be updated in the repo.)
149 git diff --exit-code
150