Skip to content

Commit 836f5d8

Browse files
elichaiFabcien
authored andcommitted
[SECP256K1] Add macOS to the CI
Summary: ``` This adds macOS to the travis so we can test all the same configurations under macOS, both with Apple's clang and proper gcc on macOS. It also runs the ctime test, and valgrind on the tests just like on linux. The current travis script is pretty messy because we added more and more configuration over time each one required more complex ifs making it harder to read, and because of the somewhat complex logic it failed[1] on macOS(having an old bash version) so I decided to just throw it into a standalone sh script instead, that way it can be formatted nicely and with -e it will fail on every error without needing to put && everywhere. Some changed in the script: Replaced the usage of libtool with the locally generated libtool (#723 (comment)) Added --error-exitcode=42 to the ctime tests because they currently silently fail on -O0 (https://travis-ci.org/github/bitcoin-core/secp256k1/jobs/681571334#L454) and disabled the ctime tests on -O0. Moved the valgrind tests to the matrix so that they'll run on both gcc and clang and on macOS. (also, now that #710 is merged we always pass -DVALGRIND when the valgrind headers exist but I left the explicit CFLAGS in those tests anyway, there's no harm in explicitly doing that) Removed the use of EXTRAFLAGS for setting CFLAGS, it's enough to just set CFLAGS directly and it can cause troubles in sh (the whole EXTRAFLAGS="--disable-openssl-tests CPPFLAGS=-DVALGRIND") We have to explicitly set the gcc version on macOS+gcc because macOS ship with a fake gcc which is basically just an alias to their clang compiler, and installing proper gcc from brew adds a gcc-* binary and doesn't replace the gcc binary, so we have to explicitly set CC=gcc-9 under that scenario, so I also explicitly install gcc@9 so it shouldn't break when macOS gets gcc-10. Bumped ubuntu to bionic because of #748 (comment) (the end of End of Standard Support is in a year anyway) it's in a separate commit so that if anyone have concerns I'll just drop that commit. https://travis-ci.org/github/elichai/secp256k1/jobs/681663742#L336 ``` Backport of secp256k1 [[bitcoin-core/secp256k1#750 | PR750]]. This backport adds a few changes to the original PR: - This PR contains a bug fix on the valgrind return value (was always 0 ) for the constant time check test. This makes the schnorr signature to trigger a false positive, and this diff includes a fix extracted from PR558. - This PR works around a bug in the brew plugin for Travis that causes an update if a package is installed via the built-in addon. However forcing no update will install a cmake version which is too old, so this workaround has not been ported. - The java tests fails with autotools on OSX due to an RPATH issue with the libraries. Since there is no trivial fix the test is skipped for now. Test Plan: Run the Travis build. https://travis-ci.org/github/Fabcien/secp256k1/builds/731184003 Note: this has been tested by part since the whole tests take > 6h Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D7610
1 parent 9b78dd9 commit 836f5d8

File tree

4 files changed

+104
-38
lines changed

4 files changed

+104
-38
lines changed

src/secp256k1/.travis.yml

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
language: c
2-
os: linux
3-
dist: xenial
2+
os:
3+
- linux
4+
- osx
5+
6+
dist: bionic
7+
# Valgrind currently supports upto macOS 10.13, the latest xcode of that version is 10.1
8+
osx_image: xcode10.1
49
addons:
510
apt:
611
packages:
@@ -11,8 +16,16 @@ addons:
1116
- libtool-bin
1217
- ninja-build
1318
- valgrind
19+
homebrew:
20+
packages:
21+
- cmake
22+
- gcc@9
23+
- gmp
24+
- ninja
25+
- valgrind
26+
update: true
1427
install:
15-
- ./travis/install_cmake.sh
28+
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./travis/install_cmake.sh; fi
1629
cache:
1730
directories:
1831
- /opt/cmake
@@ -42,7 +55,7 @@ env:
4255
- MULTISET=no
4356
- CTIMETEST=yes
4457
- BENCH=yes
45-
- SECP256K1_BENCH_ITERS=2
58+
- ITERS=2
4659
jobs:
4760
- SCALAR=32bit RECOVERY=yes
4861
- SCALAR=32bit FIELD=32bit ECDH=yes EXPERIMENTAL=yes MULTISET=yes
@@ -58,45 +71,49 @@ env:
5871
- BIGNUM=no STATICPRECOMPUTATION=no
5972
- AUTOTOOLS_TARGET=distcheck CMAKE_TARGET=install CTIMETEST= BENCH=
6073
- AUTOTOOLS_EXTRA_FLAGS=CPPFLAGS=-DDETERMINISTIC CMAKE_EXTRA_FLAGS=-DCMAKE_C_FLAGS=-DDETERMINISTIC
61-
- AUTOTOOLS_EXTRA_FLAGS=CFLAGS=-O0 CMAKE_EXTRA_FLAGS=-DCMAKE_BUILD_TYPE=Debug
74+
- AUTOTOOLS_EXTRA_FLAGS=CFLAGS=-O0 CMAKE_EXTRA_FLAGS=-DCMAKE_BUILD_TYPE=Debug CTIMETEST=
6275
- AUTOTOOLS_TARGET=check-java CMAKE_TARGET=check-secp256k1-java JNI=yes ECDH=yes EXPERIMENTAL=yes CTIMETEST= BENCH=
6376
- ECMULTGENPRECISION=2
6477
- ECMULTGENPRECISION=8
78+
- VALGRIND=yes
79+
BIGNUM=no ENDOMORPHISM=yes ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes OPENSSL_TESTS=no MULTISET=yes
80+
AUTOTOOLS_EXTRA_FLAGS=CPPFLAGS=-DVALGRIND AUTOTOOLS_TARGET=
81+
CMAKE_EXTRA_FLAGS=-DCMAKE_C_FLAGS=-DVALGRIND CMAKE_TARGET="secp256k1-tests secp256k1-exhaustive_tests"
82+
# The same as above but without endomorphism.
83+
- VALGRIND=yes
84+
BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes OPENSSL_TESTS=no MULTISET=yes
85+
AUTOTOOLS_EXTRA_FLAGS=CPPFLAGS=-DVALGRIND AUTOTOOLS_TARGET=
86+
CMAKE_EXTRA_FLAGS=-DCMAKE_C_FLAGS=-DVALGRIND CMAKE_TARGET="secp256k1-tests secp256k1-exhaustive_tests"
6587
- SCHNORR=no
6688
jobs:
6789
fast_finish: true
6890
include:
6991
- compiler: clang
92+
os: linux
7093
env: HOST=i686-linux-gnu ENDOMORPHISM=yes OPENSSL_TESTS=no
7194
- compiler: clang
95+
os: linux
7296
env: HOST=i686-linux-gnu BIGNUM=no OPENSSL_TESTS=no
7397
- compiler: gcc
98+
os: linux
7499
env: HOST=i686-linux-gnu ENDOMORPHISM=yes BIGNUM=no OPENSSL_TESTS=no
75100
- compiler: gcc
101+
os: linux
76102
env: HOST=i686-linux-gnu OPENSSL_TESTS=no
77-
- compiler: gcc
78-
env:
79-
- VALGRIND=yes
80-
- BIGNUM=no ENDOMORPHISM=yes ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes OPENSSL_TESTS=no MULTISET=yes
81-
- AUTOTOOLS_EXTRA_FLAGS=CPPFLAGS=-DVALGRIND AUTOTOOLS_TARGET=
82-
- CMAKE_EXTRA_FLAGS=-DCMAKE_C_FLAGS=-DVALGRIND CMAKE_TARGET="secp256k1-tests secp256k1-exhaustive_tests"
83-
- compiler: gcc
84-
env: # The same as above but without endomorphism.
85-
- VALGRIND=yes
86-
- BIGNUM=no ENDOMORPHISM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes OPENSSL_TESTS=no MULTISET=yes
87-
- AUTOTOOLS_EXTRA_FLAGS=CPPFLAGS=-DVALGRIND AUTOTOOLS_TARGET=
88-
- CMAKE_EXTRA_FLAGS=-DCMAKE_C_FLAGS=-DVALGRIND CMAKE_TARGET="secp256k1-tests secp256k1-exhaustive_tests"
89103

104+
before_script:
105+
# This limits the iterations in the benchmarks below to ITER iterations.
106+
- export SECP256K1_BENCH_ITERS="$ITERS"
107+
108+
# travis auto terminates jobs that go for 10 minutes without printing to stdout,
109+
# but travis_wait doesn't work well with forking programs like valgrind
110+
# (https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received https://github.com/bitcoin-core/secp256k1/pull/750#issuecomment-623476860)
90111
script:
112+
- function keep_alive() { while true; do echo -en "\a"; sleep 60; done }
113+
- keep_alive &
91114
- ./travis/build_autotools.sh
92115
- ./travis/build_cmake.sh
93-
- # travis_wait extends the 10 minutes without output allowed (https://docs.travis-ci.com/user/common-build-problems/#build-times-out-because-no-output-was-received)
94-
- # the `--error-exitcode` is required to make the test fail if valgrind found errors, otherwise it'll return 0 (http://valgrind.org/docs/manual/manual-core.html)
95-
- if [ -n "$VALGRIND" ]; then
96-
travis_wait 30 valgrind --error-exitcode=42 ./buildautotools/tests 16 &&
97-
travis_wait 30 valgrind --error-exitcode=42 ./buildautotools/exhaustive_tests;
98-
fi
99-
- if [ -n "$VALGRIND" ]; then
100-
travis_wait 30 valgrind --error-exitcode=42 ./buildcmake/secp256k1-tests 16 &&
101-
travis_wait 30 valgrind --error-exitcode=42 ./buildcmake/secp256k1-exhaustive_tests;
102-
fi
116+
- kill %keep_alive
117+
118+
after_script:
119+
- valgrind --version

src/secp256k1/src/modules/schnorr/schnorr_impl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ static int secp256k1_schnorr_sig_sign(
152152
secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &Rj, &k);
153153
secp256k1_ge_set_gej(&R, &Rj);
154154

155+
/*
156+
* We declassify R to allow using it as a branch point.
157+
* This is fine because R is not a secret.
158+
*/
159+
secp256k1_declassify(ctx, &R, sizeof(R));
155160
/** Negate the nonce if R.y is not a quadratic residue. */
156161
secp256k1_scalar_cond_negate(&k, !secp256k1_fe_is_quad_var(&R.y));
157162

src/secp256k1/travis/build_autotools.sh

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ export LC_ALL=C
44

55
set -ex
66

7+
# FIXME The java tests will fail on macOS with autotools due to the
8+
# libsepc256k1_jni library referencing the libsecp256k1 library with an absolute
9+
# path. This needs to be rewritten with install_name_tool to use relative paths
10+
# via the @variables supported by the macOS loader.
11+
if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$JNI" = "yes" ]
12+
then
13+
echo "Skipping the java tests built with autotools on OSX"
14+
exit 0
15+
fi
16+
717
if [ -n "$HOST" ]; then
818
USE_HOST="--host=$HOST"
919
fi
@@ -12,6 +22,13 @@ if [ "x$HOST" = "xi686-linux-gnu" ]; then
1222
CC="$CC -m32"
1323
fi
1424

25+
if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$TRAVIS_COMPILER" = "gcc" ]
26+
then
27+
CC="gcc-9"
28+
fi
29+
30+
$CC --version
31+
1532
./autogen.sh
1633

1734
mkdir buildautotools
@@ -45,28 +62,38 @@ trap 'print_logs' ERR
4562

4663
make -j2 $AUTOTOOLS_TARGET
4764

65+
if [ -n "$VALGRIND" ]; then
66+
# the `--error-exitcode` is required to make the test fail if valgrind found
67+
# errors, otherwise it'll return 0
68+
# (http://valgrind.org/docs/manual/manual-core.html)
69+
valgrind --error-exitcode=42 ./tests 16
70+
valgrind --error-exitcode=42 ./exhaustive_tests
71+
fi
72+
4873
if [ -n "$BENCH" ]; then
4974
if [ -n "$VALGRIND" ]; then
50-
EXEC='libtool --mode=execute valgrind --error-exitcode=42';
75+
# Using the local `libtool` because on macOS the system's libtool has
76+
# nothing to do with GNU libtool
77+
EXEC='./libtool --mode=execute valgrind --error-exitcode=42';
5178
else
5279
EXEC= ;
5380
fi
54-
$EXEC ./bench_ecmult &>> bench.log
55-
$EXEC ./bench_internal &>> bench.log
56-
$EXEC ./bench_sign &>> bench.log
57-
$EXEC ./bench_verify &>> bench.log
81+
$EXEC ./bench_ecmult >> bench.log 2>&1
82+
$EXEC ./bench_internal >> bench.log 2>&1
83+
$EXEC ./bench_sign >> bench.log 2>&1
84+
$EXEC ./bench_verify >> bench.log 2>&1
5885
if [ "$RECOVERY" == "yes" ]; then
59-
$EXEC ./bench_recover &>> bench.log
86+
$EXEC ./bench_recover >> bench.log 2>&1
6087
fi
6188
if [ "$ECDH" == "yes" ]; then
62-
$EXEC ./bench_ecdh &>> bench.log
89+
$EXEC ./bench_ecdh >> bench.log 2>&1
6390
fi
6491
if [ "$MULTISET" == "yes" ]; then
65-
$EXEC ./bench_multiset &>> bench.log
92+
$EXEC ./bench_multiset >> bench.log 2>&1
6693
fi
6794
fi
6895
if [ -n "$CTIMETEST" ]; then
69-
libtool --mode=execute valgrind ./valgrind_ctime_test &> valgrind_ctime_test.log
96+
./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1
7097
fi
7198

7299
popd

src/secp256k1/travis/build_cmake.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ set -ex
77
if [ "x$HOST" = "xi686-linux-gnu" ]; then
88
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DCMAKE_C_FLAGS=-m32"
99
fi
10+
if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$TRAVIS_COMPILER" = "gcc" ]
11+
then
12+
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DCMAKE_C_COMPILER=gcc-9"
13+
fi
1014

1115
# "auto" is not a valid value for SECP256K1_ECMULT_GEN_PRECISION with cmake.
1216
# In this case we use the default value instead by not setting the cache
@@ -18,8 +22,13 @@ fi
1822
mkdir -p buildcmake/install
1923
pushd buildcmake
2024

21-
# Use the cmake version installed via the install_cmake.sh script.
22-
CMAKE_COMMAND=/opt/cmake/bin/cmake
25+
# Use the cmake version installed via the install_cmake.sh script on linux
26+
if [ "$TRAVIS_OS_NAME" = "linux" ]
27+
then
28+
CMAKE_COMMAND=/opt/cmake/bin/cmake
29+
else
30+
CMAKE_COMMAND=cmake
31+
fi
2332
${CMAKE_COMMAND} --version
2433

2534
${CMAKE_COMMAND} -GNinja .. \
@@ -41,4 +50,12 @@ ${CMAKE_COMMAND} -GNinja .. \
4150

4251
ninja $CMAKE_TARGET
4352

53+
if [ -n "$VALGRIND" ]; then
54+
# the `--error-exitcode` is required to make the test fail if valgrind found
55+
# errors, otherwise it'll return 0
56+
# (http://valgrind.org/docs/manual/manual-core.html)
57+
valgrind --error-exitcode=42 ./secp256k1-tests 16
58+
valgrind --error-exitcode=42 ./secp256k1-exhaustive_tests
59+
fi
60+
4461
popd

0 commit comments

Comments
 (0)