Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 1 | // 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 Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 5 | #include <gflags/gflags.h> |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 8 | #include <string.h> |
| 9 | #include <ctime> |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 10 | |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 11 | #include "base/logging.h" |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 12 | #include "base/string_util.h" |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 13 | #ifdef WORKAROUND_CROSBUG14304 |
| 14 | #include "base/string_split.h" |
| 15 | #endif |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 16 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 17 | #include "main.h" |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 18 | #include "utils.h" |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 19 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 20 | #include "all_tests.h" |
| 21 | #include "testbase.h" |
| 22 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 23 | using std::string; |
| 24 | using std::vector; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 25 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 26 | DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds"); |
| 27 | DEFINE_string(tests, "", "colon-separated list of tests to run; " |
| 28 | "all tests if omitted"); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 29 | |
Alexey Marinichev | 0f9aa1b | 2010-03-30 14:38:16 -0700 | [diff] [blame] | 30 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 31 | bool 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 Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 43 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 44 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 45 | return false; |
| 46 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 47 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 48 | void 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 Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 57 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame] | 58 | SetBasePathFromArgv0(argv[0], "src"); |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 59 | google::ParseCommandLineFlags(&argc, &argv, false); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 60 | if (!Init()) { |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 61 | printf("# Error: Failed to initialize %s.\n", argv[0]); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 62 | return 1; |
| 63 | } |
| 64 | |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 65 | InitContext(); |
Alexey Marinichev | 0f3605d | 2010-08-25 14:31:19 -0700 | [diff] [blame] | 66 | printf("# board_id: %s - %s\n", |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 67 | glGetString(GL_VENDOR), glGetString(GL_RENDERER)); |
| 68 | DestroyContext(); |
Alexey Marinichev | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 69 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 70 | 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 Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 78 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 79 | 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 Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 85 | glbench::TestBase* tests[] = { |
| 86 | glbench::GetSwapTest(), |
| 87 | glbench::GetClearTest(), |
| 88 | glbench::GetFillRateTest(), |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 89 | glbench::GetWindowManagerCompositingTest(false), |
| 90 | glbench::GetWindowManagerCompositingTest(true), |
Alexey Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame] | 91 | glbench::GetTriangleSetupTest(), |
Alexey Marinichev | be37f88 | 2010-06-07 20:35:07 -0700 | [diff] [blame] | 92 | glbench::GetYuvToRgbTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 93 | glbench::GetReadPixelTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 94 | glbench::GetAttributeFetchShaderTest(), |
| 95 | glbench::GetVaryingsAndDdxyShaderTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 96 | glbench::GetTextureUpdateTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 99 | 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 Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 110 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 111 | delete tests[i]; |
| 112 | tests[i] = NULL; |
| 113 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 114 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame^] | 115 | printDateTime(); |
| 116 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 117 | return 0; |
| 118 | } |