Salome HOME
[EDF27816] : Get rid of SALOME session for 3 last tests (YacsLoader, YacsLoader_Swig...
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 15 Jun 2023 15:25:17 +0000 (17:25 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 22 Aug 2023 10:54:40 +0000 (12:54 +0200)
23 files changed:
src/CTestTestfileInstall.cmake
src/runtime/CORBAComponent.cxx
src/runtime/PythonNode.cxx
src/runtime/PythonNode.hxx
src/runtime/RuntimeSALOME.cxx
src/runtime/RuntimeSALOME.hxx
src/runtime/Test/TestRuntime.cxx
src/runtime/Test/echoSrv.cxx
src/runtime/Test/runtimeTest.cxx
src/runtime/Test/runtimeTest.sh
src/runtime/TypeConversions.cxx
src/yacsloader/Test/CTestTestfileInstall.cmake
src/yacsloader/Test/TestYacsLoader.cxx
src/yacsloader/Test/YacsLoaderTest.cxx
src/yacsloader/Test/echoSrv.cxx
src/yacsloader/Test/runYacsLoaderTest.sh
src/yacsloader_swig/Test/CMakeLists.txt
src/yacsloader_swig/Test/CTestTestfileInstall.cmake
src/yacsloader_swig/Test/runUnitTest.sh [deleted file]
src/yacsloader_swig/Test/testExec.py
src/yacsloader_swig/Test/testLoader.py
src/yacsloader_swig/Test/testSave.py
src/yacsloader_swig/Test/testYacsLoaderSwig.py [new file with mode: 0644]

index e377f6957e34f773a1df5f32b6bc2d5745afffa9..7e351c0a17677920f2e52d400cf2f36c682dffe9 100644 (file)
@@ -18,7 +18,7 @@
 #
 
 #SET(SALOME_TEST_DRIVER "$ENV{ABSOLUTE_APPLI_PATH}/bin/salome/appliskel/salome_test_driver.py")
-SET(SALOME_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/salome_test_driver.py")
+SET(PYTHON_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/python_test_driver.py")
 
 SET(COMPONENT_NAME YACS)
 SET(TIMEOUT        500)
index 09677357455e0a4d1c8309d924762fbe9efe829d..e3e21455fe5c397aa45527065325b2bc02f043ff 100644 (file)
@@ -101,12 +101,10 @@ bool CORBAComponent::isLoaded(Task *askingNode) const
 void CORBAComponent::load(Task *askingNode)
 {
   DEBTRACE( "CORBAComponent::load" );
-  CORBA::ORB_ptr orb;
   try
     {
       DEBTRACE( "+++++++++++++++++" << getCompoName() << " +++++++++++++++++" );
-      orb = getSALOMERuntime()->getOrb();
-      _objComponent= orb->string_to_object(getCompoName().c_str());
+      _objComponent= getSALOMERuntime()->getFromNS(getCompoName().c_str());
 #ifdef REFCNT
       std::cerr << "CORBAComponent::load:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
 #endif
index 3334d97e2a41c0ef119f043a45cfc0eca16f349d..d0f40b944e9c461cf7475940d33185cf9af92f90 100644 (file)
@@ -678,33 +678,34 @@ void PythonNode::executeRemote()
   }
   DEBTRACE( "++++++++++++++ ENDOF PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
 }
-void PythonNode::executeLocalInternal(const std::string& codeStr)
+
+void PythonNode::ExecuteLocalInternal(const std::string& codeStr, PyObject *context, std::string& errorDetails)
 {
   DEBTRACE(  code );
-  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
+  DEBTRACE( "context refcnt: " << context->ob_refcnt );
   std::ostringstream stream;
   stream << "/tmp/PythonNode_";
   stream << getpid();
   AutoPyRef code=Py_CompileString(codeStr.c_str(), stream.str().c_str(), Py_file_input);
   if(code == NULL)
   {
-    _errorDetails=""; 
-    AutoPyRef new_stderr = newPyStdOut(_errorDetails);
+    errorDetails=""; 
+    AutoPyRef new_stderr = newPyStdOut(errorDetails);
     PySys_SetObject((char*)"stderr", new_stderr);
     PyErr_Print();
     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
-    throw Exception("Error during execution");
+    throw YACS::Exception("Error during execution");
   }
   {
-    AutoPyRef res = PyEval_EvalCode(  code, _context, _context);
+    AutoPyRef res = PyEval_EvalCode(  code, context, context);
   }
-  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
+  DEBTRACE( "context refcnt: " << context->ob_refcnt );
   fflush(stdout);
   fflush(stderr);
   if(PyErr_Occurred ())
   {
-    _errorDetails="";
-    AutoPyRef new_stderr = newPyStdOut(_errorDetails);
+    errorDetails="";
+    AutoPyRef new_stderr = newPyStdOut(errorDetails);
     PySys_SetObject((char*)"stderr", new_stderr);
     ofstream errorfile(stream.str().c_str());
     if (errorfile.is_open())
@@ -714,10 +715,15 @@ void PythonNode::executeLocalInternal(const std::string& codeStr)
       }
     PyErr_Print();
     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
-    throw Exception("Error during execution");
+    throw YACS::Exception("Error during execution");
   }
 }
 
+void PythonNode::executeLocalInternal(const std::string& codeStr)
+{
+  ExecuteLocalInternal(codeStr,_context,_errorDetails);
+}
+
 void PythonNode::executeLocal()
 {
   DEBTRACE( "++++++++++++++ PyNode::executeLocal: " << getName() << " ++++++++++++++++++++" );
index d83997cde3a257b07385da8baf77f41665dfa524..49b6a2e7c136a4e7df630a4316a13048829cd2dd 100644 (file)
@@ -108,6 +108,7 @@ namespace YACS
       void setSqueezeStatus(bool sqStatus) { _autoSqueeze=sqStatus; }
       bool getSqueezeStatus() const { return _autoSqueeze; }
       void squeezeMemorySafe();
+      static void ExecuteLocalInternal(const std::string& codeStr, PyObject *context, std::string& errorDetails);
     private:
       void executeLocalInternal(const std::string& codeStr);
     protected:
index 15ad04febd098b34a8024e58ccb78d0d7c9fd252..55401af07229a27a718aefaaae0b12b289f80cd1 100644 (file)
 #include "SALOME_ResourcesManager.hxx"
 #include "SALOME_ContainerManager.hxx"
 #include "SALOMEconfig.h"
+#include "SALOME_Embedded_NamingService.hxx"
 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
 
 #endif
 #include <omniORB4/CORBA.h>
 #include <iostream>
 #include <sstream>
+#include <string>
 #include <cassert>
+#include <memory>
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
@@ -464,6 +467,38 @@ void RuntimeSALOME::fini()
     }
 }
 
+PyObject *RuntimeSALOME::launchSubProcess(const std::vector<std::string>& cmds)
+{
+  std::ostringstream oss; oss << "from subprocess import Popen" << std::endl;
+  oss << "p = Popen([";
+  for(auto i = 0 ; i < cmds.size() ; ++i)
+  {
+    oss << " " << "\"" << cmds[i] << "\"";
+    if(i < cmds.size()-1)
+      oss << ", ";
+    else
+      oss << " ";
+  }
+  oss << "])";
+  AutoGIL agil;
+  AutoPyRef context = PyDict_New();
+  PyDict_SetItemString( context, "__builtins__", getBuiltins() );
+  std::string errorDetails;
+  try
+  {
+    PythonNode::ExecuteLocalInternal(oss.str().c_str(),context,errorDetails);
+  }
+  catch(const YACS::Exception& e)
+  {
+    std::cerr << e.what() << std::endl << errorDetails << std::endl;
+    throw e;
+  }
+  PyObject *ret = PyDict_GetItemString(context,"p");
+  Py_XINCREF(ret);
+  Py_XINCREF(ret);
+  return ret;
+}
+
 std::vector< std::pair<std::string,int> > RuntimeSALOME::getCatalogOfComputeNodes() const
 {
   CORBA::ORB_ptr orb(getOrb());
@@ -1875,6 +1910,36 @@ CORBA::ORB_ptr RuntimeSALOME::getOrb() const
   return _orb;
 }
 
+/*!
+ * Retrieve from custom NS the entry. Custom NS is supposed to be hosted in current process.
+ * This method try to emulate CORBA ns convention : "corbaname:rir:#test.my_context/Echo.Object" is converted into "Echo"
+ * 
+ * See Engines::EmbeddedNamingService
+ */
+CORBA::Object_var RuntimeSALOME::getFromNS(const char *entry) const
+{
+  CORBA::Object_var ret;
+  std::string entryCpp(entry);
+  if(entryCpp.substr(0,4) == "IOR:")
+  {
+    ret = _orb->string_to_object( entry );
+  }
+  else
+  {
+    auto pos = entryCpp.find_last_of('/');
+    std::string entry1( entryCpp.substr(pos+1,std::string::npos) );
+    pos = entry1.find_last_of('.');
+    std::string entry2( entry1.substr(0,pos) );
+    Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+    std::unique_ptr<Engines::IORType> iorRet( ns->Resolve( entry2.c_str() ) );
+    auto len = iorRet->length();
+    std::unique_ptr<char[]> iorTrans(new char[len+1]); iorTrans[len] = '\0';
+    for(auto i = 0 ; i < len ; ++i) iorTrans[i] = (*iorRet)[i];
+    ret = _orb->string_to_object(iorTrans.get());
+  }
+  return ret;
+}
+
 PyObject * RuntimeSALOME::getPyOrb() const
 {
   return _pyorb;
index 51370ac47d037c8c7a9ce3ce55b9f18ee1f9e099..1e94f0af3ecf3ec9b48ed478f98b57608a63dbc2 100644 (file)
@@ -84,6 +84,7 @@ namespace YACS
 
       virtual void init(long flags, int argc, char* argv[]);
       virtual void fini();
+      PyObject *launchSubProcess(const std::vector<std::string>& cmds);
       virtual std::vector< std::pair<std::string,int> > getCatalogOfComputeNodes() const;
       virtual InputPort* createInputPort(const std::string& name,
                                          const std::string& impl,
@@ -236,6 +237,7 @@ namespace YACS
       void loadModulCatalog();
 
       CORBA::ORB_ptr getOrb() const;
+      CORBA::Object_var getFromNS(const char *entry) const;
       PyObject * getPyOrb() const;
       PyObject * getBuiltins() const;
       DynamicAny::DynAnyFactory_ptr getDynFactory() const;
index ec16d53b358229871717e7b720c54077103649ff..bf813ba89f5ac8e5bed61a8bd1e7e7edb360570a 100644 (file)
@@ -20,6 +20,8 @@
 #define UNIT_TEST_HEADER " --- TEST src/runtime"
 
 #include "runtimeTest.hxx"
+#include "PythonCppUtils.hxx"
+#include "SALOME_Embedded_NamingService.hxx"
 
 using namespace YACS;
 using namespace std;
@@ -29,5 +31,26 @@ using namespace std;
 CPPUNIT_TEST_SUITE_REGISTRATION( RuntimeTest );
 
 // --- generic Main program from bases/Test
+#include "BasicMainTestInternal.hxx"
+#include "RuntimeSALOME.hxx"
 
-#include "BasicMainTest.hxx"
+int main()
+{
+  YACS::ENGINE::RuntimeSALOME::setRuntime();
+  YACS::ENGINE::RuntimeSALOME *rt = YACS::ENGINE::getSALOMERuntime();
+  if( !rt )
+    return 1;
+  Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+  CORBA::ORB_ptr orb = rt->getOrb();
+  CORBA::String_var ior = orb->object_to_string( ns );
+  AutoPyRef proc = rt->launchSubProcess({"./runtimeTestEchoSrv",std::string(ior)});
+  usleep(3000000);
+  int ret = BasicMainTestInternal();
+  //
+  {
+    AutoGIL agil;
+    AutoPyRef terminateStr = PyUnicode_FromString("terminate");
+    AutoPyRef dummy = PyObject_CallMethodObjArgs(proc,terminateStr,nullptr);
+  }
+  return ret;
+}
index 77c10f6a1f96cf0d03b01a10ce10a151b1a32e28..33fca7b2f96b4f08fc7291e1967d15913e50710b 100644 (file)
@@ -27,7 +27,10 @@ using namespace std;
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
 
-static CORBA::Boolean bindObjectToName(CORBA::ORB_ptr, CORBA::Object_ptr,const char*);
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService)
+
+static CORBA::Boolean bindObjectToName(Engines::EmbeddedNamingService_ptr ns, CORBA::Object_ptr,const char*);
 
 static ostream& operator<<(ostream& os, const CORBA::Exception& e)
 {
@@ -325,6 +328,15 @@ int main(int argc, char** argv)
   try {
     orb = CORBA::ORB_init(argc, argv);
 
+    std::string theIOR( argv[1] );
+    
+    CORBA::Object_var obj = orb->string_to_object(theIOR.c_str());
+    Engines::EmbeddedNamingService_var ns = Engines::EmbeddedNamingService::_narrow( obj );
+    if( CORBA::is_nil( ns ) )
+      return 1;
+    //std::cout << getpid() << std::endl;
+    //usleep(20000000);
+
     {
       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
       PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
@@ -339,7 +351,7 @@ int main(int argc, char** argv)
       v <<= omniPolicy::LOCAL_CALLS_SHORTCUT;
       pl2[0] = orb->create_policy(omniPolicy::LOCAL_SHORTCUT_POLICY_TYPE, v);
       pl2[1] = root_poa->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION);
-      PortableServer::POA_ptr shortcut_poa = root_poa->create_POA("shortcut", poa_man, pl2);
+      PortableServer::POA_var shortcut_poa = root_poa->create_POA("shortcut", poa_man, pl2);
 
       // Create and activate servant
       Echo_i* myecho = new Echo_i();
@@ -350,7 +362,7 @@ int main(int argc, char** argv)
       DEBTRACE("'" << (char*)sior << "'");
       myechoref = eo::Echo::_narrow(obj);
 
-      if( !bindObjectToName(orb, myechoref,"Echo") ) return 1;
+      if( !bindObjectToName(ns, myechoref,"Echo") ) return 1;
 
       // Decrement the reference count of the object implementation, so
       // that it will be properly cleaned up when the POA has determined
@@ -362,21 +374,21 @@ int main(int argc, char** argv)
       obj=myC->_this();
       eo::C_var myCref=eo::C::_narrow(obj);
       myC->_remove_ref();
-      if( !bindObjectToName(orb, myCref,"C") ) return 1;
+      if( !bindObjectToName(ns, myCref,"C") ) return 1;
 
       //create object D and register it in naming service
       D_i* myD = new D_i();
       obj=myD->_this();
       eo::D_var myDref=eo::D::_narrow(obj);
       myD->_remove_ref();
-      if( !bindObjectToName(orb, myDref,"D") ) return 1;
+      if( !bindObjectToName(ns, myDref,"D") ) return 1;
 
       //create object Obj and register it in naming service
       Obj_i* myObj = new Obj_i();
       obj=myObj->_this();
       eo::Obj_var myObjref=eo::Obj::_narrow(obj);
       myObj->_remove_ref();
-      if( !bindObjectToName(orb, myObjref,"Obj") ) return 1;
+      if( !bindObjectToName(ns, myObjref,"Obj") ) return 1;
     }
     orb->run();
   }
@@ -403,90 +415,16 @@ int main(int argc, char** argv)
 //////////////////////////////////////////////////////////////////////
 
 static CORBA::Boolean
-bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref,const char *name)
+bindObjectToName(Engines::EmbeddedNamingService_ptr ns, CORBA::Object_ptr objref,const char *name)
 {
-  CosNaming::NamingContext_var rootContext;
-
-  try {
-    // Obtain a reference to the root context of the Name service:
-    CORBA::Object_var obj;
-    obj = orb->resolve_initial_references("NameService");
-
-    // Narrow the reference returned.
-    rootContext = CosNaming::NamingContext::_narrow(obj);
-    if( CORBA::is_nil(rootContext) ) {
-      DEBTRACE("Failed to narrow the root naming context.");
-      return 0;
-    }
-  }
-  catch(CORBA::ORB::InvalidName& ex) {
-    // This should not happen!
-    DEBTRACE("Service required is invalid [does not exist]." );
-    return 0;
-  }
-
-  try {
-    // Bind a context called "test" to the root context:
-
-    CosNaming::Name contextName;
-    contextName.length(1);
-    contextName[0].id   = (const char*) "test";       // string copied
-    contextName[0].kind = (const char*) "my_context"; // string copied
-    // Note on kind: The kind field is used to indicate the type
-    // of the object. This is to avoid conventions such as that used
-    // by files (name.type -- e.g. test.ps = postscript etc.)
-
-    CosNaming::NamingContext_var testContext;
-    try {
-      // Bind the context to root.
-      testContext = rootContext->bind_new_context(contextName);
-    }
-    catch(CosNaming::NamingContext::AlreadyBound& ex) {
-      // If the context already exists, this exception will be raised.
-      // In this case, just resolve the name and assign testContext
-      // to the object returned:
-      CORBA::Object_var obj;
-      obj = rootContext->resolve(contextName);
-      testContext = CosNaming::NamingContext::_narrow(obj);
-      if( CORBA::is_nil(testContext) ) {
-        DEBTRACE("Failed to narrow naming context.");
-        return 0;
-      }
-    }
-
-    // Bind objref with name Echo to the testContext:
-    CosNaming::Name objectName;
-    objectName.length(1);
-    objectName[0].id   = name;   // string copied
-    objectName[0].kind = (const char*) "Object"; // string copied
-
-    try {
-      testContext->bind(objectName, objref);
-    }
-    catch(CosNaming::NamingContext::AlreadyBound& ex) {
-      testContext->rebind(objectName, objref);
-    }
-    // Note: Using rebind() will overwrite any Object previously bound
-    //       to /test/Echo with obj.
-    //       Alternatively, bind() can be used, which will raise a
-    //       CosNaming::NamingContext::AlreadyBound exception if the name
-    //       supplied is already bound to an object.
-
-    // Amendment: When using OrbixNames, it is necessary to first try bind
-    // and then rebind, as rebind on it's own will throw a NotFoundexception if
-    // the Name has not already been bound. [This is incorrect behaviour -
-    // it should just bind].
-  }
-  catch(CORBA::COMM_FAILURE& ex) {
-    DEBTRACE("Caught system exception COMM_FAILURE -- unable to contact the "
-             << "naming service.");
-    return 0;
-  }
-  catch(CORBA::SystemException&) {
-    DEBTRACE("Caught a CORBA::SystemException while using the naming service.");
-    return 0;
-  }
-
+  CORBA::String_var iorNSUg = orb->object_to_string(objref);
+  std::string iorNS(iorNSUg);
+  Engines::IORType iorInput;
+  auto len = iorNS.length();
+  iorInput.length( len );
+  for(auto i = 0 ; i < len ; ++i)
+    iorInput[i] = iorNS[i];
+  ns->Register(iorInput,name);
   return 1;
 }
 
index 6af3df6a97558dac331b2e52d8e1e1ae68e74f40..01fa8b123adee0652878efcea7b9e43c93ff691d 100644 (file)
@@ -1665,7 +1665,7 @@ void RuntimeTest::classTeardown()
   _tc_seqlong->decrRef();
   _tc_string->decrRef();
 
-  _myRuntime->fini();
+  //_myRuntime->fini();
   delete _myRuntime;
 }
 
index a88954398f667c13d306f9fd4d5db0b9bbe55d16..c5b7cdae45e118b44a5f0b33593e9606c863e3c9 100644 (file)
 
 BASEDIR=`pwd`
 TESTDIR=$(mktemp -d  --suffix=.yacstest)
-OMNIORB_CONFIG=${TESTDIR}/omniorb.cfg
-OMNINAMES_LOGDIR=${TESTDIR}/omnilog
 
 export TESTDIR
-export OMNIORB_CONFIG
-export OMNINAMES_LOGDIR
 
 echo ${TESTDIR}
-echo ${OMNIORB_CONFIG}
-
-# do not use the default port 2810 for omninames (to improve, cf. SALOME)
-echo "InitRef = NameService=corbaname::localhost:2910" > ${OMNIORB_CONFIG}
-
-rm -rf ${OMNINAMES_LOGDIR}
-mkdir  ${OMNINAMES_LOGDIR}
-
-echo $$
-
-omniNames -start 2910 &
-pidomni=$!
-echo $pidomni
-
-#wait enough time to let omniNames start
-sleep 2
-
-./runtimeTestEchoSrv &
-pidecho=$!
-echo $pidecho
 
 # this find should work both for make test and for salome test
 mkdir -p ${TESTDIR}/lib/salome
@@ -56,16 +32,15 @@ cp $LIBTEST ${TESTDIR}/lib/salome
 
 export TESTCOMPONENT_ROOT_DIR=${TESTDIR}
 
-#wait enough time to let runtimeTestEchoSrv start and register
-sleep 2
-
 cp xmlrun.sh ${TESTDIR}
 cp TestRuntime ${TESTDIR}
+cp runtimeTestEchoSrv ${TESTDIR}
+LIBDIR=$BASEDIR/../../test/lib
 cd ${TESTDIR}
-./TestRuntime
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR ./TestRuntime
 ret=$?
+echo $ret
 cd -
 
-kill -9 $pidecho $pidomni
 cat /tmp/${USER}/UnitTestsResult
 exit $ret
index 1d194dfdc91d6b3ce87e7a495270b215a42b7507..faed21173c3464acc45cffd425204299ab06d611 100644 (file)
@@ -1039,7 +1039,7 @@ namespace YACS
           CORBA::Object_var obref;
           try
             {
-              obref = getSALOMERuntime()->getOrb()->string_to_object(o.c_str());
+              obref = getSALOMERuntime()->getFromNS(o.c_str());
 #ifdef REFCNT
               DEBTRACE("obref refCount: " << obref->_PR_getobj()->pd_refCount);
 #endif
@@ -2084,7 +2084,7 @@ namespace YACS
             {
               try
                 {
-                  obref=getSALOMERuntime()->getOrb()->string_to_object(o.c_str());
+                  obref=getSALOMERuntime()->getFromNS(o.c_str());
                 }
               catch(CORBA::Exception& ex)
                 {
index 9d64cbd80ec49a17131005d4e17cf8bd58a2eeb0..51ef9b3306e4d7b8b8105ff0f16e1d43ff9bfaf1 100644 (file)
@@ -19,7 +19,7 @@
 
 IF(NOT WIN32)
   SET(TEST_NAME ${COMPONENT_NAME}_YacsLoaderTest)
-  ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} ./runYacsLoaderTest.sh)
+  ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} ./runYacsLoaderTest.sh)
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
                                     LABELS "${COMPONENT_NAME}"
                                     ENVIRONMENT "LD_LIBRARY_PATH=${YACS_TEST_LIB}:$ENV{LD_LIBRARY_PATH}")
