]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue 19241: ability to run HDF tests with 'salome test' command occ/19241
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Thu, 10 Dec 2020 07:11:24 +0000 (10:11 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Sat, 19 Dec 2020 20:29:37 +0000 (23:29 +0300)
test.hdfs/CMakeLists.txt
test.hdfs/CTestTestfileInstall.cmake
test.hdfs/test_hdf.py
test.hdfs/testme.py
test.hdfs/tests.set [deleted file]
test.hdfs/tests.set.in [new file with mode: 0644]

index eeb8fe24037ab6cc170138fa0693ab27c95ca382..030dd713dd1883900d7df3caa86d98ce32c9175e 100644 (file)
 
 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})
index ad8cb7d2fb88c004a0638f455d999ed7aa30ef44..d6a3dbbb9df2737a13a7b11a0a43479901cc9995 100644 (file)
 
 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()
index b58ea3b838ef5b39dfdd3e35d9917a70c5145b57..526fad9916aa3baa1be4942fb882230ad8acb99d 100644 (file)
@@ -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)
index 395c6c0629e9f95251af4103a17005cdcfe16fcd..57d798fb084c669ac8e700e053fe5fa8ec9d9135 100644 (file)
@@ -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
 # 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 (file)
index 1e7956a..0000000
+++ /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 (file)
index 0000000..9acd7b2
--- /dev/null
@@ -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()