Skip to content

Commit

Permalink
UnitTests and Coverage reporting
Browse files Browse the repository at this point in the history
4966 - Comms Service Discovery
4967 - Comms Settings
4968 - Comms Status

Jira-Id: SECO-4966, SECO-4967, SECO-4968

Signed-off-by: Mika Joenpera <mika.joenpera@unikie.com>
  • Loading branch information
joenpera committed Apr 29, 2024
1 parent 082b52a commit e5c03fe
Show file tree
Hide file tree
Showing 8 changed files with 691 additions and 232 deletions.
33 changes: 33 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,33 @@
Name Stmts Miss Cover Missing
-----------------------------------------------------------------
mdm_agent.py 440 306 30% 103-104, 143, 163-208, 234-239, 248-250, 258-261, 267, 274-342, 355, 364-368, 378-473, 481-526, 536-571, 582-605, 626, 637-643, 659-695, 713-717, 723-737, 750-811, 822-873, 877-889
src/__init__.py 0 0 100%
src/cbma_adaptation.py 473 383 19% 94-106, 109-112, 122-177, 182-190, 193-217, 223-237, 240-247, 252-276, 282-319, 322-335, 338-348, 351-354, 357-379, 382-385, 388-425, 428-435, 438-448, 451-458, 462-509, 513-529, 532-571, 578-591, 594-618, 625-639, 643-670, 676-702, 712-723, 726-737, 748-775, 782-807, 819-879, 886-893, 900-914
src/cbma_paths.py 7 0 100%
src/comms_command.py 192 131 32% 88, 90, 92, 94-102, 105, 107, 109, 111-114, 116-119, 125, 147-220, 230-317, 321-335, 338-344, 348-362, 365-371, 410-434
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 2 96% 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 296 14 95% 70, 194, 225-227, 240-242, 258, 264, 294, 302, 321-323, 528
src/constants.py 29 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_command.py 26 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 2714 899 67%
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

0 comments on commit e5c03fe

Please sign in to comment.