blob: 7b3b60d132ba287139985066be8e83671a815a8d [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.");
33
34GLint g_max_texture_size;
35bool g_hasty;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080036
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070037bool 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 Marinichev19b5a5d2010-02-18 11:37:26 -080049 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080050
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070051 return false;
52}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080053
Daniel Kurtz980f3242013-04-01 00:45:50 +080054bool 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. Friedel8faad302011-04-26 14:40:49 -070071void 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 Friedelc04bdd42013-01-30 18:55:49 -080080bool PassesSanityCheck(void) {
Ilja Friedel3907fd12014-04-15 14:29:43 -070081 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 Friedelc04bdd42013-01-30 18:55:49 -080085 printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n",
Ilja Friedel3907fd12014-04-15 14:29:43 -070086 size[0], size[1]);
Ilja Friedelc04bdd42013-01-30 18:55:49 -080087 return false;
88 }
Ilja Friedel3907fd12014-04-15 14:29:43 -070089 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 Friedelc04bdd42013-01-30 18:55:49 -080098 return true;
99}
100
Alexey Marinichev592b8622010-02-04 15:20:10 -0800101int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -0800102 SetBasePathFromArgv0(argv[0], "src");
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700103 google::ParseCommandLineFlags(&argc, &argv, false);
Simon Que7f840e72012-12-19 12:05:42 -0800104
105 g_main_gl_interface.reset(GLInterface::Create());
106 if (!g_main_gl_interface->Init()) {
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700107 printf("# Error: Failed to initialize %s.\n", argv[0]);
Alexey Marinichev592b8622010-02-04 15:20:10 -0800108 return 1;
109 }
110
Alexey Marinichev0f3605d2010-08-25 14:31:19 -0700111 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -0700112 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
Ilja Friedel1b180392013-03-12 17:09:06 -0700113 if (!PassesSanityCheck())
114 return 1;
Simon Que06860822012-12-18 13:17:56 -0800115 g_main_gl_interface->Cleanup();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -0700116
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700117 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 Marinichevf50ecb12010-06-14 15:21:41 -0700125
Ilja Friedel3907fd12014-04-15 14:29:43 -0700126 g_hasty = FLAGS_hasty;
Daniel Kurtz980f3242013-04-01 00:45:50 +0800127 vector<string> enabled_tests, disabled_tests;
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700128 base::SplitString(FLAGS_tests, ':', &enabled_tests);
Daniel Kurtz980f3242013-04-01 00:45:50 +0800129 base::SplitString(FLAGS_blacklist, ':', &disabled_tests);
Ilja Friedel3907fd12014-04-15 14:29:43 -0700130
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700131 glbench::TestBase* tests[] = {
Ilja Friedel3907fd12014-04-15 14:29:43 -0700132 // Please add new tests at the end of this list as tests are known to bleed
133 // state. Reordering them or inserting a new test may cause a change in the
134 // output images and MD5 causing graphics_GLBench failures.
135 // TODO(ihf): Fix this.
Ilja Friedelb4efb4a2014-04-07 22:58:10 -0700136 glbench::GetSwapTest(),
Ilja Friedel6f72b2b2014-04-11 05:47:22 +0000137 glbench::GetContextTest(),
138 glbench::GetClearTest(),
139 glbench::GetFillRateTest(),
140 glbench::GetWindowManagerCompositingTest(false),
141 glbench::GetWindowManagerCompositingTest(true),
142 glbench::GetTriangleSetupTest(),
143 glbench::GetYuvToRgbTest(),
144 glbench::GetReadPixelTest(),
145 glbench::GetAttributeFetchShaderTest(),
146 glbench::GetVaryingsAndDdxyShaderTest(),
Simon Que3562e0a2012-12-28 12:01:12 -0800147 glbench::GetTextureReuseTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -0700148 glbench::GetTextureUpdateTest(),
Simon Quecd8cfe32012-12-27 10:37:45 -0800149 glbench::GetTextureUploadTest(),
Ilja Friedel3907fd12014-04-15 14:29:43 -0700150 glbench::GetFboFillRateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -0800151 };
152
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700153 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
154 do {
155 for (unsigned int i = 0; i < arraysize(tests); i++) {
Daniel Kurtz980f3242013-04-01 00:45:50 +0800156 if (!test_is_enabled(tests[i], enabled_tests) ||
157 test_is_disabled(tests[i], disabled_tests))
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700158 continue;
Simon Que06860822012-12-18 13:17:56 -0800159 if (!g_main_gl_interface->Init()) {
160 printf("Initialize failed\n");
Stuart Abercrombieddd7fae2012-06-04 11:55:24 -0700161 return 1;
162 }
Stuart Abercrombie7a3fa0b2012-07-30 17:47:40 -0700163 glbench::ClearBuffers();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700164 tests[i]->Run();
Simon Que06860822012-12-18 13:17:56 -0800165 g_main_gl_interface->Cleanup();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700166 }
167 } while (GetUTime() < done);
168
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700169 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700170 delete tests[i];
171 tests[i] = NULL;
172 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800173
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700174 printDateTime();
175
Alexey Marinichev592b8622010-02-04 15:20:10 -0800176 return 0;
177}