]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF27816] : Add non regression test
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 22 Aug 2023 09:16:00 +0000 (11:16 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 22 Aug 2023 09:40:51 +0000 (11:40 +0200)
src/Container/Container_i.cxx
src/Container/Test/CMakeLists.txt
src/Container/Test/CTestTestfileInstall.cmake
src/Container/Test/testProxy.py [new file with mode: 0644]

index 92209ebb647f330e9cc9ab7b500bacc9487a02f4..8e740c5a87ca5bb46091374ff1cbc7cfe3b7ce15 100644 (file)
@@ -1063,7 +1063,8 @@ for k,v in env:
 )foo";
   Engines::PyScriptNode_var scriptNode = this->createPyScriptNode(NODE_NAME,SCRIPT);
   auto sz = env.length();
-  Engines::listofstring keys( sz ), vals( sz );
+  Engines::listofstring keys, vals;
+  keys.length( sz ); vals.length( sz );
   for( auto i = 0 ; i < sz ; ++i )
   {
     keys[i] = CORBA::string_dup( env[i].key );
index 6bdfa41b2500289b83b0ad09bddc069022c166bb..fe3991a88affcfc8a69f2dbf6a958408e579da58 100644 (file)
@@ -18,7 +18,7 @@
 #
 
 SET(LOCAL_TEST_DIR ${KERNEL_TEST_DIR}/Container)
-INSTALL(FILES testcontainer.py DESTINATION ${LOCAL_TEST_DIR})
+INSTALL(FILES testcontainer.py testProxy.py DESTINATION ${LOCAL_TEST_DIR})
 
 INSTALL(FILES CTestTestfileInstall.cmake
         DESTINATION ${LOCAL_TEST_DIR}
index b41691f5fc81d5afc8f5b7bf7fa6d08fe458210c..d1a79ba5d85a5ee72d78c443bccb8964eba9fb24 100644 (file)
 #
 
 IF(NOT WIN32)
-  SET(TEST_NAME ${COMPONENT_NAME}_testcontainer)
-  ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} testcontainer.py)
-  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
-                                    LABELS "${COMPONENT_NAME}"
-                                    ENVIRONMENT "LD_LIBRARY_PATH=${KERNEL_TEST_LIB}:$ENV{LD_LIBRARY_PATH}"
-                      )
+  set(TEST_NAMES testcontainer testProxy)
+  foreach(tfile ${TEST_NAMES})
+    SET(TEST_NAME ${COMPONENT_NAME}_${tfile})
+    ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} ${tfile}.py)
+    SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
+                                      LABELS "${COMPONENT_NAME}"
+                                      ENVIRONMENT "LD_LIBRARY_PATH=${KERNEL_TEST_LIB}:$ENV{LD_LIBRARY_PATH}")
+  endforeach()
 ENDIF()
diff --git a/src/Container/Test/testProxy.py b/src/Container/Test/testProxy.py
new file mode 100644 (file)
index 0000000..d3e7b50
--- /dev/null
@@ -0,0 +1,107 @@
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2023  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 unittest
+import os
+import salome
+import Engines
+import pickle
+import tempfile
+
+class TestProxy(unittest.TestCase):
+    def testProxy(self):
+        """
+        [EDF27816] : This test checks two things :
+        - Capability of ContainerManager to launch a Container with overriden environement
+        - Management of proxy creation to manage big obj exchange between process (here between Container and the current process)
+        """
+        hostname = "localhost"
+        rp=Engines.ResourceParameters(name=hostname,
+                                        hostname=hostname,
+                                        can_launch_batch_jobs=False,
+                                        can_run_containers=True,
+                                        OS="Linux",
+                                        componentList=[],
+                                        nb_proc=1,
+                                        mem_mb=1000,
+                                        cpu_clock=1000,
+                                        nb_node=1,
+                                        nb_proc_per_node=1,
+                                        policy="first",
+                                        resList=[])
+
+        cp=Engines.ContainerParameters(container_name="container_test",
+                                        mode="start",
+                                        workingdir=os.getcwd(),
+                                        nb_proc=1,
+                                        isMPI=False,
+                                        parallelLib="",
+                                        resource_params=rp)
+
+        with tempfile.TemporaryDirectory() as tmpdirname:
+            val_for_jj = "3333"
+            val_for_big_obj = str( tmpdirname )
+            val_for_thres = "100" # force proxy file
+            # Override environement for all containers launched
+            salome.cm.SetOverrideEnvForContainersSimple(env = [("jj",val_for_jj),("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",val_for_thres)])
+            cont = salome.cm.GiveContainer(cp)
+            ## Time to test it
+            script_st = """import os
+a = os.environ["SALOME_FILE_BIG_OBJ_DIR"]
+b = os.environ["jj"]
+c = os.environ["SALOME_BIG_OBJ_ON_DISK_THRES"]
+j = a,b,c"""
+            pyscript = cont.createPyScriptNode("testScript",script_st)
+            a,b,c = pickle.loads(pyscript.execute(["j"],pickle.dumps(([],{}))))[0]
+            assert( a == val_for_big_obj )
+            assert( b == val_for_jj )
+            assert( c == val_for_thres )
+            # check environment using POSIX API in the container process
+            for k,v in [("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",val_for_thres),("jj",val_for_jj)]:
+                assert( {elt.key:elt.value.value() for elt in cont.get_os_environment()}[k] == v )
+            #
+            import SALOME_PyNode
+            poa = salome.orb.resolve_initial_references("RootPOA")
+            obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( ([],{}) ))
+            id_o = poa.activate_object(obj)
+            refPtr = poa.id_to_reference(id_o)
+            script_st2 = """ob = list( range(100) )""" # size of pickled ob must be greater than val_for_thres
+            pyscript2 = cont.createPyScriptNode("testScript2",script_st2)
+            pyscript2.executeFirst(refPtr)
+            ret2 = pyscript2.executeSecond(["ob"])
+            assert( len(ret2) == 1)
+            ret2 = ret2[0]
+            ret3 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret2).data() )
+            assert( isinstance( ret3, SALOME_PyNode.BigObjectOnDiskList ) )
+            assert( val_for_big_obj == os.path.dirname( ret3.getFileName() ) )# very important part of test
+            assert( ret3.get() == list(range(100)) )
+            fn = ret3.getFileName()
+            assert( os.path.exists( fn ) )
+            ret3.unlinkOnDestructor()
+            del ret3
+            import gc
+            gc.collect(0)
+            assert( not os.path.exists( fn ) ) # at destruction of ret3 the corresponding pckl file must be destructed
+            cont.Shutdown()
+
+if __name__ == '__main__':
+    salome.standalone()
+    salome.salome_init()
+    unittest.main()