From e08ccd8725be99e5c78e84fb431c5845a107d5d8 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Tue, 20 May 2025 14:18:19 +0200 Subject: [PATCH 1/2] 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:: 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 --- config/runtime/util/gcov-reset.jinja2 | 12 ++++++++ config/runtime/util/gcov-upload.jinja2 | 39 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 config/runtime/util/gcov-reset.jinja2 create mode 100644 config/runtime/util/gcov-upload.jinja2 diff --git a/config/runtime/util/gcov-reset.jinja2 b/config/runtime/util/gcov-reset.jinja2 new file mode 100644 index 0000000000..9cd380589e --- /dev/null +++ b/config/runtime/util/gcov-reset.jinja2 @@ -0,0 +1,12 @@ + - from: inline + repository: + metadata: + format: Lava-Test Test Definition 1.0 + name: reset-gcov + description: Reset GCOV data + run: + steps: + - GCOV_RESET="/sys/kernel/debug/gcov/reset" + - if [ -f ${GCOV_RESET} ]; then echo 1 > ${GCOV_RESET}; fi + name: reset-gcov + path: inline/reset-gcov.yaml diff --git a/config/runtime/util/gcov-upload.jinja2 b/config/runtime/util/gcov-upload.jinja2 new file mode 100644 index 0000000000..a2c74f3c0e --- /dev/null +++ b/config/runtime/util/gcov-upload.jinja2 @@ -0,0 +1,39 @@ + - from: inline + name: upload + path: inline/upload.yaml + repository: + metadata: + description: GCOV artifacts upload + format: Lava-Test Test Definition 1.0 + name: upload + environment: + - lava-test-shell + os: + - debian + run: + steps: + - GCDA=/sys/kernel/debug/gcov + # Bail out if $GCDA doesn't exist (as GCOV is likely not enabled) + - test -d ${GCDA} || exit 0 + - TEMPDIR=$(mktemp -d) + - UPLOAD_PATH="{{ node.name }}-{{ node.id }}" + - UPLOAD_NAME="gcov.tar.xz" + # Retrieve GCOV artifacts + # Taken from https://www.kernel.org/doc/html/v6.12/dev-tools/gcov.html#appendix-b-gather-on-test-sh + - find $GCDA -type d -exec mkdir -p $TEMPDIR/\{\} \; + - find $GCDA -name '*.gcda' -exec sh -c 'cat < $0 > '$TEMPDIR'/$0' {} \; + - find $GCDA -name '*.gcno' -exec sh -c 'cp -d $0 '$TEMPDIR'/$0' {} \; + - tar cJf ${UPLOAD_NAME} -C $TEMPDIR sys + - rm -rf $TEMPDIR + # Use set +x so we can don't echo secret tokens in the logs + - set +x + - . /lava-${LAVA_JOB_ID}/secrets + - >- + lava-test-case "artifact-upload:coverage_data:{{ storage_config.base_url }}/${UPLOAD_PATH}/${UPLOAD_NAME}" + --shell curl -X POST {{ storage_config.base_url }}/upload + -H "Authorization: Bearer ${UPLOAD_TOKEN}" + -F "file0=@${UPLOAD_NAME}" + -F "path=${UPLOAD_PATH}" + +secrets: + UPLOAD_TOKEN: {{ storage_config.name }}-token From 33aa7caefd1692a825eb13e17a8fe01caa6c4a14 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Tue, 6 May 2025 18:22:02 +0200 Subject: [PATCH 2/2] config: runtime: tests: ltp: enable support for code coverage When enabling code coverage support using in-kernel GCOV, we must first reset coverage "recording" right before starting the test, then ensure we pack and upload the resulting artifacts. Those steps are executed by including the corresponding sub-templates whenever the kernel has been built with GCOV support, IOW when the `coverage` fragment is part of the build config. Signed-off-by: Arnaud Ferraris --- config/runtime/tests/ltp.jinja2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/runtime/tests/ltp.jinja2 b/config/runtime/tests/ltp.jinja2 index 617593f7d0..fe1085e48a 100644 --- a/config/runtime/tests/ltp.jinja2 +++ b/config/runtime/tests/ltp.jinja2 @@ -3,6 +3,9 @@ timeout: minutes: {{ job_timeout|default(15) }} definitions: +{% if "coverage" in node.data.config_full %} +{% include "util/gcov-reset.jinja2" %} +{% endif %} - repository: https://github.com/kernelci/test-definitions from: git revision: kernelci.org @@ -12,3 +15,6 @@ TST_CMDFILES: "{{ tst_cmdfiles|default('') }}" SKIP_INSTALL: "{{ skip_install }}" SKIPFILE: {{ skipfile }} +{% if "coverage" in node.data.config_full %} +{% include "util/gcov-upload.jinja2" %} +{% endif %}