index afa308c424a20fdabe449e329928a8fb9d0980e6..cc9f87cfa9f94938214b6cf5c18a5ae7eee44a7a 100644 (file)
 #define UNIT_TEST_HEADER " --- TEST src/yacsloader"
 
 #include "YacsLoaderTest.hxx"
+#include "RuntimeSALOME.hxx"
+#include "PythonCppUtils.hxx"
+
+#if SALOME_KERNEL
+#include "SALOME_Embedded_NamingService.hxx"
+#include "SALOME_ContainerManager.hxx"
+#include "SALOME_NamingService_Wrapper.hxx"
+#endif
 
 using namespace YACS;
 using namespace std;
@@ -30,4 +38,30 @@ CPPUNIT_TEST_SUITE_REGISTRATION( YacsLoaderTest );
 
 // --- generic Main program from bases/Test
 
-#include "BasicMainTest.hxx"
+#include "BasicMainTestInternal.hxx"
+#include "RuntimeSALOME.hxx"
+
+int main()
+{
+  YACS::ENGINE::RuntimeSALOME::setRuntime();
+  YACS::ENGINE::RuntimeSALOME *rt = YACS::ENGINE::getSALOMERuntime();
+  if( !rt )
+    return 1;
+  Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+  CORBA::ORB_ptr orb = rt->getOrb();
+  CORBA::String_var ior = orb->object_to_string( ns );
+  AutoPyRef proc = rt->launchSubProcess({"./echoSrv",std::string(ior)});
+  //std::cout << getpid() << std::endl;
+  usleep(3000000);
+  int ret = BasicMainTestInternal();
+  //
+  SALOME_NamingService_Wrapper namingService(orb);
+  CORBA::Object_var objDSM(namingService.Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS));
+  Engines::ContainerManager_var dsm(Engines::ContainerManager::_narrow(objDSM));
+  dsm->ShutdownContainers();
+  //
+  AutoGIL agil;
+  AutoPyRef terminateStr = PyUnicode_FromString("terminate");
+  AutoPyRef dummy = PyObject_CallMethodObjArgs(proc,terminateStr,nullptr);
+  return ret;
+}
index e63361827505986ae8f5844f8ff24e99903048e8..43df387c81fa344ba7f472aab6b5cc6ac1b67fed 100644 (file)
@@ -70,6 +70,7 @@ int driverTest(Proc* &p, const char* schema)
       DEBTRACE("+++++++++++++++++++   END execution " << schema);
       std::ofstream g("titi");
       p->writeDot(g);
