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" |
Ben Chan | 3bbf4f1 | 2014-04-09 13:38:20 -0700 | [diff] [blame] | 12 | #include "base/strings/string_split.h" |
| 13 | #include "base/strings/string_util.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 | 3907fd1 | 2014-04-15 14:29:43 -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 | 3907fd1 | 2014-04-15 14:29:43 -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."); |
Daniel Kurtz | 5419f18 | 2014-06-03 17:09:22 +0800 | [diff] [blame^] | 33 | DEFINE_bool(list, false, "List available tests"); |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 34 | |
| 35 | GLint g_max_texture_size; |
| 36 | bool g_hasty; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 37 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 38 | bool test_is_enabled(glbench::TestBase* test, |
| 39 | const vector<string>& enabled_tests) { |
| 40 | if (enabled_tests.empty()) |
| 41 | return true; |
| 42 | |
| 43 | const char* test_name = test->Name(); |
| 44 | for (vector<string>::const_iterator i = enabled_tests.begin(); |
| 45 | i != enabled_tests.end(); ++i) { |
| 46 | // This is not very precise, but will do until there's a need for something |
| 47 | // more flexible. |
| 48 | if (strstr(test_name, i->c_str())) |
| 49 | return true; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 50 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 51 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 52 | return false; |
| 53 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 54 | |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 55 | bool test_is_disabled(glbench::TestBase* test, |
| 56 | const vector<string>& disabled_tests) { |
| 57 | if (disabled_tests.empty()) |
| 58 | return false; |
| 59 | |
| 60 | const char* test_name = test->Name(); |
| 61 | for (vector<string>::const_iterator i = disabled_tests.begin(); |
| 62 | i != disabled_tests.end(); ++i) { |
| 63 | // This is not very precise, but will do until there's a need for something |
| 64 | // more flexible. |
| 65 | if (strstr(test_name, i->c_str())) |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 72 | void printDateTime(void) { |
| 73 | struct tm *ttime; |
| 74 | time_t tm = time(0); |
| 75 | char time_string[64]; |
| 76 | ttime = localtime(&tm); |
| 77 | strftime(time_string, 63, "%c",ttime); |
| 78 | printf("# DateTime: %s\n", time_string); |
| 79 | } |
| 80 | |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 81 | bool PassesSanityCheck(void) { |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 82 | GLint size[2]; |
| 83 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, size); |
| 84 | printf("# MAX_VIEWPORT_DIMS=(%d, %d)\n", size[0], size[1]); |
| 85 | if (size[0] < g_width || size[1] < g_height) { |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 86 | printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n", |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 87 | size[0], size[1]); |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 88 | return false; |
| 89 | } |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 90 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, size); |
| 91 | printf("# GL_MAX_TEXTURE_SIZE=%d\n", size[0]); |
| 92 | if (size[0] < g_width || size[0] < g_height) { |
| 93 | printf("# Error: MAX_TEXTURE_SIZE=%d is too small.\n", |
| 94 | size[0]); |
| 95 | return false; |
| 96 | } |
| 97 | g_max_texture_size = size[0]; |
| 98 | |
Ilja Friedel | c04bdd4 | 2013-01-30 18:55:49 -0800 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 102 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame] | 103 | SetBasePathFromArgv0(argv[0], "src"); |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 104 | google::ParseCommandLineFlags(&argc, &argv, false); |
Simon Que | 7f840e7 | 2012-12-19 12:05:42 -0800 | [diff] [blame] | 105 | |
| 106 | g_main_gl_interface.reset(GLInterface::Create()); |
| 107 | if (!g_main_gl_interface->Init()) { |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 108 | printf("# Error: Failed to initialize %s.\n", argv[0]); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 109 | return 1; |
| 110 | } |
| 111 | |
Alexey Marinichev | 0f3605d | 2010-08-25 14:31:19 -0700 | [diff] [blame] | 112 | printf("# board_id: %s - %s\n", |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 113 | glGetString(GL_VENDOR), glGetString(GL_RENDERER)); |
Ilja Friedel | 1b18039 | 2013-03-12 17:09:06 -0700 | [diff] [blame] | 114 | if (!PassesSanityCheck()) |
| 115 | return 1; |
Simon Que | 0686082 | 2012-12-18 13:17:56 -0800 | [diff] [blame] | 116 | g_main_gl_interface->Cleanup(); |
Alexey Marinichev | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 117 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 118 | if (argc == 1) { |
| 119 | printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]); |
| 120 | } else { |
| 121 | printf("# Running: "); |
| 122 | for (int i = 0; i < argc; i++) printf("%s ", argv[i]); |
| 123 | printf("\n"); |
| 124 | } |
| 125 | printDateTime(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 126 | |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 127 | g_hasty = FLAGS_hasty; |
Ilja Friedel | 977aadd | 2014-04-29 20:45:03 -0700 | [diff] [blame] | 128 | if (!g_hasty) |
| 129 | g_initial_temperature = GetMachineTemperature(); |
| 130 | |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 131 | vector<string> enabled_tests, disabled_tests; |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 132 | base::SplitString(FLAGS_tests, ':', &enabled_tests); |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 133 | base::SplitString(FLAGS_blacklist, ':', &disabled_tests); |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 134 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 135 | glbench::TestBase* tests[] = { |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 136 | // Please add new tests at the end of this list as tests are known to bleed |
| 137 | // state. Reordering them or inserting a new test may cause a change in the |
| 138 | // output images and MD5 causing graphics_GLBench failures. |
| 139 | // TODO(ihf): Fix this. |
Ilja Friedel | b4efb4a | 2014-04-07 22:58:10 -0700 | [diff] [blame] | 140 | glbench::GetSwapTest(), |
Ilja Friedel | 6f72b2b | 2014-04-11 05:47:22 +0000 | [diff] [blame] | 141 | glbench::GetContextTest(), |
| 142 | glbench::GetClearTest(), |
| 143 | glbench::GetFillRateTest(), |
| 144 | glbench::GetWindowManagerCompositingTest(false), |
| 145 | glbench::GetWindowManagerCompositingTest(true), |
| 146 | glbench::GetTriangleSetupTest(), |
| 147 | glbench::GetYuvToRgbTest(), |
| 148 | glbench::GetReadPixelTest(), |
| 149 | glbench::GetAttributeFetchShaderTest(), |
| 150 | glbench::GetVaryingsAndDdxyShaderTest(), |
Simon Que | 3562e0a | 2012-12-28 12:01:12 -0800 | [diff] [blame] | 151 | glbench::GetTextureReuseTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 152 | glbench::GetTextureUpdateTest(), |
Simon Que | cd8cfe3 | 2012-12-27 10:37:45 -0800 | [diff] [blame] | 153 | glbench::GetTextureUploadTest(), |
Ilja Friedel | 3907fd1 | 2014-04-15 14:29:43 -0700 | [diff] [blame] | 154 | glbench::GetFboFillRateTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
Daniel Kurtz | 5419f18 | 2014-06-03 17:09:22 +0800 | [diff] [blame^] | 157 | if (FLAGS_list) { |
| 158 | for (unsigned int i = 0; i < arraysize(tests); i++) |
| 159 | printf("%s\n", tests[i]->Name()); |
| 160 | return 0; |
| 161 | } |
| 162 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 163 | uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration; |
| 164 | do { |
| 165 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Daniel Kurtz | 980f324 | 2013-04-01 00:45:50 +0800 | [diff] [blame] | 166 | if (!test_is_enabled(tests[i], enabled_tests) || |
| 167 | test_is_disabled(tests[i], disabled_tests)) |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 168 | continue; |
Simon Que | 0686082 | 2012-12-18 13:17:56 -0800 | [diff] [blame] | 169 | if (!g_main_gl_interface->Init()) { |
| 170 | printf("Initialize failed\n"); |
Stuart Abercrombie | ddd7fae | 2012-06-04 11:55:24 -0700 | [diff] [blame] | 171 | return 1; |
| 172 | } |
Stuart Abercrombie | 7a3fa0b | 2012-07-30 17:47:40 -0700 | [diff] [blame] | 173 | glbench::ClearBuffers(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 174 | tests[i]->Run(); |
Simon Que | 0686082 | 2012-12-18 13:17:56 -0800 | [diff] [blame] | 175 | g_main_gl_interface->Cleanup(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 176 | } |
| 177 | } while (GetUTime() < done); |
| 178 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 179 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 180 | delete tests[i]; |
| 181 | tests[i] = NULL; |
| 182 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 183 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 184 | printDateTime(); |
Ilja Friedel | 977aadd | 2014-04-29 20:45:03 -0700 | [diff] [blame] | 185 | // Signal to harness that we finished normally. |
| 186 | printf("@TEST_END\n"); |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 187 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 188 | return 0; |
| 189 | } |