blob: 8e4514dfc361c01ce941f60408d1d41edee01301 [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. "
Daniel Kurtz8290ac92014-06-03 17:13:33 +080032 "Useful for running in BVT or debugging a failure. Implies notemp");
Daniel Kurtz5419f182014-06-03 17:09:22 +080033DEFINE_bool(list, false, "List available tests");
Daniel Kurtz8290ac92014-06-03 17:13:33 +080034DEFINE_bool(notemp, false, "Skip temperature checking");
Ilja Friedel3907fd12014-04-15 14:29:43 -070035
36GLint g_max_texture_size;
37bool g_hasty;
Daniel Kurtz8290ac92014-06-03 17:13:33 +080038bool g_notemp;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080039
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070040bool test_is_enabled(glbench::TestBase* test,
41 const vector<string>& enabled_tests) {
42 if (enabled_tests.empty())
43 return true;
44
45 const char* test_name = test->Name();
46 for (vector<string>::const_iterator i = enabled_tests.begin();
47 i != enabled_tests.end(); ++i) {
48 // This is not very precise, but will do until there's a need for something
49 // more flexible.
50 if (strstr(test_name, i->c_str()))
51 return true;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080052 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080053
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070054 return false;
55}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080056
Daniel Kurtz980f3242013-04-01 00:45:50 +080057bool test_is_disabled(glbench::TestBase* test,
58 const vector<string>& disabled_tests) {
59 if (disabled_tests.empty())
60 return false;
61
62 const char* test_name = test->Name();
63 for (vector<string>::const_iterator i = disabled_tests.begin();
64 i != disabled_tests.end(); ++i) {
65 // This is not very precise, but will do until there's a need for something
66 // more flexible.
67 if (strstr(test_name, i->c_str()))
68 return true;
69 }
70
71 return false;
72}
73
Ilja H. Friedel8faad302011-04-26 14:40:49 -070074void printDateTime(void) {
75 struct tm *ttime;
76 time_t tm = time(0);
77 char time_string[64];
78 ttime = localtime(&tm);
79 strftime(time_string, 63, "%c",ttime);
80 printf("# DateTime: %s\n", time_string);
81}
82
Ilja Friedelc04bdd42013-01-30 18:55:49 -080083bool PassesSanityCheck(void) {
Ilja Friedel3907fd12014-04-15 14:29:43 -070084 GLint size[2];
85 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, size);
86 printf("# MAX_VIEWPORT_DIMS=(%d, %d)\n", size[0], size[1]);
87 if (size[0] < g_width || size[1] < g_height) {
Ilja Friedelc04bdd42013-01-30 18:55:49 -080088 printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n",
Ilja Friedel3907fd12014-04-15 14:29:43 -070089 size[0], size[1]);
Ilja Friedelc04bdd42013-01-30 18:55:49 -080090 return false;
91 }
Ilja Friedel3907fd12014-04-15 14:29:43 -070092 glGetIntegerv(GL_MAX_TEXTURE_SIZE, size);
93 printf("# GL_MAX_TEXTURE_SIZE=%d\n", size[0]);
94 if (size[0] < g_width || size[0] < g_height) {
95 printf("# Error: MAX_TEXTURE_SIZE=%d is too small.\n",
96 size[0]);
97 return false;
98 }
99 g_max_texture_size = size[0];
100
Ilja Friedelc04bdd42013-01-30 18:55:49 -0800101 return true;
102}
103
Alexey Marinichev592b8622010-02-04 15:20:10 -0800104int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -0800105 SetBasePathFromArgv0(argv[0], "src");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700106 google::ParseCommandLineFlags(&argc, &argv, false);
Simon Que7f840e72012-12-19 12:05:42 -0800107
108 g_main_gl_interface.reset(GLInterface::Create());
109 if (!g_main_gl_interface->Init()) {
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700110 printf("# Error: Failed to initialize %s.\n", argv[0]);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800111 return 1;
112 }
113
Alexey Marinichev0f3605d2010-08-25 14:31:19 -0700114 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -0700115 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
Ilja Friedel1b180392013-03-12 17:09:06 -0700116 if (!PassesSanityCheck())
117 return 1;
Simon Que06860822012-12-18 13:17:56 -0800118 g_main_gl_interface->Cleanup();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -0700119
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700120 if (argc == 1) {
121 printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]);
122 } else {
123 printf("# Running: ");
124 for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
125 printf("\n");
126 }
127 printDateTime();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700128
Ilja Friedel3907fd12014-04-15 14:29:43 -0700129 g_hasty = FLAGS_hasty;
Daniel Kurtz8290ac92014-06-03 17:13:33 +0800130 g_notemp = FLAGS_notemp || g_hasty;
131
132 if (!g_notemp)
Ilja Friedel977aadd2014-04-29 20:45:03 -0700133 g_initial_temperature = GetMachineTemperature();
134
Daniel Kurtz980f3242013-04-01 00:45:50 +0800135 vector<string> enabled_tests, disabled_tests;
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700136 base::SplitString(FLAGS_tests, ':', &enabled_tests);
Daniel Kurtz980f3242013-04-01 00:45:50 +0800137 base::SplitString(FLAGS_blacklist, ':', &disabled_tests);
Ilja Friedel3907fd12014-04-15 14:29:43 -0700138
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700139 glbench::TestBase* tests[] = {
Ilja Friedel3907fd12014-04-15 14:29:43 -0700140 // Please add new tests at the end of this list as tests are known to bleed
141 // state. Reordering them or inserting a new test may cause a change in the
142 // output images and MD5 causing graphics_GLBench failures.
143 // TODO(ihf): Fix this.
Ilja Friedelb4efb4a2014-04-07 22:58:10 -0700144 glbench::GetSwapTest(),
Ilja Friedel6f72b2b2014-04-11 05:47:22 +0000145 glbench::GetContextTest(),
146 glbench::GetClearTest(),
147 glbench::GetFillRateTest(),
148 glbench::GetWindowManagerCompositingTest(false),
149 glbench::GetWindowManagerCompositingTest(true),
150 glbench::GetTriangleSetupTest(),
151 glbench::GetYuvToRgbTest(),
152 glbench::GetReadPixelTest(),
153 glbench::GetAttributeFetchShaderTest(),
154 glbench::GetVaryingsAndDdxyShaderTest(),
Simon Que3562e0a2012-12-28 12:01:12 -0800155 glbench::GetTextureReuseTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -0700156 glbench::GetTextureUpdateTest(),
Simon Quecd8cfe32012-12-27 10:37:45 -0800157 glbench::GetTextureUploadTest(),
Ilja Friedel3907fd12014-04-15 14:29:43 -0700158 glbench::GetFboFillRateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -0800159 };
160
Daniel Kurtz5419f182014-06-03 17:09:22 +0800161 if (FLAGS_list) {
162 for (unsigned int i = 0; i < arraysize(tests); i++)
163 printf("%s\n", tests[i]->Name());
164 return 0;
165 }
166
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700167 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
168 do {
169 for (unsigned int i = 0; i < arraysize(tests); i++) {
Daniel Kurtz980f3242013-04-01 00:45:50 +0800170 if (!test_is_enabled(tests[i], enabled_tests) ||
171 test_is_disabled(tests[i], disabled_tests))
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700172 continue;
Simon Que06860822012-12-18 13:17:56 -0800173 if (!g_main_gl_interface->Init()) {
174 printf("Initialize failed\n");
Stuart Abercrombieddd7fae2012-06-04 11:55:24 -0700175 return 1;
176 }
Stuart Abercrombie7a3fa0b2012-07-30 17:47:40 -0700177 glbench::ClearBuffers();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700178 tests[i]->Run();
Simon Que06860822012-12-18 13:17:56 -0800179 g_main_gl_interface->Cleanup();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700180 }
181 } while (GetUTime() < done);
182
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700183 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700184 delete tests[i];
185 tests[i] = NULL;
186 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800187
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700188 printDateTime();
Ilja Friedel977aadd2014-04-29 20:45:03 -0700189 // Signal to harness that we finished normally.
190 printf("@TEST_END\n");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700191
Alexey Marinichev592b8622010-02-04 15:20:10 -0800192 return 0;
193}