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