Back to index

salome-kernel  6.5.0
Public Member Functions | Private Member Functions
SALOMELocalTraceTest Class Reference

#include <SALOMELocalTraceTest.hxx>

List of all members.

Public Member Functions

void setUp ()
void tearDown ()
void testSingletonBufferPool ()
 Open and close a trace on a file, test singleton.
void testLoadBufferPoolLocal ()
 open a trace on console, multithread writing on file, close
void testLoadBufferPoolFile ()
 open a trace on a file, multithread writing on file, close

Private Member Functions

 CPPUNIT_TEST_SUITE (SALOMELocalTraceTest)
 CPPUNIT_TEST (testSingletonBufferPool)
 CPPUNIT_TEST (testLoadBufferPoolLocal)
 CPPUNIT_TEST (testLoadBufferPoolFile)
 CPPUNIT_TEST_SUITE_END ()

Detailed Description

Definition at line 28 of file SALOMELocalTraceTest.hxx.


Member Function Documentation

Definition at line 40 of file SALOMELocalTraceTest.cxx.

{
}

Definition at line 51 of file SALOMELocalTraceTest.cxx.

{
}

open a trace on a file, multithread writing on file, close

Definition at line 135 of file SALOMELocalTraceTest.cxx.

{
  const char *theFileName = TRACEFILE;

  std::string s = "file:";
  s += theFileName;
  //s = "local";
  CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite

  std::ofstream traceFile;
  traceFile.open(theFileName, std::ios::out | std::ios::trunc);
  CPPUNIT_ASSERT(traceFile); // file created empty, then closed
  traceFile.close();

  // --- NUM_THREADS thread creation for trace generation.

  pthread_t threads[NUM_THREADS];
  int rc, t;
  for(t=0;t<NUM_THREADS;t++)
    {
      MESSAGE("Creating thread " << t);
      rc = pthread_create(&threads[t], NULL, PrintHello, &t) ;
      CPPUNIT_ASSERT( !rc);
    }

  // --- wait for end of each thread producing trace.

  for(t=0;t<NUM_THREADS;t++)
    {
      pthread_join(threads[t], NULL);
      MESSAGE("--------------------- end of PrintHello thread " << t);
    }
  MESSAGE(" ---- end of PrintHello threads ---- ");

  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1);
  bp1->deleteInstance(bp1);
}

Here is the call graph for this function:

open a trace on console, multithread writing on file, close

Definition at line 98 of file SALOMELocalTraceTest.cxx.

{
  std::string s = "local";
  CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite

  // --- numThread thread creation for trace generation.
  int numThread = 2;
  pthread_t threads[numThread];
  int rc, t;
  for(t=0;t<numThread;t++)
    {
      MESSAGE("Creating thread " << t);
      rc = pthread_create(&threads[t], NULL, PrintHello, &t) ;
      CPPUNIT_ASSERT( !rc);
    }

  // --- wait for end of each thread producing trace.

  for(t=0;t<numThread;t++)
    {
      pthread_join(threads[t], NULL);
      MESSAGE("--------------------- end of PrintHello thread " << t);
    }
  MESSAGE(" ---- end of PrintHello threads ---- ");

  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1);
  bp1->deleteInstance(bp1);
}

Here is the call graph for this function:

Open and close a trace on a file, test singleton.

Definition at line 64 of file SALOMELocalTraceTest.cxx.

{
  // --- trace on file
  const char *theFileName = TRACEFILE;

  std::string s = "file:";
  s += theFileName;
  CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite

  std::ofstream traceFile;
  traceFile.open(theFileName, std::ios::out | std::ios::app);
  CPPUNIT_ASSERT(traceFile); // file created empty, then closed
  traceFile.close();

  LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1);
  LocalTraceBufferPool* bp2 = LocalTraceBufferPool::instance();
  CPPUNIT_ASSERT(bp1 == bp2);
  bp1->deleteInstance(bp1);
}

The documentation for this class was generated from the following files: