diff --git a/CTestConfig.cmake b/CTestConfig.cmake new file mode 100644 index 0000000000000000000000000000000000000000..d694799651173d8cced79bcd83282cd18bb983ba --- /dev/null +++ b/CTestConfig.cmake @@ -0,0 +1,13 @@ +## This file should be placed in the root directory of your project. +## Then modify the CMakeLists.txt file in the root directory of your +## project to incorporate the testing dashboard. +## # The following are required to uses Dart and the Cdash dashboard +## ENABLE_TESTING() +## INCLUDE(CTest) +set(CTEST_PROJECT_NAME "DD4hep") +set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "aidasoft.desy.de") +set(CTEST_DROP_LOCATION "/CDash/submit.php?project=DD4hep") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index 0c9bab6f62113f8b967b10e7c0f17a454ba63238..19529af1c92934d1c16cd33c5baab856a03cce94 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -1,21 +1,31 @@ #-------------------------------------------------- -include_directories( ./include ) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/include + ${ROOT_INCLUDE_DIR} + ) +link_libraries(DD4hepG4 DD4hepCore DDSegmentation ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) #-------------------------------------------------- -SET( test_name "example_test" ) - +SET( test_name "test_example" ) ADD_EXECUTABLE( ${test_name} ./src/${test_name}.cc ) - ADD_TEST( t_${test_name} "${EXECUTABLE_OUTPUT_PATH}/${test_name}" ) SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) +SET( test_name "test_units" ) +ADD_EXECUTABLE( ${test_name} ./src/${test_name}.cc ) +ADD_TEST( t_${test_name} "${EXECUTABLE_OUTPUT_PATH}/${test_name}" ${CMAKE_CURRENT_SOURCE_DIR}/units.xml ) +SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) +SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) + #-------------------------------------------------- -install(FILES ./include/DDTest.h +install(FILES ./include/DD4hep/DDTest.h DESTINATION include/DD4hep ) + diff --git a/DDTest/README b/DDTest/README new file mode 100644 index 0000000000000000000000000000000000000000..b74fb3c3d18b04b75b769d2df5d8a7eb0cec0df1 --- /dev/null +++ b/DDTest/README @@ -0,0 +1,52 @@ +####################################################################### +# +# DDTest - (unit) tests for DD4hep +# +# F.Gaede, DESY, 2014 +####################################################################### + + +Package for the definition of (unit) tests using the CTest mechanism. + + +If build with -DBUILD_TESTING=1 (default), testing will be enabled. + +Run the tests with: + + cd build + make install + make test + +run the tests with verbose output: + + ctest -V + +---------------------------------------------------------------------------------------- + +New test programs can be added to ./DDTest/src as test_xxx.cc + +Add corresponding lines to ./DDTest/CMakeLists.txt: + + SET( test_name "test_xxx" ) + ADD_EXECUTABLE( ${test_name} ./src/${test_name}.cc ) + ADD_TEST( t_${test_name} "${EXECUTABLE_OUTPUT_PATH}/${test_name}" ) + SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) + SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) + +---------------------------------------------------------------------------------------- + +Nightly test results will be published at + + http://aidasoft.desy.de/CDash/index.php + + +This is not yet implemented. For now the command: + + make Experimental + + +will publish the result at the dashboard. + +---------------------------------------------------------------------------------------- + + diff --git a/DDTest/include/DDTest.h b/DDTest/include/DD4hep/DDTest.h similarity index 94% rename from DDTest/include/DDTest.h rename to DDTest/include/DD4hep/DDTest.h index de968c3a8820f53a59605821ebc120d8a0d9e217..236ad1d87770ba3c9231ec2866a982538bcf9d09 100644 --- a/DDTest/include/DDTest.h +++ b/DDTest/include/DD4hep/DDTest.h @@ -76,7 +76,10 @@ namespace DD4hep{ } else { - pass( name ) ; + std::stringstream sstr ; + sstr << " " << name<< " : [" << v1 << "] == [" << v2 <<"]" ; + + pass( sstr.str() ) ; } return ; @@ -96,7 +99,10 @@ namespace DD4hep{ } else { - pass( name ) ; + std::stringstream sstr ; + sstr << " " << name<< " : [" << c << "] " ; + + pass( sstr.str() ) ; } return ; } @@ -114,7 +120,7 @@ namespace DD4hep{ _passed++; _last_test_status = true ; - _out << "[" << _testname << "] test " << last_test_status() << " : " << msg << std::endl; + _out << "[" << _testname << "] test " << last_test_status() << ": " << msg << std::endl; } diff --git a/DDTest/src/example_test.cc b/DDTest/src/test_example.cc similarity index 80% rename from DDTest/src/example_test.cc rename to DDTest/src/test_example.cc index 686a88d5b16dd8060a74f3c2ac932132d46df188..80dfc1dcc5cb02e0931c5dc93f8d96ad4c670f53 100644 --- a/DDTest/src/example_test.cc +++ b/DDTest/src/test_example.cc @@ -1,4 +1,4 @@ -#include "DDTest.h" +#include "DD4hep/DDTest.h" #include <exception> #include <iostream> #include <assert.h> @@ -36,9 +36,9 @@ int main(int argc, char** argv ){ test( 1.1 * pi_f > pi_d , " example comparison: 1.1* float(M_PI) > double( M_PI) " ) ; // ... guess which of these will pass ... - // test( double(pi_f) == pi_d , " example comparison: float(M_PI) == double( M_PI) " ) ; - // test( double(pi_f) < pi_d , " example comparison: float(M_PI) < double( M_PI) " ) ; - // test( double(pi_f) > pi_d , " example comparison: float(M_PI) > double( M_PI) " ) ; + // test( pi_f == pi_d , " example comparison: float(M_PI) == double( M_PI) " ) ; + // test( pi_f < pi_d , " example comparison: float(M_PI) < double( M_PI) " ) ; + // test( pi_f > pi_d , " example comparison: float(M_PI) > double( M_PI) " ) ; // -------------------------------------------------------------------- diff --git a/DDTest/src/test_units.cc b/DDTest/src/test_units.cc new file mode 100644 index 0000000000000000000000000000000000000000..e681c9a78257acd2447d043bcd96f0f4869d0118 --- /dev/null +++ b/DDTest/src/test_units.cc @@ -0,0 +1,94 @@ +#include "DD4hep/DDTest.h" + +#include "DD4hep/LCDD.h" +#include "DD4hep/TGeoUnits.h" + +#include <exception> +#include <iostream> +#include <sstream> +#include <assert.h> +#include <cmath> + +using namespace std ; +using namespace DD4hep ; +using namespace Geometry; +using namespace tgeo ; + +// this should be the first line in your test +DDTest test = DDTest( "units" ) ; + +//============================================================================= +/** Helper class for floating point comparisons using string representations */ +class STR { + STR() {} + float _val ; + std::string _str ; +public: + STR ( float val ) : _val( val ){ + std::stringstream s1 ; + s1 << _val ; + _str = s1.str() ; + } + std::string str() const { return _str ; } + + bool operator==( const STR& s2) const { + return this->str() == s2.str() ; + } +}; + +std::ostream& operator<<(std::ostream& os , const STR& s) { + os << s.str() ; + return os ; +} +//============================================================================= + +int main(int argc, char** argv ){ + + test.log( "test units" ); + + if( argc < 2 ) { + std::cout << " usage: test_units units.xml " << std::endl ; + exit(1) ; + } + + try{ + + // ----- write your tests in here ------------------------------------- + + LCDD& lcdd = LCDD::getInstance(); + + lcdd.fromCompact( argv[1] ); + + + // ======= deg and rad: + double al0_rad = lcdd.constant<double>( "alpha_half_arc_deg" ) / rad ; + double al1_rad = lcdd.constant<double>( "alpha_half_arc_rad" ) / rad ; + + test( STR(al0_rad), STR(al1_rad) , " alpha_half_arc in rad " ) ; + + double al0_deg = lcdd.constant<double>( "alpha_half_arc_deg" ) / deg ; + double al1_deg = lcdd.constant<double>( "alpha_half_arc_rad" ) / deg ; + + test( STR(al0_deg), STR(al1_deg) , " alpha_half_arc in deg " ) ; + + + //======== densities ========= + double rho1 = lcdd.constant<double>( "rho1" ) / kg * m3 ; + double rho2 = lcdd.constant<double>( "rho2" ) / g * cm3 ; + + test( STR(rho1), STR(1000.*rho2) , " densities [kg/m3] - [g/cm3] " ) ; + + // -------------------------------------------------------------------- + + + } catch( exception &e ){ + //} catch( ... ){ + + test.log( e.what() ); + test.error( "exception occurred" ); + } + + return 0; +} + +//============================================================================= diff --git a/DDTest/units.xml b/DDTest/units.xml new file mode 100644 index 0000000000000000000000000000000000000000..9d90bf17a28d251409c6f2b09832f7bb505d89a1 --- /dev/null +++ b/DDTest/units.xml @@ -0,0 +1,49 @@ +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + + <info name="units_test" + title="units" + url="" + author="gaede" + status="test" + version="$Id: $"> + <comment>minimal compact file used for units conversion tests</comment> + </info> + + <includes> + </includes> + + <define> + <!-- need to define world volume --> + <constant name="world_side" value="10*m"/> + <constant name="world_x" value="world_side/2"/> + <constant name="world_y" value="world_side/2"/> + <constant name="world_z" value="world_side/2"/> + + <constant name="M_PI" value="3.14159265358979323846"/> + + <!-- some constants with units --> + <constant name="alpha_half_arc_deg" value="180.*deg"/> + <constant name="alpha_half_arc_rad" value="M_PI*rad"/> + + <constant name="rho1" value="2.5e3*kg/m3"/> + <constant name="rho2" value="2.5*g/cm3"/> + + </define> + + <!-- need to define vacuum and air --> + <materials> + <material name="Vacuum"> + <D type="density" unit="g/cm3" value="0.00000001" /> + <fraction n="1" ref="H" /> + </material> + <material name="Air"> + <D type="density" unit="g/cm3" value="0.0012"/> + <fraction n="0.754" ref="N"/> + <fraction n="0.234" ref="O"/> + <fraction n="0.012" ref="Ar"/> + </material> + </materials> + +</lccdd>