Back to index

salome-med  6.5.0
MPIMainTest.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef _MPIMAINTEST_HXX_
00021 #define _MPIMAINTEST_HXX_
00022 
00023 #include <cppunit/CompilerOutputter.h>
00024 #include <cppunit/TestResult.h>
00025 #include <cppunit/TestResultCollector.h>
00026 #include <cppunit/TextTestProgressListener.h>
00027 #include <cppunit/BriefTestProgressListener.h>
00028 #include <cppunit/extensions/TestFactoryRegistry.h>
00029 #include <cppunit/TestRunner.h>
00030 #include <stdexcept>
00031 
00032 #include <mpi.h>
00033 
00034 #include <iostream>
00035 #include <fstream>
00036 #ifndef WIN32
00037 #include <fpu_control.h>
00038 #endif
00039 
00040 // ============================================================================
00045 // ============================================================================
00046 
00047 int main(int argc, char* argv[])
00048 {
00049 #ifndef WIN32
00050   fpu_control_t cw = _FPU_DEFAULT & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM);
00051   _FPU_SETCW(cw);
00052 #endif
00053   MPI_Init(&argc,&argv);
00054   int rank;
00055   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00056   
00057   // --- Create the event manager and test controller
00058   CPPUNIT_NS::TestResult controller;
00059 
00060   // ---  Add a listener that colllects test result
00061   CPPUNIT_NS::TestResultCollector result;
00062   controller.addListener( &result );        
00063 
00064   // ---  Add a listener that print dots as test run.
00065 #ifdef WIN32
00066   CPPUNIT_NS::TextTestProgressListener progress;
00067 #else
00068   CPPUNIT_NS::BriefTestProgressListener progress;
00069 #endif
00070   controller.addListener( &progress );      
00071 
00072   // ---  Get the top level suite from the registry
00073 
00074   CPPUNIT_NS::Test *suite =
00075     CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
00076 
00077   // ---  Adds the test to the list of test to run
00078 
00079   CPPUNIT_NS::TestRunner runner;
00080   runner.addTest( suite );
00081   runner.run( controller);
00082 
00083   // ---  Print test in a compiler compatible format.
00084 
00085   std::ostringstream testFileName;
00086   testFileName<<"UnitTestsResult"<<rank;
00087   std::ofstream testFile;
00088   testFile.open(testFileName.str().c_str(), std::ios::out |  std::ios::trunc);
00089   //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
00090   CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
00091   outputter.write(); 
00092 
00093   // ---  Run the tests.
00094 
00095   bool wasSucessful = result.wasSuccessful();
00096   testFile.close();
00097 
00098   // ---  Return error code 1 if the one of test failed.
00099 
00100   MPI_Finalize();
00101   
00102   return wasSucessful ? 0 : 1;
00103 }
00104 
00105 #endif