From 92caaf0cf07d2e90eea68e32db05e77cc229cc41 Mon Sep 17 00:00:00 2001 From: Karel Srot Date: Fri, 13 Dec 2024 12:07:37 +0100 Subject: [PATCH] install latest coverage module change --include pattern for coverage report avoid re-loading coverage module do not define PYTHONPATH add fix for import --- plans/upstream-keylime-all-tests.fmf | 9 +-------- setup/enable_keylime_coverage/test.sh | 9 +++++---- setup/generate_coverage_report/test.sh | 13 +++++++------ upstream/run_keylime_tests/test.sh | 8 ++++---- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/plans/upstream-keylime-all-tests.fmf b/plans/upstream-keylime-all-tests.fmf index 23b0d947..d505570e 100644 --- a/plans/upstream-keylime-all-tests.fmf +++ b/plans/upstream-keylime-all-tests.fmf @@ -11,7 +11,7 @@ discover: - /setup/apply_workarounds - /setup/configure_tpm_emulator - /setup/install_upstream_keylime - - /setup/install_upstream_rust_keylime + - /setup/install_rust_keylime_from_copr #- /setup/enable_keylime_debug_messages - /setup/enable_keylime_coverage # change IMA policy to simple and run one attestation scenario @@ -19,16 +19,9 @@ discover: - /setup/configure_kernel_ima_module/ima_policy_simple - /functional/basic-attestation-on-localhost # now change IMA policy to signing and run all tests - - /setup/configure_kernel_ima_module/ima_policy_signing - - "^/functional/.*" - - "^/compatibility/.*" - - "^/regression/.*" - - /update/basic-attestation-on-localhost/all - - "/sanity/.*" # run upstream test suite - /upstream/run_keylime_tests - /setup/generate_coverage_report - - /setup/generate_upstream_rust_keylime_code_coverage execute: how: tmt diff --git a/setup/enable_keylime_coverage/test.sh b/setup/enable_keylime_coverage/test.sh index 18e6a3d9..b0138ea8 100755 --- a/setup/enable_keylime_coverage/test.sh +++ b/setup/enable_keylime_coverage/test.sh @@ -7,7 +7,7 @@ rlJournalStart rlPhaseStartSetup "Install coverage script its dependencies" rlRun 'rlImport "./test-helpers"' || rlDie "cannot import keylime-tests/test-helpers library" rpm -q python3-coverage && rlRun "rpm -e python3-coverage" - rlRun "pip3 install coverage==6.5.0" + rlRun "pip3 install coverage" INSTALL_DIR=$( dirname $(find /usr/local/lib*/python*/site-packages -name coverage ) ) rlRun "touch $__INTERNAL_limeCoverageDir/enabled" rlPhaseEnd @@ -27,9 +27,10 @@ rlJournalStart fi rlRun "cat > ${LIBDIR}/sitecustomize.py <<_EOF import sys -sys.path.append(\"${INSTALL_DIR}\") -import coverage -coverage.process_startup() +if 'coverage' not in sys.modules: + sys.path.append(\"${INSTALL_DIR}\") + import coverage + coverage.process_startup() _EOF" grep -q COVERAGE_PROCESS_START /etc/bashrc || rlRun "echo 'export COVERAGE_PROCESS_START=/var/tmp/limeLib/coverage/coveragerc' >> /etc/bashrc" SERVICES="verifier registrar" diff --git a/setup/generate_coverage_report/test.sh b/setup/generate_coverage_report/test.sh index 6b85d62b..6bee3ecf 100755 --- a/setup/generate_coverage_report/test.sh +++ b/setup/generate_coverage_report/test.sh @@ -31,6 +31,7 @@ UPLOAD_SERVICE=$( uploadServiceFind ) #export PACKIT_SOURCE_SHA=a79b05642bbe04af0ef0a356afd4f5af276898bb OMIT_FILES="--omit=/var/lib/keylime/secure/unzipped/*,*/keylime/backport_dataclasses.py" +INCLUDE_FILES='*/*keylime*/*,*/*keylime*' rlJournalStart @@ -49,22 +50,22 @@ rlJournalStart rlAssertExists .coverage # packit summary report rlLogInfo "keylime-tests code coverage summary report" - rlRun -s "coverage report --include '*keylime*' $OMIT_FILES" + rlRun -s "coverage report --include "$INCLUDE_FILES" $OMIT_FILES" rlAssertGreater "coverage report should contain at least 100 files" $( grep -c keylime $rlRun_LOG ) 100 - rlRun "coverage xml --include '*keylime*' $OMIT_FILES" + rlRun "coverage xml --include $INCLUDE_FILES $OMIT_FILES" rlRun "mv coverage.xml coverage.packit.xml" rlRun "mv .coverage .coverage.packit" # testsuite summary report if [ -f coverage.testsuite ]; then rlLogInfo "keylime testsuite code coverage summary report" rlRun "cp coverage.testsuite .coverage" - rlRun "coverage report --include '*keylime*' $OMIT_FILES" + rlRun "coverage report --include "$INCLUDE_FILES" $OMIT_FILES" fi # unittests summary report if [ -f coverage.unittests ]; then rlLogInfo "keylime unittests code coverage summary report" rlRun "cp coverage.unittests .coverage" - rlRun "coverage report --include '*keylime*' $OMIT_FILES" + rlRun "coverage report --include "$INCLUDE_FILES" $OMIT_FILES" fi # now create overall report including upstream tests [ -f coverage.testsuite ] && rlRun "cp coverage.testsuite .coverage.testsuite" @@ -74,8 +75,8 @@ rlJournalStart rlRun "coverage combine" ls -l .coverage* rlLogInfo "combined code coverage summary report" - rlRun "coverage html --include '*keylime*' $OMIT_FILES --show-contexts" - rlRun -s "coverage report --include '*keylime*' $OMIT_FILES" + rlRun "coverage html --include "$INCLUDE_FILES" $OMIT_FILES --show-contexts" + rlRun -s "coverage report --include "$INCLUDE_FILES" $OMIT_FILES" CURRENT_COVERAGE=$( sed -nE 's/TOTAL.* ([0-9]*)%/\1/ p' $rlRun_LOG ) rlLogInfo "Current total coverage is ${CURRENT_COVERAGE}%" [ "${PATCH_COVERAGE_THRESHOLD}" == "total" ] && PATCH_COVERAGE_THRESHOLD=${CURRENT_COVERAGE} diff --git a/upstream/run_keylime_tests/test.sh b/upstream/run_keylime_tests/test.sh index a1191924..885dffb7 100755 --- a/upstream/run_keylime_tests/test.sh +++ b/upstream/run_keylime_tests/test.sh @@ -39,10 +39,10 @@ rlJournalStart rlRun "cp -r /var/tmp/keylime_sources/* $TmpDir" pushd $TmpDir/test - # Let's define PYTHONPATH to the keylime source, which will make it - # so that we will use primarily the code from the keylime sources - # tree under testing, instead of the installed (rpm) modules. - rlRun "export PYTHONPATH=\"\${TmpDir}\"" + # Let's not define PYTHONPATH se we measure installed modules + #rlRun "export PYTHONPATH=\"\${TmpDir}\"" + # fix for import + rlRun "sed -i 's/from test.utils/from utils/' test_create_runtime_policy.py" # if TPM emulator is present if limeTPMEmulated; then