Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/cmake/Modules/G4TestDriver.cmake is written in an unsupported language. File is not indexed.

0001 #-----------------------------------------------------------------------
0002 # Geant4 test driver
0003 #   Script arguments:
0004 #     CMD command to be executed for the test
0005 #     PRE command to be executed before the test command
0006 #     POST command to be executed after the test command
0007 #     OUT file to collect stdout
0008 #     ERR file to collect stderr
0009 #     ENV evironment VAR1=Value1;VAR2=Value2
0010 #     CWD current working directory
0011 #     TST test name (used to name output/error files)
0012 #     TIM timeout
0013 #     DBG debug flag
0014 
0015 if(DBG)
0016   message(STATUS "ENV=${ENV}")
0017 endif()
0018 
0019 #-----------------------------------------------------------------------
0020 # Message arguments
0021 #
0022 if(CMD)
0023   string(REPLACE "#" ";" _cmd "${CMD}")
0024   string(REPLACE "@" "=" _cmd "${_cmd}")
0025   if(DBG)
0026     set(_cmd gdb --args ${_cmd})
0027   endif()
0028 endif()
0029 
0030 if(PRE)
0031   string(REPLACE "#" ";" _pre ${PRE})
0032 endif()
0033 
0034 if(POST)
0035   string(REPLACE "#" ";" _post ${POST})
0036 endif()
0037 
0038 if(OUT)
0039   set(_out OUTPUT_FILE ${OUT})
0040 else()
0041   if(NOT DBG)
0042     set(_out OUTPUT_VARIABLE _outvar)
0043   endif()
0044 endif()
0045 
0046 if(ERR)
0047   set(_err ERROR_FILE ${ERR})
0048 else()
0049   if(NOT DBG)
0050     set(_err ERROR_VARIABLE _errvar)
0051   endif()
0052 endif()
0053 
0054 if(TIM)
0055   math(EXPR _timeout "${TIM} - 120")
0056 else()
0057   if(NOT $ENV{CTEST_TIMEOUT} STREQUAL "")
0058      math(EXPR _timeout "$ENV{CTEST_TIMEOUT} - 120")
0059   else()
0060      math(EXPR _timeout "1500 - 120")
0061   endif()
0062 endif()
0063 
0064 if(CWD)
0065   set(_cwd WORKING_DIRECTORY ${CWD})
0066 endif()
0067 
0068 #-----------------------------------------------------------------------
0069 # Environment settings
0070 #
0071 if(ENV)
0072   string(REPLACE "@" "=" _env ${ENV})
0073   string(REPLACE "#" ";" _env ${_env})
0074   foreach(pair ${_env})
0075     string(REPLACE "=" ";" pair ${pair})
0076     list(GET pair 0 var)
0077     list(GET pair 1 val)
0078     set(ENV{${var}} ${val})
0079     if(DBG)
0080       message(STATUS "testdriver[ENV]:${var}==>${val}")
0081     endif()
0082   endforeach()
0083 endif()
0084 
0085 #-----------------------------------------------------------------------
0086 # Execute pre command
0087 #
0088 if(PRE)
0089   execute_process(COMMAND ${_pre} ${_cwd} RESULT_VARIABLE _rc)
0090   if(_rc)
0091     message(FATAL_ERROR "pre-command error code : ${_rc}")
0092   endif()
0093 endif()
0094 
0095 #-----------------------------------------------------------------------
0096 # Execute test
0097 #
0098 if(CMD)
0099   execute_process(COMMAND ${_cmd} ${_out} ${_err} ${_cwd} TIMEOUT ${_timeout} RESULT_VARIABLE _rc)
0100   message("G4Test rc: ${_rc}")
0101   if(_errvar)
0102     message("G4Test stderr:\n ${_errvar}")
0103     if(TST)
0104       file(WRITE ${TST}.err ${_errvar})
0105     endif()
0106   endif()
0107   if(_outvar)
0108     message("G4Test stdout:\n ${_outvar}")
0109     if(TST)
0110       file(WRITE ${TST}.out ${_outvar})
0111     endif()
0112   endif()
0113 
0114   # - FATAL_ERROR if the test returned an error code or wrote anything to
0115   # the stderr
0116   if(_errvar OR _rc)
0117     message(FATAL_ERROR "Test failed!!!")
0118   endif()
0119 endif()
0120 
0121 #-----------------------------------------------------------------------
0122 # Execute post test command
0123 #
0124 if(POST)
0125   execute_process(COMMAND ${_post} ${_cwd} RESULT_VARIABLE _rc)
0126   if(_rc)
0127     message(FATAL_ERROR "post-command error code : ${_rc}")
0128   endif()
0129 endif()
0130