Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParallelTestGridConversion.C
Go to the documentation of this file.
1 #include "ComLine.H"
11 #include "TestGridConversion.H"
12 #include "COMM.H"
13 
14 
15 namespace GridConversion{
16 
20  typedef IRAD::Comm::CommunicatorObject CommType;
50  int ParallelTest(int argc,char *argv[])
51  {
52 
53  // The default verbosity is 0
54  int verblevel = 0;
55 
56  // This sets everything up with MPI
57  GridConversion::CommType communicator(&argc,&argv);
58  int rank = communicator.Rank();
59  int nproc = communicator.Size();
60  bool do_stdout = !rank;
61 
62  // This line creates the GridConversion::TestComLine object and passes in
63  // the command line arguments as a (const char **).
64  TestComLine comline((const char **)(argv));
65  // The call to comline.Initialize() reads the command line arguments
66  // from the array passed in the previous line.
67  comline.Initialize();
68 
69 
70  // The ProcessOptions() call does detailed examination of the command
71  // line arguments to check for user errors or other problems. This call
72  // will return non-zero if there were errors on the commandline.
73  int clerr = comline.ProcessOptions();
74  // Check if the user just wanted to get the help and exit
75  if(!comline.GetOption("help").empty()){
76  // Print out the "long usage" (i.e. help) message to stdout
77  if(do_stdout){
78  std::cout << comline.LongUsage() << std::endl;
79  if(verblevel > 1)
80  std::cout << "GridConversion::ParallelTest: Exiting test function (success)"
81  << std::endl;
82  }
83  communicator.SetExit(1);
84  }
85  if(communicator.Check())
86  return(0);
87  if(clerr){
88  if(do_stdout){
89  std::cout << comline.ErrorReport() << std::endl
90  << std::endl << comline.ShortUsage() << std::endl;
91  if(verblevel > 2)
92  std::cout << "GridConversion::ParallelTest: Exiting test function (fail)" << std::endl;
93  }
94  communicator.SetExit(1);
95  }
96  if(communicator.Check())
97  return(1);
98 
99  // These outstreams allow the output to file to be set up and separated
100  // from the stdout.
101  std::ofstream Ouf;
102  std::ostream *Out = NULL;
103  if(do_stdout)
104  Out = &std::cout;
105 
106  // The next few lines populate some strings based on the
107  // users input from the commandline.
108  std::string OutFileName(comline.GetOption("output"));
109  std::string TestName(comline.GetOption("name"));
110  std::string ListName(comline.GetOption("list"));
111  std::string sverb(comline.GetOption("verblevel"));
112 
113  // The following block parses and sets the verbosity level
114  if(!sverb.empty()){
115  verblevel = 1;
116  if(sverb != ".true."){
117  std::istringstream Istr(sverb);
118  Istr >> verblevel;
119  if(verblevel < 0)
120  verblevel = 1;
121  }
122  }
123 
124  // This block sets up the output file if the user specified one
125  if(!OutFileName.empty()){
126  if(Out){
127  Ouf.open(OutFileName.c_str());
128  if(!Ouf){
129  std::cout << "GridConversion::ParallelTest> Error: Could not open output file, "
130  << OutFileName << " for test output. Exiting (fail)." << std::endl;
131  communicator.SetExit(1);
132  }
133  Out = &Ouf;
134  }
135  if(communicator.Check())
136  return(1);
137  }
138 
139  if(verblevel > 1 && Out)
140  *Out << "GridConversion::ParallelTest: Entering test function" << std::endl;
141 
142  // Make an instance of the GridConversion testing object, GridConversion::ParallelTestingObject
143  GridConversion::ParallelTestingObject<GridConversion::CommType,GridConversion::TestResults> test(communicator);
144  // Make an instance of the GridConversion results object, GridConversion::TestResults
146 
147  // If the user specified a name, then run only the named test
148  if(!TestName.empty()){
149  // This call runs a test by name
150  test.RunTest(TestName,results);
151  }
152  // Otherwise, if the user specified a list, then read the list and
153  // run the listed tests.
154  else if(!ListName.empty()){
155  std::ifstream ListInf;
156  ListInf.open(ListName.c_str());
157  if(!ListInf){
158  if(Out)
159  *Out << "GridConversion::ParallelTest> Error: Could not open list of tests in file "
160  << ListName << ". Exiting (fail)." << std::endl;
161  communicator.SetExit(1);
162  }
163  if(communicator.Check())
164  return(1);
165  std::string testname;
166  while(std::getline(ListInf,testname))
167  test.RunTest(testname,results);
168  ListInf.close();
169  }
170  else {
171  // This call runs all the tests for the GridConversion namespace.
172  test.Process(results);
173  }
174  if(Out)
175  *Out << results << std::endl;
176 
177  if(Out && Ouf)
178  Ouf.close();
179 
180  if((verblevel > 1) && Out)
181  *Out << "GridConversion::ParallelTest: Exiting test function (success)" << std::endl;
182 
183  return(0);
184  }
185 };
186 
187 int main(int argc,char *argv[])
188 {
189  return(GridConversion::ParallelTest(argc,argv));
190 }
ComLineObject for GridConversion testing command-line interface.
Testing utilities for GridConversion.
IRAD::Util::TestResults TestResults
Project-specific test results type.
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
void test(void)
Definition: flotsam.C:99
int main(int argc, char *argv[])
Definition: blastest.C:94
int ParallelTest(int argc, char *argv[])
Drives the GridConversion::TestObject.
static int rank
Definition: advectest.C:66