From aca33b83a4a038b9e72ec77db9d7f3c23972e243 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 13 Feb 2024 19:27:19 -0600 Subject: [PATCH] tests: one file for safety and coverage tests (#1865) * one file for all tests * clean up * unreachable * Revert "unreachable" This reverts commit 4b792b1f9b5290b57975d21c24be5029be16b0e3. --- .github/workflows/test.yaml | 17 ----------------- pyproject.toml | 2 +- tests/safety/test.sh | 23 +++++++++++++++++++++++ tests/safety/test_coverage.sh | 27 --------------------------- 4 files changed, 24 insertions(+), 45 deletions(-) delete mode 100755 tests/safety/test_coverage.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5f65560d..8f1c5f01 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -89,23 +89,6 @@ jobs: scons -j$(nproc) ${{ matrix.flags }} && \ tests/safety/test.sh" - safety_coverage: - name: safety coverage - runs-on: ubuntu-20.04 - timeout-minutes: 20 - steps: - - uses: actions/checkout@v2 - - name: Build Docker image - run: eval "$BUILD" - - name: Run safety coverage test - timeout-minutes: 5 - run: | - ${{ env.RUN }} "cd .. && \ - scons -c && \ - scons -j$(nproc) opendbc/ cereal/ && \ - cd panda/tests/safety && \ - ./test_coverage.sh" - misra: name: MISRA C:2012 runs-on: ubuntu-20.04 diff --git a/pyproject.toml b/pyproject.toml index 2b5b18c3..72bce22b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,4 +9,4 @@ flake8-implicit-str-concat.allow-multiline=false [tool.pytest.ini_options] # FIXME: pytest 8.0.0 now collects all files, stop pytest-cpp from running these # the `not Base` filter is needed due to a bug in pytest w/ unittest: https://github.com/pytest-dev/pytest/issues/11552 -addopts = "--ignore=test.sh --ignore=test_coverage.sh -n auto -k 'not Base'" +addopts = "--ignore=test.sh -n auto -k 'not Base'" diff --git a/tests/safety/test.sh b/tests/safety/test.sh index 22620dfe..13703b26 100755 --- a/tests/safety/test.sh +++ b/tests/safety/test.sh @@ -4,8 +4,31 @@ set -e DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" cd $DIR +# reset coverage data and generate gcc note file +rm -f ../libpanda/*.gcda +scons -j$(nproc) -D --coverage + +# run safety tests and generate coverage data HW_TYPES=( 6 9 ) for hw_type in "${HW_TYPES[@]}"; do echo "Testing HW_TYPE: $hw_type" HW_TYPE=$hw_type pytest test_*.py done + +# generate and open report +if [ "$1" == "--report" ]; then + geninfo ../libpanda/ -o coverage.info + genhtml coverage.info -o coverage-out + sensible-browser coverage-out/index.html +fi + +# test coverage +GCOV_OUTPUT=$(gcov -n ../libpanda/panda.c) +INCOMPLETE_COVERAGE=$(echo "$GCOV_OUTPUT" | paste -s -d' \n' | grep -E "File.*(safety\/safety_.*)|(safety)\.h" | grep -v "100.00%" || true) +if [ -n "$INCOMPLETE_COVERAGE" ]; then + echo "FAILED: Some files have less than 100% coverage:" + echo "$INCOMPLETE_COVERAGE" + exit 1 +else + echo "SUCCESS: All checked files have 100% coverage!" +fi diff --git a/tests/safety/test_coverage.sh b/tests/safety/test_coverage.sh deleted file mode 100755 index fa27716a..00000000 --- a/tests/safety/test_coverage.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -set -e - -# reset coverage data and generate gcc note file -rm -f ../libpanda/*.gcda -scons -j$(nproc) -D --coverage - -# run safety tests to generate coverage data -./test.sh - -# generate and open report -if [ "$1" == "--report" ]; then - geninfo ../libpanda/ -o coverage.info - genhtml coverage.info -o coverage-out - sensible-browser coverage-out/index.html -fi - -# test coverage -GCOV_OUTPUT=$(gcov -n ../libpanda/panda.c) -INCOMPLETE_COVERAGE=$(echo "$GCOV_OUTPUT" | paste -s -d' \n' | grep -E "File.*(safety\/safety_.*)|(safety)\.h" | grep -v "100.00%" || true) -if [ -n "$INCOMPLETE_COVERAGE" ]; then - echo "FAILED: Some files have less than 100% coverage:" - echo "$INCOMPLETE_COVERAGE" - exit 1 -else - echo "SUCCESS: All checked files have 100% coverage!" -fi