Back to index

salome-kernel  6.5.0
SALOMETraceCollectorTest.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SALOMETraceCollectorTest.hxx"
00024 
00025 #include <iostream>
00026 #include <fstream>
00027 #include <string>
00028 #include <cstdlib>
00029 #include "LocalTraceBufferPool.hxx"
00030 #include "utilities.h"
00031 
00032 
00033 // ============================================================================
00037 // ============================================================================
00038 
00039 void 
00040 SALOMETraceCollectorTest::setUp()
00041 {
00042 }
00043 
00044 // ============================================================================
00048 // ============================================================================
00049 
00050 void 
00051 SALOMETraceCollectorTest::tearDown()
00052 {
00053 }
00054 
00055 #define NUM_THREADS  20
00056 #define NUM_MESSAGES 20
00057 void *PrintHello(void *threadid);
00058 
00059 // ============================================================================
00063 // ============================================================================
00064 
00065 void 
00066 SALOMETraceCollectorTest::testLoadBufferPoolCORBA()
00067 {
00068   std::string s = "with_logger";
00069   CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
00070 
00071   // --- NUM_THREADS thread creation for trace generation.
00072 
00073   pthread_t threads[NUM_THREADS];
00074   int rc, t;
00075   for(t=0;t<NUM_THREADS;t++)
00076     {
00077       MESSAGE("Creating thread " << t);
00078       rc = pthread_create(&threads[t], NULL, PrintHello, &t) ;
00079       CPPUNIT_ASSERT( !rc);
00080     }
00081 
00082   // --- wait for end of each thread producing trace.
00083 
00084   for(t=0;t<NUM_THREADS;t++)
00085     {
00086       pthread_join(threads[t], NULL);
00087       MESSAGE("--------------------- end of PrintHello thread " << t);
00088     }
00089   MESSAGE(" ---- end of PrintHello threads ---- ");
00090 
00091   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
00092   CPPUNIT_ASSERT(bp1);
00093   bp1->deleteInstance(bp1);
00094 }
00095 
00096 // ============================================================================
00101 // ============================================================================
00102 
00103 void *PrintHello(void *threadid)
00104 {
00105 #if defined(_DEBUG_) || defined(_DEBUG)
00106   long id_thread = (long)threadid;
00107       for (int i=0; i<NUM_MESSAGES;i++) 
00108         MESSAGE("Hello World! This is a trace test : " << id_thread 
00109                 << " - iter " << i);
00110 #endif
00111   pthread_exit(NULL);
00112 }