blob: e71f1c3ef78b900546d10d0e23cb1ad43a972490 [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");
Daniel Kurtz88959fb2015-12-24 14:26:00 +080035DEFINE_bool(verbose, false, "Print extra debugging messages");
Ilja Friedel3907fd12014-04-15 14:29:43 -070036
Daniel Kurtz88959fb2015-12-24 14:26:00 +080037bool g_verbose;
Ilja Friedel3907fd12014-04-15 14:29:43 -070038GLint g_max_texture_size;
39bool g_hasty;
Daniel Kurtz8290ac92014-06-03 17:13:33 +080040bool g_notemp;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080041
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070042bool test_is_enabled(glbench::TestBase* test,
43 const vector<string>& enabled_tests) {
44 if (enabled_tests.empty())
45 return true;
46
47 const char* test_name = test->Name();
48 for (vector<string>::const_iterator i = enabled_tests.begin();
49 i != enabled_tests.end(); ++i) {
50 // This is not very precise, but will do until there's a need for something
51 // more flexible.
52 if (strstr(test_name, i->c_str()))
53 return true;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080054 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080055
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070056 return false;
57}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080058
Daniel Kurtz980f3242013-04-01 00:45:50 +080059bool test_is_disabled(glbench::TestBase* test,
60 const vector<string>& disabled_tests) {
61 if (disabled_tests.empty())
62 return false;
63
64 const char* test_name = test->Name();
65 for (vector<string>::const_iterator i = disabled_tests.begin();
66 i != disabled_tests.end(); ++i) {
67 // This is not very precise, but will do until there's a need for something
68 // more flexible.
69 if (strstr(test_name, i->c_str()))
70 return true;
71 }
72
73 return false;
74}
75
Ilja H. Friedel8faad302011-04-26 14:40:49 -070076void printDateTime(void) {
77 struct tm *ttime;
78 time_t tm = time(0);
79 char time_string[64];
80 ttime = localtime(&tm);
81 strftime(time_string, 63, "%c",ttime);
82 printf("# DateTime: %s\n", time_string);
83}
84
Ilja Friedelc04bdd42013-01-30 18:55:49 -080085bool PassesSanityCheck(void) {
Ilja Friedel3907fd12014-04-15 14:29:43 -070086 GLint size[2];
87 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, size);
88 printf("# MAX_VIEWPORT_DIMS=(%d, %d)\n", size[0], size[1]);
89 if (size[0] < g_width || size[1] < g_height) {
Ilja Friedelc04bdd42013-01-30 18:55:49 -080090 printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n",
Ilja Friedel3907fd12014-04-15 14:29:43 -070091 size[0], size[1]);
Ilja Friedelc04bdd42013-01-30 18:55:49 -080092 return false;
93 }
Ilja Friedel3907fd12014-04-15 14:29:43 -070094 glGetIntegerv(GL_MAX_TEXTURE_SIZE, size);
95 printf("# GL_MAX_TEXTURE_SIZE=%d\n", size[0]);
96 if (size[0] < g_width || size[0] < g_height) {
97 printf("# Error: MAX_TEXTURE_SIZE=%d is too small.\n",
98 size[0]);
99 return false;
100 }
101 g_max_texture_size = size[0];
102
Ilja Friedelc04bdd42013-01-30 18:55:49 -0800103 return true;
104}
105
Alexey Marinichev592b8622010-02-04 15:20:10 -0800106int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -0800107 SetBasePathFromArgv0(argv[0], "src");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700108 google::ParseCommandLineFlags(&argc, &argv, false);
Simon Que7f840e72012-12-19 12:05:42 -0800109
Daniel Kurtz88959fb2015-12-24 14:26:00 +0800110 g_verbose = FLAGS_verbose;
111
Simon Que7f840e72012-12-19 12:05:42 -0800112 g_main_gl_interface.reset(GLInterface::Create());
113 if (!g_main_gl_interface->Init()) {
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700114 printf("# Error: Failed to initialize %s.\n", argv[0]);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800115 return 1;
116 }
117
Alexey Marinichev0f3605d2010-08-25 14:31:19 -0700118 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -0700119 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
Ilja Friedel1b180392013-03-12 17:09:06 -0700120 if (!PassesSanityCheck())
121 return 1;
Simon Que06860822012-12-18 13:17:56 -0800122 g_main_gl_interface->Cleanup();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -0700123
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700124 if (argc == 1) {
125 printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]);
126 } else {
127 printf("# Running: ");
128 for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
129 printf("\n");
130 }
131 printDateTime();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700132
Ilja Friedel3907fd12014-04-15 14:29:43 -0700133 g_hasty = FLAGS_hasty;
Daniel Kurtz8290ac92014-06-03 17:13:33 +0800134 g_notemp = FLAGS_notemp || g_hasty;
135
136 if (!g_notemp)
Ilja Friedel977aadd2014-04-29 20:45:03 -0700137 g_initial_temperature = GetMachineTemperature();
138
Alex Vakulenko298290d2016-01-20 16:07:13 -0800139 vector<string> enabled_tests =
140 base::SplitString(FLAGS_tests, ":", base::TRIM_WHITESPACE,
141 base::SPLIT_WANT_ALL);
142 vector<string> disabled_tests =
143 base::SplitString(FLAGS_blacklist, ":", base::TRIM_WHITESPACE,
144 base::SPLIT_WANT_ALL);
Ilja Friedel3907fd12014-04-15 14:29:43 -0700145
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700146 glbench::TestBase* tests[] = {
Ilja Friedel3907fd12014-04-15 14:29:43 -0700147 // Please add new tests at the end of this list as tests are known to bleed
148 // state. Reordering them or inserting a new test may cause a change in the
149 // output images and MD5 causing graphics_GLBench failures.
150 // TODO(ihf): Fix this.
Ilja Friedelb4efb4a2014-04-07 22:58:10 -0700151 glbench::GetSwapTest(),
Ilja Friedel6f72b2b2014-04-11 05:47:22 +0000152 glbench::GetContextTest(),
153 glbench::GetClearTest(),
154 glbench::GetFillRateTest(),
155 glbench::GetWindowManagerCompositingTest(false),
156 glbench::GetWindowManagerCompositingTest(true),
157 glbench::GetTriangleSetupTest(),
158 glbench::GetYuvToRgbTest(),
159 glbench::GetReadPixelTest(),
160 glbench::GetAttributeFetchShaderTest(),
161 glbench::GetVaryingsAndDdxyShaderTest(),
Simon Que3562e0a2012-12-28 12:01:12 -0800162 glbench::GetTextureReuseTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -0700163 glbench::GetTextureUpdateTest(),
Simon Quecd8cfe32012-12-27 10:37:45 -0800164 glbench::GetTextureUploadTest(),
Ilja Friedel3907fd12014-04-15 14:29:43 -0700165 glbench::GetFboFillRateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -0800166 };
167
Daniel Kurtz5419f182014-06-03 17:09:22 +0800168 if (FLAGS_list) {
169 for (unsigned int i = 0; i < arraysize(tests); i++)
170 printf("%s\n", tests[i]->Name());
171 return 0;
172 }
173
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700174 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
175 do {
176 for (unsigned int i = 0; i < arraysize(tests); i++) {
Daniel Kurtz980f3242013-04-01 00:45:50 +0800177 if (!test_is_enabled(tests[i], enabled_tests) ||
178 test_is_disabled(tests[i], disabled_tests))
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700179 continue;
Simon Que06860822012-12-18 13:17:56 -0800180 if (!g_main_gl_interface->Init()) {
181 printf("Initialize failed\n");
Stuart Abercrombieddd7fae2012-06-04 11:55:24 -0700182 return 1;
183 }
Stuart Abercrombie7a3fa0b2012-07-30 17:47:40 -0700184 glbench::ClearBuffers();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700185 tests[i]->Run();
Simon Que06860822012-12-18 13:17:56 -0800186 g_main_gl_interface->Cleanup();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700187 }
188 } while (GetUTime() < done);
189
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700190 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700191 delete tests[i];
192 tests[i] = NULL;
193 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800194
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700195 printDateTime();
Ilja Friedel977aadd2014-04-29 20:45:03 -0700196 // Signal to harness that we finished normally.
197 printf("@TEST_END\n");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700198
Alexey Marinichev592b8622010-02-04 15:20:10 -0800199 return 0;
200}