+      p->shutdown(10);
       g.close();
       DEBTRACE("+++++++++++++++++++ END test " << schema);
       return 0;
@@ -204,6 +205,7 @@ void YacsLoaderTest::cschema()
               CPPUNIT_ASSERT_EQUAL(string("Hello Hello coucou!!"), string(text) );
             }
         }
+      p->shutdown(10);
       delete p;
     }
 #endif
@@ -237,6 +239,7 @@ void YacsLoaderTest::dschema()
               CPPUNIT_ASSERT_EQUAL( string("Hello Hello coucou!!"), string(text));
             }
         }
+      p->shutdown(10);
       delete p;
     }
 #endif
@@ -667,6 +670,7 @@ void YacsLoaderTest::foreachs()
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach2.xml", p->getEffectiveState() == YACS::DONE );
   delete p;
   ret = driverTest(p, "samples/foreach3.xml");
+  p->shutdown(10);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach3.xml", ret == 1);
   delete p;
   ret = driverTest(p, "samples/foreach4.xml");
@@ -684,6 +688,7 @@ void YacsLoaderTest::foreachs()
   ret = driverTest(p, "samples/foreach8.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach8.xml", ret == 0);
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach8.xml", p->getEffectiveState() == YACS::DONE );
+  p->shutdown(10);
   delete p;
   ret = driverTest(p, "samples/foreach_init2fin.xml");
   CPPUNIT_ASSERT_MESSAGE("Schema: foreach_init2fin.xml", ret == 0);
