2 #include "SALOMELocalTraceTest.hxx"
8 #include "LocalTraceBufferPool.hxx"
14 // ============================================================================
18 // ============================================================================
21 SALOMELocalTraceTest::setUp()
25 // ============================================================================
29 // ============================================================================
32 SALOMELocalTraceTest::tearDown()
36 #define TRACEFILE "/tmp/traceUnitTest.log"
38 // ============================================================================
40 * Open and close a trace on a file, test singleton
42 // ============================================================================
45 SALOMELocalTraceTest::testSingletonBufferPool()
48 char *theFileName = TRACEFILE;
52 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
55 traceFile.open(theFileName, ios::out | ios::app);
56 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
59 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
61 LocalTraceBufferPool* bp2 = LocalTraceBufferPool::instance();
62 CPPUNIT_ASSERT(bp1 == bp2);
63 bp1->deleteInstance(bp1);
69 #define NUM_MESSAGES 5
70 void *PrintHello(void *threadid);
72 // ============================================================================
74 * open a trace on console, multithread writing on file, close
76 // ============================================================================
79 SALOMELocalTraceTest::testLoadBufferPoolLocal()
82 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
84 // --- numThread thread creation for trace generation.
86 pthread_t threads[numThread];
88 for(t=0;t<numThread;t++)
90 MESSAGE("Creating thread " << t);
91 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t) ;
95 // --- wait for end of each thread producing trace.
97 for(t=0;t<numThread;t++)
99 int ret = pthread_join(threads[t], NULL);
100 MESSAGE("--------------------- end of PrintHello thread " << t);
102 MESSAGE(" ---- end of PrintHello threads ---- ");
104 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
106 bp1->deleteInstance(bp1);
109 // ============================================================================
111 * open a trace on a file, multithread writing on file, close
113 // ============================================================================
116 SALOMELocalTraceTest::testLoadBufferPoolFile()
118 char *theFileName = TRACEFILE;
123 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
126 traceFile.open(theFileName, ios::out | ios::trunc);
127 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
130 // --- NUM_THREADS thread creation for trace generation.
132 pthread_t threads[NUM_THREADS];
134 for(t=0;t<NUM_THREADS;t++)
136 MESSAGE("Creating thread " << t);
137 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t) ;
138 CPPUNIT_ASSERT( !rc);
141 // --- wait for end of each thread producing trace.
143 for(t=0;t<NUM_THREADS;t++)
145 int ret = pthread_join(threads[t], NULL);
146 MESSAGE("--------------------- end of PrintHello thread " << t);
148 MESSAGE(" ---- end of PrintHello threads ---- ");
150 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
152 bp1->deleteInstance(bp1);
155 // ============================================================================
157 * NUM_THREAD are created with function PrintHello,
158 * which produces NUM_MESSAGES traces.
160 // ============================================================================
162 void *PrintHello(void *threadid)
164 int id_thread = (int)threadid;
165 for (int i=0; i<NUM_MESSAGES;i++)
166 MESSAGE("Hello World! This is a trace test : " << id_thread