From f804e40d789ae3740d51a05e6b0d9d304f48c79b Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 19 Apr 2019 16:52:00 +0300 Subject: [PATCH] Add unit tests to load HDF files and check results. --- CMakeLists.txt | 4 ++ make.sh | 1 + test.hdfs/CMakeLists.txt | 66 ++++++++++++++++++++++++++++ test.hdfs/delta_p.py | 27 ++++++++++++ test.hdfs/roselend.py | 27 ++++++++++++ test.hdfs/te_fluide.py | 27 ++++++++++++ test.hdfs/te_solide.py | 27 ++++++++++++ test.hdfs/test.py | 41 ++++++++++++++++++ test.hdfs/test_hdf.py | 93 ++++++++++++++++++++++++++++++++++++++++ test.hdfs/usine.py | 27 ++++++++++++ 10 files changed, 340 insertions(+) create mode 100644 test.hdfs/CMakeLists.txt create mode 100644 test.hdfs/delta_p.py create mode 100644 test.hdfs/roselend.py create mode 100644 test.hdfs/te_fluide.py create mode 100644 test.hdfs/te_solide.py create mode 100644 test.hdfs/test.py create mode 100644 test.hdfs/test_hdf.py create mode 100644 test.hdfs/usine.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 777a006d8..09bd369cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,10 @@ IF(ADD_COMPATIBILITY_TESTS) ADD_CUSTOM_TARGET(run_compatibility_tests COMMAND ${CMAKE_CTEST_COMMAND} -C "${CMAKE_BUILD_TYPE}" -LE "tests_compatibility") ENDIF(ADD_COMPATIBILITY_TESTS) +IF(ADD_HDF_TESTS) + ADD_SUBDIRECTORY (test.hdfs) +ENDIF(ADD_HDF_TESTS) + IF(SHAPER_BUILD_DOC) INCLUDE(FindSphinx) ADD_SUBDIRECTORY (doc) diff --git a/make.sh b/make.sh index dcb39447e..df47b7a47 100755 --- a/make.sh +++ b/make.sh @@ -41,6 +41,7 @@ CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Release}" CMAKE_ARGS="${CMAKE_ARGS} -DUSE_TEST_COVERAGE=${USE_TEST_COVERAGE:-OFF}" CMAKE_ARGS="${CMAKE_ARGS} -DADD_MODELS_TESTS=${ADD_MODELS_TESTS:-FALSE}" CMAKE_ARGS="${CMAKE_ARGS} -DADD_COMPATIBILITY_TESTS=${ADD_COMPATIBILITY_TESTS:-FALSE}" +CMAKE_ARGS="${CMAKE_ARGS} -DADD_HDF_TESTS=${ADD_HDF_TESTS:-FALSE}" CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH=${SHAPER_ROOT_DIR}" CMAKE_ARGS="${CMAKE_ARGS} ${SOURCES_DIR}" diff --git a/test.hdfs/CMakeLists.txt b/test.hdfs/CMakeLists.txt new file mode 100644 index 000000000..65813884f --- /dev/null +++ b/test.hdfs/CMakeLists.txt @@ -0,0 +1,66 @@ +# Copyright (C) 2014-2019 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 +# + +ENABLE_TESTING() + +SET(RESTRICTED_ROOT_DIR $ENV{RESTRICTED_ROOT_DIR} CACHE PATH "Path to the restricted repository") + +if (EXISTS ${RESTRICTED_ROOT_DIR}) + file(GLOB hdfFilesRestr "${RESTRICTED_ROOT_DIR}/SHAPER/test.hdfs/*.hdf") + + if (WIN32) # different separators and path to libraries variable name + SET(_JUSTPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${SUIT_LIB_DIR};$ENV{PATH}") + STRING(REPLACE "\\" "/" _JUSTPATH "${_JUSTPATH}") + STRING(REPLACE ";" "\\;" _JUSTPATH "${_JUSTPATH}") + SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS};$ENV{PYTHONPATH}") + STRING(REPLACE "\\" "/" _PYTHONPATH "${_PYTHONPATH}") + STRING(REPLACE ";" "\\;" _PYTHONPATH "${_PYTHONPATH}") + else() + SET(_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${SUIT_LIB_DIR}:$ENV{LD_LIBRARY_PATH}") + SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS}:$ENV{PYTHONPATH}") + endif() + + foreach(eachFilePath ${hdfFilesRestr}) + # Strip the ".hdf" suffix + GET_FILENAME_COMPONENT(aTestName ${eachFilePath} NAME_WE) + + # Add "SubprojectName_" prefix + GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME) + SET(aTestName "${aSubprojectName}_${aTestName}") + + # Full path to the python test file being executed + SET(aTestFilePath "${eachFilePath}") + IF(EXISTS ${aTestFilePath}) + ADD_TEST(NAME ${aTestName} COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/test.py" "$ENV{KERNEL_ROOT_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" "${aTestFilePath}") + if (WIN32) # different path to libraries variable name + SET_TESTS_PROPERTIES(${aTestName} PROPERTIES ENVIRONMENT "PATH=${_JUSTPATH};PYTHONPATH=${_PYTHONPATH}" + LABELS "models_hdf") + else() + SET_TESTS_PROPERTIES(${aTestName} PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${_LD_LIBRARY_PATH};PYTHONPATH=${_PYTHONPATH}" + LABELS "models_hdf") + endif() + # Debug output... + # MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFilePath}") + ELSE(EXISTS ${aTestFilePath}) + MESSAGE(WARNING "Can not find the test file: ${aTestFilePath}") + ENDIF(EXISTS ${aTestFilePath}) + endforeach(eachFilePath ${ARGN}) + + ADD_CUSTOM_TARGET(run_hdf_tests COMMAND ${CMAKE_CTEST_COMMAND} -C "${CMAKE_BUILD_TYPE}" -L "models_hdf") +endif() diff --git a/test.hdfs/delta_p.py b/test.hdfs/delta_p.py new file mode 100644 index 000000000..25ea15af0 --- /dev/null +++ b/test.hdfs/delta_p.py @@ -0,0 +1,27 @@ +# Copyright (C) 2014-2019 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 +# + +if __name__ == "__main__": + model.testNbResults(aPartFeature, 1) + model.testNbSubResults(aPartFeature, [0]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.FACE, [231]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.EDGE, [968]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.VERTEX, [1936]) + model.testResultsVolumes(aPartFeature, [1429610.103267467]) diff --git a/test.hdfs/roselend.py b/test.hdfs/roselend.py new file mode 100644 index 000000000..25ea15af0 --- /dev/null +++ b/test.hdfs/roselend.py @@ -0,0 +1,27 @@ +# Copyright (C) 2014-2019 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 +# + +if __name__ == "__main__": + model.testNbResults(aPartFeature, 1) + model.testNbSubResults(aPartFeature, [0]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.FACE, [231]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.EDGE, [968]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.VERTEX, [1936]) + model.testResultsVolumes(aPartFeature, [1429610.103267467]) diff --git a/test.hdfs/te_fluide.py b/test.hdfs/te_fluide.py new file mode 100644 index 000000000..25ea15af0 --- /dev/null +++ b/test.hdfs/te_fluide.py @@ -0,0 +1,27 @@ +# Copyright (C) 2014-2019 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 +# + +if __name__ == "__main__": + model.testNbResults(aPartFeature, 1) + model.testNbSubResults(aPartFeature, [0]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.FACE, [231]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.EDGE, [968]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.VERTEX, [1936]) + model.testResultsVolumes(aPartFeature, [1429610.103267467]) diff --git a/test.hdfs/te_solide.py b/test.hdfs/te_solide.py new file mode 100644 index 000000000..25ea15af0 --- /dev/null +++ b/test.hdfs/te_solide.py @@ -0,0 +1,27 @@ +# Copyright (C) 2014-2019 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 +# + +if __name__ == "__main__": + model.testNbResults(aPartFeature, 1) + model.testNbSubResults(aPartFeature, [0]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.FACE, [231]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.EDGE, [968]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.VERTEX, [1936]) + model.testResultsVolumes(aPartFeature, [1429610.103267467]) diff --git a/test.hdfs/test.py b/test.hdfs/test.py new file mode 100644 index 000000000..69b88b668 --- /dev/null +++ b/test.hdfs/test.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +if __name__ == '__main__': + + from subprocess import Popen + from time import sleep + import sys, os + + salomeKernelDir = sys.argv[1] + sourceDir = sys.argv[2] + testfile = sys.argv[3] + + portlogfile = os.getcwd() + "/.salome_port" + testlogfile = os.getcwd() + "/test.log" + # remove port file if any + try: + os.remove(portlogfile) + except: + pass + + proc = Popen([salomeKernelDir + "/bin/salome/runSalome.py", "--modules", "SHAPER,GEOM", "--gui", "--ns-port-log=" + portlogfile, sourceDir + "/test_hdf.py", "args:" + testfile + "," + portlogfile + "," + testlogfile + "," + salomeKernelDir + "," + sourceDir]) + + iter = 0 + while not os.path.exists(portlogfile) and iter < 100: + sleep(0.1) + iter += 1 + + while os.path.exists(portlogfile): + sleep(0.1) + + isOk = True + with open(testlogfile, 'r') as inputFile: + s = inputFile.read() + print(s) + for line in s: + isOk = isOk and s.find("FAIL") < 0 + try: + os.remove(testlogfile) + except: + pass + + assert isOk, "Test failed" diff --git a/test.hdfs/test_hdf.py b/test.hdfs/test_hdf.py new file mode 100644 index 000000000..5f5532d49 --- /dev/null +++ b/test.hdfs/test_hdf.py @@ -0,0 +1,93 @@ +# Copyright (C) 2014-2019 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 +# + +import salome, os, sys +import SalomePyQt + +import unittest +import subprocess + +import ModelHighAPI, ModelAPI, PartSetAPI +from GeomAPI import GeomAPI_Shape +from salome.shaper import model + +class TestHDF(unittest.TestCase): + testfile = "" + reffile = "" + + 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') + self.session.emitMessage("connect_to_study") + + self.sg = SalomePyQt.SalomePyQt() + self.sg.activateModule("Shaper") + self.session = ModelAPI.ModelAPI_Session.get() + self.partSet = self.session.moduleDocument() + + def tearDown(self): + salome.sg.UpdateView() + self.sg.processEvents() + salome.sg.FitAll() + + def test_hdf_file(self): + self.assertTrue(self.partSet.size("Parts") > 0) + aPartsList = [] + for aPartIndex in range(self.partSet.size("Parts")): + self.session.startOperation() + aPart = ModelAPI.modelAPI_ResultPart(ModelAPI.objectToResult(self.partSet.object("Parts", aPartIndex))) + aPart.activate() + self.session.finishOperation() + + aPartFeature = PartSetAPI.PartSetAPI_Part(self.partSet.currentFeature(True)) + # check reference data + exec(open(self.reffile, "rb").read()) + + +if __name__ == "__main__": + if len(sys.argv) > 1: + TestHDF.testfile = sys.argv[1] + if len(sys.argv) > 2: + salomePortFile = sys.argv[2] + if len(sys.argv) > 3: + sys.stderr = open(sys.argv[3], 'w') + if len(sys.argv) > 4: + salomeKernelDir = sys.argv[4] + if len(sys.argv) > 5: + TestHDF.reffile = sys.argv[5] + + aTest = unittest.TestLoader().loadTestsFromTestCase(TestHDF) + unittest.TextTestRunner(stream=sys.stderr).run(aTest) + +# test_program = unittest.main(argv=[sys.argv[0]], exit=False) + proc = subprocess.Popen(salomeKernelDir + "/bin/salome/killSalome.py") + + try: + os.remove(salomePortFile) + except: + print("Cannot remove file", file=f) + +# assert test_program.result.wasSuccessful(), "Test failed" diff --git a/test.hdfs/usine.py b/test.hdfs/usine.py new file mode 100644 index 000000000..25ea15af0 --- /dev/null +++ b/test.hdfs/usine.py @@ -0,0 +1,27 @@ +# Copyright (C) 2014-2019 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 +# + +if __name__ == "__main__": + model.testNbResults(aPartFeature, 1) + model.testNbSubResults(aPartFeature, [0]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.FACE, [231]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.EDGE, [968]) + model.testNbSubShapes(aPartFeature, GeomAPI_Shape.VERTEX, [1936]) + model.testResultsVolumes(aPartFeature, [1429610.103267467]) -- 2.39.2