From 4d15cdc0faedb0f74252c0f95ee8d9cc23f87784 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:35:45 -0800 Subject: [PATCH 1/2] Update nwbinspector validation workflow (#122) * fail workflow if nwbinspector issues found * update tests to avoid inspector violations * fix formatting * update output file name --- .github/workflows/tests.yml | 6 +++++- tests/testNWBFile.cpp | 4 ++-- tests/testUtils.hpp | 14 +++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c024d06a..063edb24 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -141,4 +141,8 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install nwbinspector - nwbinspector nwb_files --threshold BEST_PRACTICE_VIOLATION + nwbinspector nwb_files --threshold BEST_PRACTICE_VIOLATION --json-file-path out.json + if ! grep -q '"messages": \[\]' out.json; then + echo "NWBInspector found issues in the NWB files" + exit 1 + fi \ No newline at end of file diff --git a/tests/testNWBFile.cpp b/tests/testNWBFile.cpp index df77c4cb..e1c51449 100644 --- a/tests/testNWBFile.cpp +++ b/tests/testNWBFile.cpp @@ -50,7 +50,7 @@ TEST_CASE("createElectricalSeries", "[nwb]") // write timeseries data std::vector mockData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}; - std::vector mockTimestamps = {0.1, 0.2, 0.3, 0.4, 0.5}; + std::vector mockTimestamps = {0.1, 0.3, 0.4, 0.5, 0.8}; std::vector positionOffset = {0, 0}; std::vector dataShape = {mockData.size(), 0}; @@ -105,7 +105,7 @@ TEST_CASE("createMultipleEcephysDatasets", "[nwb]") // write electrical series data std::vector mockData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}; - std::vector mockTimestamps = {0.1, 0.2, 0.3, 0.4, 0.5}; + std::vector mockTimestamps = {0.1, 0.3, 0.4, 0.5, 0.8}; std::vector positionOffset = {0, 0}; std::vector dataShape = {mockData.size(), 0}; diff --git a/tests/testUtils.hpp b/tests/testUtils.hpp index 90440919..b8c85a7b 100644 --- a/tests/testUtils.hpp +++ b/tests/testUtils.hpp @@ -100,14 +100,22 @@ inline std::vector> getMockData2D(SizeType numSamples = 1000, } inline std::vector getMockTimestamps(SizeType numSamples = 1000, - SizeType samplingRate = 30000) + SizeType samplingRate = 30000, + double maxOffset = 0.00001) { std::vector mockTimestamps(numSamples); double samplingPeriod = 1.0 / samplingRate; + std::random_device rd; + std::mt19937 rng(rd()); // random number generator + std::uniform_real_distribution<> dis(-maxOffset, + maxOffset); // range of floats + for (SizeType i = 0; i < numSamples; ++i) { - mockTimestamps[i] = i * samplingPeriod; // Each timestamp is the sample - // number times the sampling period + // Each timestamp is the sample number times the sampling period with an + // offset + double offset = dis(rng); + mockTimestamps[i] = i * samplingPeriod + offset; } return mockTimestamps; From a532ec50703f61cb4c1718c0ef34a6d50e5e8307 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:36:40 -0800 Subject: [PATCH 2/2] Add coverage workflow (#120) * update coverage commands * add coverage workflow * install aqnwb dependencies * update lcov arguments --- .github/workflows/coverage.yml | 48 ++++++++++++++++++++++++++++++++++ CMakePresets.json | 13 +++++++++ cmake/coverage.cmake | 4 +-- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..29adcbac --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,48 @@ +name: Coverage + +on: + push: + branches: + - main + + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install LCov and dependencies + run: | + sudo apt-get update -q + sudo apt-get install -q -y lcov libhdf5-dev libboost-all-dev + git clone https://github.com/catchorg/Catch2.git + cd Catch2 + git checkout "v3.5.3" + cmake -Bbuild -H. -DBUILD_TESTING=OFF + sudo cmake --build build/ --target install + + - name: Configure + run: cmake --preset=ci-coverage + + - name: Build + run: cmake --build build/coverage -j 2 + + - name: Test + working-directory: build/coverage + run: ctest --output-on-failure --no-tests=error -j 2 + + - name: Process coverage info + run: cmake --build build/coverage -t coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + file: build/coverage/coverage.info + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 0ff72039..6d802390 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -120,6 +120,19 @@ "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" } }, + { + "name": "coverage-darwin", + "binaryDir": "${sourceDir}/build/coverage", + "inherits": "ci-darwin", + "hidden": true, + "cacheVariables": { + "ENABLE_COVERAGE": "ON", + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage", + "CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage", + "CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage" + } + }, { "name": "ci-coverage", "inherits": ["coverage-linux", "dev-mode"], diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index c89cc161..6c4b03e2 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -7,14 +7,14 @@ set( lcov -c -q -o "${PROJECT_BINARY_DIR}/coverage.info" -d "${PROJECT_BINARY_DIR}" - --include "${PROJECT_SOURCE_DIR}/*" + --include "${PROJECT_SOURCE_DIR}/src/*" CACHE STRING "; separated command to generate a trace for the 'coverage' target" ) set( COVERAGE_HTML_COMMAND - genhtml --legend -f -q + genhtml --legend -q "${PROJECT_BINARY_DIR}/coverage.info" -p "${PROJECT_SOURCE_DIR}" -o "${PROJECT_BINARY_DIR}/coverage_html"