From: Anthony Geay Date: Tue, 17 Aug 2021 15:35:39 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=65b0b42f670df86cea60bbc0bcb83e46aa975e9d;p=modules%2Fkernel.git WIP --- diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index bf37b0b8f..8e78458d2 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -227,7 +227,8 @@ def salome_init_without_session(): salome_study_init_without_session() naming_service = NamingService() from KernelSDS import GetDSMInstance - dsm = GetDSMInstance() + import sys + dsm = GetDSMInstance(sys.argv) def salome_init_with_session(path=None, embedded=False): """ diff --git a/src/SALOMESDS/KernelSDS.cxx b/src/SALOMESDS/KernelSDS.cxx index 3c21b267a..190112b08 100644 --- a/src/SALOMESDS/KernelSDS.cxx +++ b/src/SALOMESDS/KernelSDS.cxx @@ -24,7 +24,7 @@ static SALOME::DataServerManager_var _dsm_singleton; -std::string GetDSMInstanceInternal() +std::string GetDSMInstanceInternal(const std::vector& argv) { CORBA::ORB_ptr orb = KERNEL::getORB(); if( CORBA::is_nil(_dsm_singleton) ) diff --git a/src/SALOMESDS/KernelSDS.hxx b/src/SALOMESDS/KernelSDS.hxx index 3f1eb0475..9782426a0 100644 --- a/src/SALOMESDS/KernelSDS.hxx +++ b/src/SALOMESDS/KernelSDS.hxx @@ -20,5 +20,6 @@ #pragma once #include +#include -std::string GetDSMInstanceInternal(); +std::string GetDSMInstanceInternal(const std::vector& argv); diff --git a/src/SALOMESDS/KernelSDS.i b/src/SALOMESDS/KernelSDS.i index cc1e46e09..a3e062298 100644 --- a/src/SALOMESDS/KernelSDS.i +++ b/src/SALOMESDS/KernelSDS.i @@ -23,17 +23,64 @@ %{ #include "KernelSDS.hxx" +#include "Utils_SALOME_Exception.hxx" %} + +namespace SALOME +{ + class SALOME_Exception + { + public: + %extend + { + std::string __str__() const + { + return std::string(self->what()); + } + } + }; +} + +using namespace SALOME; + +%exception { + try { + $action + } + catch (SALOME::SALOME_Exception& _e) { + // Reraise with SWIG_Python_Raise + SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME::SALOME_Exception(static_cast< const SALOME::SALOME_Exception& >(_e))),SWIGTYPE_p_INTERP_KERNEL__Exception,SWIG_POINTER_OWN), "INTERP_KERNEL::Exception", SWIGTYPE_p_INTERP_KERNEL__Exception); + SWIG_fail; + } +} + %inline { - std::string GetDSMInstanceInternal(); + std::string GetDSMInstanceInternal(PyObject *argv) + { + if(!PyList_Check(argv)) + THROW_SALOME_EXCEPTION("Not a pylist"); + Py_ssize_t sz=PyList_Size(pyLi); + std::vector argvCpp(sz); + for(Py_ssize_t i = 0 ; i < sz ; ++i) + { + PyObject *obj = PyList_GetItem(pyLi,i); + if(!PyUnicode_Check(obj)) + THROW_SALOME_EXCEPTION("Not a pylist of strings"); + { + Py_ssize_t dummy; + argvCpp[i] = PyUnicode_AsUTF8AndSize(obj,&dummy); + } + } + GetDSMInstanceInternal(argvCpp); + } } %pythoncode %{ -def GetDSMInstance(): +def GetDSMInstance(argv): import SALOME import CORBA orb=CORBA.ORB_init(['']) - return orb.string_to_object(GetDSMInstanceInternal()) + return orb.string_to_object(GetDSMInstanceInternal(argv)) %} diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index c509d74fb..d61a9e1ed 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -43,7 +43,7 @@ def generateKey(varName,scopeName): time.sleep(3) dss.atomicApply([t]) def work(t): - i,varName,scopeName=t + IORNS,i,varName,scopeName=t if i==0: generateKey(varName,scopeName) return 0 @@ -51,7 +51,7 @@ def work(t): import TestSalomeSDSHelper0 import os,subprocess fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py" - proc = subprocess.Popen(["python3", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(["python3", fname, IORNS], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err=proc.communicate() if proc.returncode!=0: print("-------------- work -----------") @@ -95,7 +95,7 @@ def func_test7(scopeName,cv,cv2,cv3,sharedNum): class SalomeSDSTest(unittest.TestCase): - def testList1(self): + def tessList1(self): a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0") self.assertEqual(a.local_copy(),[]) a.append(5) @@ -114,7 +114,7 @@ class SalomeSDSTest(unittest.TestCase): a.ptr().getMyDataScopeServer().deleteVar("a") pass - def testDict1(self): + def tessDict1(self): a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0") a["ab"]=4 self.assertEqual(a.local_copy(),{"ab":4}) @@ -135,7 +135,7 @@ class SalomeSDSTest(unittest.TestCase): a.ptr().getMyDataScopeServer().deleteVar("a") pass - def testReadOnly1(self): + def tessReadOnly1(self): a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0") self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]}) self.assertRaises(Exception,a.__getitem__,"ab") @@ -166,12 +166,13 @@ class SalomeSDSTest(unittest.TestCase): # nbProc=8 pool=mp.Pool(processes=nbProc) - asyncResult=pool.map_async(work,[(i,varName,scopeName) for i in range(nbProc)]) + from NamingService import NamingService + asyncResult=pool.map_async(work,[(NamingService.IOROfNS(),i,varName,scopeName) for i in range(nbProc)]) print("asyncResult=", asyncResult) self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here ! dsm.removeDataScope(scopeName) - def testTransaction2(self): + def tessTransaction2(self): scopeName="Scope1" varName="a" dsm=salome.naming_service.Resolve("/DataServerManager") @@ -195,7 +196,7 @@ class SalomeSDSTest(unittest.TestCase): wk.waitFor() self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10]) - def testTransaction3(self): + def tessTransaction3(self): scopeName="Scope1" varName="a" dsm=salome.naming_service.Resolve("/DataServerManager") @@ -217,7 +218,7 @@ class SalomeSDSTest(unittest.TestCase): dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]}) - def testTransaction4(self): + def tessTransaction4(self): scopeName="Scope1" varName="a" dsm=salome.naming_service.Resolve("/DataServerManager") @@ -241,7 +242,7 @@ class SalomeSDSTest(unittest.TestCase): dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]}) - def testTransaction5(self): + def tessTransaction5(self): """ Like testTransaction2 but without transactions. """ scopeName="Scope1" varName="a" @@ -275,7 +276,7 @@ class SalomeSDSTest(unittest.TestCase): keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)] self.assertEqual(set(keys),set(['ab','cd'])) - def testTransaction6(self): + def tessTransaction6(self): """ Test to test RdWr global vars with transaction""" scopeName="Scope1" varName="a" @@ -324,7 +325,7 @@ class SalomeSDSTest(unittest.TestCase): dsm.removeDataScope(scopeName) pass - def testTransaction7(self): + def tessTransaction7(self): """Like testTransaction5 but after a recovery.""" scopeName="Scope1" varName="a" @@ -348,7 +349,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]}) pass - def testTransaction8(self): + def tessTransaction8(self): """ EDF 16833 and EDF17719 """ funcContent="""def comptchev(a,b): return "d" not in a @@ -385,7 +386,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3) pass - def testTransaction9(self): + def tessTransaction9(self): """ EDF 16833 and EDF17719 : use case 2. Trying to createRdExt during add key session""" funcContent="""def comptchev(a,b): return a==b @@ -415,7 +416,7 @@ class SalomeSDSTest(unittest.TestCase): pass - def testLockToDump(self): + def tessLockToDump(self): """ Test to check that holdRequests method. This method wait for clean server status and hold it until activeRequests is called. Warning this method expects a not overloaded machine to be run because test is based on ellapse time. """ @@ -469,7 +470,8 @@ class SalomeSDSTest(unittest.TestCase): pass def setUp(self): - salome.salome_init() + #salome.salome_init() + salome.salome_init_without_session() pass pass diff --git a/src/SALOMESDS/TestSalomeSDSHelper0.py b/src/SALOMESDS/TestSalomeSDSHelper0.py index be356d492..a7014ad10 100644 --- a/src/SALOMESDS/TestSalomeSDSHelper0.py +++ b/src/SALOMESDS/TestSalomeSDSHelper0.py @@ -21,7 +21,7 @@ import pickle import salome import sys -salome.salome_init() +salome.salome_init_without_session() scopeName="Scope1" varName="a" @@ -32,8 +32,12 @@ def obj2Str(obj): def str2Obj(strr): return pickle.loads(strr) -def waitKey(): - dsm=salome.naming_service.Resolve("/DataServerManager") +def waitKey(IORNS): + import Engines + import CORBA + orb = CORBA.ORB_init(['']) + ns = orb.string_to_object(IORNS) + dsm=ns.Resolve("/DataServerManager") dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) assert(not isCreated) wk=dss.waitForKeyInVar(varName,obj2Str("ef")) @@ -41,4 +45,7 @@ def waitKey(): return str2Obj(dss.waitForMonoThrRev(wk))==[11,14,100] if __name__=="__main__": - sys.exit(not waitKey()) + IORNS = sys.argv[-1] + print(50*"#") + print(sys.argv) + sys.exit(not waitKey(IORNS))