| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <fcntl.h> | 5 #include <gflags/gflags.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | |
| 9 #include <sys/mman.h> | |
| 10 | 8 |
| 11 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" |
| 12 | 11 |
| 13 #include "main.h" | 12 #include "main.h" |
| 14 #include "utils.h" | 13 #include "utils.h" |
| 15 #include "yuv2rgb.h" | |
| 16 | 14 |
| 17 #include "all_tests.h" | 15 #include "all_tests.h" |
| 18 #include "testbase.h" | 16 #include "testbase.h" |
| 19 | 17 |
| 18 using std::string; |
| 19 using std::vector; |
| 20 | 20 |
| 21 const int enabled_tests_max = 8; | 21 DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds"); |
| 22 // TODO: fix enabled_tests. | 22 DEFINE_string(tests, "", "colon-separated list of tests to run; " |
| 23 const char *enabled_tests[enabled_tests_max+1] = {NULL}; | 23 "all tests if omitted"); |
| 24 int seconds_to_run = 0; | |
| 25 | 24 |
| 26 | 25 |
| 27 // TODO: use proper command line parsing library. | 26 bool test_is_enabled(glbench::TestBase* test, |
| 28 static void ParseArgs(int argc, char *argv[]) { | 27 const vector<string>& enabled_tests) { |
| 29 const char **enabled_tests_ptr = enabled_tests; | 28 if (enabled_tests.empty()) |
| 30 bool test_name_arg = false; | 29 return true; |
| 31 bool duration_arg = false; | 30 |
| 32 for (int i = 0; i < argc; i++) { | 31 const char* test_name = test->Name(); |
| 33 if (test_name_arg) { | 32 for (vector<string>::const_iterator i = enabled_tests.begin(); |
| 34 test_name_arg = false; | 33 i != enabled_tests.end(); ++i) { |
| 35 *enabled_tests_ptr++ = argv[i]; | 34 // This is not very precise, but will do until there's a need for something |
| 36 if (enabled_tests_ptr - enabled_tests >= enabled_tests_max) | 35 // more flexible. |
| 37 break; | 36 if (strstr(test_name, i->c_str())) |
| 38 } else if (duration_arg) { | 37 return true; |
| 39 duration_arg = false; | |
| 40 seconds_to_run = atoi(argv[i]); | |
| 41 } else if (strcmp("-t", argv[i]) == 0) { | |
| 42 test_name_arg = true; | |
| 43 } else if (strcmp("-d", argv[i]) == 0) { | |
| 44 duration_arg = true; | |
| 45 } | |
| 46 } | 38 } |
| 47 *enabled_tests_ptr++ = NULL; | 39 |
| 40 return false; |
| 48 } | 41 } |
| 49 | 42 |
| 50 | |
| 51 int main(int argc, char *argv[]) { | 43 int main(int argc, char *argv[]) { |
| 52 SetBasePathFromArgv0(argv[0], "src"); | 44 SetBasePathFromArgv0(argv[0], "src"); |
| 53 ParseArgs(argc, argv); | 45 google::ParseCommandLineFlags(&argc, &argv, true); |
| 54 if (!Init()) { | 46 if (!Init()) { |
| 55 printf("# Failed to initialize.\n"); | 47 printf("# Failed to initialize.\n"); |
| 56 return 1; | 48 return 1; |
| 57 } | 49 } |
| 58 | 50 |
| 51 vector<string> enabled_tests; |
| 52 SplitString(FLAGS_tests, ':', &enabled_tests); |
| 53 |
| 59 glbench::TestBase* tests[] = { | 54 glbench::TestBase* tests[] = { |
| 60 glbench::GetSwapTest(), | 55 glbench::GetSwapTest(), |
| 61 glbench::GetClearTest(), | 56 glbench::GetClearTest(), |
| 62 #if defined(USE_OPENGL) | 57 #if defined(USE_OPENGL) |
| 63 glbench::GetFillRateTest(), | 58 glbench::GetFillRateTest(), |
| 64 glbench::GetTriangleSetupTest(), | 59 glbench::GetTriangleSetupTest(), |
| 65 glbench::GetWindowManagerCompositingTest(false), | 60 glbench::GetWindowManagerCompositingTest(false), |
| 66 glbench::GetWindowManagerCompositingTest(true), | 61 glbench::GetWindowManagerCompositingTest(true), |
| 67 #endif | 62 #endif |
| 68 glbench::GetYuvToRgbTest(), | 63 glbench::GetYuvToRgbTest(), |
| 69 glbench::GetReadPixelTest(), | 64 glbench::GetReadPixelTest(), |
| 70 glbench::GetAttributeFetchShaderTest(), | 65 glbench::GetAttributeFetchShaderTest(), |
| 71 glbench::GetVaryingsAndDdxyShaderTest(), | 66 glbench::GetVaryingsAndDdxyShaderTest(), |
| 72 glbench::GetTextureUpdateTest(), | 67 glbench::GetTextureUpdateTest(), |
| 73 }; | 68 }; |
| 74 | 69 |
| 70 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration; |
| 71 do { |
| 72 for (unsigned int i = 0; i < arraysize(tests); i++) { |
| 73 if (!test_is_enabled(tests[i], enabled_tests)) |
| 74 continue; |
| 75 InitContext(); |
| 76 tests[i]->Run(); |
| 77 DestroyContext(); |
| 78 } |
| 79 } while (GetUTime() < done); |
| 80 |
| 75 for (unsigned int i = 0; i < arraysize(tests); i++) { | 81 for (unsigned int i = 0; i < arraysize(tests); i++) { |
| 76 InitContext(); | |
| 77 tests[i]->Run(); | |
| 78 DestroyContext(); | |
| 79 delete tests[i]; | 82 delete tests[i]; |
| 80 tests[i] = NULL; | 83 tests[i] = NULL; |
| 81 } | 84 } |
| 82 | 85 |
| 83 return 0; | 86 return 0; |
| 84 } | 87 } |
| OLD | NEW |