blob: 3e7d04a7577f538ad24105b3c9551f42e03a3012 [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>
8
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -08009#include "base/logging.h"
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070010#include "base/string_util.h"
Alexey Marinichevaf0b26d2010-02-24 13:03:13 -080011
Alexey Marinichev592b8622010-02-04 15:20:10 -080012#include "main.h"
Alexey Marinichev3c199732010-03-11 10:33:35 -080013#include "utils.h"
Alexey Marinichev592b8622010-02-04 15:20:10 -080014
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070015#include "all_tests.h"
16#include "testbase.h"
17
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070018using std::string;
19using std::vector;
Alexey Marinichev592b8622010-02-04 15:20:10 -080020
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070021DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds");
22DEFINE_string(tests, "", "colon-separated list of tests to run; "
23 "all tests if omitted");
Alexey Marinichev1876c6c2010-06-28 12:41:05 -070024DEFINE_bool(get_board_id, false, "return the board id for checksums");
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080025
Alexey Marinichev0f9aa1b2010-03-30 14:38:16 -070026
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070027bool test_is_enabled(glbench::TestBase* test,
28 const vector<string>& enabled_tests) {
29 if (enabled_tests.empty())
30 return true;
31
32 const char* test_name = test->Name();
33 for (vector<string>::const_iterator i = enabled_tests.begin();
34 i != enabled_tests.end(); ++i) {
35 // This is not very precise, but will do until there's a need for something
36 // more flexible.
37 if (strstr(test_name, i->c_str()))
38 return true;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080039 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080040
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070041 return false;
42}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080043
Alexey Marinichev592b8622010-02-04 15:20:10 -080044int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -080045 SetBasePathFromArgv0(argv[0], "src");
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070046 google::ParseCommandLineFlags(&argc, &argv, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -080047 if (!Init()) {
48 printf("# Failed to initialize.\n");
49 return 1;
50 }
51
Alexey Marinichev1876c6c2010-06-28 12:41:05 -070052 if (FLAGS_get_board_id) {
53 InitContext();
54 printf("%s / %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
55 DestroyContext();
56 return 0;
57 }
58
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070059 vector<string> enabled_tests;
60 SplitString(FLAGS_tests, ':', &enabled_tests);
61
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070062 glbench::TestBase* tests[] = {
63 glbench::GetSwapTest(),
64 glbench::GetClearTest(),
Alexey Marinicheve735df62010-05-24 15:52:07 -070065#if defined(USE_OPENGL)
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070066 glbench::GetFillRateTest(),
Alexey Marinicheve735df62010-05-24 15:52:07 -070067 glbench::GetTriangleSetupTest(),
68 glbench::GetWindowManagerCompositingTest(false),
69 glbench::GetWindowManagerCompositingTest(true),
70#endif
Alexey Marinichevbe37f882010-06-07 20:35:07 -070071 glbench::GetYuvToRgbTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070072 glbench::GetReadPixelTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070073 glbench::GetAttributeFetchShaderTest(),
74 glbench::GetVaryingsAndDdxyShaderTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070075 glbench::GetTextureUpdateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -080076 };
77
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070078 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
79 do {
80 for (unsigned int i = 0; i < arraysize(tests); i++) {
81 if (!test_is_enabled(tests[i], enabled_tests))
82 continue;
83 InitContext();
84 tests[i]->Run();
85 DestroyContext();
86 }
87 } while (GetUTime() < done);
88
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070089 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070090 delete tests[i];
91 tests[i] = NULL;
92 }
Alexey Marinichev592b8622010-02-04 15:20:10 -080093
94 return 0;
95}