index 6212fc3b0a22aba2f88b382ec0b55e4289a6735f..21930e01d5c120b20f41843cd50141cdf23ac3e8 100644 (file)
 #include <echo.hh>
 
 #include <iostream>
+#include <memory>
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
 
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService)
+
 using namespace std;
 
 CORBA::ORB_var orb;
-static CORBA::Boolean bindObjectToName(CORBA::ORB_ptr, CORBA::Object_ptr,const char*);
+static CORBA::Boolean bindObjectToName(Engines::EmbeddedNamingService_ptr ns, CORBA::Object_ptr,const char*);
 
 static ostream& operator<<(ostream& os, const CORBA::Exception& e)
 {
@@ -377,6 +381,15 @@ int main(int argc, char** argv)
   try {
     orb = CORBA::ORB_init(argc, argv);
 
+    std::string theIOR( argv[1] );
+    
+    CORBA::Object_var obj = orb->string_to_object(theIOR.c_str());
+    Engines::EmbeddedNamingService_var ns = Engines::EmbeddedNamingService::_narrow( obj );
+    if( CORBA::is_nil( ns ) )
+      return 1;
+    //std::cout << getpid() << std::endl;
+    //usleep(20000000);
+
     {
       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
       PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
@@ -408,29 +421,28 @@ int main(int argc, char** argv)
       // print the reference as a stringified IOR.
       CORBA::String_var sior(orb->object_to_string(obj2));
       DEBTRACE("'" << (char*)sior << "'");
-
-      if( !bindObjectToName(orb, myechoref,"Echo") ) return 1;
+      if( !bindObjectToName(ns, myechoref,"Echo") ) return 1;
 
       //create object C and register it in naming service
       C_i* myC = new C_i();
       CORBA::Object_var obj3 =myC->_this();
       eo::C_var myCref=eo::C::_narrow(obj3);
       myC->_remove_ref();
-      if( !bindObjectToName(orb, myCref,"C") ) return 1;
+      if( !bindObjectToName(ns, myCref,"C") ) return 1;
 
       //create object D and register it in naming service
       D_i* myD = new D_i();
       CORBA::Object_var obj4=myD->_this();
       eo::D_var myDref=eo::D::_narrow(obj4);
       myD->_remove_ref();
-      if( !bindObjectToName(orb, myDref,"D") ) return 1;
+      if( !bindObjectToName(ns, myDref,"D") ) return 1;
 
       //create object Obj and register it in naming service
       Obj_i* myObj = new Obj_i();
       CORBA::Object_var obj5=myObj->_this();
       eo::Obj_var myObjref=eo::Obj::_narrow(obj5);
       myObj->_remove_ref();
-      if( !bindObjectToName(orb, myObjref,"Obj") ) return 1;
+      if( !bindObjectToName(ns, myObjref,"Obj") ) return 1;
     }
     orb->run();
     std::cout << "Returned from orb->run()." << std::endl;
@@ -459,90 +471,16 @@ int main(int argc, char** argv)
 //////////////////////////////////////////////////////////////////////
 
 static CORBA::Boolean
-bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref,const char *name)
+bindObjectToName(Engines::EmbeddedNamingService_ptr ns, CORBA::Object_ptr objref,const char *name)
 {
-  CosNaming::NamingContext_var rootContext;
-
-  try {
-    // Obtain a reference to the root context of the Name service:
-    CORBA::Object_var obj;
-    obj = orb->resolve_initial_references("NameService");
-
-    // Narrow the reference returned.
-    rootContext = CosNaming::NamingContext::_narrow(obj);
-    if( CORBA::is_nil(rootContext) ) {
-      DEBTRACE("Failed to narrow the root naming context.");
-      return 0;
-    }
-  }
-  catch(CORBA::ORB::InvalidName& ex) {
-    // This should not happen!
-    DEBTRACE("Service required is invalid [does not exist]." );
-    return 0;
-  }
-
-  try {
-    // Bind a context called "test" to the root context:
-
-    CosNaming::Name contextName;
-    contextName.length(1);
-    contextName[0].id   = (const char*) "test";       // string copied
-    contextName[0].kind = (const char*) "my_context"; // string copied
-    // Note on kind: The kind field is used to indicate the type
-    // of the object. This is to avoid conventions such as that used
-    // by files (name.type -- e.g. test.ps = postscript etc.)
-
-    CosNaming::NamingContext_var testContext;
-    try {
-      // Bind the context to root.
-      testContext = rootContext->bind_new_context(contextName);
-    }
-    catch(CosNaming::NamingContext::AlreadyBound& ex) {
-      // If the context already exists, this exception will be raised.
-      // In this case, just resolve the name and assign testContext
-      // to the object returned:
-      CORBA::Object_var obj;
-      obj = rootContext->resolve(contextName);
-      testContext = CosNaming::NamingContext::_narrow(obj);
-      if( CORBA::is_nil(testContext) ) {
-        DEBTRACE("Failed to narrow naming context.");
-        return 0;
-      }
-    }
-
-    // Bind objref with name Echo to the testContext:
-    CosNaming::Name objectName;
-    objectName.length(1);
-    objectName[0].id   = name;   // string copied
-    objectName[0].kind = (const char*) "Object"; // string copied
-
-    try {
-      testContext->bind(objectName, objref);
-    }
-    catch(CosNaming::NamingContext::AlreadyBound& ex) {
-      testContext->rebind(objectName, objref);
-    }
-    // Note: Using rebind() will overwrite any Object previously bound
-    //       to /test/Echo with obj.
-    //       Alternatively, bind() can be used, which will raise a
-    //       CosNaming::NamingContext::AlreadyBound exception if the name
-    //       supplied is already bound to an object.
-
-    // Amendment: When using OrbixNames, it is necessary to first try bind
-    // and then rebind, as rebind on it's own will throw a NotFoundexception if
-    // the Name has not already been bound. [This is incorrect behaviour -
-    // it should just bind].
-  }
-  catch(CORBA::COMM_FAILURE& ex) {
-    DEBTRACE("Caught system exception COMM_FAILURE -- unable to contact the "
-             << "naming service.");
-    return 0;
-  }
-  catch(CORBA::SystemException&) {
-    DEBTRACE("Caught a CORBA::SystemException while using the naming service.");
-    return 0;
-  }
-
+  CORBA::String_var iorNSUg = orb->object_to_string(objref);
+  std::string iorNS(iorNSUg);
+  Engines::IORType iorInput;
+  auto len = iorNS.length();
+  iorInput.length( len );
+  for(auto i = 0 ; i < len ; ++i)
+    iorInput[i] = iorNS[i];
+  ns->Register(iorInput,name);
   return 1;
 }
 
index dcc3b46ea6ad7b3187cdbbfc568299c0c3796abb..615a8a48b614b1d8b7e208a3c56553ad69b4e708 100644 (file)
@@ -19,8 +19,6 @@
 #
 
 # script used by "salome test" command
-./echoSrv &
-pidecho=$!
 
 BASEDIR=`pwd`
 TESTDIR=$(mktemp -d --suffix=.yacstest)
@@ -34,12 +32,11 @@ LIBDIR=$BASEDIR/../lib
 cp xmlrun.sh $TESTDIR
 cp *.py $TESTDIR
 ln -s $BASEDIR/samples $TESTDIR/samples
+cp $BASEDIR/echoSrv $TESTDIR
 cd $TESTDIR
 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR $BASEDIR/TestYacsLoader
 ret=$?
 cd $BASEDIR
 echo "exec status TestYacsLoader " $ret
 
-kill -9 $pidecho
-
 exit $ret
index 7d7e15a9b70f3d4deef659c1e338b4275dc97bdb..b1092982d6d2fce01e4f36190e4a9f0d41a306f1 100644 (file)
@@ -41,6 +41,7 @@ IF(NOT WIN32)
     testResume.py
     testSave.py
     testSaveLoadRun.py
+    testYacsLoaderSwig.py
     optim_plugin.py
     testValidationChecks.py
     testProgress.py
@@ -51,8 +52,6 @@ IF(NOT WIN32)
    )
   INSTALL(PROGRAMS ${LOCAL_TEST_FILES}
         DESTINATION ${LOCAL_TEST_DIR})
