blob: c683f5874d231bbff1cde387144900db676db1e5 [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#ifdef WORKAROUND_CROSBUG14304
14#include "base/string_split.h"
15#endif
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -080016
Alexey Marinichev592b8622010-02-04 15:20:10 -080017#include "main.h"
Alexey Marinichev3c199732010-03-11 10:33:35 -080018#include "utils.h"
Alexey Marinichev592b8622010-02-04 15:20:10 -080019
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070020#include "all_tests.h"
21#include "testbase.h"
22
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070023using std::string;
24using std::vector;
Alexey Marinichev592b8622010-02-04 15:20:10 -080025
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070026DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds");
27DEFINE_string(tests, "", "colon-separated list of tests to run; "
28 "all tests if omitted");
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080029
Alexey Marinichev0f9aa1b2010-03-30 14:38:16 -070030
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070031bool test_is_enabled(glbench::TestBase* test,
32 const vector<string>& enabled_tests) {
33 if (enabled_tests.empty())
34 return true;
35
36 const char* test_name = test->Name();
37 for (vector<string>::const_iterator i = enabled_tests.begin();
38 i != enabled_tests.end(); ++i) {
39 // This is not very precise, but will do until there's a need for something
40 // more flexible.
41 if (strstr(test_name, i->c_str()))
42 return true;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080043 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080044
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070045 return false;
46}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080047
Ilja H. Friedel8faad302011-04-26 14:40:49 -070048void printDateTime(void) {
49 struct tm *ttime;
50 time_t tm = time(0);
51 char time_string[64];
52 ttime = localtime(&tm);
53 strftime(time_string, 63, "%c",ttime);
54 printf("# DateTime: %s\n", time_string);
55}
56
Alexey Marinichev592b8622010-02-04 15:20:10 -080057int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -080058 SetBasePathFromArgv0(argv[0], "src");
Ilja H. Friedel8faad302011-04-26 14:40:49 -070059 google::ParseCommandLineFlags(&argc, &argv, false);
Alexey Marinichev592b8622010-02-04 15:20:10 -080060 if (!Init()) {
Ilja H. Friedel8faad302011-04-26 14:40:49 -070061 printf("# Error: Failed to initialize %s.\n", argv[0]);
Alexey Marinichev592b8622010-02-04 15:20:10 -080062 return 1;
63 }
64
Alexey Marinichevc587a0e2010-07-14 14:51:12 -070065 InitContext();
Alexey Marinichev0f3605d2010-08-25 14:31:19 -070066 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -070067 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
68 DestroyContext();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -070069
Ilja H. Friedel8faad302011-04-26 14:40:49 -070070 if (argc == 1) {
71 printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]);
72 } else {
73 printf("# Running: ");
74 for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
75 printf("\n");
76 }
77 printDateTime();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070078
Ilja H. Friedel8faad302011-04-26 14:40:49 -070079 vector<string> enabled_tests;
80#ifdef WORKAROUND_CROSBUG14304
81 base::SplitString(FLAGS_tests, ':', &enabled_tests);
82#else
83 SplitString(FLAGS_tests, ':', &enabled_tests);
84#endif
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070085 glbench::TestBase* tests[] = {
86 glbench::GetSwapTest(),
87 glbench::GetClearTest(),
88 glbench::GetFillRateTest(),
Alexey Marinicheve735df62010-05-24 15:52:07 -070089 glbench::GetWindowManagerCompositingTest(false),
90 glbench::GetWindowManagerCompositingTest(true),
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070091 glbench::GetTriangleSetupTest(),
Alexey Marinichevbe37f882010-06-07 20:35:07 -070092 glbench::GetYuvToRgbTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070093 glbench::GetReadPixelTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070094 glbench::GetAttributeFetchShaderTest(),
95 glbench::GetVaryingsAndDdxyShaderTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070096 glbench::GetTextureUpdateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -080097 };
98
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070099 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
100 do {
101 for (unsigned int i = 0; i < arraysize(tests); i++) {
102 if (!test_is_enabled(tests[i], enabled_tests))
103 continue;
104 InitContext();
105 tests[i]->Run();
106 DestroyContext();
107 }
108 } while (GetUTime() < done);
109
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700110 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -0700111 delete tests[i];
112 tests[i] = NULL;
113 }
Alexey Marinichev592b8622010-02-04 15:20:10 -0800114
Ilja H. Friedel8faad302011-04-26 14:40:49 -0700115 printDateTime();
116
Alexey Marinichev592b8622010-02-04 15:20:10 -0800117 return 0;
118}