Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 5 | #include <gflags/gflags.h> |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 9 | #include "base/logging.h" |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 10 | #include "base/string_util.h" |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 11 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 12 | #include "main.h" |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 13 | #include "utils.h" |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 14 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 15 | #include "all_tests.h" |
| 16 | #include "testbase.h" |
| 17 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 18 | using std::string; |
| 19 | using std::vector; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 20 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 21 | DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds"); |
| 22 | DEFINE_string(tests, "", "colon-separated list of tests to run; " |
| 23 | "all tests if omitted"); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 24 | |
Alexey Marinichev | 0f9aa1b | 2010-03-30 14:38:16 -0700 | [diff] [blame] | 25 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 26 | bool test_is_enabled(glbench::TestBase* test, |
| 27 | const vector<string>& enabled_tests) { |
| 28 | if (enabled_tests.empty()) |
| 29 | return true; |
| 30 | |
| 31 | const char* test_name = test->Name(); |
| 32 | for (vector<string>::const_iterator i = enabled_tests.begin(); |
| 33 | i != enabled_tests.end(); ++i) { |
| 34 | // This is not very precise, but will do until there's a need for something |
| 35 | // more flexible. |
| 36 | if (strstr(test_name, i->c_str())) |
| 37 | return true; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 38 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 39 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 40 | return false; |
| 41 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 42 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 43 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame] | 44 | SetBasePathFromArgv0(argv[0], "src"); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 45 | google::ParseCommandLineFlags(&argc, &argv, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 46 | if (!Init()) { |
| 47 | printf("# Failed to initialize.\n"); |
| 48 | return 1; |
| 49 | } |
| 50 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 51 | vector<string> enabled_tests; |
| 52 | SplitString(FLAGS_tests, ':', &enabled_tests); |
| 53 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 54 | glbench::TestBase* tests[] = { |
| 55 | glbench::GetSwapTest(), |
| 56 | glbench::GetClearTest(), |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 57 | #if defined(USE_OPENGL) |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 58 | glbench::GetFillRateTest(), |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 59 | glbench::GetTriangleSetupTest(), |
| 60 | glbench::GetWindowManagerCompositingTest(false), |
| 61 | glbench::GetWindowManagerCompositingTest(true), |
| 62 | #endif |
Alexey Marinichev | be37f88 | 2010-06-07 20:35:07 -0700 | [diff] [blame] | 63 | glbench::GetYuvToRgbTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 64 | glbench::GetReadPixelTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 65 | glbench::GetAttributeFetchShaderTest(), |
| 66 | glbench::GetVaryingsAndDdxyShaderTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 67 | glbench::GetTextureUpdateTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 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 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 81 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 82 | delete tests[i]; |
| 83 | tests[i] = NULL; |
| 84 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 85 | |
| 86 | return 0; |
| 87 | } |