-  INSTALL(PROGRAMS runUnitTest.sh
-        DESTINATION ${LOCAL_TEST_DIR})
   INSTALL(FILES CTestTestfileInstall.cmake
         DESTINATION ${LOCAL_TEST_DIR}
         RENAME CTestTestfile.cmake)
index fad6c31a84049e43b5bad9c5f4428f865b94bb5f..fbb046d97984098d49fca3399e6c0ca82b7c8312 100644 (file)
 
 IF(NOT WIN32)
   SET(TEST_NAME ${COMPONENT_NAME}_YacsLoaderTest_swig)
-  ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} ./runUnitTest.sh)
+  ADD_TEST(${TEST_NAME} testYacsLoaderSwig.py)
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
-                                     LABELS "${COMPONENT_NAME}"
+                                    LABELS "${COMPONENT_NAME}"
+                                    ENVIRONMENT "SALOME_EMB_SERVANT=1"
                       )
 
   SET(TEST_NAME ${COMPONENT_NAME}_StdAloneYacsLoaderTest1)
diff --git a/src/yacsloader_swig/Test/runUnitTest.sh b/src/yacsloader_swig/Test/runUnitTest.sh
deleted file mode 100755 (executable)
index 3029264..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-# Copyright (C) 2006-2023  CEA, EDF
-#
-# 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
-#
-
-# script used by "salome test" command
-../yacsloader/echoSrv &
-pidecho=$!
-
-# give some time for echoSrv to start...
-sleep 3
-
-export TESTCOMPONENT_ROOT_DIR=`pwd`/../runtime
-
-#python3 -m unittest discover
-MODULES_TO_TEST="testEdit testExec testLoader testSave "
-
-python3 -m unittest $MODULES_TO_TEST
-ret=$?
-echo "exec status salome_test_driver " $ret
-
-kill -9 $pidecho
-
-exit $ret
index eac472abb76af52319cae0ea11d0b8b4f5308427..6ed7c4ad8c75dcdbd9381480a4d9a642b628bba1 100755 (executable)
@@ -185,11 +185,20 @@ class TestExec(unittest.TestCase):
     pass
 
 if __name__ == '__main__':
