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> |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 8 | #include <string.h> |
| 9 | #include <ctime> |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 10 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 11 | #include "base/logging.h" |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 12 | #include "base/string_util.h" |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 13 | #include "base/string_split.h" |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 14 | |
Simon Que | 7f840e7 | 2012-12-19 12:05:42 -0800 | [diff] [blame] | 15 | #include "glinterface.h" |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 16 | #include "main.h" |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 17 | #include "utils.h" |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 18 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 19 | #include "all_tests.h" |
| 20 | #include "testbase.h" |
| 21 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 22 | using std::string; |
| 23 | using std::vector; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 24 | |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 25 | DEFINE_int32(duration, 0, |
| 26 | "Run all tests again and again in a loop for at least this many seconds."); |
| 27 | DEFINE_string(tests, "", |
| 28 | "Colon-separated list of tests to run; all tests if omitted."); |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 29 | DEFINE_string(blacklist, "", "colon-separated list of tests to disable"); |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 30 | DEFINE_bool(hasty, false, |
| 31 | "Run a smaller set of tests with less accurate results. " |
| 32 | "Useful for running in BVT or debugging a failure."); |
| 33 | |
| 34 | GLint g_max_texture_size; |
| 35 | bool g_hasty; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 36 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 37 | bool test_is_enabled(glbench::TestBase* test, |
| 38 | const vector<string>& enabled_tests) { |
| 39 | if (enabled_tests.empty()) |
| 40 | return true; |
| 41 | |
| 42 | const char* test_name = test->Name(); |
| 43 | for (vector<string>::const_iterator i = enabled_tests.begin(); |
| 44 | i != enabled_tests.end(); ++i) { |
| 45 | // This is not very precise, but will do until there's a need for something |
| 46 | // more flexible. |
| 47 | if (strstr(test_name, i->c_str())) |
| 48 | return true; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 49 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 50 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 51 | return false; |
| 52 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 53 | |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 54 | bool test_is_disabled(glbench::TestBase* test, |
| 55 | const vector<string>& disabled_tests) { |
| 56 | if (disabled_tests.empty()) |
| 57 | return false; |
| 58 | |
| 59 | const char* test_name = test->Name(); |
| 60 | for (vector<string>::const_iterator i = disabled_tests.begin(); |
| 61 | i != disabled_tests.end(); ++i) { |
| 62 | // This is not very precise, but will do until there's a need for something |
| 63 | // more flexible. |
| 64 | if (strstr(test_name, i->c_str())) |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | return false; |
| 69 | } |
| 70 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 71 | void printDateTime(void) { |
| 72 | struct tm *ttime; |
| 73 | time_t tm = time(0); |
| 74 | char time_string[64]; |
| 75 | ttime = localtime(&tm); |
| 76 | strftime(time_string, 63, "%c",ttime); |
| 77 | printf("# DateTime: %s\n", time_string); |
| 78 | } |
| 79 | |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 80 | bool PassesSanityCheck(void) { |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 81 | GLint size[2]; |
| 82 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, size); |
| 83 | printf("# MAX_VIEWPORT_DIMS=(%d, %d)\n", size[0], size[1]); |
| 84 | if (size[0] < g_width || size[1] < g_height) { |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 85 | printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n", |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 86 | size[0], size[1]); |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 87 | return false; |
| 88 | } |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 89 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, size); |
| 90 | printf("# GL_MAX_TEXTURE_SIZE=%d\n", size[0]); |
| 91 | if (size[0] < g_width || size[0] < g_height) { |
| 92 | printf("# Error: MAX_TEXTURE_SIZE=%d is too small.\n", |
| 93 | size[0]); |
| 94 | return false; |
| 95 | } |
| 96 | g_max_texture_size = size[0]; |
| 97 | |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 98 | return true; |
| 99 | } |
| 100 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 101 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame] | 102 | SetBasePathFromArgv0(argv[0], "src"); |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 103 | google::ParseCommandLineFlags(&argc, &argv, false); |
Simon Que | 7f840e7 | 2012-12-19 12:05:42 -0800 | [diff] [blame] | 104 | |
| 105 | g_main_gl_interface.reset(GLInterface::Create()); |
| 106 | if (!g_main_gl_interface->Init()) { |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 107 | printf("# Error: Failed to initialize %s.\n", argv[0]); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 108 | return 1; |
| 109 | } |
| 110 | |
Alexey Marinichev | 0f3605d | 2010-08-25 14:31:19 -0700 | [diff] [blame] | 111 | printf("# board_id: %s - %s\n", |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 112 | glGetString(GL_VENDOR), glGetString(GL_RENDERER)); |
Ilja Friedel | 1b18039 | 2013-03-12 17:09:06 -0700 | [diff] [blame] | 113 | if (!PassesSanityCheck()) |
| 114 | return 1; |
Simon Que | 0686082 | 2012-12-18 13:17:56 -0800 | [diff] [blame] | 115 | g_main_gl_interface->Cleanup(); |
Alexey Marinichev | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 116 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 117 | if (argc == 1) { |
| 118 | printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]); |
| 119 | } else { |
| 120 | printf("# Running: "); |
| 121 | for (int i = 0; i < argc; i++) printf("%s ", argv[i]); |
| 122 | printf("\n"); |
| 123 | } |
| 124 | printDateTime(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 125 | |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 126 | g_hasty = FLAGS_hasty; |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 127 | vector<string> enabled_tests, disabled_tests; |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 128 | base::SplitString(FLAGS_tests, ':', &enabled_tests); |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 129 | base::SplitString(FLAGS_blacklist, ':', &disabled_tests); |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 130 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 131 | glbench::TestBase* tests[] = { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 132 | glbench::GetAttributeFetchShaderTest(), |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 133 | glbench::GetClearTest(), |
| 134 | glbench::GetContextTest(), |
| 135 | glbench::GetFboFillRateTest(), |
| 136 | glbench::GetFillRateTest(), |
| 137 | glbench::GetReadPixelTest(), |
| 138 | glbench::GetSwapTest(), |
Simon Que | 3562e0a | 2012-12-28 12:01:12 -0800 | [diff] [blame] | 139 | glbench::GetTextureReuseTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 140 | glbench::GetTextureUpdateTest(), |
Simon Que | cd8cfe3 | 2012-12-27 10:37:45 -0800 | [diff] [blame] | 141 | glbench::GetTextureUploadTest(), |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 142 | glbench::GetTriangleSetupTest(), |
| 143 | glbench::GetVaryingsAndDdxyShaderTest(), |
| 144 | glbench::GetWindowManagerCompositingTest(false), |
| 145 | glbench::GetWindowManagerCompositingTest(true), |
| 146 | glbench::GetYuvToRgbTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 147 | }; |
| 148 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 149 | uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration; |
| 150 | do { |
| 151 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 152 | if (!test_is_enabled(tests[i], enabled_tests) || |
| 153 | test_is_disabled(tests[i], disabled_tests)) |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 154 | continue; |
Simon Que | 0686082 | 2012-12-18 13:17:56 -0800 | [diff] [blame] | 155 | if (!g_main_gl_interface->Init()) { |
| 156 | printf("Initialize failed\n"); |
Stuart Abercrombie | ddd7fae | 2012-06-04 11:55:24 -0700 | [diff] [blame] | 157 | return 1; |
| 158 | } |
Stuart Abercrombie | 7a3fa0b | 2012-07-30 17:47:40 -0700 | [diff] [blame] | 159 | glbench::ClearBuffers(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 160 | tests[i]->Run(); |
Simon Que | 0686082 | 2012-12-18 13:17:56 -0800 | [diff] [blame] | 161 | g_main_gl_interface->Cleanup(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 162 | } |
| 163 | } while (GetUTime() < done); |
| 164 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 165 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 166 | delete tests[i]; |
| 167 | tests[i] = NULL; |
| 168 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 169 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 170 | printDateTime(); |
| 171 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 172 | return 0; |
| 173 | } |