1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-25 11:39:02 +00:00
trezor-firmware/core/tools/coverage-report
Roman Zeyde c48cfbc59e chore(core): update coverage to 5.5
Because `coverage` 4.5.4 requires Python <=3.8 (EOL).

[no changelog]
2025-04-16 15:14:53 +03:00

49 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
readonly COVERAGE_THRESHOLD=${COVERAGE_THRESHOLD:-0}
if [ ${COVERAGE_THRESHOLD} -ne 0 ]; then
echo "COVERAGE_THRESHOLD set to ${COVERAGE_THRESHOLD}%"
fi
# Moving coverage files from src (tests usually save it there).
mv -v src/.coverage* . 2>/dev/null
# Collect JSON coverage files (generated by `prof`) into a single .coverage file
ls -l .coverage*
./tools/coverage-collect.py .coverage .coverage*.json* || exit 1
EXCLUDES="\
src/typing.py,\
src/apps/ethereum/tokens.py,\
src/apps/webauthn/knownapps.py,\
src/apps/common/coininfo.py,\
src/trezor/messages.py,\
src/trezor/enums/__init__.py"
# Uses core/.coveragerc configuration file
coverage html \
--omit="$EXCLUDES" \
--fail-under=${COVERAGE_THRESHOLD}
EXIT_CODE=$?
RESULT=$(grep pc_cov htmlcov/index.html | egrep -o '[0-9]{1,3}%')
# Catching the case when coverage is less than threshold
if [ ${EXIT_CODE} -eq 2 ]; then
echo "ERROR: Code coverage is less than ${COVERAGE_THRESHOLD}% - ${RESULT}"
echo "See core/htmlcov/index.html for details."
exit 1
fi
# Catching all other errors
if [ ${EXIT_CODE} -ne 0 ]; then
echo "ERROR: Coverage generation failed with exit code ${EXIT_CODE} - see output above"
exit ${EXIT_CODE}
fi
# Happy path
echo "SUCCESS: COVERAGE: ${RESULT}"
echo "See core/htmlcov/index.html for details."