-  dir_test = tempfile.mkdtemp(suffix=".yacstest")
-  file_test = os.path.join(dir_test,"UnitTestsResult")
-  with open(file_test, 'a') as f:
-        f.write("  --- TEST src/yacsloader: testExec.py\n")
-        suite = unittest.makeSuite(TestExec)
-        result = unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
-
+  import salome
+  import NamingService
+  import os
+  import subprocess
+  salome.salome_init()
+  ior = NamingService.NamingService.IOROfNS()
+  p = subprocess.Popen(["../yacsloader/echoSrv",ior])
+  import time
+  time.sleep(3)
+  with tempfile.TemporaryDirectory(suffix=".yacstest") as dir_test:
+    file_test = os.path.join(dir_test,"UnitTestsResult")
+    with open(file_test, 'a') as f:
+      f.write("  --- TEST src/yacsloader: testExec.py\n")
+      suite = unittest.makeSuite(TestExec)
+      result = unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+  p.terminate()
   sys.exit(not result.wasSuccessful())
index 5b8fc61e2e0548568b869b0ba067a069f81ffe66..be94a30589c5cbd6f5ee9b4c8df24da5fc2fd7c2 100755 (executable)
@@ -84,12 +84,22 @@ class TestLoader(unittest.TestCase):
     pass
 
 if __name__ == '__main__':
