Skip to content

Commit 9ec5c5a

Browse files
committed
Merge remote-tracking branch 'lucascolley/windows' into windows
2 parents 1a76a43 + a35af8c commit 9ec5c5a

File tree

8 files changed

+281
-139
lines changed

8 files changed

+281
-139
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,31 @@ jobs:
1616
tests:
1717
name: ${{ matrix.environment }} ${{ matrix.runs-on }}
1818
runs-on: ${{ matrix.runs-on }}
19-
env:
20-
XSREF_TABLES_PATH: "${{ github.workspace }}/xsref/tables"
2119
strategy:
2220
fail-fast: false
2321
matrix:
2422
environment: [tests-ci]
2523
runs-on: [ubuntu-latest, macos-latest, windows-latest]
2624

2725
steps:
26+
- name: Set XSREF_TABLES_PATH
27+
shell: bash
28+
run: |
29+
if [ "$RUNNER_OS" == "Windows" ]; then
30+
echo "XSREF_TABLES_PATH=${{ github.workspace }}\\xsref\\tables" >> $GITHUB_ENV
31+
else
32+
echo "XSREF_TABLES_PATH=${{ github.workspace }}/xsref/tables" >> $GITHUB_ENV
33+
fi
2834
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2935
- uses: prefix-dev/setup-pixi@92815284c57faa15cd896c4d5cfb2d59f32dc43d # v0.8.3
3036
with:
3137
pixi-version: v0.44.0
3238
cache: true
3339
environments: ${{ matrix.environment }}
3440
- name: Run tests
35-
run: pixi run --environment=tests-ci tests-ci
41+
run: pixi run --environment=tests-ci tests-coverage-ci
42+
- name: Upload HTML coverage report
43+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
44+
with:
45+
name: cov-html
46+
path: build/coverage_report/**

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,3 @@ build/
4343

4444
# xsref
4545
xsref/
46-
47-
# IDEs
48-
.vscode

pixi.lock

Lines changed: 183 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,44 +65,52 @@ tests.cmd = ["ctest", "--output-on-failure", "--test-dir", "build/tests"]
6565
tests.depends-on = ["clone-xsref", "build-tests"]
6666
tests.cwd = "."
6767

68+
## Coverage
69+
70+
[feature.coverage.dependencies]
71+
lcov = ">=1.16,<2"
72+
73+
[feature.coverage.tasks]
74+
# Configure with tests and coverage
75+
configure-coverage.cmd = [
76+
"cmake",
77+
# Enable building tests
78+
"-DBUILD_TESTS=ON",
79+
# Enable Coverage
80+
"-DCMAKE_BUILD_TYPE=Coverage",
81+
# The source is in the root directory
82+
"-S .",
83+
# We want to build in the build directory
84+
"-B build",
85+
]
86+
configure-coverage.cwd = "."
87+
configure-coverage.env.XSREF_TABLES_PATH = "$PWD/xsref/tables"
88+
# Open coverage report
89+
open-coverage.cmd = ["open", "index.html"]
90+
open-coverage.cwd = "build/coverage_report"
91+
92+
## Tests CI
93+
6894
[feature.tests-ci.dependencies]
6995
ccache = ">=4.11.2,<5"
7096

7197
[feature.tests-ci.tasks]
98+
# Build and generate coverage report
99+
# TODO: use a task arg for parallelism https://github.com/prefix-dev/pixi/pull/3433
72100
build-tests-ci.cmd = ["cmake", "--build", "build", "-j3"]
73-
build-tests-ci.depends-on = ["clone-xsref", "configure-tests"]
101+
build-tests-ci.depends-on = ["clone-xsref", "configure-coverage"]
74102
build-tests-ci.cwd = "."
75-
76-
# run tests
103+
# Run tests
77104
tests-ci.cmd = ["ctest", "--output-on-failure", "--test-dir", "build/tests", "-j3"]
78105
tests-ci.depends-on = ["build-tests-ci"]
79106
tests-ci.cwd = "."
80-
81-
## Coverage
82-
83-
# [feature.coverage.dependencies]
84-
# lcov = ">=1.16,<2"
85-
86-
# [feature.coverage.tasks.configure-coverage]
87-
# cmd = [
88-
# "cmake",
89-
# "-DCMAKE_BUILD_TYPE=Coverage",
90-
# # The source is in the root directory
91-
# "-S .",
92-
# # We want to build in the build directory
93-
# "-B build",
94-
# ]
95-
96-
# [feature.coverage.tasks.coverage]
97-
# depends-on = ["configure-coverage"]
98-
# cmd = ["cmake", "--build", "build", "--target", "coverage_html"]
99-
100-
# [feature.coverage.tasks.tests-coverage]
101-
# # Generate the coverage report and then run tests under the same configuration
102-
# depends-on = ["coverage"]
103-
# cwd = "build"
104-
# cmd = "ctest"
107+
# Coverage
108+
coverage.cmd = ["cmake", "--build", "build", "--target", "coverage_html", "-j3"]
109+
coverage.depends-on = ["tests-ci"]
110+
coverage.cwd = "."
111+
# Tests and coverage
112+
tests-coverage-ci.depends-on = ["coverage"]
105113

106114
[environments]
107115
default = { features = ["build", "tests"], solve-group = "default" }
108-
tests-ci = { features = ["build", "tests", "tests-ci"], solve-group = "default" }
116+
tests-ci = { features = ["build", "tests", "tests-ci", "coverage"], solve-group = "default" }

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ target_include_directories(xsf INTERFACE ${CMAKE_SOURCE_DIR}/include)
88

99
set(TEST_BASE_DIR "${CMAKE_SOURCE_DIR}/tests")
1010

11+
include(${CMAKE_SOURCE_DIR}/tests/Coverage.cmake)
12+
1113
file(GLOB TEST_SOURCES "*/test_*.cpp")
1214
foreach(test_file ${TEST_SOURCES})
1315
# Families of tests go in subfolders of xsf/tests. Test files in different

