test/test_main.cpp

Go to the documentation of this file.
00001 #include <getopt.h>
00002 
00003 #include "Epetra_ConfigDefs.h"
00004 #ifdef HAVE_MPI
00005 #include <mpi.h>
00006 #include "Epetra_MpiComm.h"
00007 #else
00008 #include "Epetra_SerialComm.h"
00009 #endif
00010 
00011 // include after mpi.h
00012 #include "pbe.h"
00013 
00014 #include "Epetra_CrsMatrix.h"
00015 #include "Epetra_Map.h"
00016 #include "EpetraExt_MatrixMatrix.h"
00017 
00018 #include <tut.h>
00019 #include <tut_reporter.h>
00020 
00021 #include "rlog/rlog.h"
00022 #include "rlog/RLogChannel.h"
00023 #include "rlog/StdioNode.h"
00024 #include "myrlog.h"
00025 
00026 using namespace std;
00027 using namespace rlog;
00028 
00029 namespace tut {
00030     test_runner_singleton runner;
00031     
00032     Epetra_Comm* comm_world;
00033 
00034     Epetra_Comm& get_comm_world() {
00035         return *comm_world;
00036     }
00037 }
00038 
00039 void usage(const Epetra_Comm& comm) {
00040     if (comm.MyPID() == 0) {
00041         cerr << "test_runner" << endl;
00042         cerr << endl;
00043         cerr << "Driver for femaXX unit tests." << endl;
00044         cerr << endl;
00045         cerr << "Usage: test_runner [options] [test_group]" << endl;
00046         cerr << endl;
00047         cerr << "options:" << endl;
00048         cerr << "  -l   Print list of unit test groups and exit." << endl;
00049         cerr << endl;
00050         cerr << "If test_group is omitted, all tests are started." << endl;
00051         cerr << endl;
00052     }
00053 }
00054 
00058 void finalize() {
00059 #ifdef HAVE_MPI
00060     MPI_Finalize();
00061 #endif
00062 }
00063 
00064 
00068 int main(int argc, char *argv[]) {
00069 #ifdef HAVE_MPI
00070     MPI_Init(&argc, &argv);
00071     atexit(finalize);
00072     tut::comm_world = new Epetra_MpiComm(MPI_COMM_WORLD);
00073 #else
00074     tut::comm_world = new Epetra_SerialComm;
00075 #endif
00076 
00077     // extern char *optarg;
00078     extern int optind, optopt;
00079     int dflg = 0;
00080     int lflg = 0;
00081     int errflg = 0;
00082     int c;
00083     while ((c = getopt(argc, argv, "dl")) != -1) {
00084         switch(c) {
00085         case 'd':
00086             dflg++;
00087             break;
00088         case 'l':
00089             lflg ++;
00090             break;
00091         case '?':
00092             fprintf(stderr, "Unrecognized option: -%c\n", optopt);
00093             errflg++;
00094         }
00095     }
00096     if (errflg) {
00097         usage(tut::get_comm_world());
00098         exit(1);
00099     }
00100     if (lflg) {
00101         tut::groupnames group_names = tut::runner.get().list_groups();
00102         for (tut::groupnames::iterator it = group_names.begin(); it != group_names.end(); ++ it) {
00103             cerr << *it << endl;
00104         }
00105         exit(0);
00106     }
00107 
00108     StdioNode stdLog;
00109 
00110     GetGlobalChannel("warning/all", Log_Warning);
00111     GetGlobalChannel("error/all", Log_Error);
00112     GetGlobalChannel("info/all", Log_Info);
00113     GetGlobalChannel("debug/all", Log_Debug);
00114 
00115     stdLog.subscribeTo(GetGlobalChannel("error"));
00116     stdLog.subscribeTo(GetGlobalChannel("warning"));
00117     if (dflg) {
00118         if (tut::comm_world->MyPID() == 0)
00119             stdLog.subscribeTo(GetGlobalChannel("info"));
00120         stdLog.subscribeTo(GetGlobalChannel("debug"));
00121     }
00122 
00123     const int nof_pbe_timers = 150;
00124     pbe_init("femaxx", nof_pbe_timers, 0, NULL);
00125 
00126     tut::reporter visi;
00127     if (tut::comm_world->MyPID() == 0)
00128         tut::runner.get().set_callback(&visi);
00129 
00130     if (optind < argc) {
00131         tut::runner.get().run_tests(argv[optind]);
00132     } else {
00133         // run all tests in all groups
00134         tut::runner.get().run_tests();
00135     }
00136 
00137     delete tut::comm_world;
00138     return 0;
00139 }

Generated on Fri Oct 26 13:35:13 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7