Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ jobs:

- name: Run CTest
if: ${{ runner.os == 'Linux' }}
continue-on-error: true
run: ctest --test-dir build --output-on-failure

- name: Valgrind test_bethe_ext00
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get install -y valgrind
valgrind --leak-check=full --track-origins=yes --error-exitcode=1 \
./build/tests/test_bethe_ext00

- name: Run compiled programs on Linux
if: ${{ runner.os == 'Linux' }}
run: |
Expand All @@ -45,3 +37,26 @@ jobs:
run: |
./build/examples/Debug/dedx_example
./build/examples/Debug/dedx_list

valgrind:
runs-on: ubuntu-latest
needs: build_and_test
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: cmake -S . -B build

- name: Build
run: cmake --build build --parallel

- name: Install Valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind

- name: Valgrind test_bethe_ext00
run: |
valgrind --leak-check=full --track-origins=yes --error-exitcode=1 \
./build/tests/test_bethe_ext00
37 changes: 37 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Coverage

on: [push, pull_request]

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install lcov
run: |
sudo apt-get update
sudo apt-get install -y lcov

- name: Configure
run: cmake --preset coverage

- name: Build
run: cmake --build --preset coverage --parallel

- name: Run tests
run: ctest --preset coverage

- name: Collect coverage
run: |
lcov --capture --directory build-coverage --output-file coverage.info
lcov --ignore-errors unused --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.info
lcov --list coverage.info

- name: Upload to Codecov
uses: codecov/codecov-action@v5
with:
files: coverage.info
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 3 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [
"llvm-vs-code-extensions.vscode-clangd", // C language server (clangd)
"ms-vscode.cmake-tools", // CMake integration + CTest
"twxs.cmake" // CMake syntax highlighting
"llvm-vs-code-extensions.vscode-clangd",
"ms-vscode.cmake-tools",
"twxs.cmake"
]
}
12 changes: 1 addition & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug loadTest",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.buildDirectory}/tests/loadTest",
"args": ["1"],
"cwd": "${workspaceFolder}/libdedx",
"MIMode": "gdb",
"preLaunchTask": "CMake: Build"
},
{
"name": "Debug dedx_example",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.buildDirectory}/examples/dedx_example",
"args": [],
"cwd": "${workspaceFolder}/libdedx",
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"preLaunchTask": "CMake: Build"
}
Expand Down
16 changes: 8 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
// CMake
"cmake.buildDirectory": "${workspaceFolder}/build",
"cmake.configureOnOpen": true,
"cmake.useCMakePresets": "always",

// CTest integration — tells VS Code Test Explorer to use CTest
"cmake.ctest.allowParallelJobs": true,
"testExplorer.useNativeTesting": true,

// Clangd (C language server)
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build",
"--clang-tidy",
"--header-insertion=never"
],
// Clangd (C language server) — clangd not currently installed, using ms-vscode.cpptools instead.
// If clangd is installed later, switch defaultFormatter below and uncomment:
// "clangd.arguments": [
// "--compile-commands-dir=${workspaceFolder}/build",
// "--clang-tidy",
// "--header-insertion=never"
// ],
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools",
"editor.formatOnSave": true
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ else()
endif()