+  import salome
+  import NamingService
+  import os
+  import subprocess
+  salome.salome_init()
+  ior = NamingService.NamingService.IOROfNS()
+  p = subprocess.Popen(["../yacsloader/echoSrv",ior])
+  import time
+  time.sleep(3)
   import tempfile
   import os
-  dir_test = tempfile.mkdtemp(suffix=".yacstest")
-  file_test = os.path.join(dir_test,"UnitTestsResult")
-  with open(file_test, 'a') as f:
-      f.write("  --- TEST src/yacsloader: testLoader.py\n")
-      suite = unittest.makeSuite(TestLoader)
-      result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+  with tempfile.TemporaryDirectory(suffix=".yacstest") as dir_test:
+    file_test = os.path.join(dir_test,"UnitTestsResult")
+    with open(file_test, 'a') as f:
+        f.write("  --- TEST src/yacsloader: testLoader.py\n")
+        suite = unittest.makeSuite(TestLoader)
+        result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+  p.terminate()
   sys.exit(not result.wasSuccessful())
index 9e5facf71eacd7e3e678eb8966f0baca4b665d1f..61fe5e6dd4182ed2c2036ae8f0d9e27ca745da1b 100755 (executable)
@@ -56,6 +56,7 @@ class TestSave(unittest.TestCase):
         l = loader.YACSLoader()
         e = pilot.ExecutorSwig()
         for schema in schemaList:
