Skip to content

Commit 2ef353c

Browse files
guitargeekmaxgalli
authored andcommitted
Add unit tests and run them in the CI
1 parent d463375 commit 2ef353c

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

.github/workflows/clang-tidy-review.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ jobs:
3030

3131
- name: install lit
3232
run: pip install lit
33-
33+
3434
- name: Run clang-tidy
3535
uses: ZedThree/clang-tidy-review@v0.21.0
3636
id: review
3737
with:
3838
build_dir: build
39-
apt_packages: cmake,libxml2,libxml2-dev,libtinfo-dev,zlib1g-dev,libzstd-dev,wget,libvdt-dev
39+
apt_packages:
40+
- cmake
41+
- libgtest-dev
42+
- libtinfo-dev
43+
- libvdt-dev
44+
- libxml2
45+
- libxml2-dev
46+
- libzstd-dev
47+
- wget
48+
- zlib1g-dev
4049
split_workflow: true
4150
config_file: .clang-tidy
4251
cmake_command: >

.github/workflows/cvmfs-ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
-DCMAKE_INSTALL_PREFIX=../install \
7777
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
7878
-DINSTALL_PYTHON=FALSE \
79+
-DBUILD_TESTS=TRUE \
7980
..;
8081
make install -j$(nproc);
8182
cd ..;
@@ -103,8 +104,21 @@ jobs:
103104
root --version
104105
combine --help
105106
107+
- name: Run Tests
108+
if: ${{ env.CMSSW_VERSION == '' }}
109+
env:
110+
LCG_RELEASE: ${{ matrix.LCG_RELEASE }}
111+
LCG_ARCH: ${{ matrix.LCG_ARCH }}
112+
run: >-
113+
source /cvmfs/sft.cern.ch/lcg/views/${LCG_RELEASE}/${LCG_ARCH}/setup.sh;
114+
source virtualenv/bin/activate;
115+
cd build;
116+
ctest --output-on-failure -j$(nproc) .;
117+
106118
- uses: ./.github/actions/run-in-cvmfs
107119
name: Counting datacard
120+
# Only run this test in CMSSW mode, because otherwise we already run this in the unit tests
121+
if: ${{ env.CMSSW_VERSION != '' }}
108122
with:
109123
script: |
110124
text2workspace.py data/tutorials/multiDim/toy-hgg-125.txt -m 125 -P HiggsAnalysis.CombinedLimit.PhysicsModel:floatingXSHiggs --PO modes=ggH,qqH

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ project(HiggsAnalysisCombinedLimit VERSION 0.0.1)
55
option( MODIFY_ROOTMAP "Modify generated Rootmap to take out classes already bundled in StatAnalysis" FALSE )
66
option( INSTALL_PYTHON "Install the Python library and scripts" TRUE )
77
option( USE_VDT "Use VDT (fast and vectorisable mathematical functions)" TRUE )
8+
option( BUILD_TESTS "Build tests" FALSE )
89

910
# Can build with CMake after e.g. setting up StatAnalysis release like this:
1011
# export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
@@ -132,3 +133,11 @@ if(INSTALL_PYTHON)
132133
INSTALL(FILES ${empty_init_py} DESTINATION ${Python_SITELIB_IN_PREFIX}/HiggsAnalysis)
133134
INSTALL(FILES ${empty_init_py} DESTINATION ${Python_SITELIB_IN_PREFIX}/HiggsAnalysis/CombinedLimit)
134135
endif()
136+
137+
138+
if(BUILD_TESTS)
139+
find_package(GTest 1.10 REQUIRED)
140+
141+
enable_testing()
142+
add_subdirectory(test)
143+
endif()

test/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Set the location of text2workspace.py, assuming installation to a virtual
2+
# environment inside the source directory.
3+
set(t2w ${CMAKE_SOURCE_DIR}/virtualenv/bin/text2workspace.py)
4+
5+
# Counting datacard - text2workspace
6+
ROOT_ADD_TEST(counting_datacard-t2w
7+
COMMAND ${t2w} toy-hgg-125.txt -m 125 -P HiggsAnalysis.CombinedLimit.PhysicsModel:floatingXSHiggs --PO modes=ggH,qqH
8+
COPY_TO_BUILDDIR ${CMAKE_SOURCE_DIR}/data/tutorials/multiDim/toy-hgg-125.txt
9+
FIXTURES_SETUP counting_datacard
10+
# Append the build directory to the library Path to we can use Combine classes
11+
ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$ENV{LD_LIBRARY_PATH}
12+
)
13+
14+
# Counting datacard - combine
15+
ROOT_ADD_TEST(counting_datacard
16+
COMMAND combine -M MultiDimFit toy-hgg-125.root --setParameterRanges r=-1,1
17+
FIXTURES_REQUIRED counting_datacard # requires corresponding text2workspace run
18+
# We compare the output to reference files to validate the best-fit parameter values
19+
WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}
20+
CHECKOUT
21+
OUTPUT counting_datacard.out
22+
OUTREF ${CMAKE_CURRENT_SOURCE_DIR}/references/counting_datacard.out
23+
# For this test, we are not interested in the standard error, but you could
24+
# compare this too:
25+
# CHECKERR
26+
# ERROR counting_datacard.err
27+
# ERRREF ${CMAKE_CURRENT_SOURCE_DIR}/references/counting_datacard.err
28+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<<< Combine >>>
2+
<<< v10.2.1 >>>
3+
>>> Random number generator seed is 123456
4+
>>> Method used is MultiDimFit
5+
Warning: Did not find a parameter with name r
6+
Doing initial fit:
7+
8+
--- MultiDimFit ---
9+
best fit parameter values:
10+
r_ggH : +0.882
11+
r_qqH : +4.683

0 commit comments

Comments
 (0)