1#!/bin/bash
2
3echo "Running in $(pwd)"
4export ARCH=${ARCH:-64}
5export BOLTDIR=lightning-rfc
6export CC=${COMPILER:-gcc}
7export COMPAT=${COMPAT:-1}
8export TEST_CHECK_DBSTMTS=${TEST_CHECK_DBSTMTS:-0}
9export DEVELOPER=${DEVELOPER:-1}
10export EXPERIMENTAL_FEATURES=${EXPERIMENTAL_FEATURES:-0}
11export PATH=$CWD/dependencies/bin:"$HOME"/.local/bin:"$PATH"
12export PYTEST_OPTS="--maxfail=5 --suppress-no-test-exit-code ${PYTEST_OPTS}"
13export PYTEST_PAR=${PYTEST_PAR:-10}
14export PYTEST_SENTRY_ALWAYS_REPORT=1
15export SLOW_MACHINE=1
16export TEST_CMD=${TEST_CMD:-"make -j $PYTEST_PAR pytest"}
17export TEST_DB_PROVIDER=${TEST_DB_PROVIDER:-"sqlite3"}
18export TEST_NETWORK=${NETWORK:-"regtest"}
19export TIMEOUT=900
20export VALGRIND=${VALGRIND:-0}
21export FUZZING=${FUZZING:-0}
22export LIGHTNINGD_POSTGRES_NO_VACUUM=1
23
24pip3 install --user -U \
25     -r requirements.lock
26
27timeout 60 pip3 install --user \
28     --use-feature=in-tree-build \
29     ./contrib/pyln-client \
30     ./contrib/pyln-proto \
31     ./contrib/pyln-testing
32
33# Install utilities that aren't dependencies, but make
34# running tests easier/feasible on CI (and pytest which
35# keeps breaking the rerunfailures plugin).
36pip3 install --user \
37     blinker \
38     flake8 \
39     flaky \
40     mako \
41     pytest-sentry \
42     pytest-test-groups==1.0.3 \
43     pytest-custom-exit-code==0.3.0 \
44     pytest-timeout \
45     pytest-json-report
46
47git clone https://github.com/lightningnetwork/lightning-rfc.git ../lightning-rfc
48git submodule update --init --recursive
49
50./configure CC="$CC"
51cat config.vars
52
53cat << EOF > pytest.ini
54[pytest]
55addopts=-p no:logging --color=yes --timeout=1800 --timeout-method=thread --test-group-random-seed=42 --force-flaky --no-success-flaky-report --max-runs=3 --junitxml=report.xml --json-report --json-report-file=report.json --json-report-indent=2
56markers =
57    slow_test: marks tests as slow (deselect with '-m "not slow_test"')
58EOF
59
60if [ "$TARGET_HOST" == "arm-linux-gnueabihf" ] || [ "$TARGET_HOST" == "aarch64-linux-gnu" ]
61then
62    export QEMU_LD_PREFIX=/usr/"$TARGET_HOST"/
63    export MAKE_HOST="$TARGET_HOST"
64    export BUILD=x86_64-pc-linux-gnu
65    export AR="$TARGET_HOST"-ar
66    export AS="$TARGET_HOST"-as
67    export CC="$TARGET_HOST"-gcc
68    export CXX="$TARGET_HOST"-g++
69    export LD="$TARGET_HOST"-ld
70    export STRIP="$TARGET_HOST"-strip
71    export CONFIGURATION_WRAPPER=qemu-"${TARGET_HOST%%-*}"-static
72
73    wget -q https://zlib.net/zlib-1.2.11.tar.gz
74    tar xf zlib-1.2.11.tar.gz
75    cd zlib-1.2.11 || exit 1
76    ./configure --prefix="$QEMU_LD_PREFIX"
77    make
78    sudo make install
79    cd .. || exit 1
80    rm zlib-1.2.11.tar.gz && rm -rf zlib-1.2.11
81
82    wget -q https://www.sqlite.org/2018/sqlite-src-3260000.zip
83    unzip -q sqlite-src-3260000.zip
84    cd sqlite-src-3260000 || exit 1
85    automake --add-missing --force-missing --copy || true
86    ./configure --disable-tcl \
87     --enable-static \
88     --disable-readline \
89     --disable-threadsafe \
90     --disable-load-extension \
91     --host="$TARGET_HOST" \
92     --prefix="$QEMU_LD_PREFIX"
93    make
94    sudo make install
95    cd .. || exit 1
96    rm sqlite-src-3260000.zip
97    rm -rf sqlite-src-3260000
98
99    wget -q https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
100    tar xf gmp-6.1.2.tar.xz
101    cd gmp-6.1.2 || exit 1
102    ./configure --disable-assembly --prefix="$QEMU_LD_PREFIX" --host="$TARGET_HOST"
103    make
104    sudo make install
105    cd ..
106    rm gmp-6.1.2.tar.xz
107    rm -rf gmp-6.1.2
108
109    ./configure CC="$TARGET_HOST-gcc" --enable-static
110
111    make -j32 CC="$TARGET_HOST-gcc" > /dev/null
112else
113    eatmydata make -j32
114    # shellcheck disable=SC2086
115    eatmydata $TEST_CMD
116fi
117