-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv-init
More file actions
136 lines (114 loc) · 4.45 KB
/
env-init
File metadata and controls
136 lines (114 loc) · 4.45 KB
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
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
readonly SCRIPT_DIR
readonly TEST_ARTIFACTS_DIR="${TEST_ARTIFACTS_DIR:-${SCRIPT_DIR}/work/artifacts}"
readonly GENERATED_LG_CONFIG="/artifacts/latest.lg-env-config.yml"
readonly KAS_CMD="${SCRIPT_DIR}/tools/build/kas-container.4.5"
export KAS_WORK_DIR="${SCRIPT_DIR}/work"
readonly KAS_CONF_BASE="${SCRIPT_DIR}/conf"
readonly HW_MACHINE="raspberrypi4-64"
readonly VIRT_MACHINE="virt-aarch64"
# Defaults
# ----
TARGET_MACHINE="${TARGET_MACHINE:-${VIRT_MACHINE}}"
SOFTWARE_VERSION="${SOFTWARE_VERSION:-latest}"
readonly TEST_VERSIONS=(
'manufacturing'
'lts'
'latest'
)
TEST_DOCKER_IMAGE="emulated-linux-testing"
# ----
# Setup
# ----
function testenv_setup() {
local -r flag="$1"
if [[ "${flag}" == "-f" ]] || ! docker inspect "${TEST_DOCKER_IMAGE}" &>/dev/null; then
DOCKER_BUILDKIT=1 docker build -t "${TEST_DOCKER_IMAGE}" "${SCRIPT_DIR}/tools/test"
fi
}
function set_machine() {
export TARGET_MACHINE="$1"
}
function set_version() {
export SOFTWARE_VERSION="$1"
}
function get_build_conf() {
echo "${KAS_CONF_BASE}/${TARGET_MACHINE}.yml:${KAS_CONF_BASE}/release/${SOFTWARE_VERSION}.yml"
}
alias buildenv-setup='${KAS_CMD} checkout $(get_build_conf)'
alias testenv-rebuild='testenv_setup -f'
alias set-machine='set_machine'
alias set-version='set_version'
# ----
# Build
# ----
alias build-dump='${KAS_CMD} dump $(get_build_conf)'
alias build-shell='${KAS_CMD} shell $(get_build_conf)'
alias build-image='${KAS_CMD} build $(get_build_conf)'
alias build-runqemu='${KAS_CMD} shell $(get_build_conf) -c "runqemu core-image-minimal-${SOFTWARE_VERSION} wic.qcow2 serial nographic slirp"'
function publish_test_artifacts() {
mkdir -p "${TEST_ARTIFACTS_DIR}"
for machine in ${VIRT_MACHINE} ${HW_MACHINE}; do
local src_path="${SCRIPT_DIR}/work/build/tmp/deploy/images/${machine}"
for version in "${TEST_VERSIONS[@]}"; do
local dest_base_path="${TEST_ARTIFACTS_DIR}/${version}."
cp "${src_path}/bootenv-${version}.img" "${dest_base_path}bootenv.img" &>/dev/null || true
cp "${src_path}/u-boot-${VIRT_MACHINE}-${version}.bin" "${dest_base_path}u-boot.bin" &>/dev/null || true
cp "${src_path}/core-image-minimal-${VIRT_MACHINE}-${version}.wic.qcow2" "${dest_base_path}system-image.wic.qcow2" &>/dev/null || true
cp "${src_path}/update-bundle-${machine}-${version}.raucb" "${dest_base_path}update-bundle-${machine}.raucb" &>/dev/null || true
cp "${src_path}/lg-env-config-${version}.yml" "${dest_base_path}lg-env-config.yml" &>/dev/null || true
done
done
}
alias build-publish='publish_test_artifacts'
# ----
# Test
# ----
function run_in_testenv() {
# Make sure the test environment is available
testenv_setup
local extra_opts=""
if [[ "$1" == "-i" ]]; then
extra_opts+="-i "
shift
fi
# Exposing the serial and network connection to the hardware
if [[ "${TARGET_MACHINE}" == "${HW_MACHINE}" ]]; then
extra_opts+="--device /dev/ttyUSB0 --network host "
fi
# For some unknown reason, pytest is not able to locate the pytest.ini
# without explicitly specifying it in non-interactive runs.
PYTEST_OPTIONS="-c /test/pytest.ini --lg-env ${GENERATED_LG_CONFIG}"
# Spawn an ephemeral test container and pass command parameters to it
docker run --rm -t \
-v "${SCRIPT_DIR}/test"/:/test/ \
-v "${TEST_ARTIFACTS_DIR}"/:/artifacts:ro \
-w /test ${extra_opts} \
-e PYTEST_ADDOPTS="${PYTEST_OPTIONS}" \
${TEST_DOCKER_IMAGE} "$@"
}
alias test-shell='run_in_testenv -i /bin/bash'
alias test-run-pytest='run_in_testenv /usr/local/bin/pytest'
# ----
# Pipeline helpers
# ----
function run_marked_tests() {
local -r marker_expression="$1"
shift
local skip_hardware="n"
if [[ "$1" == "no-hardware" ]]; then
skip_hardware="y"
shift
fi
echo "=== Running ${marker_expression} on emulation ==="
set-machine "${VIRT_MACHINE}"
test-run-pytest -n auto -m "(${marker_expression}) and not hardware_only" $@
if [[ "${skip_hardware}" == "n" ]]; then
echo "=== Running ${marker_expression} on hardware ==="
set-machine "${HW_MACHINE}"
test-run-pytest -m "(${marker_expression}) and not emulation_only" $@
fi
}
alias run-pre-merge-tests='run_marked_tests "smoketest"'
alias run-nightly-tests='run_marked_tests "smoketest or nightly"'