Debian Codegraph @

.ci/docker.run

raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 set -eo pipefail
5
6 source $DOCKER_BUILD_DIR/.ci/docker-prelude.sh
7
8 export CONFIGURE_OPTIONS=
9
10 if [ -d build ]; then
11 rm -rf build
12 fi
13
14 if [ -d ./build-no-tests ]; then
15 rm -rf build-no-tests
16 fi
17
18 if [ -d ./config_test ]; then
19 rm -rf config_test
20 fi
21
22 if [ -z "$WITH_CRYPTO" ]; then
23 echo "variable WITH_CRYPTO not set, defaulting to ossl"
24 export WITH_CRYPTO="ossl"
25 fi
26
27 little_endian=$(echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}')
28 if [ $little_endian -eq 0 ]; then
29 export CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --with-integrationtcti=libtpms"
30 fi
31
32 if [ "$WITH_CRYPTO" != "ossl" ]; then
33 export CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --disable-fapi --disable-policy"
34 fi
35
36 ./bootstrap
37
38 # Is it a fuzz run, if so build the fuzz test and exit.
39 if [ "$GEN_FUZZ" == "1" ]; then
40 ./configure --with-fuzzing=libfuzzer --enable-tcti-fuzzing \
41 --disable-tcti-device --disable-tcti-mssim --disable-tcti-swtpm \
42 --disable-shared --with-crypto="$WITH_CRYPTO"
43 make -j$(nproc) check
44 exit 0
45 fi
46
47 if [ "$TEST_TCTI_CONFIG" != "true" ]; then
48 #
49 # General build runs
50 #
51
52 # build with no tests enabled
53 mkdir ./build-no-tests
54 pushd ./build-no-tests
55
56 echo "PWD: $(pwd)"
57 echo "ls -la ../ $(ls -la ../)"
58
59 ../configure --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
60 make -j$(nproc)
61 popd
62
63 if [ "$WITH_CRYPTO" == "none" ]; then
64 echo "Exiting without running tests becuase crypto backend is none"
65 exit 0
66 fi
67
68 # build with all tests enabled
69 mkdir ./build
70 pushd ./build
71
72 if [[ "$CC" == "gcc" && "$ENABLE_COVERAGE" == "true" ]]; then
73 export CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --enable-code-coverage";
74 fi
75
76 if ldconfig -p 2>/dev/null| grep libasan > /dev/null && ldconfig -p 2>/dev/null| grep libubsan > /dev/null; then
77 if [ $little_endian -eq 1 ]; then
78 SANITIZER_OPTION="--with-sanitizer=undefined,address"
79 fi
80 fi
81
82 if [ "$SCANBUILD" == "yes" ]; then
83 scan-build --status-bugs ../configure --enable-unit --enable-self-generated-certificate --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
84 elif [ "$CC" == "clang" ]; then
85 ../configure --enable-unit --enable-self-generated-certificate --enable-integration --with-maxloglevel=none --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
86 else
87 if [ "$WITH_TCTI" == "mssim" ]; then
88 ../configure $SANITIZER_OPTION --disable-tcti-swtpm --enable-unit --enable-self-generated-certificate --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
89 else
90 ../configure $SANITIZER_OPTION --with-maxloglevel=none --enable-debug=yes --enable-unit --enable-self-generated-certificate --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
91 fi
92 fi
93
94 if [ "$SCANBUILD" == "yes" ]; then
95 scan-build --status-bugs make -j
96 elif [ "$CC" == "clang" ]; then
97 make -j distcheck
98 else
99 make -j check
100 fi
101
102 popd
103
104 else # TEST_TCTI_CONFIG == true
105 mkdir ./config_test
106 pushd ./config_test
107 if [ "$CC" == "gcc" ]; then
108 # No TCTI - expect to fail
109 echo "========================== START TEST - NO TCTI =========================="
110 (../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --disable-tcti-swtpm --disable-tcti-mssim --disable-tcti-device && exit 1) || echo "failed as expected";
111 # only device TCTI
112 echo "========================== START TEST - device TCTI =========================="
113 mkdir -p ./dev/tpm0 && ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --disable-tcti-swtpm --disable-tcti-mssim --enable-tcti-device --with-device=./dev/tpm0
114 make -j check TESTS="test/unit/tcti-device" && rm -rf ./dev
115 # only mssim TCTI
116 echo "========================== START TEST - mssim TCTI =========================="
117 ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --disable-tcti-swtpm --enable-tcti-mssim --disable-tcti-device
118 make -j check TESTS="test/unit/tcti-mssim"
119 # device and mssim TCTIs
120 echo "========================== START TEST - mssim & device TCTI =========================="
121 ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --disable-tcti-swtpm --enable-tcti-mssim --enable-tcti-device
122 make -j check TESTS="test/unit/tcti-device test/unit/tcti-mssim"
123 # only swtmp TCTI
124 echo "========================== START TEST - swtpm TCTI =========================="
125 ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --enable-tcti-swtpm --disable-tcti-mssim --disable-tcti-device
126 make -j check TESTS="test/unit/tcti-swtpm"
127 # swtmp and device TCTIs
128 echo "========================== START TEST - swtpm & device TCTI =========================="
129 ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --enable-tcti-swtpm --disable-tcti-mssim --enable-tcti-device
130 make -j check TESTS="test/unit/tcti-swtpm test/unit/tcti-device"
131 # swtmp and mssim TCTIs
132 echo "========================== START TEST - swtpm & mssim TCTI =========================="
133 ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --enable-tcti-swtpm --enable-tcti-mssim --disable-tcti-device
134 make -j check TESTS="test/unit/tcti-swtpm test/unit/tcti-mssim"
135 # all TCTIs
136 echo "========================== START TEST - swtpm & mssim & device TCTI =========================="
137 ../configure --disable-doxygen-doc --enable-unit --enable-self-generated-certificate --enable-integration --enable-tcti-swtpm --enable-tcti-mssim --enable-tcti-device
138 make -j check TESTS="test/unit/tcti-swtpm test/unit/tcti-mssim test/unit/tcti-device"
139 fi # CC == gcc
140 popd
141 fi # TEST_TCTI_CONFIG
142
143 # back in root git directory, check for whitespace errors. We do this post CI
144 # so people can verify the rest of their patch works in CI before dying.
145 # git diff --check fails with a non-zero return code causing the shell to die
146 # as it has a set -e executed.
147 if [ -n "$BASE_REF" ]; then
148 echo "Running whitespace check"
149 git fetch origin "$BASE_REF"
150 git diff --check "origin/$BASE_REF"
151 fi
152
153 if [ "$ENABLE_COVERAGE" == "true" ]; then
154 bash <(curl -s https://codecov.io/bash)
155 fi
156 exit 0