Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnitTests and Coverage reporting #444

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions modules/sc-mesh-secure-deployment/src/nats/coverage_report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Name Stmts Miss Cover Missing
-----------------------------------------------------------------
mdm_agent.py 442 307 31% 104-105, 144, 164-209, 233, 237-240, 248-251, 259-262, 268, 275-343, 356-357, 366-370, 380-475, 483-528, 538-573, 584-607, 628, 639-645, 661-697, 715-719, 725-739, 752-813, 824-875, 879-891
src/__init__.py 0 0 100%
src/bat_ctrl_utils.py 130 19 85% 40-41, 78-79, 135-136, 161-162, 173, 193-194, 224-225, 254-263, 277-279
src/cbma_adaptation.py 454 368 19% 83-84, 92-104, 114-183, 188-196, 199-223, 229-243, 246-253, 261-298, 301-314, 317-327, 330-333, 336-346, 349-356, 360-407, 411-427, 430-469, 477-490, 493-518, 525-539, 543-570, 585-618, 626-656, 666-677, 680-691, 702-730, 737-764, 776-838, 845-852, 859-873
src/cbma_paths.py 7 0 100%
src/comms_command.py 192 39 80% 88, 90, 94-102, 105, 107, 112, 117, 125, 154-156, 159-162, 167-169, 176, 187, 201-202, 255-260, 271, 282, 311, 329-330, 342, 356-357, 369, 429-431
src/comms_common.py 26 0 100%
src/comms_config_store.py 21 0 100%
src/comms_controller.py 38 5 87% 33, 48, 79-82
src/comms_if_monitor.py 56 3 95% 85, 95-96
src/comms_service_discovery.py 88 14 84% 114-115, 147, 152-153, 162, 180-211
src/comms_settings.py 253 27 89% 12-13, 148-149, 164-184, 249-256, 312-315, 355, 362
src/comms_status.py 302 23 92% 70, 194, 225-227, 240-242, 247, 251-253, 257-261, 270, 278, 294, 302, 330, 433, 436-438
src/constants.py 44 0 100%
src/interface.py 5 0 100%
src/validation.py 104 2 98% 221-222
tests/__init__.py 0 0 100%
tests/service_discovery_helper.py 22 0 100%
tests/test_bat_ctrl_utils.py 129 10 92% 232-233, 241-242, 245-246, 249-250, 253-254
tests/test_command.py 210 0 100%
tests/test_config_store.py 26 0 100%
tests/test_constants.py 27 0 100%
tests/test_controller.py 32 0 100%
tests/test_if_monitor.py 25 1 96% 32
tests/test_mdm_agent.py 56 0 100%
tests/test_service_discovery.py 45 6 87% 32-33, 55-56, 78-79
tests/test_settings.py 153 0 100%
tests/test_status.py 128 8 94% 28-35
tests/test_validation.py 146 0 100%
-----------------------------------------------------------------
TOTAL 3161 832 74%
Not tested files as not MDM content or tested elsewhere:
batadvvis.py,batstat.py,fmo_agent.py,comms_nats_discovery.py,cbma/*,debug_tests/*,comms_mesh_telemetry.py,comms_interface_info.py
35 changes: 30 additions & 5 deletions modules/sc-mesh-secure-deployment/src/nats/run_unittests_PC.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
#!/bin/bash

# Check if the script is being run by root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run with root privileges."
exit 1
fi

# preconditions
if [ ! -f "$(pwd)/$(basename $0)" ]; then
echo "Script is not being executed in the same folder"
exit 1
fi

needed_apps="batctl swig"
for app in $needed_apps; do
if ! command -v $app &> /dev/null
then
echo "$app is not installed. exit. Tips: sudo apt-get install $app"
exit 1
fi
done

# python virtualenv
python3 -m venv unittest
source unittest/bin/activate
Expand All @@ -8,13 +29,17 @@ source unittest/bin/activate
pip install coverage==7.4.4 # this is for testing purpose
pip install -r requirements.txt

# discover and run unittests
coverage run -m unittest discover -v
report=$(coverage report -m)
# List of files not to used for coverage calculation.
# Files tested elsewhere or not needed to be tested or not mesh shield content
not_used="batadvvis.py,batstat.py,fmo_agent.py,comms_nats_discovery.py,cbma/*,debug_tests/*,comms_mesh_telemetry.py,comms_interface_info.py"

# print report lines starting with "TOTAL"
echo "$report" | grep -e "^src" -e "^mdm" -e "^tests"
# discover and run unittests
coverage run --omit="$not_used" -m unittest discover -v
REPORT=$(coverage report -m)

# print and save coverage report
echo "$REPORT" | tee coverage_report.txt
echo -e "Not tested files as not MDM content or tested elsewhere:\n $not_used" >> coverage_report.txt
# deactivate virtualenv
deactivate

Loading
Loading