]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF27816] : Add non regression test agy/edf27816_3_integ
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:16:00 +0000 (11:16 +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 939af3b4a94af1d7b79da44ad0142a9ed299973f..cba79036f661d5a082931aeaa3a8ba719954417c 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 9a36b03fa53c03a495248254affe42cf51b775e2..33652968087d5dcf00c9efdba16396ac29612897 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 193320341474ffebf599028ccfdc4af8f13998c2..c70298257855ab52e3bd42eab6397fbcc5a26460 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()