Salome HOME
Merge branch 'V9_9_BR'
[modules/kernel.git] / src / SALOMETraceCollector / Test / SALOMETraceCollectorTest.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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 #include "Basics_Utils.hxx"
32
33 #ifdef WIN32
34 #define setenv Kernel_Utils::setenv
35 #endif 
36
37 // ============================================================================
38 /*!
39  *
40  */
41 // ============================================================================
42
43 void 
44 SALOMETraceCollectorTest::setUp()
45 {
46 }
47
48 // ============================================================================
49 /*!
50  *
51  */
52 // ============================================================================
53
54 void 
55 SALOMETraceCollectorTest::tearDown()
56 {
57 }
58
59 #define NUM_THREADS  20
60 #define NUM_MESSAGES 20
61 void *PrintHello(void *threadid);
62
63 // ============================================================================
64 /*!
65  *  open a trace on a CORBA, multithread writing on file, close
66  */
67 // ============================================================================
68
69 void 
70 SALOMETraceCollectorTest::testLoadBufferPoolCORBA()
71 {
72   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
73   std::string s = "with_logger";
74   CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
75
76   // --- NUM_THREADS thread creation for trace generation.
77
78   pthread_t threads[NUM_THREADS];
79   int rc, t;
80   for(t=0;t<NUM_THREADS;t++)
81     {
82       MESSAGE("Creating thread " << t);
83       rc = pthread_create(&threads[t], NULL, PrintHello, &t) ;
84       CPPUNIT_ASSERT( !rc);
85     }
86
87   // --- wait for end of each thread producing trace.
88
89   for(t=0;t<NUM_THREADS;t++)
90     {
91       pthread_join(threads[t], NULL);
92       MESSAGE("--------------------- end of PrintHello thread " << t);
93     }
94   MESSAGE(" ---- end of PrintHello threads ---- ");
95
96   CPPUNIT_ASSERT(bp1);
97   bp1->deleteInstance(bp1);
98 }
99
100 // ============================================================================
101 /*!
102  * NUM_THREAD are created with function PrintHello,
103  * which produces NUM_MESSAGES traces.
104  */
105 // ============================================================================
106
107 void *PrintHello(void *threadid)
108 {
109   SALOME_UNUSED(threadid); // unused in release mode
110 #if defined(_DEBUG_) || defined(_DEBUG)
111   long id_thread = (long)threadid;
112       for (int i=0; i<NUM_MESSAGES;i++) 
113         MESSAGE("Hello World! This is a trace test : " << id_thread 
114                 << " - iter " << i);
115 #endif
116   pthread_exit(NULL);
117 #ifdef WIN32
118   return NULL;
119 #endif
120 }