summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-perf/lib/TestCase.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2013-04-01 18:02:25 +0000
committerEnrico Granata <egranata@apple.com>2013-04-01 18:02:25 +0000
commit8fab9fdac2e7b5c5557af20b9a0c772410970496 (patch)
tree46020025302e12c98e190a74a2855c406c22eb3c /lldb/tools/lldb-perf/lib/TestCase.cpp
parent10230d4d6edc19d6cbe85e34cb4c26350deac79e (diff)
downloadbcm5719-llvm-8fab9fdac2e7b5c5557af20b9a0c772410970496.tar.gz
bcm5719-llvm-8fab9fdac2e7b5c5557af20b9a0c772410970496.zip
Integrating option parsing in TestCase for added convenience
To hook it up to individual test cases: - define GetLongOptions() in your test case class to return something other than NULL (hopefully an array of options :-) - implement ParseOption() to check for the short option char and do the right thing - return true at the end if you want more options to come your way or false if you don’t - make sure that your Setup() call takes int& and char**& so that optind post-processing can happen - and call TestCase::Setup from your setup llvm-svn: 178482
Diffstat (limited to 'lldb/tools/lldb-perf/lib/TestCase.cpp')
-rw-r--r--lldb/tools/lldb-perf/lib/TestCase.cpp70
1 files changed, 69 insertions, 1 deletions
diff --git a/lldb/tools/lldb-perf/lib/TestCase.cpp b/lldb/tools/lldb-perf/lib/TestCase.cpp
index 7a7c48ad637..c4b01998c23 100644
--- a/lldb/tools/lldb-perf/lib/TestCase.cpp
+++ b/lldb/tools/lldb-perf/lib/TestCase.cpp
@@ -28,9 +28,77 @@ TestCase::TestCase () :
m_listener = m_debugger.GetListener();
}
+static std::string
+GetShortOptionString (struct option *long_options)
+{
+ std::string option_string;
+ for (int i = 0; long_options[i].name != NULL; ++i)
+ {
+ if (long_options[i].flag == NULL)
+ {
+ option_string.push_back ((char) long_options[i].val);
+ switch (long_options[i].has_arg)
+ {
+ default:
+ case no_argument:
+ break;
+ case required_argument:
+ option_string.push_back (':');
+ break;
+ case optional_argument:
+ option_string.append (2, ':');
+ break;
+ }
+ }
+ }
+ return option_string;
+}
+
bool
-TestCase::Setup (int argc, const char** argv)
+TestCase::Setup (int& argc, const char**& argv)
{
+ bool done = false;
+
+ struct option* long_options = GetLongOptions();
+
+ if (long_options)
+ {
+ std::string short_option_string (GetShortOptionString(long_options));
+
+ #if __GLIBC__
+ optind = 0;
+ #else
+ optreset = 1;
+ optind = 1;
+ #endif
+ while (!done)
+ {
+ int long_options_index = -1;
+ const int short_option = ::getopt_long_only (argc,
+ const_cast<char **>(argv),
+ short_option_string.c_str(),
+ long_options,
+ &long_options_index);
+
+ switch (short_option)
+ {
+ case 0:
+ // Already handled
+ break;
+
+ case -1:
+ done = true;
+ break;
+
+ default:
+ done = !ParseOption(short_option, optarg);
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ }
+
return false;
}
OpenPOWER on IntegriCloud