Skip to content

Commit

Permalink
Merge pull request #722 from gundam-organization/feature/UpdatedTesting
Browse files Browse the repository at this point in the history
Update testing scripts with corrections for developent branch
  • Loading branch information
ClarkMcGrew authored Jan 14, 2025
2 parents c7705c5 + 3b41653 commit eac8129
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 128 deletions.
12 changes: 6 additions & 6 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ option( USE_STATIC_LINKS "Use static link of libraries and apps instead of share
option( CXX_WARNINGS "Enable most C++ warning flags." ON )
option( CXX_MARCH_FLAG "Enable cpu architecture specific optimisations." OFF )
option( CMAKE_CXX_EXTENSIONS "Enable GNU extensions to C++ language (-std=gnu++14)." OFF )
option( ENABLE_GOOGLE_TESTS "Build Google tests." OFF )

option( ENABLE_TESTS "Build CMake tests (optionally uses googletest)." ON )
option( SKIP_GOOGLE_TEST "Skip GTest unit tests (other tests enabled)." ON )

# Reading options
##################
Expand Down Expand Up @@ -91,10 +91,10 @@ if( WITH_DOXYGEN )

# note the option ALL which allows to build the docs together with the application
add_custom_target( doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else()
cmessage( FATAL_ERROR "Doxygen need to be installed to generate the doxygen documentation." )
endif()
Expand Down
12 changes: 8 additions & 4 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#######################################################################
# Handle the testing infrastructure in the "tests" directory. By
# default, ENABLE_TESTS only enables the most basic testing.
#######################################################################


if( ENABLE_GOOGLE_TESTS )
message("")
cmessage( WARNING "Defining tests...")
if( ENABLE_TESTS )
cmessage( STATUS "Build GUNDAM test and validations")
include( CTest )
add_subdirectory( ${CMAKE_SOURCE_DIR}/tests )
else()
cmessage(WARNING "GUNDAM tests and validations are disabled.")
endif()

72 changes: 35 additions & 37 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#

cmessage( STATUS "Setting up tests..." )
enable_testing()

# Run the gundam-tests.sh script which runs scripted tests. The
# COMMAND is a little complicated since the testing script needs to
Expand All @@ -30,42 +29,41 @@ add_test(

## Compiled unit tests using GoogleTest. These are only run if GTest
## is found.
find_package(GTest QUIET)
if(GTEST_FOUND)
if( WITH_CACHE_MANAGER )

cmessage( STATUS "Compiling google tests..." )
# Setup the hemi test suite for the host

add_executable(gundamGTest_host.exe
GTests/hemiArrayTest.cpp
GTests/hemiExecutionPolicyTest.cpp
GTests/cachedSumsTest.cpp
GTests/hemiExternals.cpp)
target_link_libraries(gundamGTest_host.exe GTest::gtest_main)
target_link_libraries(gundamGTest_host.exe GundamCacheManager)
target_compile_definitions(gundamGTest_host.exe PUBLIC HEMI_CUDA_DISABLE)
gtest_discover_tests(gundamGTest_host.exe)

if(CMAKE_CUDA_COMPILER)
# Setup the hemi test suite for the device.
add_executable(gundamGTest_device.exe
GTests/hemiArrayTest.cu
GTests/hemiExecutionPolicyTest.cu
GTests/hemiLaunch.cu
GTests/cachedSumsTest.cu
GTests/hemiExternals.cpp)
target_link_libraries(gundamGTest_device.exe GTest::gtest_main)
target_link_libraries(gundamGTest_device.exe GundamCacheManager)
gtest_discover_tests(gundamGTest_device.exe)
endif(CMAKE_CUDA_COMPILER)

else( WITH_CACHE_MANAGER )

cmessage( WARNING "WITH_CACHE_MANAGER is set to false. Skipping Google test executables." )

endif( WITH_CACHE_MANAGER )
if (SKIP_GOOGLE_TEST)
cmessage( WARNING "GTest unit testing explicitly disabled by user")
else(SKIP_GOOGLE_TEST)
# Use the pre cmake 1.10 interface because we set 3.5 as the minimum cmake
find_package(GTest)
endif(SKIP_GOOGLE_TEST)
if (GTEST_FOUND)
cmessage( STATUS "GTest package enabled for developer unit tests.")
enable_testing()

# Setup the hemi test suite for the host
add_executable(gundamGTest_host.exe
GTests/hemiArrayTest.cpp
GTests/hemiExecutionPolicyTest.cpp
GTests/cachedSumsTest.cpp
GTests/hemiExternals.cpp)
target_link_libraries(gundamGTest_host.exe GTest::gtest_main)
target_link_libraries(gundamGTest_host.exe GundamCacheManager)
target_compile_definitions(gundamGTest_host.exe PUBLIC HEMI_CUDA_DISABLE)
gtest_discover_tests(gundamGTest_host.exe)

if(CMAKE_CUDA_COMPILER)
# Setup the hemi test suite for the device.
add_executable(gundamGTest_device.exe
GTests/hemiArrayTest.cu
GTests/hemiExecutionPolicyTest.cu
GTests/hemiLaunch.cu
GTests/cachedSumsTest.cu
GTests/hemiExternals.cpp)
target_link_libraries(gundamGTest_device.exe GTest::gtest_main)
target_link_libraries(gundamGTest_device.exe GundamCacheManager)
gtest_discover_tests(gundamGTest_device.exe)
else(CMAKE_CUDA_COMPILER)
cmessage( WARNING "CUDA compiler not available. Skip CUDA unit tests.")
endif(CMAKE_CUDA_COMPILER)
else(GTEST_FOUND)
cmessage( WARNING "Google test is not available." )
cmessage( WARNING "GTest package not available. Developer tests disabled.")
endif(GTEST_FOUND)
1 change: 1 addition & 0 deletions tests/extended-tests/200NormalizationMCMC-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fitterEngineConfig:
algorithm: "Migrad"
errors: "Hesse"
print_level: 2
tolerance: 1E-6

propagatorConfig:
throwAsimovFitParameters: false
Expand Down
1 change: 1 addition & 0 deletions tests/extended-tests/200NormalizationMCMCPhys-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fitterEngineConfig:
algorithm: "Migrad"
errors: "Hesse"
print_level: 2
tolerance: 1E-6

propagatorConfig:
throwAsimovFitParameters: false
Expand Down
2 changes: 1 addition & 1 deletion tests/fast-tests/100MultiParTree.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# !/bin/bash
# Wrap a ROOT macro as a script.
root <<EOF
root -b -n <<EOF

#include <iostream>
#include <sstream>
Expand Down
1 change: 1 addition & 0 deletions tests/fast-tests/200NormalizationAsimov-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fitterEngineConfig:
algorithm: "Migrad"
errors: "Hesse"
print_level: 2
tolerance: 1E-6

propagatorConfig:
throwAsimovFitParameters: false
Expand Down
70 changes: 62 additions & 8 deletions tests/regular-tests/100CheckGeneralSpline.C
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main() {
double data[dim];
data[0] = -3.0;
data[1] = 0.0;
std::cout << "Number of knots " << nKnots << std::endl;
std::cout << "Test1: Number of knots " << nKnots << std::endl;
for (int knot = 0; knot < nKnots; ++knot) {
double xx;
double yy;
Expand All @@ -77,8 +77,8 @@ int main() {
}
TGraph generalSpline;
int point = 0;
for (double xxx = spline.GetXmin();
xxx<=spline.GetXmax(); xxx += 0.01) {
for (double xxx = spline.GetXmin()-1.0;
xxx<=spline.GetXmax()+1.0; xxx += 0.01) {
double splineValue = spline.Eval(xxx);
double calcValue
= CalculateGeneralSpline(xxx,-100.0, 100.0,
Expand All @@ -97,7 +97,7 @@ int main() {
#define TEST2
#ifdef TEST2
{
// Define a TSpline3 and make sure that GeneralSpline reproduces it
// Define a TGraph and make sure that GeneralSpline reproduces it
TGraph graph(3);
graph.SetPoint(0,-3.0, 0.0);
graph.SetPoint(1, 0.1, 1.0);
Expand All @@ -116,7 +116,7 @@ int main() {
double data[dim];
data[0] = -3.0;
data[1] = 0.0;
std::cout << "Number of knots " << nKnots << std::endl;
std::cout << "Test2: Number of knots " << nKnots << std::endl;
for (int knot = 0; knot < nKnots; ++knot) {
double xx;
double yy;
Expand All @@ -129,14 +129,14 @@ int main() {
}
TGraph generalSpline;
int point = 0;
for (double xxx = spline.GetXmin();
xxx<=spline.GetXmax(); xxx += 0.01) {
for (double xxx = spline.GetXmin()-1.0;
xxx<=spline.GetXmax()+1.0; xxx += 0.01) {
double splineValue = spline.Eval(xxx);
double calcValue
= CalculateGeneralSpline(xxx,-100.0, 100.0,
data, dim);
generalSpline.SetPoint(point++, xxx, calcValue);
TOLERANCE("Test1: Spline Mismatch", splineValue, calcValue, 1E-6);
TOLERANCE("Test2: Spline Mismatch", splineValue, calcValue, 1E-6);
}
generalSpline.SetLineWidth(3);
generalSpline.SetLineColor(kGreen);
Expand All @@ -146,6 +146,60 @@ int main() {
}
#endif


#define TEST3
#ifdef TEST3
{
// Define a large spline and make sure that GeneralSpline reproduces
// it
TGraph graph;
int count = 0;
for (int i = -10; i<11; ++i) {
double v = i;
graph.SetPoint(count++,v, std::abs(v));
}
TSpline3 spline("splineOfGraph",&graph);
graph.Draw("AC*");
graph.SetMinimum(-0.5);
graph.SetMaximum(15.0);
spline.SetLineWidth(5);
spline.SetLineColor(kRed);
spline.Draw("same");
const int nKnots = spline.GetNp();
const int dim = 3*nKnots + 2;
double data[dim];
data[0] = -3.0;
data[1] = 0.0;
std::cout << "Test1: Number of knots " << nKnots << std::endl;
for (int knot = 0; knot < nKnots; ++knot) {
double xx;
double yy;
double ss;
spline.GetKnot(knot,xx,yy);
ss = spline.Derivative(xx);
data[2+3*knot+0] = yy;
data[2+3*knot+1] = ss;
data[2+3*knot+2] = xx;
}
TGraph generalSpline;
int point = 0;
for (double xxx = spline.GetXmin() - 2.0;
xxx<=spline.GetXmax() + 2.0; xxx += 0.01) {
double splineValue = spline.Eval(xxx);
double calcValue
= CalculateGeneralSpline(xxx,-100.0, 100.0,
data, dim);
generalSpline.SetPoint(point++, xxx, calcValue);
TOLERANCE("Test3: Spline Mismatch", splineValue, calcValue, 1E-6);
}
generalSpline.SetLineWidth(3);
generalSpline.SetLineColor(kGreen);
generalSpline.Draw("same");
gPad->Print("100CheckGeneralSpline3.pdf");
gPad->Print("100CheckGeneralSpline3.png");
}
#endif

return status;
}
exit(main());
Expand Down
Loading

0 comments on commit eac8129

Please sign in to comment.