blob: 0c7bbcfab6d4a1b45d44d36c11ab04fbd900ba33 [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"
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070012#include "base/string_util.h"
Ilja H. Friedel8faad302011-04-26 14:40:49 -070013#include "base/string_split.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
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070025DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds");
26DEFINE_string(tests, "", "colon-separated list of tests to run; "
27 "all tests if omitted");
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080028
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070029bool test_is_enabled(glbench::TestBase* test,
30 const vector<string>& enabled_tests) {
31 if (enabled_tests.empty())
32 return true;
33
34 const char* test_name = test->Name();
35 for (vector<string>::const_iterator i = enabled_tests.begin();
36 i != enabled_tests.end(); ++i) {
37 // This is not very precise, but will do until there's a need for something
38 // more flexible.
39 if (strstr(test_name, i->c_str()))
40 return true;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080041 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080042
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070043 return false;
44}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080045
Ilja H. Friedel8faad302011-04-26 14:40:49 -070046void printDateTime(void) {
47 struct tm *ttime;
48 time_t tm = time(0);
49 char time_string[64];
50 ttime = localtime(&tm);
51 strftime(time_string, 63, "%c",ttime);
52 printf("# DateTime: %s\n", time_string);
53}
54
Ilja Friedelc04bdd42013-01-30 18:55:49 -080055bool PassesSanityCheck(void) {
56 GLint viewport[2];
57 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport);
Ilja Friedel1b180392013-03-12 17:09:06 -070058 printf("# MAX_VIEWPORT_DIMS=(%d, %d)\n", viewport[0], viewport[1]);
Ilja Friedelc04bdd42013-01-30 18:55:49 -080059 if (viewport[0] < g_width || viewport[1] < g_height) {
60 printf("# Error: MAX_VIEWPORT_DIMS=(%d, %d) are too small.\n",
61 viewport[0], viewport[1]);
62 return false;
63 }
64 return true;
65}
66
Alexey Marinichev592b8622010-02-04 15:20:10 -080067int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -080068 SetBasePathFromArgv0(argv[0], "src");
Ilja H. Friedel8faad302011-04-26 14:40:49 -070069 google::ParseCommandLineFlags(&argc, &argv, false);
Simon Que7f840e72012-12-19 12:05:42 -080070
71 g_main_gl_interface.reset(GLInterface::Create());
72 if (!g_main_gl_interface->Init()) {
Ilja H. Friedel8faad302011-04-26 14:40:49 -070073 printf("# Error: Failed to initialize %s.\n", argv[0]);
Alexey Marinichev592b8622010-02-04 15:20:10 -080074 return 1;
75 }
76
Alexey Marinichev0f3605d2010-08-25 14:31:19 -070077 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -070078 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
Ilja Friedel1b180392013-03-12 17:09:06 -070079 if (!PassesSanityCheck())
80 return 1;
Simon Que06860822012-12-18 13:17:56 -080081 g_main_gl_interface->Cleanup();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -070082
Ilja H. Friedel8faad302011-04-26 14:40:49 -070083 if (argc == 1) {
84 printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]);
85 } else {
86 printf("# Running: ");
87 for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
88 printf("\n");
89 }
90 printDateTime();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070091
Ilja H. Friedel8faad302011-04-26 14:40:49 -070092 vector<string> enabled_tests;
Ilja H. Friedel8faad302011-04-26 14:40:49 -070093 base::SplitString(FLAGS_tests, ':', &enabled_tests);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070094 glbench::TestBase* tests[] = {
95 glbench::GetSwapTest(),
Simon Que06860822012-12-18 13:17:56 -080096 glbench::GetContextTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070097 glbench::GetClearTest(),
98 glbench::GetFillRateTest(),
Alexey Marinicheve735df62010-05-24 15:52:07 -070099 glbench::GetWindowManagerCompositingTest(false),
100 glbench::GetWindowManagerCompositingTest(true),
Alexey Marinichev2de76ab2010-07-12 18:17:42 -0700101 glbench::GetTriangleSetupTest(),
Alexey Marinichevbe37f882010-06-07 20:35:07 -0700102 glbench::GetYuvToRgbTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700103 glbench::GetReadPixelTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700104 glbench::GetAttributeFetchShaderTest(),
105 glbench::GetVaryingsAndDdxyShaderTest(),
Simon Que3562e0a2012-12-28 12:01:12 -0800106 glbench::GetTextureReuseTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -0700107 glbench::GetTextureUpdateTest(),
Simon Quecd8cfe32012-12-27 10:37:45 -0800108 glbench::GetTextureUploadTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -0800109 };
110
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700111 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
112 do {
113 for (unsigned int i = 0; i < arraysize(tests); i++) {
114 if (!test_is_enabled(tests[i], enabled_tests))
115 continue;
Simon Que06860822012-12-18 13:17:56 -0800116 if (!g_main_gl_interface->Init()) {
117 printf("Initialize failed\n");
Stuart Abercrombieddd7fae2012-06-04 11:55:24 -0700118 return 1;
119 }
Stuart Abercrombie7a3fa0b2012-07-30 17:47:40 -0700120 glbench::ClearBuffers();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700121 tests[i]->Run();
Simon Que06860822012-12-18 13:17:56 -0800122 g_main_gl_interface->Cleanup();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -0700123 }
124 } while (GetUTime() < done);
125
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700126 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700127 delete tests[i];
128 tests[i] = NULL;
129 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800130
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700131 printDateTime();
132
Alexey Marinichev592b8622010-02-04 15:20:10 -0800133 return 0;
134}