1 #ifndef __TESTING_PROGRAM_H__ 9 #define __TESTING_PROGRAM_H__ 17 namespace ix {
namespace test {
37 AddOption(
'p',
"enable-profiling",1,
"level");
38 AddHelp(
'h',
"Print out long version of help and exit.");
39 AddHelp(
'l',
"List the available tests and exit.");
40 AddHelp(
'o',
"Set the output file to <filename>. (default = stdout)");
41 std::ostringstream Ostr;
42 Ostr <<
"Set the test list file to <filename>. (no default).\n\t\t" 43 <<
"The test list file should be a text file with one test\n\t\t" 46 AddHelp(
"name",
"Run test by name. (no default)");
48 Ostr <<
"Command-line interface for a general testing program.";
50 AddHelp(
'd',
"Set the debugging level for the program.(default=1)");
51 AddHelp(
'p',std::string(
"Enable profiling. Profiling level > 1 enables")+
52 std::string(
" profiling\n\t\tbarriers. (default=1)"));
53 AddHelp(
'v',std::string(
"Set the verbosity level for the program.")+
54 std::string(
" Anything\n\t\tlarger than 2 is debugging level.")+
55 std::string(
"\n\t\tExamples:\n\t\t\t-v (defaults to 1)\n\t\t\t")+
56 std::string(
"-v 0 (silence)\n\t\t\t--verblevel=2")+
57 std::string(
" (high verbosity)"));
66 template<
typename TestObjectType>
76 program(
int narg,
char **args) : ProgramType(narg,args){};
77 program(Global &inglob) : ProgramType(inglob){};
78 program(CommandLineType &incom) : ProgramType(incom){};
79 program(CommandLineType &incom,Global &inglob) :
80 ProgramType(incom,inglob){};
83 ErrOut(
"Failed to initialize.\n");
84 ErrOut(CommandLine().
ErrorReport()+std::string(
"\n"));
85 ErrOut(
"Use -h,--help for usage help.\n\n");
86 ErrOut(CommandLine().
ShortUsage()+std::string(
"\n"));
90 if(!CommandLine().
GetOption(
'h').empty()){
94 if(!CommandLine().
GetOption(
'l').empty()){
95 std::ostringstream outStream;
96 outStream <<
"Available tests are:" << std::endl;
97 testObject.ListTests(outStream);
98 StdOut(outStream.str());
109 std::string sverb(CommandLine().
GetOption(
'v'));
111 if(sverb ==
".true.")
114 std::istringstream Istr(sverb);
117 SetVerbLevel(verbLevel);
119 SetDebugStream(ErrStream());
120 SetDebugLevel(verbLevel - 1);
125 std::string sprof(CommandLine().
GetOption(
'p'));
127 if(sprof ==
".true.")
130 std::istringstream Istr(sprof);
141 std::string sdebug(CommandLine().
GetOption(
'd'));
143 if(sdebug ==
".true.")
146 std::istringstream Istr(sdebug);
150 SetDebugLevel(debugLevel);
153 outFileName = CommandLine().GetOption(
'o');
154 testName = CommandLine().GetOption(
'n');
155 listFileName = CommandLine().GetOption(
'l');
160 FunctionEntry(
"Run");
162 if(!testName.empty()){
164 FunctionEntry(testName);
165 testObject.RunTest(testName,testResult);
166 FunctionExit(testName);
167 }
else if(!listFileName.empty()){
168 std::ifstream listInf;
169 listInf.open(listFileName.c_str());
171 std::ostringstream errStream;
172 errStream <<
"Error: Could not open list of tests in file " 173 << listFileName <<
"." << std::endl;
174 ErrOut(errStream.str());
178 std::string testName;
179 while(std::getline(listInf,testName)){
180 FunctionEntry(testName);
181 testObject.RunTest(testName,testResult);
182 FunctionExit(testName);
188 FunctionEntry(
"AllTests");
189 testObject.Process(testResult);
190 FunctionExit(
"AllTests");
197 std::ostringstream outStream;
198 outStream << testResult << std::endl;
199 if(!outFileName.empty()){
201 Ouf.open(outFileName.c_str());
203 std::ostringstream errStream;
204 errStream <<
"Error: Could not open output file, " 205 << outFileName <<
" for test ouput." 207 ErrOut(errStream.str());
210 Ouf << outStream.str();
213 StdOut(outStream.str());
215 std::ostringstream profileStream;
216 Report(profileStream);
218 StdOut(profileStream.str(),1);
program_command_line CommandLineType
std::string ErrorReport()
Error reporting.
std::string GetOption(const char &s)
Get the value of an option.
program(CommandLineType &incom, Global &inglob)
Performance profiling object.
Defines MPI-specific parallel global and program classes.
ix::global::GlobalObj< std::string, std::string, ProfilerType > Global
Performance Profiling interface definition.
std::string _description
application description.
ix::profiler::ProfilerObj ProfilerType
program(CommandLineType &incom)
program(int narg, char **args)
TestObjectType::Results testResult
void AddOption(char s, const std::string &l, int=0)
User interface to describe simple option.
Base global object header.
TestObjectType testObject
virtual void Initialize()
virtual function for program specific Initialization.
program_command_line(const char *args[])
ComLineObject for testing program command-line interface.
ix::global::Program< Global, CommandLineType > ProgramType
TestObjectType & TestObject()
std::string LongUsage()
Generate long usage string.
ComLineObject()
Default constructor.
void AddHelp(char s, const std::string &help)
Specify usage for an option.
std::string ShortUsage()
Generate short usage string.