From: Artem Zhidkov Date: Thu, 10 Dec 2020 07:11:24 +0000 (+0300) Subject: Issue 19241: ability to run HDF tests with 'salome test' command X-Git-Tag: V9_7_0a1~65 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=24e87540f9a19d0b116c4374da3fca343744ced1;p=modules%2Fshaper.git Issue 19241: ability to run HDF tests with 'salome test' command --- diff --git a/test.hdfs/CMakeLists.txt b/test.hdfs/CMakeLists.txt index eeb8fe240..030dd713d 100644 --- a/test.hdfs/CMakeLists.txt +++ b/test.hdfs/CMakeLists.txt @@ -19,7 +19,27 @@ ENABLE_TESTING() -INCLUDE(tests.set) +# get all restricted HDF tests +SET(hdfFilesRestr "") +IF (EXISTS $ENV{RESTRICTED_ROOT_DIR}) + FILE(GLOB hdfFilesRestr "$ENV{RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/*.hdf") +ENDIF() + +# get all HDF tests from the current drectory +file(GLOB hdfFilesCur "${CMAKE_CURRENT_SOURCE_DIR}/*.hdf") + +# collect test names +set(TEST_NAMES "") +foreach(eachFilePath IN LISTS hdfFilesCur hdfFilesRestr) + # Strip the ".hdf" suffix + get_filename_component(aTestName ${eachFilePath} NAME_WE) + # Check corresponding ".py" file with reference data exists + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${aTestName}.py") + set(TEST_NAMES ${TEST_NAMES} ${aTestName}) + else() + message(WARNING "File ${aTestName}.py containing reference data for ${aTestName}.hdf does not exist") + endif() +endforeach() SET(COMPONENT_NAME SHAPER) SET(TIMEOUT 600) @@ -28,11 +48,21 @@ SET(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/HDFs") SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) +SET(PUBLIC_TESTS "") +SET(RESTRICTED_TESTS "") FOREACH(tfile ${TEST_NAMES}) SET(TEST_NAME ${COMPONENT_NAME}_HDF_${tfile}) - GET_HDF(HDF_TEST_FILE ${tfile}) + + IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.hdf") + SET(HDF_TEST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.hdf") + SET(PUBLIC_TESTS ${PUBLIC_TESTS} ${tfile}) + ELSEIF(EXISTS "$ENV{RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/${tfile}.hdf") + SET(HDF_TEST_FILE "$ENV{RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/${tfile}.hdf") + SET(RESTRICTED_TESTS ${RESTRICTED_TESTS} ${tfile}) + ENDIF() + ADD_TEST(NAME ${TEST_NAME} - COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/testme.py" "$ENV{KERNEL_ROOT_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" "${HDF_TEST_FILE}") + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/testme.py" "${HDF_TEST_FILE}" "${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py") SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env};SHAPER_UNIT_TEST_IN_PROGRESS=1") SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME};models_hdf") SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES TIMEOUT ${TIMEOUT}) @@ -54,5 +84,10 @@ INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} RENAME CTestTestfile.cmake) -INSTALL(FILES testme.py DESTINATION ${TEST_INSTALL_DIRECTORY}) -INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) +INSTALL(FILES testme.py DESTINATION ${TEST_INSTALL_DIRECTORY} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) +FILE(COPY test_hdf.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +CONFIGURE_FILE(tests.set.in ${CMAKE_CURRENT_BINARY_DIR}/tests.set @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) diff --git a/test.hdfs/CTestTestfileInstall.cmake b/test.hdfs/CTestTestfileInstall.cmake index ad8cb7d2f..d6a3dbbb9 100644 --- a/test.hdfs/CTestTestfileInstall.cmake +++ b/test.hdfs/CTestTestfileInstall.cmake @@ -19,14 +19,18 @@ INCLUDE(tests.set) -SET(COMPONENT_NAME SHAPER) -SET(TIMEOUT 600) +SET(COMPONENT_NAME SHAPER) +SET(SALOME_TEST_DRIVER "testme.py") +SET(TIMEOUT 600) -FOREACH(tfile ${TEST_NAMES}) +FOREACH(tfile ${PUBLIC_TESTS}) SET(TEST_NAME ${COMPONENT_NAME}_HDF_${tfile}) - GET_HDF(HDF_TEST_FILE ${tfile}) - ADD_TEST(NAME ${TEST_NAME} - COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/testme.py" "$ENV{KERNEL_ROOT_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" "${HDF_TEST_FILE}") + ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} "${TIMEOUT}" "${tfile}.hdf" "${tfile}.py") + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() + +FOREACH(tfile ${RESTRICTED_TESTS}) + SET(TEST_NAME ${COMPONENT_NAME}_HDF_${tfile}) + ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} "${TIMEOUT}" "$ENV{RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/${tfile}.hdf" "${tfile}.py") SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") - SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES TIMEOUT ${TIMEOUT}) ENDFOREACH() diff --git a/test.hdfs/test_hdf.py b/test.hdfs/test_hdf.py index b58ea3b83..526fad991 100644 --- a/test.hdfs/test_hdf.py +++ b/test.hdfs/test_hdf.py @@ -34,10 +34,6 @@ class TestHDF(unittest.TestCase): def setUp(self): salome.salome_close() - # leave file name only (trim path and extension) - fileName = os.path.basename(self.testfile) - self.reffile = self.reffile + "/" + os.path.splitext(fileName)[0] + ".py" - salome.salome_init(self.testfile, embedded=1) myStudyName = salome.myStudy._get_Name() self.session = salome.naming_service.Resolve('/Kernel/Session') @@ -77,13 +73,11 @@ if __name__ == "__main__": if len(sys.argv) > 1: TestHDF.testfile = sys.argv[1] if len(sys.argv) > 2: - salomePortFile = sys.argv[2] + TestHDF.reffile = sys.argv[2] if len(sys.argv) > 3: - errFile = open(sys.argv[3], 'w') + salomePortFile = sys.argv[3] if len(sys.argv) > 4: - salomeKernelDir = sys.argv[4] - if len(sys.argv) > 5: - TestHDF.reffile = sys.argv[5] + errFile = open(sys.argv[4], 'w') aTest = unittest.TestLoader().loadTestsFromTestCase(TestHDF) unittest.TextTestRunner(stream=errFile).run(aTest) @@ -91,7 +85,7 @@ if __name__ == "__main__": # close Salome GUI port = salome_utils.getPortNumber() - proc = subprocess.Popen([salomeKernelDir + "/bin/salome/killSalomeWithPort.py", "{}".format(port)]) + proc = subprocess.Popen(["killSalomeWithPort.py", "{}".format(port)]) try: os.remove(salomePortFile) diff --git a/test.hdfs/testme.py b/test.hdfs/testme.py index 395c6c062..57d798fb0 100644 --- a/test.hdfs/testme.py +++ b/test.hdfs/testme.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + # Copyright (C) 2020 CEA/DEN, EDF R&D # # This library is free software; you can redistribute it and/or @@ -17,20 +19,25 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -#!/usr/bin/env python - if __name__ == '__main__': import subprocess from time import sleep import sys, os + import tempfile - salomeKernelDir = sys.argv[1] - sourceDir = sys.argv[2] - testfile = sys.argv[3] + testTimeout = 600 + if len(sys.argv) > 3: + testTimeout = int(sys.argv[1]) + hdffile = sys.argv[2] + testdatafile = sys.argv[3] + else: + hdffile = sys.argv[1] + testdatafile = sys.argv[2] - portlogfile = os.getcwd() + "/.salome_port" - testlogfile = os.getcwd() + "/test.log" + tempdir = tempfile.gettempdir() + portlogfile = tempdir + "/.salome_port" + testlogfile = tempdir + "/test.log" # remove port file if any try: os.remove(portlogfile) @@ -40,9 +47,9 @@ if __name__ == '__main__': isOk = True error = "" - proc = subprocess.Popen([salomeKernelDir + "/bin/salome/runSalome.py", "--modules", "SHAPER,GEOM", "--gui", "--splash", "0", "--ns-port-log=" + portlogfile, sourceDir + "/test_hdf.py", "args:" + testfile + "," + portlogfile + "," + testlogfile + "," + salomeKernelDir + "," + sourceDir], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + proc = subprocess.Popen(["runSalome.py", "--modules", "SHAPER,GEOM", "--gui", "--splash", "0", "--ns-port-log=" + portlogfile, "test_hdf.py", "args:" + hdffile + "," + testdatafile + "," + portlogfile + "," + testlogfile], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) try: - proc.communicate(timeout = 600) + proc.communicate(timeout = testTimeout) except TimeoutExpired: isOk = False proc.kill() diff --git a/test.hdfs/tests.set b/test.hdfs/tests.set deleted file mode 100644 index 1e7956a8d..000000000 --- a/test.hdfs/tests.set +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2020 CEA/DEN, EDF R&D -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -set(RESTRICTED_ROOT_DIR $ENV{RESTRICTED_ROOT_DIR} CACHE PATH "Path to the restricted repository") - -# get all restricted HDF tests -set(hdfFilesRestr "") -if (EXISTS ${RESTRICTED_ROOT_DIR}) - file(GLOB hdfFilesRestr "${RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/*.hdf") -endif() - -# get all HDF tests from the current drectory -file(GLOB hdfFilesCur "${CMAKE_CURRENT_SOURCE_DIR}/*.hdf") -set(hdfFilesRestr ${hdfFilesCur} ${hdfFilesRestr}) - -# collect test names -set(TEST_NAMES "") -foreach(eachFilePath ${hdfFilesRestr}) - # Strip the ".hdf" suffix - get_filename_component(aTestName ${eachFilePath} NAME_WE) - # Check corresponding ".py" file with reference data exists - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${aTestName}.py") - set(TEST_NAMES ${aTestName} ${TEST_NAMES}) - else() - message(WARNING "File ${aTestName}.py containing reference data for ${aTestName}.hdf does not exist") - endif() -endforeach() - -# return full path to HDF file related to the given test name -function(GET_HDF hdfFullPath testName) - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${testName}.hdf") - set(${hdfFullPath} "${CMAKE_CURRENT_SOURCE_DIR}/${testName}.hdf" PARENT_SCOPE) - elseif(EXISTS "${RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/${testName}.hdf") - set(${hdfFullPath} "${RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/${testName}.hdf" PARENT_SCOPE) - endif() -endfunction(GET_HDF) \ No newline at end of file diff --git a/test.hdfs/tests.set.in b/test.hdfs/tests.set.in new file mode 100644 index 000000000..9acd7b2bd --- /dev/null +++ b/test.hdfs/tests.set.in @@ -0,0 +1,26 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(PUBLIC_TESTS @PUBLIC_TESTS@) + +IF(EXISTS $ENV{RESTRICTED_ROOT_DIR}) + SET(RESTRICTED_TESTS @RESTRICTED_TESTS@) +ELSE() + SET(RESTRICTED_TESTS "") +ENDIF()