Salome HOME
WIP
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 15:35:39 +0000 (17:35 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 15:35:39 +0000 (17:35 +0200)
src/KERNEL_PY/__init__.py
src/SALOMESDS/KernelSDS.cxx
src/SALOMESDS/KernelSDS.hxx
src/SALOMESDS/KernelSDS.i
src/SALOMESDS/TestSalomeSDS.py
src/SALOMESDS/TestSalomeSDSHelper0.py

index bf37b0b8f34691a1a0f5e95fe61d9d8972fee849..8e78458d28ada9842164057fcbcdebccfb5947be 100644 (file)
@@ -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):
     """
index 3c21b267aefd23859dfb2d3dc989a2fcaa54bd5e..190112b0837f01f85c75fe1809e009ebd087fd8e 100644 (file)
@@ -24,7 +24,7 @@
 
 static SALOME::DataServerManager_var _dsm_singleton;
 
-std::string GetDSMInstanceInternal()
+std::string GetDSMInstanceInternal(const std::vector<std::string>& argv)
 {
   CORBA::ORB_ptr orb = KERNEL::getORB();
   if( CORBA::is_nil(_dsm_singleton) )
index 3f1eb0475eed707f053461c4041abe1493e71233..9782426a080ffc1afe65b5806d39d08806580410 100644 (file)
@@ -20,5 +20,6 @@
 #pragma once
 
 #include <string>
+#include <vector>
 
-std::string GetDSMInstanceInternal();
+std::string GetDSMInstanceInternal(const std::vector<std::string>& argv);
index cc1e46e09d9776aa23071a46da7e247b0ea3d0c5..a3e06229873caed1f9d6904306aff18afa154696 100644 (file)
 
 %{
 #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<std::string> 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))
 %}
index c509d74fbf309be5f42200fb26d4a32e797a0e4a..d61a9e1ed3bc6f249bcfb301f9026ee693efee79 100644 (file)
@@ -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
index be356d492ef2c6b0946f3f10d92ec8bc530f1677..a7014ad10733351182805a836b02262c8d08659a 100644 (file)
@@ -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))