Skip to content

Commit

Permalink
Merge pull request #31 from paulsengroup/fix-unit-tests
Browse files Browse the repository at this point in the history
Various changes to CI and unit tests

[ci full]
  • Loading branch information
robomics authored Jun 18, 2022
2 parents a50b4b6 + 20b40f4 commit ad556a9
Show file tree
Hide file tree
Showing 29 changed files with 486 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Build Docker image
on:
create:
branches-ignore:
- "*"
- "**"
tags:
- 'v*.*.*'

Expand Down
44 changes: 34 additions & 10 deletions .github/workflows/unit-tests-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: |
- name: Detect number available CPUs
run: |
ncpus=$(python -c 'import multiprocessing as mp; print(mp.cpu_count())')
echo "CMAKE_BUILD_PARALLEL_LEVEL=$ncpus" >> $GITHUB_ENV
echo "CTEST_PARALLEL_LEVEL=$ncpus" >> $GITHUB_ENV
- name: Generate requirements.txt for pip
run: |
echo 'conan==${{ matrix.conan-ver }}' > requirements.txt
echo 'cmake==${{ matrix.cmake-ver }}' >> requirements.txt
echo 'scipy' >> requirements.txt
- uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -104,19 +113,34 @@ jobs:
-B "${{ github.workspace }}/build"
- name: Build project
run: cmake --build ${{ github.workspace }}/build -j $(nproc)
run: cmake --build ${{ github.workspace }}/build

- name: Generate R package requirement list
run: |
printf 'Package: foo\nVersion: 0.0.1\nLicense: MIT\nDescription: foo\n"' >> DESCRIPTION
printf 'Title: foo\nAuthor: me\nMaintainer: me\nImports: wCorr' >> DESCRIPTION
- name: Install setup-r action dependencies
run: brew install imagemagick@6 libgit2

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.2.0'

- name: Install R packages
uses: r-lib/actions/setup-r-dependencies@v2
with:
cache: true

- name: Run unit tests
working-directory: ${{ github.workspace }}/build
run: |
ctest --test-dir . \
--schedule-random \
--output-on-failure \
--no-tests=error \
--timeout 120 \
--repeat after-timeout:3 \
-E '(SciPy)|(wCorr)' \
-j $(nproc)
ctest --test-dir . \
--schedule-random \
--output-on-failure \
--no-tests=error \
--timeout 60
- name: Inspect MoDLE version
run: |
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/unit-tests-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ jobs:
--output-on-failure \
--no-tests=error \
--timeout 120 \
--repeat after-timeout:3 \
-j $(nproc)
- name: Run integration tests
Expand Down Expand Up @@ -359,12 +358,11 @@ jobs:
- name: Run unit tests
working-directory: ${{ github.workspace }}/build
run: |
ctest --test-dir . \
--schedule-random \
--output-on-failure \
--no-tests=error \
--timeout 120 \
--repeat after-timeout:3 \
ctest --test-dir . \
--schedule-random \
--output-on-failure \
--no-tests=error \
--timeout 60 \
-j $(nproc)
- name: Run integration tests
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ RUN cd "$src_dir/build" \
--output-on-failure \
--no-tests=error \
--timeout 60 \
--repeat after-timeout:3 \
&& rm -rf "$src_dir/test/Testing"

