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 %} 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