blob: 9eabee2045122bdd470e1fb77c6adc48d83653eb [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();
Alexey Marinichev0f3605d2010-08-25 14:31:19 -070052 printf("# board_id: %s - %s\n",
Alexey Marinichevc587a0e2010-07-14 14:51:12 -070053 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 Marinicheve735df62010-05-24 15:52:07 -070063 glbench::GetWindowManagerCompositingTest(false),
64 glbench::GetWindowManagerCompositingTest(true),
Alexey Marinichev2de76ab2010-07-12 18:17:42 -070065 glbench::GetTriangleSetupTest(),
Alexey Marinichevbe37f882010-06-07 20:35:07 -070066 glbench::GetYuvToRgbTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070067 glbench::GetReadPixelTest(),
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070068 glbench::GetAttributeFetchShaderTest(),
69 glbench::GetVaryingsAndDdxyShaderTest(),
Alexey Marinichev9c891ef2010-05-21 15:28:59 -070070 glbench::GetTextureUpdateTest(),
Alexey Marinichev592b8622010-02-04 15:20:10 -080071 };
72
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070073 uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration;
74 do {
75 for (unsigned int i = 0; i < arraysize(tests); i++) {
76 if (!test_is_enabled(tests[i], enabled_tests))
77 continue;
78 InitContext();
79 tests[i]->Run();
80 DestroyContext();
81 }
82 } while (GetUTime() < done);
83
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070084 for (unsigned int i = 0; i < arraysize(tests); i++) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070085 delete tests[i];
86 tests[i] = NULL;
87 }
Alexey Marinichev592b8622010-02-04 15:20:10 -080088
89 return 0;
90}