Skip to content

Commit

Permalink
install latest coverage module
Browse files Browse the repository at this point in the history
change --include pattern for coverage report

avoid re-loading coverage module

do not define PYTHONPATH

add fix for import
  • Loading branch information
kkaarreell committed Dec 16, 2024
1 parent 3406dc7 commit 92caaf0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
9 changes: 1 addition & 8 deletions plans/upstream-keylime-all-tests.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@ 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
# this is to utilize also a different parser
- /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
Expand Down
9 changes: 5 additions & 4 deletions setup/enable_keylime_coverage/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions setup/generate_coverage_report/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

Check warning

Code scanning / shellcheck

The surrounding quotes actually unquote this. Remove or escape them. Warning test

The surrounding quotes actually unquote this. Remove or escape them.
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"

Check warning

Code scanning / shellcheck

The surrounding quotes actually unquote this. Remove or escape them. Warning test

The surrounding quotes actually unquote this. Remove or escape them.
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"

Check warning

Code scanning / shellcheck

The surrounding quotes actually unquote this. Remove or escape them. Warning test

The surrounding quotes actually unquote this. Remove or escape them.
fi
# now create overall report including upstream tests
[ -f coverage.testsuite ] && rlRun "cp coverage.testsuite .coverage.testsuite"
Expand All @@ -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"

Check warning

Code scanning / shellcheck

The surrounding quotes actually unquote this. Remove or escape them. Warning test

The surrounding quotes actually unquote this. Remove or escape them.
rlRun -s "coverage report --include "$INCLUDE_FILES" $OMIT_FILES"

Check warning

Code scanning / shellcheck

The surrounding quotes actually unquote this. Remove or escape them. Warning test

The surrounding quotes actually unquote this. Remove or escape them.
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}
Expand Down
8 changes: 4 additions & 4 deletions upstream/run_keylime_tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92caaf0

Please sign in to comment.