From 47d5aa53ba6810fc3544991223aba61e035cdc31 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 29 Oct 2021 16:03:59 +0300 Subject: [PATCH] Debug --- .../SALOMETraceCollector.cxx | 11 +++-------- .../SALOMETraceCollector.hxx | 4 ---- .../Test/SALOMETraceCollectorTest.cxx | 2 +- .../Test/TestSALOMETraceCollector.cxx | 2 +- .../Test/TestSALOMETraceCollector.py | 2 ++ .../TraceCollector_WaitForServerReadiness.cxx | 5 +++-- .../TraceCollector_WaitForServerReadiness.hxx | 3 +-- src/Utils/OpUtil.cxx | 9 ++++++++- src/Utils/Utils_ORB_INIT.cxx | 17 +++++++++++++---- 9 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/SALOMETraceCollector/SALOMETraceCollector.cxx b/src/SALOMETraceCollector/SALOMETraceCollector.cxx index 8d69598dc..716cd5985 100644 --- a/src/SALOMETraceCollector/SALOMETraceCollector.cxx +++ b/src/SALOMETraceCollector/SALOMETraceCollector.cxx @@ -33,17 +33,12 @@ #include #include -#include "OpUtil.hxx" #include "Utils_SALOME_Exception.hxx" #include "SALOMETraceCollector.hxx" #include "TraceCollector_WaitForServerReadiness.hxx" #include #include CORBA_CLIENT_HEADER(Logger) -// Class attributes initialisation, for class method SALOMETraceCollector::run - -CORBA::ORB_ptr SALOMETraceCollector::_orb = 0; - // ============================================================================ /*! * This class is for use with CORBA, inside SALOME. @@ -62,7 +57,6 @@ BaseTraceCollector* SALOMETraceCollector::instance() if (_singleton == 0) // another thread may have got { // the lock after the first test BaseTraceCollector* myInstance = new SALOMETraceCollector(); - _orb = KERNEL::GetRefToORB(); sem_init(&_sem,0,0); // to wait until run thread is initialized pthread_t traceThread; @@ -100,7 +94,7 @@ void* SALOMETraceCollector::run(void* /*bid*/) SALOME_Logger::Logger_var m_pInterfaceLogger; CORBA::Object_var obj; - obj = TraceCollector_WaitForServerReadiness(_orb,"Logger"); + obj = TraceCollector_WaitForServerReadiness("Logger"); if (!CORBA::is_nil(obj)) m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj); if (CORBA::is_nil(m_pInterfaceLogger)) @@ -129,7 +123,8 @@ void* SALOMETraceCollector::run(void* /*bid*/) } myTraceBuffer->retrieve(myTrace); - if (!CORBA::is_nil(_orb)) + //if (!CORBA::is_nil(_orb)) + if (true) { if (myTrace.traceType == ABORT_MESS) { diff --git a/src/SALOMETraceCollector/SALOMETraceCollector.hxx b/src/SALOMETraceCollector/SALOMETraceCollector.hxx index e557dc0eb..6bb8e73e4 100644 --- a/src/SALOMETraceCollector/SALOMETraceCollector.hxx +++ b/src/SALOMETraceCollector/SALOMETraceCollector.hxx @@ -29,7 +29,6 @@ #define _SALOMETRACECOLLECTOR_HXX_ #include -#include #include "BaseTraceCollector.hxx" #include "LocalTraceBufferPool.hxx" @@ -56,9 +55,6 @@ class SALOMETRACECOLLECTOR_EXPORT SALOMETraceCollector: protected: SALOMETraceCollector(); - - private: - static CORBA::ORB_ptr _orb; }; #endif diff --git a/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx b/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx index 317bd27b0..15abff957 100644 --- a/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx +++ b/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx @@ -69,6 +69,7 @@ void *PrintHello(void *threadid); void SALOMETraceCollectorTest::testLoadBufferPoolCORBA() { + LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); std::string s = "with_logger"; CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite @@ -92,7 +93,6 @@ SALOMETraceCollectorTest::testLoadBufferPoolCORBA() } MESSAGE(" ---- end of PrintHello threads ---- "); - LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); CPPUNIT_ASSERT(bp1); bp1->deleteInstance(bp1); } diff --git a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx index 5461210c2..a40e77358 100644 --- a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx +++ b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx @@ -27,7 +27,7 @@ // --- Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +//CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); // --- generic Main program from Basic/Test diff --git a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py index 5f7010972..a6cdbf1cd 100644 --- a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py +++ b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.py @@ -47,6 +47,8 @@ clt.waitLogger("Logger") # execute Unit Test command = ['./TestSALOMETraceCollector'] +valgrind = ['valgrind', '--leak-check=full'] +#command = valgrind+command ret = subprocess.call(command) # kill Test process diff --git a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx index 040b13db7..3320bdfb9 100644 --- a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx +++ b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx @@ -26,6 +26,7 @@ // $Header$ // #include "TraceCollector_WaitForServerReadiness.hxx" +#include "OpUtil.hxx" #include #include @@ -47,8 +48,7 @@ */ // ============================================================================ -CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb, - std::string serverName) +CORBA::Object_ptr TraceCollector_WaitForServerReadiness(const std::string& serverName) { long TIMESleep = 500000000; int NumberOfTries = 40; @@ -60,6 +60,7 @@ CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb, ts_rem.tv_nsec=0; ts_rem.tv_sec=0; + CORBA::ORB_var orb = KERNEL::GetRefToORB(); CORBA::Object_var obj; try diff --git a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx index c62302bbd..177686bf0 100644 --- a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx +++ b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx @@ -32,7 +32,6 @@ #include #include -CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr theOrb, - std::string serverName); +CORBA::Object_ptr TraceCollector_WaitForServerReadiness(const std::string& serverName); #endif diff --git a/src/Utils/OpUtil.cxx b/src/Utils/OpUtil.cxx index d5fc76152..f421ea5fb 100644 --- a/src/Utils/OpUtil.cxx +++ b/src/Utils/OpUtil.cxx @@ -25,16 +25,23 @@ // Module : SALOME // #include "OpUtil.hxx" +#include #if !defined(SALOME_LIGHT) #include "Utils_SINGLETON.hxx" #include "Utils_ORB_INIT.hxx" +namespace +{ + std::recursive_mutex mutex; //!< mutex to protect access to static data +} + UTILS_EXPORT CORBA::ORB_var KERNEL::GetRefToORB() { + std::lock_guard g(mutex); ORB_INIT &init = *SINGLETON_::Instance(); - CORBA::ORB_var &orb = init(); + CORBA::ORB_var orb = init(); return orb; } diff --git a/src/Utils/Utils_ORB_INIT.cxx b/src/Utils/Utils_ORB_INIT.cxx index ab39d9375..73bf981d8 100644 --- a/src/Utils/Utils_ORB_INIT.cxx +++ b/src/Utils/Utils_ORB_INIT.cxx @@ -35,11 +35,16 @@ # include # include +#include ORB_INIT::ORB_INIT( void ): _orb( CORBA::ORB::_nil() ) { } +namespace +{ + std::recursive_mutex mutex; //!< mutex to protect access to static data +} ORB_INIT::~ORB_INIT() { @@ -76,6 +81,7 @@ void ORB_INIT::explicit_destroy() CORBA::ORB_var &ORB_INIT::operator() () { try { + std::lock_guard g(mutex); if ( CORBA::is_nil( _orb ) ) { try @@ -86,13 +92,16 @@ CORBA::ORB_var &ORB_INIT::operator() () } std::vector args = GetArgcArgv(); int argc = args.size(); - char** argv = new char*[argc]; - for (int i = 0; i < argc; ++i) - argv[i] = strdup(args.at(i).c_str()); + char** argv = argc > 0 ? new char*[argc] : nullptr; + for (int i = 0; i < argc; ++i) { + argv[i] = new char[args.at(i).size()+1]; + strcpy(argv[i], args.at(i).c_str()); + } _orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ; for (int i = 0; i < argc; ++i) delete[] argv[i]; - delete[] argv; + if (argc>0) + delete[] argv; } catch( const CORBA::Exception & ) { -- 2.39.2