# ---- Data paths (baked into dedx_config.h at configure time) ----
set(DEDX_DATA_PATH_LOCAL "${PROJECT_SOURCE_DIR}/libdedx/data/")
# DEDX_DATA_PATH_LOCAL is used at runtime to prefer the source-tree data dir over the install path.
# Pass -DDEDX_DATA_PATH_LOCAL= (empty) to disable it, e.g. in install smoke tests.
set(DEDX_DATA_PATH_LOCAL "${PROJECT_SOURCE_DIR}/libdedx/data/" CACHE STRING "Build-tree data path (empty to force use of install path)")
if(WIN32)
set(DEDX_DATA_PATH "data/")
else()
Expand All @@ -49,7 +51,10 @@ configure_file(
include_directories("${PROJECT_SOURCE_DIR}/libdedx")
include_directories("${PROJECT_BINARY_DIR}")
link_directories("${PROJECT_SOURCE_DIR}/libdedx")
add_subdirectory(buildbins)
option(DEDX_BUILD_BINARY_TABLE "Build the binary data tables (requires a working install of libdedx data)" ON)
if(DEDX_BUILD_BINARY_TABLE)
add_subdirectory(buildbins)
endif()
add_subdirectory(examples)
add_subdirectory(libdedx)

Expand Down
31 changes: 12 additions & 19 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
include_directories("${PROJECT_SOURCE_DIR}")

add_executable(loadTest loadTest.c)

target_link_libraries(loadTest dedx)

if(NOT WIN32)
target_link_libraries(loadTest m)
endif()

# enable_testing() is called in the root CMakeLists.txt
add_test(NAME test_initialiaze COMMAND loadTest 1)
add_test(NAME test_load_ASTAR COMMAND loadTest 2)
add_test(NAME test_load_PSTAR COMMAND loadTest 3)
add_test(NAME test_load_MSTAR COMMAND loadTest 4)
add_test(NAME test_load_ICRU49_proton COMMAND loadTest 5)
add_test(NAME test_load_ICRU49_helium COMMAND loadTest 6)
add_test(NAME test_load_Bethe COMMAND loadTest 7)
add_test(NAME test_load_ICRU73 COMMAND loadTest 8)
add_test(NAME test_load_ICRU73_NEW COMMAND loadTest 9)

# ---- New-style tests: one file per physics program ----
# Each test_*.c has its own main() and returns number of failures.
# Adding a new program test is as simple as adding a test_<program>.c file.
Expand All @@ -35,3 +16,15 @@ foreach(test_src ${TEST_SOURCES})

add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()

if(NOT WIN32)
add_test(
NAME test_install_consumer
COMMAND ${CMAKE_COMMAND}
-DSOURCE_DIR=${PROJECT_SOURCE_DIR}
-DTEST_BINARY_DIR=${PROJECT_BINARY_DIR}
-DCMAKE_COMMAND=${CMAKE_COMMAND}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
-P ${PROJECT_SOURCE_DIR}/tests/install_smoke_test.cmake)
endif()
26 changes: 26 additions & 0 deletions tests/install_consumer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <dedx.h>
#include <dedx_tools.h>
#include <dedx_wrappers.h>
#include <stdio.h>

int main(void) {
int err = 0;
int major = 0;
int minor = 0;
int patch = 0;
float stp;

dedx_get_version(&major, &minor, &patch);
stp = dedx_get_simple_stp(DEDX_PROTON, DEDX_WATER, 100.0f, &err);
if (err != 0) {
fprintf(stderr, "dedx_get_simple_stp failed: err=%d\n", err);
return 1;
}
if (stp <= 0.0f) {
fprintf(stderr, "unexpected stopping power: %f\n", stp);
return 1;
}

printf("libdedx %d.%d.%d OK, stp=%f\n", major, minor, patch, stp);
return 0;
}
56 changes: 56 additions & 0 deletions tests/install_smoke_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set(smoke_root "${TEST_BINARY_DIR}/install-smoke")
set(smoke_build "${smoke_root}/build")
set(smoke_prefix "${smoke_root}/prefix")
set(smoke_consumer "${smoke_root}/install_consumer")

file(REMOVE_RECURSE "${smoke_root}")
file(MAKE_DIRECTORY "${smoke_root}")

set(configure_args
-S "${SOURCE_DIR}"
-B "${smoke_build}"
-DCMAKE_INSTALL_PREFIX=${smoke_prefix}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DDEDX_DATA_PATH_LOCAL= # force use of installed data, not source tree
-DDEDX_BUILD_BINARY_TABLE=OFF # tables are already built; don't delete and fail to rebuild them
)
Comment thread
nbassler marked this conversation as resolved.
if(DEFINED CMAKE_GENERATOR AND NOT CMAKE_GENERATOR STREQUAL "")
list(PREPEND configure_args -G "${CMAKE_GENERATOR}")
endif()

execute_process(COMMAND "${CMAKE_COMMAND}" ${configure_args}
RESULT_VARIABLE rc)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "install smoke configure failed: ${rc}")
endif()

execute_process(COMMAND "${CMAKE_COMMAND}" --build "${smoke_build}" --parallel
RESULT_VARIABLE rc)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "install smoke build failed: ${rc}")
endif()

execute_process(COMMAND "${CMAKE_COMMAND}" --install "${smoke_build}"
RESULT_VARIABLE rc)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "install smoke install failed: ${rc}")
endif()

execute_process(
COMMAND "${CMAKE_C_COMPILER}"
"-I${smoke_prefix}/include"
"-L${smoke_prefix}/lib"
"${SOURCE_DIR}/tests/install_consumer.c"
-o "${smoke_consumer}"
-ldedx
-lm
RESULT_VARIABLE rc)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "install smoke consumer compile failed: ${rc}")
endif()

execute_process(COMMAND "${smoke_consumer}"
RESULT_VARIABLE rc)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "install smoke consumer run failed: ${rc}")
endif()
Loading
Loading