From 48c644b2626191b0bc01319bb058ff6da9d0c8d5 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 22 Aug 2023 11:16:00 +0200 Subject: [PATCH] [EDF27816] : Add non regression test --- src/Container/Container_i.cxx | 3 +- src/Container/Test/CMakeLists.txt | 2 +- src/Container/Test/CTestTestfileInstall.cmake | 14 ++- src/Container/Test/testProxy.py | 107 ++++++++++++++++++ 4 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 src/Container/Test/testProxy.py diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 92209ebb6..8e740c5a8 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -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 ); diff --git a/src/Container/Test/CMakeLists.txt b/src/Container/Test/CMakeLists.txt index 6bdfa41b2..fe3991a88 100644 --- a/src/Container/Test/CMakeLists.txt +++ b/src/Container/Test/CMakeLists.txt @@ -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} diff --git a/src/Container/Test/CTestTestfileInstall.cmake b/src/Container/Test/CTestTestfileInstall.cmake index b41691f5f..d1a79ba5d 100644 --- a/src/Container/Test/CTestTestfileInstall.cmake +++ b/src/Container/Test/CTestTestfileInstall.cmake @@ -18,10 +18,12 @@ # 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 index 000000000..d3e7b50db --- /dev/null +++ b/src/Container/Test/testProxy.py @@ -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() -- 2.39.2