diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-09-04 01:36:26 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-09-04 01:36:26 +0000 |
commit | 205525eef4c2c904b4ca1a19f98e8b6b5002404d (patch) | |
tree | 5cb0f3f2ab6c2d3c21e49d771ab7434f454957cb /infrastructure | |
parent | cdf951635090755796c1b3bb1a7d70811b7c6c80 (diff) |
Add support for all logging options in test executables.
Merged back changes from the test refactor branch to reduce diffs.
Diffstat (limited to 'infrastructure')
-rw-r--r-- | infrastructure/buildenv-testmain-template.cpp | 107 |
1 files changed, 18 insertions, 89 deletions
diff --git a/infrastructure/buildenv-testmain-template.cpp b/infrastructure/buildenv-testmain-template.cpp index 5baff684..e5392d66 100644 --- a/infrastructure/buildenv-testmain-template.cpp +++ b/infrastructure/buildenv-testmain-template.cpp @@ -244,13 +244,16 @@ int main(int argc, char * const * argv) { "execute-only", required_argument, NULL, 'e' }, { NULL, 0, NULL, 0 } }; - - int ch; - - while ((ch = getopt_long(argc, argv, "c:d:e:qs:t:vPTUVW:", longopts, NULL)) + + int c; + std::string options("c:d:e:s:"); + options += Logging::OptionParser::GetOptionString(); + Logging::OptionParser LogLevel; + + while ((c = getopt_long(argc, argv, options.c_str(), longopts, NULL)) != -1) { - switch(ch) + switch(c) { case 'c': { @@ -272,108 +275,34 @@ int main(int argc, char * const * argv) } break; - case 's': - { - bbstored_args += " "; - bbstored_args += optarg; - } - break; - case 'e': { run_only_named_tests.push_back(optarg); } break; - #ifndef WIN32 - case 'P': - { - Console::SetShowPID(true); - } - break; - #endif - - case 'q': - { - if(logLevel == Log::NOTHING) - { - BOX_FATAL("Too many '-q': " - "Cannot reduce logging " - "level any more"); - return 2; - } - logLevel--; - } - break; - - case 'v': - { - if(logLevel == Log::EVERYTHING) - { - BOX_FATAL("Too many '-v': " - "Cannot increase logging " - "level any more"); - return 2; - } - logLevel++; - } - break; - - case 'V': + case 's': { - logLevel = Log::EVERYTHING; + bbstored_args += " "; + bbstored_args += optarg; } break; - case 'W': + default: { - logLevel = Logging::GetNamedLevel(optarg); - if (logLevel == Log::INVALID) + int ret = LogLevel.ProcessOption(c); + if(ret != 0) { - BOX_FATAL("Invalid logging level: " << optarg); - return 2; + fprintf(stderr, "Unknown option code " + "'%c'\n", c); + exit(2); } } - break; - - case 't': - { - Logging::SetProgramName(optarg); - Console::SetShowTag(true); - } - break; - - case 'T': - { - Console::SetShowTime(true); - } - break; - - case 'U': - { - Console::SetShowTime(true); - Console::SetShowTimeMicros(true); - } - break; - - case '?': - { - fprintf(stderr, "Unknown option: '%c'\n", - optopt); - exit(2); - } - - default: - { - fprintf(stderr, "Unknown option code '%c'\n", - ch); - exit(2); - } } } Logging::FilterSyslog(Log::NOTHING); - Logging::FilterConsole((Log::Level)logLevel); + Logging::FilterConsole(LogLevel.GetCurrentLevel()); argc -= optind - 1; argv += optind - 1; |