blob: 0090d217de506519b0c4744e9b0af26e53cd9a4c [file] [log] [blame]
Alexey Marinichev592b8622010-02-04 15:20:10 -08001// 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 Marinichevf50ecb12010-06-14 15:21:41 -07005#include <gflags/gflags.h>
Alexey Marinichev592b8622010-02-04 15:20:10 -08006#include <stdio.h>
7#include <stdlib.h>
Ilja H. Friedel8faad302011-04-26 14:40:49 -07008#include <string.h>
9#include <ctime>
Alexey Marinichev592b8622010-02-04 15:20:10 -080010
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -080011#include "base/logging.h"
Ben Chan3bbf4f12014-04-09 13:38:20 -070012#include "base/strings/string_split.h"
13#include "base/strings/string_util.h"
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -080014
Simon Que7f840e72012-12-19 12:05:42 -080015#include "glinterface.h"
Alexey Marinichev592b8622010-02-04 15:20:10 -080016#include "main.h"
Alexey Marinichev3c199732010-03-11 10:33:35 -080017#include "utils.h"
Alexey Marinichev592b8622010-02-04 15:20:10 -080018
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070019#include "all_tests.h"
20#include "testbase.h"
21
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070022using std::string;
23using std::vector;
Alexey Marinichev592b8622010-02-04 15:20:10 -080024
Ilja Friedel3907fd12014-04-15 14:29:43 -070025DEFINE_int32(duration, 0,
26 "Run all tests again and again in a loop for at least this many seconds.");
27DEFINE_string(tests, "",
28 "Colon-separated list of tests to run; all tests if omitted.");
Daniel Kurtz980f3242013-04-01 00:45:50 +080029DEFINE_string(blacklist, "", "colon-separated list of tests to disable");
Ilja Friedel3907fd12014-04-15 14:29:43 -070030DEFINE_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 Kurtz5419f182014-06-03 17:09:22 +080033DEFINE_bool(list, false, "List available tests");
Ilja Friedel3907fd12014-04-15 14:29:43 -070034
35GLint g_max_texture_size;
36bool g_hasty;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080037
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070038bool 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 Marinichev19b5a5d2010-02-18 11:37:26 -080050 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080051
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070052 return false;
53}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080054
Daniel Kurtz980f3242013-04-01 00:45:50 +080055bool 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. Friedel8faad302011-04-26 14:40:49 -070072void 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 Friedelc04bdd42013-01-30 18:55:49 -080081bool PassesSanityCheck(void) {
Ilja Friedel3907fd12014-04-15 14:29:43 -070082 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 Friedelc04bdd42013-01-30 18:55:49 -080086 printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n",
Ilja Friedel3907fd12014-04-15 14:29:43 -070087 size[0], size[1]);
Ilja Friedelc04bdd42013-01-30 18:55:49 -080088 return false;
89 }
Ilja Friedel3907fd12014-04-15 14:29:43 -070090 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 Friedelc04bdd42013-01-30 18:55:49 -080099 return true;
100}
101
Alexey Marinichev592b8622010-02-04 15:20:10 -0800102int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -0800103 SetBasePathFromArgv0(argv[0], "src");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700104 google::ParseCommandLineFlags(&argc, &argv, false);
Simon Que7f840e72012-12-19 12:05:42 -0800105
106 g_main_gl_interface.reset(GLInterface::Create());
107 if (!g_main_gl_interface->Init()) {
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700108 printf("# Error: Failed to initialize %s.\n", argv[0]);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800109 return 1;
110 }
111
Alexey Marinichev0f3605d2010-08-25 14:31:19 -0700112 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -0700113 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
Ilja Friedel1b180392013-03-12 17:09:06 -0700114 if (!PassesSanityCheck())
115 return 1;
Simon Que06860822012-12-18 13:17:56 -0800116 g_main_gl_interface->Cleanup();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -0700117
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700118 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 Marinichevf50ecb12010-06-14 15:21:41 -0700126
Ilja Friedel3907fd12014-04-15 14:29:43 -0700127 g_hasty = FLAGS_hasty;
Ilja Friedel977aadd2014-04-29 20:45:03 -0700128 if (!g_hasty)
129 g_initial_temperature = GetMachineTemperature();
130
Daniel Kurtz980f3242013-04-01 00:45:50 +0800131 vector<string> enabled_tests, disabled_tests;
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700132 base::SplitString(FLAGS_tests, ':', &enabled_tests);
Daniel Kurtz980f3242013-04-01 00:45:50 +0800133 base::SplitString(FLAGS_blacklist, ':', &disabled_tests);
Ilja Friedel3907fd12014-04-15 14:29:43 -0700134
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700135 glbench::TestBase* tests[] = {
Ilja Friedel3907fd12014-04-15 14:29:43 -0700136 // 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 Friedelb4efb4a2014-04-07 22:58:10 -0700140 glbench::GetSwapTest(),
Ilja Friedel6f72b2b2014-04-11 05:47:22 +0000141 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 Que3562e0a2012-12-28 12:01:12 -0800151 glbench::GetTextureReuseTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -0700152 glbench::GetTextureUpdateTest(),
Simon Quecd8cfe32012-12-27 10:37:45 -0800153 glbench::GetTextureUploadTest(),
Ilja Friedel3907fd12014-04-15 14:29:43 -0700154 glbench::GetFboFillRateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -0800155 };
156
Daniel Kurtz5419f182014-06-03 17:09:22 +0800157 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 Marinichevf50ecb12010-06-14 15:21:41 -0700163 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
164 do {
165 for (unsigned int i = 0; i < arraysize(tests); i++) {
Daniel Kurtz980f3242013-04-01 00:45:50 +0800166 if (!test_is_enabled(tests[i], enabled_tests) ||
167 test_is_disabled(tests[i], disabled_tests))
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700168 continue;
Simon Que06860822012-12-18 13:17:56 -0800169 if (!g_main_gl_interface->Init()) {
170 printf("Initialize failed\n");
Stuart Abercrombieddd7fae2012-06-04 11:55:24 -0700171 return 1;
172 }
Stuart Abercrombie7a3fa0b2012-07-30 17:47:40 -0700173 glbench::ClearBuffers();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700174 tests[i]->Run();
Simon Que06860822012-12-18 13:17:56 -0800175 g_main_gl_interface->Cleanup();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700176 }
177 } while (GetUTime() < done);
178
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700179 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700180 delete tests[i];
181 tests[i] = NULL;
182 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800183
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700184 printDateTime();
Ilja Friedel977aadd2014-04-29 20:45:03 -0700185 // Signal to harness that we finished normally.
186 printf("@TEST_END\n");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700187
Alexey Marinichev592b8622010-02-04 15:20:10 -0800188 return 0;
189}