tests/Coverage.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
2+
3+
# Enable coverage compilation option
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
6+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
7+
endif()
8+
if(MSVC)
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /coverage")
10+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /coverage")
11+
endif()
12+
13+
# Add custom targets for generating coverage reports
14+
add_custom_target(coverage
15+
COMMAND lcov --capture --directory . --output-file coverage.info
16+
COMMAND lcov --output-file coverage.info --extract coverage.info '*/include/xsf/*'
17+
COMMAND lcov --list coverage.info
18+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
19+
COMMENT "Generating coverage report"
20+
)
21+
22+
# Generate coverage reports in HTML format
23+
add_custom_target(coverage_html
24+
COMMAND genhtml --demangle-cpp --legend coverage.info --output-directory coverage_report
25+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
26+
COMMENT "Generating HTML coverage report"
27+
)
28+
add_dependencies(coverage_html coverage)
29+
30+
endif() # CMAKE_BUILD_TYPE=Coverage

tests/scipy_special_tests/test_cyl_bessel_i.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TEST_CASE("cyl_bessel_i dD->D scipy_special_tests", "[cyl_bessel_i][dD->D][scipy
3535
auto [desired, fallback] = output;
3636
auto out = xsf::cyl_bessel_i(v, z);
3737
auto error = xsf::extended_relative_error(out, desired);
38-
tol = adjust_tolerance(tol);
38+
tol = adjust_tolerance(tol, 12.0);
3939
CAPTURE(v, z, out, desired, error, tol, fallback);
4040
REQUIRE(error <= tol);
4141
}

tests/testing_utils.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,25 @@ Catch::Generators::GeneratorWrapper<std::tuple<T1, T2, T3>> xsf_test_cases(
132132
}
133133

134134
template <typename T>
135-
T adjust_tolerance(T tol) {
135+
T adjust_tolerance(T tol, T factor = 4) {
136136
// Add some wiggle room to tolerance from table.
137-
return 4 * std::max(std::numeric_limits<T>::epsilon(), tol);
137+
return factor * std::max(std::numeric_limits<T>::epsilon(), tol);
138138
}
139139

140140
std::string get_platform_str() {
141-
/* This is going to get a string "<compiler>-<os>-<architecture>" using conditional
142-
* compilation, but for now we're just stubbing things out. */
141+
/* This should use Boost.Predef
142+
* https://www.boost.org/doc/libs/1_87_0/libs/predef/doc/index.html
143+
* (Boost isn't a dependency yet but this is planned)
144+
* and we should have tolerance files for a wider variety of
145+
* compiler/os/architecture combos, including for specific compiler
146+
* versions. For now, there are these two platforms with tolerance
147+
* files and we use the former with Clang on Mac and the later
148+
* otherwise. */
149+
#if defined(__clang__) && defined(__APPLE__)
150+
return "clang-darwin-aarch64";
151+
#else
143152
return "gcc-linux-x86_64";
153+
#endif
144154
}
145155

146156
} // namespace

0 commit comments

Comments
 (0)