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 | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 51 | InitContext(); |
Alexey Marinichev | 0f3605d | 2010-08-25 14:31:19 -0700 | [diff] [blame] | 52 | printf("# board_id: %s - %s\n", |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 53 | glGetString(GL_VENDOR), glGetString(GL_RENDERER)); |
| 54 | DestroyContext(); |
Alexey Marinichev | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 55 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 56 | vector<string> enabled_tests; |
| 57 | SplitString(FLAGS_tests, ':', &enabled_tests); |
| 58 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 59 | glbench::TestBase* tests[] = { |
| 60 | glbench::GetSwapTest(), |
| 61 | glbench::GetClearTest(), |
| 62 | glbench::GetFillRateTest(), |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 63 | glbench::GetWindowManagerCompositingTest(false), |
| 64 | glbench::GetWindowManagerCompositingTest(true), |
Alexey Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame] | 65 | glbench::GetTriangleSetupTest(), |
Alexey Marinichev | be37f88 | 2010-06-07 20:35:07 -0700 | [diff] [blame] | 66 | glbench::GetYuvToRgbTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 67 | glbench::GetReadPixelTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 68 | glbench::GetAttributeFetchShaderTest(), |
| 69 | glbench::GetVaryingsAndDdxyShaderTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 70 | glbench::GetTextureUpdateTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 73 | uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration; |
| 74 | do { |
| 75 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
| 76 | if (!test_is_enabled(tests[i], enabled_tests)) |
| 77 | continue; |
| 78 | InitContext(); |
| 79 | tests[i]->Run(); |
| 80 | DestroyContext(); |
| 81 | } |
| 82 | } while (GetUTime() < done); |
| 83 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 84 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 85 | delete tests[i]; |
| 86 | tests[i] = NULL; |
| 87 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |