diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 25987fab0a..ae9f825430 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,12 +8,15 @@ on: jobs: test-simulator: runs-on: ubuntu-latest + env: + LCOV_CAPTURE_FLAGS: --quiet --capture --include "${PWD}/src/*" --exclude '*/src/mesh/generated/*' --directory .pio/build/coverage/src --base-directory "${PWD}" steps: - name: Install libs needed for native build shell: bash run: | sudo apt-get update --fix-missing sudo apt-get install -y libbluetooth-dev libgpiod-dev libyaml-cpp-dev openssl libssl-dev libulfius-dev liborcania-dev libusb-1.0-0-dev libi2c-dev + sudo apt-get install -y lcov - name: Checkout code uses: actions/checkout@v4 @@ -24,7 +27,7 @@ jobs: shell: bash run: | python -m pip install --upgrade pip - pip install -U platformio adafruit-nrfutil + pip install -U platformio adafruit-nrfutil dotmap pip install -U meshtastic --pre - name: Upgrade platformio @@ -36,17 +39,25 @@ jobs: run: bin/build-native.sh # We now run integration test before other build steps (to quickly see runtime failures) - - name: Build for native - run: platformio run -e native + - name: Build for native/coverage + run: | + platformio run -e coverage + lcov ${{ env.LCOV_CAPTURE_FLAGS }} --initial --output-file coverage_base.info - name: Integration test run: | - .pio/build/native/program & sleep 10 # 5 seconds was not enough + .pio/build/coverage/program & + PID=$! + timeout 20 bash -c "until ls -al /proc/$PID/fd | grep socket; do sleep 1; done" echo "Simulator started, launching python test..." python3 -c 'from meshtastic.test import testSimulator; testSimulator()' + wait + lcov ${{ env.LCOV_CAPTURE_FLAGS }} --test-name integration --output-file coverage_integration.info - name: PlatformIO Tests - run: platformio test -e native --junit-output-path testreport.xml + run: | + platformio test -e coverage --junit-output-path testreport.xml + lcov ${{ env.LCOV_CAPTURE_FLAGS }} --test-name tests --output-file coverage_tests.info - name: Test Report uses: dorny/test-reporter@v1.9.1 @@ -56,6 +67,19 @@ jobs: path: testreport.xml reporter: java-junit + - name: Generate Code Coverage Report + run: | + lcov --quiet --add-tracefile coverage_base.info --add-tracefile coverage_integration.info --add-tracefile coverage_tests.info --output-file coverage_src.info + mkdir code-coverage-report + genhtml --quiet --legend --prefix "${PWD}" coverage_src.info --output-directory code-coverage-report + mv coverage_*.info code-coverage-report + + - name: Save Code Coverage Report + uses: actions/upload-artifact@v4 + with: + name: code-coverage-report + path: code-coverage-report + hardware-tests: runs-on: test-runner steps: diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 2d33b723d6..69b2c0a380 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -358,7 +358,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta #ifdef ARCH_PORTDUINO case meshtastic_AdminMessage_exit_simulator_tag: LOG_INFO("Exiting simulator"); - _exit(0); + exit(0); break; #endif diff --git a/test/test_crypto/test_main.cpp b/test/test_crypto/test_main.cpp index 652d5dbcbc..91e8331d50 100644 --- a/test/test_crypto/test_main.cpp +++ b/test/test_crypto/test_main.cpp @@ -176,9 +176,7 @@ void setup() RUN_TEST(test_DH25519); RUN_TEST(test_AES_CTR); RUN_TEST(test_PKC_Decrypt); + exit(UNITY_END()); // stop unit testing } -void loop() -{ - UNITY_END(); // stop unit testing -} \ No newline at end of file +void loop() {} \ No newline at end of file diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index aa11142f71..cad87ea8c5 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -9,3 +9,7 @@ build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} + +[env:coverage] +extends = env:native +build_flags = -lgcov --coverage -fprofile-abs-path ${env:native.build_flags}