Salome HOME
Copyrights update
[modules/kernel.git] / src / SALOMETraceCollector / Test / SALOMETraceCollectorTest.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20
21 #include "SALOMETraceCollectorTest.hxx"
22
23 #include <iostream>
24 #include <fstream>
25 #include <string>
26 #include <cstdlib>
27 #include "LocalTraceBufferPool.hxx"
28 #include "utilities.h"
29
30 using namespace std;
31
32 // ============================================================================
33 /*!
34  *
35  */
36 // ============================================================================
37
38 void 
39 SALOMETraceCollectorTest::setUp()
40 {
41 }
42
43 // ============================================================================
44 /*!
45  *
46  */
47 // ============================================================================
48
49 void 
50 SALOMETraceCollectorTest::tearDown()
51 {
52 }
53
54 #define NUM_THREADS  20
55 #define NUM_MESSAGES 20
56 void *PrintHello(void *threadid);
57
58 // ============================================================================
59 /*!
60  *  open a trace on a CORBA, multithread writing on file, close
61  */
62 // ============================================================================
63
64 void 
65 SALOMETraceCollectorTest::testLoadBufferPoolCORBA()
66 {
67   string s = "with_logger";
68   CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
69
70   // --- NUM_THREADS thread creation for trace generation.
71
72   pthread_t threads[NUM_THREADS];
73   int rc, t;
74   for(t=0;t<NUM_THREADS;t++)
75     {
76       MESSAGE("Creating thread " << t);
77       rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t) ;
78       CPPUNIT_ASSERT( !rc);
79     }
80
81   // --- wait for end of each thread producing trace.
82
83   for(t=0;t<NUM_THREADS;t++)
84     {
85       int ret = pthread_join(threads[t], NULL);
86       MESSAGE("--------------------- end of PrintHello thread " << t);
87     }
88   MESSAGE(" ---- end of PrintHello threads ---- ");
89
90   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
91   CPPUNIT_ASSERT(bp1);
92   bp1->deleteInstance(bp1);
93 }
94
95 // ============================================================================
96 /*!
97  * NUM_THREAD are created with function PrintHello,
98  * which produces NUM_MESSAGES traces.
99  */
100 // ============================================================================
101
102 void *PrintHello(void *threadid)
103 {
104   int id_thread = (int)threadid;
105   for (int i=0; i<NUM_MESSAGES;i++)
106     MESSAGE("Hello World! This is a trace test : " << id_thread 
107             << " - iter " << i);
108   pthread_exit(NULL);
109 }