-
Notifications
You must be signed in to change notification settings - Fork 18
/
run_functional_tests.sh
executable file
·80 lines (66 loc) · 2.54 KB
/
run_functional_tests.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
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
set -ex
DOCKER=${DOCKER:-0}
PLATFORM=${PLATFORM:-sgx}
# Variable to enable performance tests
ENABLE_PERF_TESTS=${ENABLE_PERF_TESTS:-}
# SNP attestation config
SNP_ATTESTATION_CONFIG=${SNP_ATTESTATION_CONFIG:-}
# If ELEVATE_PRIVILEGES is non-empty, the functional tests will be run with
# the NET_BIND_SERVICE capability, allowing certain tests that bind
# priviledged ports to run. Note that this isn't necessary in our CI
# environment, as Docker makes all ports unpriviledged anyway. Requires sudo
# access and libcap2-bin to be installed.
ELEVATE_PRIVILEGES=${ELEVATE_PRIVILEGES:-}
if [ "$DOCKER" = "1" ]; then
export CCF_HOST=${CCF_HOST:-"localhost"}
export CCF_PORT=${CCF_PORT:-8000}
export CCF_URL="https://${CCF_HOST}:${CCF_PORT}"
./docker/run-dev.sh &
CCF_NETWORK_PID=$!
trap "kill $CCF_NETWORK_PID" EXIT
# wait until the network is ready
timeout=120
while ! curl -s -f -k $CCF_URL/parameters > /dev/null; do
echo "Waiting for service to be ready..."
sleep 1
timeout=$((timeout - 1))
if [ $timeout -eq 0 ]; then
echo "Service failed to become ready, exiting"
exit 1
fi
done
# Turn off pytest output capture to allow test logs to be interleaved with
# the docker logs.
TEST_ARGS="-s"
else
SCITT_DIR=/tmp/scitt
TEST_ARGS="--start-cchost --platform=$PLATFORM --enclave-package=$SCITT_DIR/lib/libscitt --constitution=$SCITT_DIR/share/scitt/constitution --snp-attestation-config=$SNP_ATTESTATION_CONFIG"
fi
echo "Setting up python virtual environment."
if [ ! -f "venv/bin/activate" ]; then
python3.8 -m venv "venv"
fi
source venv/bin/activate
pip install --disable-pip-version-check -q -e ./pyscitt
pip install --disable-pip-version-check -q wheel
pip install --disable-pip-version-check -q -r test/requirements.txt
# Enable performance tests if the variable is set
if [ -n "$ENABLE_PERF_TESTS" ]; then
TEST_ARGS="$TEST_ARGS --enable-perf"
echo "Performance tests enabled"
fi
mkdir -p out
TEST_ARGS="$TEST_ARGS --basetemp=out"
echo "Running functional tests..."
if [ -n "$ELEVATE_PRIVILEGES" ]; then
sudo -E --preserve-env=PATH \
capsh --keep=1 --user=$(id -un) --inh=cap_net_bind_service --addamb=cap_net_bind_service \
-- -c "pytest ./test -v -rA $TEST_ARGS $(printf "'%s' " "$@")"
else
pytest ./test -v -rA $TEST_ARGS "$@"
fi
# OB pipeline can't copy out symlinks which are created by pytest.
find out -maxdepth 1 -type l -delete