-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.sh
executable file
·168 lines (150 loc) · 5.02 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#! /bin/bash
set -euo pipefail
GITREPO_ROOT="${1:-$(readlink -f "$(dirname "$0")/..")}"
# Test options: test stages, additional checkers, compile options
TEST_BUILD_DIR=${TEST_BUILD_DIR:-build-test}
TEST_WITH_STATICTESTS=${TEST_WITH_STATICTESTS:-0}
TEST_WITH_BUILD=${TEST_WITH_BUILD:-1}
TEST_WITH_TESTSUITE=${TEST_WITH_TESTSUITE:-1}
TEST_WITH_DOCS=${TEST_WITH_DOCS:-0}
TEST_WITH_COVERAGE=${TEST_WITH_COVERAGE:-0}
TEST_WITH_SOTA_TOOLS=${TEST_WITH_SOTA_TOOLS:-1}
TEST_WITH_P11=${TEST_WITH_P11:-0}
TEST_WITH_OSTREE=${TEST_WITH_OSTREE:-1}
TEST_WITH_FAULT_INJECTION=${TEST_WITH_FAULT_INJECTION:-0}
TEST_CC=${TEST_CC:-gcc}
TEST_CMAKE_GENERATOR=${TEST_CMAKE_GENERATOR:-Ninja}
TEST_CMAKE_BUILD_TYPE=${TEST_CMAKE_BUILD_TYPE:-Valgrind}
TEST_INSTALL_DESTDIR=${TEST_INSTALL_DESTDIR:-/persistent}
TEST_INSTALL_RELEASE_NAME=${TEST_INSTALL_RELEASE_NAME:-}
TEST_SOTA_PACKED_CREDENTIALS=${TEST_SOTA_PACKED_CREDENTIALS:-}
TEST_DRYRUN=${TEST_DRYRUN:-0}
TEST_PARALLEL_LEVEL=${TEST_PARALLEL_LEVEL:-6}
TEST_TESTSUITE_ONLY=${TEST_TESTSUITE_ONLY:-}
TEST_TESTSUITE_EXCLUDE=${TEST_TESTSUITE_EXCLUDE:-}
TEST_PKCS11_MODULE_PATH=${TEST_PKCS11_MODULE_PATH:-/usr/lib/softhsm/libsofthsm2.so}
# note: on Ubuntu bionic, use /usr/lib/engines/engine_pkcs11.so on xenial
TEST_PKCS11_ENGINE_PATH=${TEST_PKCS11_ENGINE_PATH:-/usr/lib/x86_64-linux-gnu/engines-1.1/libpkcs11.so}
git config --global --add safe.directory /home/runner/work/aktualizr/aktualizr
# Build CMake arguments
CMAKE_ARGS=()
CMAKE_ARGS+=("-G$TEST_CMAKE_GENERATOR")
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=${TEST_CMAKE_BUILD_TYPE}")
if [[ $TEST_WITH_SOTA_TOOLS = 1 ]]; then CMAKE_ARGS+=("-DBUILD_SOTA_TOOLS=ON"); fi
if [[ $TEST_WITH_P11 = 1 ]]; then
CMAKE_ARGS+=("-DBUILD_P11=ON")
CMAKE_ARGS+=("-DPKCS11_ENGINE_PATH=${TEST_PKCS11_ENGINE_PATH}")
CMAKE_ARGS+=("-DTEST_PKCS11_MODULE_PATH=${TEST_PKCS11_MODULE_PATH}")
fi
if [[ $TEST_WITH_OSTREE = 1 ]]; then CMAKE_ARGS+=("-DBUILD_OSTREE=ON"); fi
if [[ $TEST_WITH_FAULT_INJECTION = 1 ]]; then CMAKE_ARGS+=("-DFAULT_INJECTION=ON"); fi
if [[ -n $TEST_SOTA_PACKED_CREDENTIALS ]]; then
CMAKE_ARGS+=("-DSOTA_PACKED_CREDENTIALS=$TEST_SOTA_PACKED_CREDENTIALS");
fi
# set these in any case so that it's immune to CMake's caching (it's often
# useful to change these while using the same build directory)
CMAKE_ARGS+=("-DTESTSUITE_ONLY=${TEST_TESTSUITE_ONLY}");
CMAKE_ARGS+=("-DTESTSUITE_EXCLUDE=${TEST_TESTSUITE_EXCLUDE}")
echo ">> CMake options: ${CMAKE_ARGS[*]}"
# failure handling
FAILURES=()
collect_failures() {
if [[ ${#FAILURES[@]} != 0 ]]; then
echo "The following checks failed:"
for check in "${FAILURES[@]}"; do
echo "- $check"
done
exit 1
fi
}
add_failure() {
set +x
FAILURES+=("$1")
}
add_fatal_failure() {
set +x
FAILURES+=("$1")
collect_failures
}
run_make() (
set +x
local target=${1:-}
shift 1
if [ -n "$target" ]; then
target=(--target "$target")
else
target=()
fi
(
set +u # needed for bash < 4.4
set -x
export CTEST_OUTPUT_ON_FAILURE=1
export CTEST_PARALLEL_LEVEL="${TEST_PARALLEL_LEVEL}"
cmake --build . "${target[@]}" -- -j"${TEST_PARALLEL_LEVEL}" "$@"
)
)
# Test stages
mkdir -p "${TEST_BUILD_DIR}"
cd "${TEST_BUILD_DIR}"
if [[ $TEST_WITH_P11 = 1 ]]; then
echo ">> Setting up P11"
if [[ $TEST_DRYRUN != 1 ]]; then
set -x
export SOFTHSM2_CONF="$PWD/softhsm2.conf"
export TOKEN_DIR="$PWD/softhsm2-tokens"
rm -rf "${TOKEN_DIR}"
mkdir -p "${TOKEN_DIR}"
cp "$GITREPO_ROOT/tests/test_data/softhsm2.conf" "${SOFTHSM2_CONF}"
"$GITREPO_ROOT/scripts/setup_hsm.sh" || add_fatal_failure "setup hsm"
set +x
fi
fi
echo ">> Running CMake"
if [[ $TEST_DRYRUN != 1 ]]; then
(
if [[ $TEST_CC = gcc ]]; then
export CC=gcc CXX=g++
elif [[ $TEST_CC = clang ]]; then
export CC=clang CXX=clang++
fi
set -x
git config --global --add safe.directory "${GITREPO_ROOT}"
cmake "${CMAKE_ARGS[@]}" "${GITREPO_ROOT}" || add_fatal_failure "cmake configure"
)
fi
if [[ $TEST_WITH_STATICTESTS = 1 ]]; then
echo ">> Running static checks"
if [[ $TEST_DRYRUN != 1 ]]; then
set -x
run_make check-format -k 0 || add_failure "formatting"
run_make clang-tidy -k 0 || add_failure "static checks"
set +x
fi
fi
if [[ $TEST_WITH_BUILD = 1 ]]; then
echo ">> Building and installing"
if [[ $TEST_DRYRUN != 1 ]]; then
set -x
run_make || add_fatal_failure "make"
# Check that 'make install' works
DESTDIR=/tmp/aktualizr run_make install || add_failure "make install"
set +x
fi
fi
if [[ $TEST_WITH_TESTSUITE = 1 ]]; then
echo ">> Running test suite"
if [[ $TEST_DRYRUN != 1 ]]; then
set -x
run_make check || add_failure "testsuite"
set +x
fi
fi
if [[ $TEST_WITH_DOCS = 1 ]]; then
echo ">> Running make docs"
if [[ $TEST_DRYRUN != 1 ]]; then
set -x
run_make docs || add_failure "make docs"
set +x
fi
fi
collect_failures