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 | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 24 | DEFINE_bool(get_board_id, false, "return the board id for checksums"); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 25 | |
Alexey Marinichev | 0f9aa1b | 2010-03-30 14:38:16 -0700 | [diff] [blame] | 26 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 27 | bool test_is_enabled(glbench::TestBase* test, |
| 28 | const vector<string>& enabled_tests) { |
| 29 | if (enabled_tests.empty()) |
| 30 | return true; |
| 31 | |
| 32 | const char* test_name = test->Name(); |
| 33 | for (vector<string>::const_iterator i = enabled_tests.begin(); |
| 34 | i != enabled_tests.end(); ++i) { |
| 35 | // This is not very precise, but will do until there's a need for something |
| 36 | // more flexible. |
| 37 | if (strstr(test_name, i->c_str())) |
| 38 | return true; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 39 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 40 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 41 | return false; |
| 42 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 43 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 44 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame] | 45 | SetBasePathFromArgv0(argv[0], "src"); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 46 | google::ParseCommandLineFlags(&argc, &argv, true); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 47 | if (!Init()) { |
| 48 | printf("# Failed to initialize.\n"); |
| 49 | return 1; |
| 50 | } |
| 51 | |
Alexey Marinichev | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 52 | if (FLAGS_get_board_id) { |
| 53 | InitContext(); |
| 54 | printf("%s / %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDERER)); |
| 55 | DestroyContext(); |
| 56 | return 0; |
| 57 | } |
| 58 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 59 | vector<string> enabled_tests; |
| 60 | SplitString(FLAGS_tests, ':', &enabled_tests); |
| 61 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 62 | glbench::TestBase* tests[] = { |
| 63 | glbench::GetSwapTest(), |
| 64 | glbench::GetClearTest(), |
| 65 | glbench::GetFillRateTest(), |
Alexey Marinichev | b70421f | 2010-07-12 18:11:27 -0700 | [diff] [blame^] | 66 | #if defined(USE_OPENGL) |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 67 | glbench::GetWindowManagerCompositingTest(false), |
| 68 | glbench::GetWindowManagerCompositingTest(true), |
Alexey Marinichev | b70421f | 2010-07-12 18:11:27 -0700 | [diff] [blame^] | 69 | glbench::GetTriangleSetupTest(), |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 70 | #endif |
Alexey Marinichev | be37f88 | 2010-06-07 20:35:07 -0700 | [diff] [blame] | 71 | glbench::GetYuvToRgbTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 72 | glbench::GetReadPixelTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 73 | glbench::GetAttributeFetchShaderTest(), |
| 74 | glbench::GetVaryingsAndDdxyShaderTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 75 | glbench::GetTextureUpdateTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 78 | uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration; |
| 79 | do { |
| 80 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
| 81 | if (!test_is_enabled(tests[i], enabled_tests)) |
| 82 | continue; |
| 83 | InitContext(); |
| 84 | tests[i]->Run(); |
| 85 | DestroyContext(); |
| 86 | } |
| 87 | } while (GetUTime() < done); |
| 88 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 89 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 90 | delete tests[i]; |
| 91 | tests[i] = NULL; |
| 92 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 93 | |
| 94 | return 0; |
| 95 | } |