summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author John Reck <jreck@google.com> 2015-10-06 22:00:55 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2015-10-06 22:00:55 +0000
commitbfcd5917d3cd3ab86d3f217b9c8521eb3cf8cb3f (patch)
treeaeaf6af93930b02dc8fd7bc3370256c44bb1a6da
parent5686addb76ae43f362297abd81e79d73624e68d0 (diff)
parentb7dd29ec266085cc7353b7bf8c8f74f9db9a167b (diff)
Merge "use get_opt for hwuitest"
-rw-r--r--libs/hwui/tests/how_to_run.txt14
-rw-r--r--libs/hwui/tests/main.cpp144
2 files changed, 122 insertions, 36 deletions
diff --git a/libs/hwui/tests/how_to_run.txt b/libs/hwui/tests/how_to_run.txt
index 85900eff2f78..b051768f3262 100644
--- a/libs/hwui/tests/how_to_run.txt
+++ b/libs/hwui/tests/how_to_run.txt
@@ -2,16 +2,4 @@ mmm -j8 frameworks/base/libs/hwui/ &&
adb push $OUT/data/local/tmp/hwuitest /data/local/tmp/hwuitest &&
adb shell /data/local/tmp/hwuitest
-
-Command arguments:
-hwuitest [testname]
-
-Default test is 'shadowgrid'
-
-List of tests:
-
-shadowgrid: creates a grid of rounded rects that cast shadows, high CPU & GPU load
-
-rectgrid: creates a grid of 1x1 rects
-
-oval: draws 1 oval
+Pass --help to get help
diff --git a/libs/hwui/tests/main.cpp b/libs/hwui/tests/main.cpp
index 0bbf08c76c90..f7945074316c 100644
--- a/libs/hwui/tests/main.cpp
+++ b/libs/hwui/tests/main.cpp
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <unistd.h>
+#include <getopt.h>
+#include <vector>
using namespace android;
using namespace android::uirenderer;
@@ -364,34 +366,130 @@ std::map<const char*, testProc, cstr_cmp> gTestMap {
{"partialinval", TreeContentAnimation::run<PartialInvalTest> },
};
-int main(int argc, char* argv[]) {
- const char* testName = argc > 1 ? argv[1] : "shadowgrid";
- testProc proc = gTestMap[testName];
- if(!proc) {
- printf("Error: couldn't find test %s\n", testName);
- return 1;
+static int gFrameCount = 150;
+static int gRepeatCount = 1;
+static std::vector<testProc> gRunTests;
+
+static void printHelp() {
+ printf("\
+USAGE: hwuitest [OPTIONS] <TESTNAME>\n\
+\n\
+OPTIONS:\n\
+ -c, --count=NUM NUM loops a test should run (example, number of frames)\n\
+ -r, --runs=NUM Repeat the test(s) NUM times\n\
+ -h, --help Display this help\n\
+ --list List all tests\n\
+\n");
+}
+
+static void listTests() {
+ printf("Tests: \n");
+ for (auto&& test : gTestMap) {
+ printf("%-20s <TODO DESCRIPTION>\n", test.first);
}
- int loopCount = 1;
- if (argc > 2) {
- loopCount = atoi(argv[2]);
- if (!loopCount) {
- printf("Invalid loop count!\n");
- return 1;
+}
+
+static const struct option LONG_OPTIONS[] = {
+ { "frames", required_argument, nullptr, 'f' },
+ { "repeat", required_argument, nullptr, 'r' },
+ { "help", no_argument, nullptr, 'h' },
+ { "list", no_argument, nullptr, 'l' },
+ { 0, 0, 0, 0 }
+};
+
+static const char* SHORT_OPTIONS = "c:r:h";
+
+void parseOptions(int argc, char* argv[]) {
+ int c;
+ // temporary variable
+ int count;
+ bool error = false;
+ opterr = 0;
+
+ while (true) {
+
+ /* getopt_long stores the option index here. */
+ int option_index = 0;
+
+ c = getopt_long(argc, argv, SHORT_OPTIONS, LONG_OPTIONS, &option_index);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 0:
+ // Option set a flag, don't need to do anything
+ // (although none of the current LONG_OPTIONS do this...)
+ break;
+
+ case 'l':
+ listTests();
+ exit(EXIT_SUCCESS);
+ break;
+
+ case 'c':
+ count = atoi(optarg);
+ if (!count) {
+ fprintf(stderr, "Invalid frames argument '%s'\n", optarg);
+ error = true;
+ } else {
+ gFrameCount = (count > 0 ? count : INT_MAX);
+ }
+ break;
+
+ case 'r':
+ count = atoi(optarg);
+ if (!count) {
+ fprintf(stderr, "Invalid repeat argument '%s'\n", optarg);
+ error = true;
+ } else {
+ gRepeatCount = (count > 0 ? count : INT_MAX);
+ }
+ break;
+
+ case 'h':
+ printHelp();
+ exit(EXIT_SUCCESS);
+ break;
+
+ case '?':
+ fprintf(stderr, "Unrecognized option '%s'\n", argv[optind - 1]);
+ // fall-through
+ default:
+ error = true;
+ break;
}
}
- int frameCount = 150;
- if (argc > 3) {
- frameCount = atoi(argv[3]);
- if (frameCount < 1) {
- printf("Invalid frame count!\n");
- return 1;
- }
+
+ if (error) {
+ fprintf(stderr, "Try 'hwuitest --help' for more information.\n");
+ exit(EXIT_FAILURE);
}
- if (loopCount < 0) {
- loopCount = INT_MAX;
+
+ /* Print any remaining command line arguments (not options). */
+ if (optind < argc) {
+ do {
+ const char* test = argv[optind++];
+ auto pos = gTestMap.find(test);
+ if (pos == gTestMap.end()) {
+ fprintf(stderr, "Unknown test '%s'\n", test);
+ exit(EXIT_FAILURE);
+ } else {
+ gRunTests.push_back(pos->second);
+ }
+ } while (optind < argc);
+ } else {
+ gRunTests.push_back(gTestMap["shadowgrid"]);
}
- for (int i = 0; i < loopCount; i++) {
- proc(frameCount);
+}
+
+int main(int argc, char* argv[]) {
+ parseOptions(argc, argv);
+
+ for (int i = 0; i < gRepeatCount; i++) {
+ for (auto&& test : gRunTests) {
+ test(gFrameCount);
+ }
}
printf("Success!\n");
return 0;