blob: b579bf707b53e69bb2d7fe36a85ebb3d9d937b6e [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 Marinichev19b5a5d2010-02-18 11:37:26 -080024
Alexey Marinichev0f9aa1b2010-03-30 14:38:16 -070025
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070026bool test_is_enabled(glbench::TestBase* test,
27 const vector<string>& enabled_tests) {
28 if (enabled_tests.empty())
29 return true;
30
31 const char* test_name = test->Name();
32 for (vector<string>::const_iterator i = enabled_tests.begin();
33 i != enabled_tests.end(); ++i) {
34 // This is not very precise, but will do until there's a need for something
35 // more flexible.
36 if (strstr(test_name, i->c_str()))
37 return true;
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080038 }
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080039
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070040 return false;
41}
Alexey Marinichev19b5a5d2010-02-18 11:37:26 -080042
Alexey Marinichev592b8622010-02-04 15:20:10 -080043int main(int argc, char *argv[]) {
Antoine Labourec7eb532010-03-12 11:01:34 -080044 SetBasePathFromArgv0(argv[0], "src");
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070045 google::ParseCommandLineFlags(&argc, &argv, true);
Alexey Marinichev592b8622010-02-04 15:20:10 -080046 if (!Init()) {
47 printf("# Failed to initialize.\n");
48 return 1;
49 }
50
Alexey Marinichevc587a0e2010-07-14 14:51:12 -070051 InitContext();
52 printf("# board_id: %s / %s\n",
53 glGetString(GL_VENDOR), glGetString(GL_RENDERER));
54 DestroyContext();
Alexey Marinichev1876c6c2010-06-28 12:41:05 -070055
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070056 vector<string> enabled_tests;
57 SplitString(FLAGS_tests, ':', &enabled_tests);
58
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070059 glbench::TestBase* tests[] = {
60 glbench::GetSwapTest(),
61 glbench::GetClearTest(),
62 glbench::GetFillRateTest(),
Alexey Marinichevb70421f2010-07-12 18:11:27 -070063#if defined(USE_OPENGL)
Alexey Marinicheve735df62010-05-24 15:52:07 -070064 glbench::GetWindowManagerCompositingTest(false),
65 glbench::GetWindowManagerCompositingTest(true),
66#endif
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070067 glbench::GetTriangleSetupTest(),
Alexey Marinichevbe37f882010-06-07 20:35:07 -070068 glbench::GetYuvToRgbTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070069 glbench::GetReadPixelTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070070 glbench::GetAttributeFetchShaderTest(),
71 glbench::GetVaryingsAndDdxyShaderTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070072 glbench::GetTextureUpdateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -080073 };
74
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070075 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
76 do {
77 for (unsigned int i = 0; i < arraysize(tests); i++) {
78 if (!test_is_enabled(tests[i], enabled_tests))
79 continue;
80 InitContext();
81 tests[i]->Run();
82 DestroyContext();
83 }
84 } while (GetUTime() < done);
85
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070086 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070087 delete tests[i];
88 tests[i] = NULL;
89 }
Alexey Marinichev592b8622010-02-04 15:20:10 -080090
91 return 0;
92}