+            print(schema)
             fileOrig = "samples/" + schema + ".xml"
             saveSchema1 = os.path.join(self.workdir, "schema1_" + schema)
             dumpSchema1 = os.path.join(self.workdir, "dump1_" + schema)
@@ -99,10 +100,20 @@ class TestSave(unittest.TestCase):
             pass
 
 if __name__ == '__main__':
-  dir_test = tempfile.mkdtemp(suffix=".yacstest")
-  file_test = os.path.join(dir_test,"UnitTestsResult")
-  with open(file_test, 'a') as f:
+  import salome
+  import NamingService
+  import os
+  import subprocess
+  salome.salome_init()
+  ior = NamingService.NamingService.IOROfNS()
+  p = subprocess.Popen(["../yacsloader/echoSrv",ior])
+  import time
+  time.sleep(3)
+  with tempfile.TemporaryDirectory(suffix=".yacstest") as dir_test:
+    file_test = os.path.join(dir_test,"UnitTestsResult")
+    with open(file_test, 'a') as f:
       f.write("  --- TEST src/yacsloader: testSave.py\n")
       suite = unittest.makeSuite(TestSave)
       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+  p.terminate()
   sys.exit(not result.wasSuccessful())
diff --git a/src/yacsloader_swig/Test/testYacsLoaderSwig.py b/src/yacsloader_swig/Test/testYacsLoaderSwig.py
new file mode 100644 (file)
index 0000000..cb26789
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# 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 salome
+import NamingService
+import os
+import sys
+import subprocess
+salome.salome_init()
+ior = NamingService.NamingService.IOROfNS()
+
+from testEdit import TestEdit
+from testExec import TestExec
+from testLoader import TestLoader
+from testSave import TestSave
+
+p = subprocess.Popen(["../yacsloader/echoSrv",ior])
+import time
+time.sleep(3)
+import tempfile
+import unittest
+zezeResult = True
+zeResultStr = []
+with tempfile.TemporaryDirectory(suffix=".yacstest") as dir_test:
+  file_test = os.path.join(dir_test,"UnitTestsResult")
+  with open(file_test, 'a') as f:
+      f.write("  --- TEST src/yacsloader: testLoader.py\n")
+      for zeTest in [TestEdit,TestExec,TestLoader,TestSave]:
+        suite = unittest.makeSuite(zeTest)
+        result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
+        zeResult = result.wasSuccessful()
+        zezeResult = zeResult and zezeResult
+        zeResultStr.append( "Result for {} is {}".format(str(zeTest),zeResult) )
+p.terminate()
+zeResultStr.append("So at the end the result is {}".format(zezeResult))
+print("\n".join(zeResultStr))
+returnCode = int( not zezeResult )
+print("Return code is {}".format( returnCode ))
+sys.exit(returnCode)