Skip to content

Commit 7d1d2dc

Browse files
committed
config: runtime: add gcov reset & upload "sub-templates"
Enabling code coverage for a given test job requires 2 actions: * reset GCOV so we only record coverage data during the test itself * pack and upload artifacts to online storage after the test completes The latter is implemented by POSTing the artifact to the storage server, providing the artifact name and URL as a LAVA test result using the following format: artifact-upload:<artifact name>:<artifact URL> This allows the pipeline to add the uploaded artifact(s) to the corresponding node so the information can be easily re-used at a later stage. As we'll enable coverage in many different tests, turn those actions into separate LAVA test definitions that can then be (conditionally) included by each test template when needed. Signed-off-by: Arnaud Ferraris <[email protected]>
1 parent d9852db commit 7d1d2dc

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

config/runtime/util/gcov-reset.jinja2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- from: inline
2+
repository:
3+
metadata:
4+
format: Lava-Test Test Definition 1.0
5+
name: reset-gcov
6+
description: Reset GCOV data
7+
run:
8+
steps:
9+
- GCOV_RESET="/sys/kernel/debug/gcov/reset"
10+
- if [ -f ${GCOV_RESET} ]; then echo 1 > ${GCOV_RESET}; fi
11+
name: reset-gcov
12+
path: inline/reset-gcov.yaml
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- from: inline
2+
name: upload
3+
path: inline/upload.yaml
4+
repository:
5+
metadata:
6+
description: GCOV artifacts upload
7+
format: Lava-Test Test Definition 1.0
8+
name: upload
9+
environment:
10+
- lava-test-shell
11+
os:
12+
- debian
13+
run:
14+
steps:
15+
- GCDA=/sys/kernel/debug/gcov
16+
# Bail out if $GCDA doesn't exist (as GCOV is likely not enabled)
17+
- test -d ${GCDA} || exit 0
18+
- TEMPDIR=$(mktemp -d)
19+
- UPLOAD_PATH="{{ node.name }}-{{ node.id }}"
20+
- UPLOAD_NAME="gcov.tar.gz"
21+
# Retrieve GCOV artifacts
22+
# Taken from https://www.kernel.org/doc/html/v6.12/dev-tools/gcov.html#appendix-b-gather-on-test-sh
23+
- find $GCDA -type d -exec mkdir -p $TEMPDIR/\{\} \;
24+
- find $GCDA -name '*.gcda' -exec sh -c 'cat < $0 > '$TEMPDIR'/$0' {} \;
25+
- find $GCDA -name '*.gcno' -exec sh -c 'cp -d $0 '$TEMPDIR'/$0' {} \;
26+
- tar czf gcov.tar.gz -C $TEMPDIR sys
27+
- rm -rf $TEMPDIR
28+
# Use set +x so we can don't echo secret tokens in the logs
29+
- set +x
30+
- . /lava-${LAVA_JOB_ID}/secrets
31+
# FIXME: this should actually be part of the rootfs
32+
- apt-get -q update
33+
- apt-get -q install -y curl
34+
- >-
35+
lava-test-case "artifact-upload:coverage_data:{{ storage_config.base_url }}/${UPLOAD_PATH}/${UPLOAD_NAME}"
36+
--shell curl -X POST {{ storage_config.base_url }}/upload
37+
-H "Authorization: Bearer ${UPLOAD_TOKEN}"
38+
-F "file0=@${UPLOAD_NAME}"
39+
-F "path=${UPLOAD_PATH}"
40+
41+
secrets:
42+
UPLOAD_TOKEN: {{ storage_config.name }}-token

0 commit comments

Comments
 (0)