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 | #include "base/string_split.h" |
Alexey Marinichev | af0b26d | 2010-02-24 13:03:13 -0800 | [diff] [blame] | 14 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 15 | #include "main.h" |
Alexey Marinichev | 3c19973 | 2010-03-11 10:33:35 -0800 | [diff] [blame] | 16 | #include "utils.h" |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 17 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 18 | #include "all_tests.h" |
| 19 | #include "testbase.h" |
| 20 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 21 | using std::string; |
| 22 | using std::vector; |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 23 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 24 | DEFINE_int32(duration, 0, "run tests in a loop for at least this many seconds"); |
| 25 | DEFINE_string(tests, "", "colon-separated list of tests to run; " |
| 26 | "all tests if omitted"); |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 27 | |
Alexey Marinichev | 0f9aa1b | 2010-03-30 14:38:16 -0700 | [diff] [blame] | 28 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 29 | bool test_is_enabled(glbench::TestBase* test, |
| 30 | const vector<string>& enabled_tests) { |
| 31 | if (enabled_tests.empty()) |
| 32 | return true; |
| 33 | |
| 34 | const char* test_name = test->Name(); |
| 35 | for (vector<string>::const_iterator i = enabled_tests.begin(); |
| 36 | i != enabled_tests.end(); ++i) { |
| 37 | // This is not very precise, but will do until there's a need for something |
| 38 | // more flexible. |
| 39 | if (strstr(test_name, i->c_str())) |
| 40 | return true; |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 41 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 42 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 43 | return false; |
| 44 | } |
Alexey Marinichev | 19b5a5d | 2010-02-18 11:37:26 -0800 | [diff] [blame] | 45 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 46 | void printDateTime(void) { |
| 47 | struct tm *ttime; |
| 48 | time_t tm = time(0); |
| 49 | char time_string[64]; |
| 50 | ttime = localtime(&tm); |
| 51 | strftime(time_string, 63, "%c",ttime); |
| 52 | printf("# DateTime: %s\n", time_string); |
| 53 | } |
| 54 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 55 | int main(int argc, char *argv[]) { |
Antoine Labour | ec7eb53 | 2010-03-12 11:01:34 -0800 | [diff] [blame] | 56 | SetBasePathFromArgv0(argv[0], "src"); |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 57 | google::ParseCommandLineFlags(&argc, &argv, false); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 58 | if (!Init()) { |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 59 | printf("# Error: Failed to initialize %s.\n", argv[0]); |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 60 | return 1; |
| 61 | } |
| 62 | |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 63 | InitContext(); |
Alexey Marinichev | 0f3605d | 2010-08-25 14:31:19 -0700 | [diff] [blame] | 64 | printf("# board_id: %s - %s\n", |
Alexey Marinichev | c587a0e | 2010-07-14 14:51:12 -0700 | [diff] [blame] | 65 | glGetString(GL_VENDOR), glGetString(GL_RENDERER)); |
| 66 | DestroyContext(); |
Alexey Marinichev | 1876c6c | 2010-06-28 12:41:05 -0700 | [diff] [blame] | 67 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 68 | if (argc == 1) { |
| 69 | printf("# Usage: %s [-save [-outdir=<directory>]] to save images\n", argv[0]); |
| 70 | } else { |
| 71 | printf("# Running: "); |
| 72 | for (int i = 0; i < argc; i++) printf("%s ", argv[i]); |
| 73 | printf("\n"); |
| 74 | } |
| 75 | printDateTime(); |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 76 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 77 | vector<string> enabled_tests; |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 78 | base::SplitString(FLAGS_tests, ':', &enabled_tests); |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 79 | glbench::TestBase* tests[] = { |
| 80 | glbench::GetSwapTest(), |
| 81 | glbench::GetClearTest(), |
| 82 | glbench::GetFillRateTest(), |
Alexey Marinichev | e735df6 | 2010-05-24 15:52:07 -0700 | [diff] [blame] | 83 | glbench::GetWindowManagerCompositingTest(false), |
| 84 | glbench::GetWindowManagerCompositingTest(true), |
Alexey Marinichev | 2de76ab | 2010-07-12 18:17:42 -0700 | [diff] [blame] | 85 | glbench::GetTriangleSetupTest(), |
Alexey Marinichev | be37f88 | 2010-06-07 20:35:07 -0700 | [diff] [blame] | 86 | glbench::GetYuvToRgbTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 87 | glbench::GetReadPixelTest(), |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 88 | glbench::GetAttributeFetchShaderTest(), |
| 89 | glbench::GetVaryingsAndDdxyShaderTest(), |
Alexey Marinichev | 9c891ef | 2010-05-21 15:28:59 -0700 | [diff] [blame] | 90 | glbench::GetTextureUpdateTest(), |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 93 | uint64_t done = GetUTime() + 1000000ULL * FLAGS_duration; |
| 94 | do { |
| 95 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
| 96 | if (!test_is_enabled(tests[i], enabled_tests)) |
| 97 | continue; |
Stuart Abercrombie | ddd7fae | 2012-06-04 11:55:24 -0700 | [diff] [blame^] | 98 | if (!InitContext()) { |
| 99 | printf("InitContext failed\n"); |
| 100 | return 1; |
| 101 | } |
Alexey Marinichev | f50ecb1 | 2010-06-14 15:21:41 -0700 | [diff] [blame] | 102 | tests[i]->Run(); |
| 103 | DestroyContext(); |
| 104 | } |
| 105 | } while (GetUTime() < done); |
| 106 | |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 107 | for (unsigned int i = 0; i < arraysize(tests); i++) { |
Alexey Marinichev | 9f9b873 | 2010-05-20 19:33:44 -0700 | [diff] [blame] | 108 | delete tests[i]; |
| 109 | tests[i] = NULL; |
| 110 | } |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 111 | |
Ilja H. Friedel | 8faad30 | 2011-04-26 14:40:49 -0700 | [diff] [blame] | 112 | printDateTime(); |
| 113 | |
Alexey Marinichev | 592b862 | 2010-02-04 15:20:10 -0800 | [diff] [blame] | 114 | return 0; |
| 115 | } |