ARG FINAL_BASE_IMAGE
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MoDLE(ConanFile):
requires = ["abseil/20211102.0",
"boost/1.79.0",
"bzip2/1.0.8",
"catch2/2.13.9",
"catch2/3.0.1",
"cli11/2.2.0",
"concurrentqueue/1.0.3",
"cpp-sort/1.13.0",
Expand Down
18 changes: 4 additions & 14 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ add_executable(test_main)

target_sources(
test_main
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/common/cli_utils_test.cpp
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/units/common/cli_utils_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/common/const_map_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/common/dna_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/contact_matrix/contact_matrix_test.cpp
Expand All @@ -32,7 +31,6 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/units/simulation_cpu/simulation_complex_unit_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/simulation_cpu/simulation_simple_unit_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/simulation_internal/extrusion_barriers_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/stats/common.hpp
${CMAKE_CURRENT_SOURCE_DIR}/units/stats/correlation_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/stats/correlation_utils_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/units/stats/descriptive_test.cpp
Expand Down Expand Up @@ -67,7 +65,7 @@ target_link_system_libraries(
absl::strings
Boost::filesystem
Boost::headers
Catch2::Catch2
Catch2::Catch2WithMain
fmt::fmt
HDF5::HDF5
spdlog::spdlog
Expand All @@ -85,12 +83,8 @@ catch_discover_tests(
" - SHORT"
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/../
REPORTER
xml
OUTPUT_DIR
${CMAKE_CURRENT_SOURCE_DIR}/Testing/
OUTPUT_SUFFIX
.xml
EXTRA_ARGS
--success)

Expand All @@ -102,12 +96,8 @@ catch_discover_tests(
" - MEDIUM"
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/../
REPORTER
xml
OUTPUT_DIR
${CMAKE_CURRENT_SOURCE_DIR}/Testing/
OUTPUT_SUFFIX
.xml
EXTRA_ARGS
--success)

Expand All @@ -119,7 +109,7 @@ catch_discover_tests(
" - LONG"
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/../
REPORTER
compact # This dramatically speeds up the test suit
OUTPUT_DIR
${CMAKE_CURRENT_SOURCE_DIR}/Testing/
EXTRA_ARGS
--success)
19 changes: 0 additions & 19 deletions test/test_main.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/units/common/cli_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT

#include <catch2/catch.hpp> // for operator""_catch_sr, AssertionHandler
#include <catch2/catch_test_macros.hpp>
// clang-format off
#include "modle/common/suppress_compiler_warnings.hpp"
DISABLE_WARNING_PUSH
Expand Down
2 changes: 1 addition & 1 deletion test/units/common/const_map_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "modle/common/const_map.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <string_view>

namespace modle::test::utils {
Expand Down
2 changes: 1 addition & 1 deletion test/units/common/dna_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "modle/common/dna.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

#include "modle/common/common.hpp"

Expand Down
22 changes: 13 additions & 9 deletions test/units/contact_matrix/contact_matrix_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <algorithm> // for generate, max
#include <boost/dynamic_bitset/dynamic_bitset.hpp> // for dynamic_bitset, dynamic_bitset<>::ref...
#include <boost/process.hpp>
#include <catch2/catch.hpp> // for operator""_catch_sr, AssertionHandler
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <filesystem> // for path
#include <stdexcept> // for runtime_error
#include <string> // for string
Expand Down Expand Up @@ -171,12 +173,14 @@ TEST_CASE("CMatrix in/decrement", "[cmatrix][short]") {

if constexpr (utils::ndebug_not_defined()) {
CHECK_THROWS_WITH(m.increment(25, 25),
Catch::Contains("Detected an out-of-bound read: attempt to access item at"));
Catch::Matchers::ContainsSubstring(
"Detected an out-of-bound read: attempt to access item at"));
CHECK(m.get_n_of_missed_updates() == 1);
CHECK(m.get_tot_contacts() == 1);

CHECK_THROWS_WITH(m.decrement(25, 25),
Catch::Contains("Detected an out-of-bound read: attempt to access item at"));
Catch::Matchers::ContainsSubstring(
"Detected an out-of-bound read: attempt to access item at"));
CHECK(m.get_n_of_missed_updates() == 1);
CHECK(m.get_tot_contacts() == 1);
}
Expand Down Expand Up @@ -368,7 +372,7 @@ TEST_CASE("CMatrix blur (SciPy)", "[cmatrix][long]") {

for (usize j = 4; j < input_matrix.nrows(); ++j) {
for (auto k = j; k < input_matrix.ncols() - 4; ++k) {
CHECK(Approx(reference_matrix.get(j, k)) == blurred_matrix.get(j, k));
CHECK(Catch::Approx(reference_matrix.get(j, k)) == blurred_matrix.get(j, k));
}
}
}
Expand Down Expand Up @@ -408,7 +412,7 @@ TEST_CASE("CMatrix blur parallel (SciPy)", "[cmatrix][long]") {

for (usize j = 4; j < input_matrix.nrows(); ++j) {
for (auto k = j; k < input_matrix.ncols() - 4; ++k) {
CHECK(Approx(reference_matrix.get(j, k)) == blurred_matrix.get(j, k));
CHECK(Catch::Approx(reference_matrix.get(j, k)) == blurred_matrix.get(j, k));
}
}
}
Expand Down Expand Up @@ -450,8 +454,8 @@ TEST_CASE("CMatrix difference of gaussians (SciPy)", "[cmatrix][long]") {

for (usize j = 4; j < input_matrix.nrows(); ++j) {
for (auto k = j; k < input_matrix.ncols() - 4; ++k) {
CHECK(Approx(reference_matrix.get(j, k)) == gauss_diff_matrix.get(j, k));
CHECK(Approx(m1.get(j, k) - m2.get(j, k)) == gauss_diff_matrix.get(j, k));
CHECK(Catch::Approx(reference_matrix.get(j, k)) == gauss_diff_matrix.get(j, k));
CHECK(Catch::Approx(m1.get(j, k) - m2.get(j, k)) == gauss_diff_matrix.get(j, k));
}
}
}
Expand Down Expand Up @@ -496,8 +500,8 @@ TEST_CASE("CMatrix difference of gaussians - parallel (SciPy)", "[cmatrix][long]

for (usize j = 4; j < input_matrix.nrows(); ++j) {
for (auto k = j; k < input_matrix.ncols() - 4; ++k) {
CHECK(Approx(reference_matrix.get(j, k)) == gauss_diff_matrix.get(j, k));
CHECK(Approx(m1.get(j, k) - m2.get(j, k)) == gauss_diff_matrix.get(j, k));
CHECK(Catch::Approx(reference_matrix.get(j, k)) == gauss_diff_matrix.get(j, k));
CHECK(Catch::Approx(m1.get(j, k) - m2.get(j, k)) == gauss_diff_matrix.get(j, k));
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/units/include/modle/test/self_deleting_folder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class SelfDeletingFolder {
tmpdir = std::filesystem::temp_directory_path();
} catch (const std::filesystem::filesystem_error& e) {
// Workaround spurious CI failures due to missing /tmp folder exception
assert(absl::StartsWith(e.what(), "std::filesystem::temp_directory_path: Not a directory"));
assert(absl::EndsWith(e.what(), "\"/tmp\""));
tmpdir = "test/data/unit_tests/scratch";
}

Expand Down
12 changes: 6 additions & 6 deletions test/units/interval_tree/interval_tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <absl/strings/str_split.h> // for StrSplit, Splitter, ByAnyChar
#include <fmt/format.h> // for format

#include <algorithm> // for max
#include <catch2/catch.hpp> // for AssertionHandler, operator""_catch_sr, SourceLineInfo
#include <filesystem> // for path
#include <string> // for string, basic_string, operator==
#include <string_view> // for string_view
#include <vector> // for vector, allocator
#include <algorithm> // for max
#include <catch2/catch_test_macros.hpp>
#include <filesystem> // for path
#include <string> // for string, basic_string, operator==
#include <string_view> // for string_view
#include <vector> // for vector, allocator

#include "modle/common/numeric_utils.hpp" // for parse_numeric_or_throw
#include "modle/compressed_io/compressed_io.hpp" // for Reader
Expand Down
12 changes: 6 additions & 6 deletions test/units/libmodle_io/bed_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <absl/strings/str_split.h> // for StrSplit, Splitter
#include <fmt/format.h> // for to_string

#include <algorithm> // for sort, max
#include <catch2/catch.hpp> // for AssertionHandler, operator""_catch_sr, SourceLineInfo
#include <filesystem> // for path
#include <string> // for string, basic_string, operator==, char_traits, stoull
#include <string_view> // for operator!=, basic_string_view, string_view, operator<
#include <vector> // for vector
#include <algorithm> // for sort, max
#include <catch2/catch_test_macros.hpp>
#include <filesystem> // for path
#include <string> // for string, basic_string, operator==, char_traits, stoull
#include <string_view> // for operator!=, basic_string_view, string_view, operator<
#include <vector> // for vector

#include "absl/strings/match.h" // for StrContains
#include "modle/bed/bed.hpp" // for BED, Parser, formatter<>::format, BED::BED3
Expand Down
12 changes: 6 additions & 6 deletions test/units/libmodle_io/bed_tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <absl/types/span.h> // for Span
#include <fmt/format.h> // for format

#include <algorithm> // for max, min
#include <catch2/catch.hpp> // for AssertionHandler, operator""_catch_sr, SourceLineInfo
#include <filesystem> // for path
#include <string> // for basic_string, operator==, string
#include <string_view> // for string_view
#include <vector> // for vector
#include <algorithm> // for max, min
#include <catch2/catch_test_macros.hpp>
#include <filesystem> // for path
#include <string> // for basic_string, operator==, string
#include <string_view> // for string_view
#include <vector> // for vector

#include "modle/bed/bed.hpp" // for BED, BED_tree, BED_tree::contains, BED_tree::count_...
#include "modle/common/common.hpp" // for usize, u8
Expand Down
10 changes: 5 additions & 5 deletions test/units/libmodle_io/compressed_io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#include "modle/compressed_io/compressed_io.hpp" // for Reader

#include <catch2/catch.hpp> // for AssertionHandler, operator""_catch_sr, Source...
#include <filesystem> // for path, operator/
#include <fstream> // for ifstream, basic_ios, basic_istream, operator<<
#include <iostream> // for cerr
#include <string> // for operator==, string, basic_string, getline
#include <catch2/catch_test_macros.hpp>
#include <filesystem> // for path, operator/
#include <fstream> // for ifstream, basic_ios, basic_istream, operator<<
#include <iostream> // for cerr
#include <string> // for operator==, string, basic_string, getline

#include "modle/test/self_deleting_folder.hpp" // for SelfDeletingFolder

Expand Down
Loading

0 comments on commit ad556a9

Please sign in to comment.