Skip to content

Commit

Permalink
Merge branch 'main' into add_read
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel authored Jan 8, 2025
2 parents 7b88122 + a532ec5 commit ebc7e14
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 8 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions cmake/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/testNWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TEST_CASE("createElectricalSeries", "[nwb]")

// write timeseries data
std::vector<float> mockData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
std::vector<double> mockTimestamps = {0.1, 0.2, 0.3, 0.4, 0.5};
std::vector<double> mockTimestamps = {0.1, 0.3, 0.4, 0.5, 0.8};
std::vector<SizeType> positionOffset = {0, 0};
std::vector<SizeType> dataShape = {mockData.size(), 0};

Expand Down Expand Up @@ -131,7 +131,7 @@ TEST_CASE("createMultipleEcephysDatasets", "[nwb]")

// write electrical series data
std::vector<float> mockData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
std::vector<double> mockTimestamps = {0.1, 0.2, 0.3, 0.4, 0.5};
std::vector<double> mockTimestamps = {0.1, 0.3, 0.4, 0.5, 0.8};
std::vector<SizeType> positionOffset = {0, 0};
std::vector<SizeType> dataShape = {mockData.size(), 0};

Expand Down
14 changes: 11 additions & 3 deletions tests/testUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ inline std::vector<std::vector<float>> getMockData2D(SizeType numSamples = 1000,
}

inline std::vector<double> getMockTimestamps(SizeType numSamples = 1000,
SizeType samplingRate = 30000)
SizeType samplingRate = 30000,
double maxOffset = 0.00001)
{
std::vector<double> 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;
Expand Down

0 comments on commit ebc7e14

Please sign in to comment.