John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
sergeyv | 7dc370b | 2016-06-17 11:21:11 -0700 | [diff] [blame] | 17 | #include "tests/common/LeakChecker.h" |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 18 | #include "tests/common/TestScene.h" |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 19 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 20 | #include "Properties.h" |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 21 | #include "hwui/Typeface.h" |
John Reck | 6104cea | 2019-01-10 14:37:17 -0800 | [diff] [blame] | 22 | #include "HardwareBitmapUploader.h" |
| 23 | #include "renderthread/RenderProxy.h" |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 24 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 25 | #include <benchmark/benchmark.h> |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 26 | #include <fnmatch.h> |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 27 | #include <getopt.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 28 | #include <pthread.h> |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 29 | #include <stdio.h> |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 30 | #include <unistd.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 31 | #include <string> |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 32 | #include <unordered_map> |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 33 | #include <vector> |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 34 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 35 | #include <errno.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 36 | #include <fcntl.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <sys/types.h> |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 39 | |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 40 | using namespace android; |
| 41 | using namespace android::uirenderer; |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 42 | using namespace android::uirenderer::test; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 43 | |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 44 | static std::vector<TestScene::Info> gRunTests; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 45 | static TestScene::Options gOpts; |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 46 | static bool gRunLeakCheck = true; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 47 | std::unique_ptr<benchmark::BenchmarkReporter> gBenchmarkReporter; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 48 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 49 | void run(const TestScene::Info& info, const TestScene::Options& opts, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 50 | benchmark::BenchmarkReporter* reporter); |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 51 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 52 | static void printHelp() { |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 53 | printf(R"( |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 54 | USAGE: hwuimacro [OPTIONS] <TESTNAME> |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 55 | |
| 56 | OPTIONS: |
| 57 | -c, --count=NUM NUM loops a test should run (example, number of frames) |
| 58 | -r, --runs=NUM Repeat the test(s) NUM times |
| 59 | -h, --help Display this help |
| 60 | --list List all tests |
| 61 | --wait-for-gpu Set this to wait for the GPU before producing the |
| 62 | next frame. Note that without locked clocks this will |
| 63 | pathologically bad performance due to large idle time |
| 64 | --report-frametime[=weight] If set, the test will print to stdout the |
| 65 | moving average frametime. Weight is optional, default is 10 |
| 66 | --cpuset=name Adds the test to the specified cpuset before running |
| 67 | Not supported on all devices and needs root |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 68 | --offscreen Render tests off device screen. This option is on by default |
| 69 | --onscreen Render tests on device screen. By default tests |
| 70 | are offscreen rendered |
| 71 | --benchmark_format Set output format. Possible values are tabular, json, csv |
John Reck | 18f442e | 2018-04-09 16:56:34 -0700 | [diff] [blame] | 72 | --renderer=TYPE Sets the render pipeline to use. May be skiagl or skiavk |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 73 | --skip-leak-check Skips the memory leak check |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 74 | --report-gpu-memory Dumps the GPU memory usage after each test run |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 75 | )"); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static void listTests() { |
| 79 | printf("Tests: \n"); |
Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 80 | for (auto&& test : TestScene::testMap()) { |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 81 | auto&& info = test.second; |
| 82 | const char* col1 = info.name.c_str(); |
| 83 | int dlen = info.description.length(); |
| 84 | const char* col2 = info.description.c_str(); |
| 85 | // World's best line breaking algorithm. |
| 86 | do { |
| 87 | int toPrint = dlen; |
| 88 | if (toPrint > 50) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 89 | char* found = (char*)memrchr(col2, ' ', 50); |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 90 | if (found) { |
| 91 | toPrint = found - col2; |
| 92 | } else { |
| 93 | toPrint = 50; |
| 94 | } |
| 95 | } |
| 96 | printf("%-20s %.*s\n", col1, toPrint, col2); |
| 97 | col1 = ""; |
| 98 | col2 += toPrint; |
| 99 | dlen -= toPrint; |
| 100 | while (*col2 == ' ') { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 101 | col2++; |
| 102 | dlen--; |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame] | 103 | } |
| 104 | } while (dlen > 0); |
| 105 | printf("\n"); |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 109 | static void moveToCpuSet(const char* cpusetName) { |
| 110 | if (access("/dev/cpuset/tasks", F_OK)) { |
| 111 | fprintf(stderr, "don't have access to cpusets, skipping...\n"); |
| 112 | return; |
| 113 | } |
| 114 | static const int BUF_SIZE = 100; |
| 115 | char buffer[BUF_SIZE]; |
| 116 | |
| 117 | if (snprintf(buffer, BUF_SIZE, "/dev/cpuset/%s/tasks", cpusetName) >= BUF_SIZE) { |
| 118 | fprintf(stderr, "Error, cpusetName too large to fit in buffer '%s'\n", cpusetName); |
| 119 | return; |
| 120 | } |
| 121 | int fd = open(buffer, O_WRONLY | O_CLOEXEC); |
| 122 | if (fd == -1) { |
| 123 | fprintf(stderr, "Error opening file %d\n", errno); |
| 124 | return; |
| 125 | } |
| 126 | pid_t pid = getpid(); |
| 127 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 128 | int towrite = snprintf(buffer, BUF_SIZE, "%ld", (long)pid); |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 129 | if (towrite >= BUF_SIZE) { |
| 130 | fprintf(stderr, "Buffer wasn't large enough?\n"); |
| 131 | } else { |
| 132 | if (write(fd, buffer, towrite) != towrite) { |
| 133 | fprintf(stderr, "Failed to write, errno=%d", errno); |
| 134 | } |
| 135 | } |
| 136 | close(fd); |
| 137 | } |
| 138 | |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 139 | static bool setBenchmarkFormat(const char* format) { |
| 140 | if (!strcmp(format, "tabular")) { |
| 141 | gBenchmarkReporter.reset(new benchmark::ConsoleReporter()); |
| 142 | } else if (!strcmp(format, "json")) { |
| 143 | gBenchmarkReporter.reset(new benchmark::JSONReporter()); |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 144 | } else { |
| 145 | fprintf(stderr, "Unknown format '%s'", format); |
| 146 | return false; |
| 147 | } |
| 148 | return true; |
| 149 | } |
| 150 | |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 151 | static bool setRenderer(const char* renderer) { |
John Reck | 18f442e | 2018-04-09 16:56:34 -0700 | [diff] [blame] | 152 | if (!strcmp(renderer, "skiagl")) { |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 153 | Properties::overrideRenderPipelineType(RenderPipelineType::SkiaGL); |
| 154 | } else if (!strcmp(renderer, "skiavk")) { |
| 155 | Properties::overrideRenderPipelineType(RenderPipelineType::SkiaVulkan); |
| 156 | } else { |
| 157 | fprintf(stderr, "Unknown format '%s'", renderer); |
| 158 | return false; |
| 159 | } |
| 160 | return true; |
| 161 | } |
| 162 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 163 | // For options that only exist in long-form. Anything in the |
| 164 | // 0-255 range is reserved for short options (which just use their ASCII value) |
| 165 | namespace LongOpts { |
| 166 | enum { |
| 167 | Reserved = 255, |
| 168 | List, |
| 169 | WaitForGpu, |
| 170 | ReportFrametime, |
| 171 | CpuSet, |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 172 | BenchmarkFormat, |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 173 | Onscreen, |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 174 | Offscreen, |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 175 | Renderer, |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 176 | SkipLeakCheck, |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 177 | ReportGpuMemory, |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 178 | }; |
| 179 | } |
| 180 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 181 | static const struct option LONG_OPTIONS[] = { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 182 | {"frames", required_argument, nullptr, 'f'}, |
| 183 | {"repeat", required_argument, nullptr, 'r'}, |
| 184 | {"help", no_argument, nullptr, 'h'}, |
| 185 | {"list", no_argument, nullptr, LongOpts::List}, |
| 186 | {"wait-for-gpu", no_argument, nullptr, LongOpts::WaitForGpu}, |
| 187 | {"report-frametime", optional_argument, nullptr, LongOpts::ReportFrametime}, |
| 188 | {"cpuset", required_argument, nullptr, LongOpts::CpuSet}, |
| 189 | {"benchmark_format", required_argument, nullptr, LongOpts::BenchmarkFormat}, |
| 190 | {"onscreen", no_argument, nullptr, LongOpts::Onscreen}, |
| 191 | {"offscreen", no_argument, nullptr, LongOpts::Offscreen}, |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 192 | {"renderer", required_argument, nullptr, LongOpts::Renderer}, |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 193 | {"skip-leak-check", no_argument, nullptr, LongOpts::SkipLeakCheck}, |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 194 | {"report-gpu-memory", no_argument, nullptr, LongOpts::ReportGpuMemory}, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 195 | {0, 0, 0, 0}}; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 196 | |
| 197 | static const char* SHORT_OPTIONS = "c:r:h"; |
| 198 | |
| 199 | void parseOptions(int argc, char* argv[]) { |
| 200 | int c; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 201 | bool error = false; |
| 202 | opterr = 0; |
| 203 | |
| 204 | while (true) { |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 205 | /* getopt_long stores the option index here. */ |
| 206 | int option_index = 0; |
| 207 | |
| 208 | c = getopt_long(argc, argv, SHORT_OPTIONS, LONG_OPTIONS, &option_index); |
| 209 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 210 | if (c == -1) break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 211 | |
| 212 | switch (c) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 213 | case 0: |
| 214 | // Option set a flag, don't need to do anything |
| 215 | // (although none of the current LONG_OPTIONS do this...) |
| 216 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 217 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 218 | case LongOpts::List: |
| 219 | listTests(); |
| 220 | exit(EXIT_SUCCESS); |
| 221 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 222 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 223 | case 'c': |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 224 | gOpts.frameCount = atoi(optarg); |
| 225 | if (!gOpts.frameCount) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 226 | fprintf(stderr, "Invalid frames argument '%s'\n", optarg); |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 227 | error = true; |
| 228 | } |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 229 | break; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 230 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 231 | case 'r': |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 232 | gOpts.repeatCount = atoi(optarg); |
| 233 | if (!gOpts.repeatCount) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 234 | fprintf(stderr, "Invalid repeat argument '%s'\n", optarg); |
| 235 | error = true; |
| 236 | } else { |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 237 | gOpts.repeatCount = (gOpts.repeatCount > 0 ? gOpts.repeatCount : INT_MAX); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 238 | } |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 239 | break; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 240 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 241 | case LongOpts::ReportFrametime: |
| 242 | if (optarg) { |
| 243 | gOpts.reportFrametimeWeight = atoi(optarg); |
| 244 | if (!gOpts.reportFrametimeWeight) { |
| 245 | fprintf(stderr, "Invalid report frametime weight '%s'\n", optarg); |
| 246 | error = true; |
| 247 | } |
| 248 | } else { |
| 249 | gOpts.reportFrametimeWeight = 10; |
| 250 | } |
| 251 | break; |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 252 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 253 | case LongOpts::WaitForGpu: |
| 254 | Properties::waitForGpuCompletion = true; |
| 255 | break; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 256 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 257 | case LongOpts::CpuSet: |
| 258 | if (!optarg) { |
| 259 | error = true; |
| 260 | break; |
| 261 | } |
| 262 | moveToCpuSet(optarg); |
| 263 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 264 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 265 | case LongOpts::BenchmarkFormat: |
| 266 | if (!optarg) { |
| 267 | error = true; |
| 268 | break; |
| 269 | } |
| 270 | if (!setBenchmarkFormat(optarg)) { |
| 271 | error = true; |
| 272 | } |
| 273 | break; |
| 274 | |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 275 | case LongOpts::Renderer: |
| 276 | if (!optarg) { |
| 277 | error = true; |
| 278 | break; |
| 279 | } |
| 280 | if (!setRenderer(optarg)) { |
| 281 | error = true; |
| 282 | } |
| 283 | break; |
| 284 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 285 | case LongOpts::Onscreen: |
| 286 | gOpts.renderOffscreen = false; |
| 287 | break; |
| 288 | |
| 289 | case LongOpts::Offscreen: |
| 290 | gOpts.renderOffscreen = true; |
| 291 | break; |
| 292 | |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 293 | case LongOpts::SkipLeakCheck: |
| 294 | gRunLeakCheck = false; |
| 295 | break; |
| 296 | |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 297 | case LongOpts::ReportGpuMemory: |
| 298 | gOpts.reportGpuMemoryUsage = true; |
| 299 | break; |
| 300 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 301 | case 'h': |
| 302 | printHelp(); |
| 303 | exit(EXIT_SUCCESS); |
| 304 | break; |
| 305 | |
| 306 | case '?': |
| 307 | fprintf(stderr, "Unrecognized option '%s'\n", argv[optind - 1]); |
Chih-Hung Hsieh | e1afb6c | 2018-10-22 12:25:50 -0700 | [diff] [blame] | 308 | [[fallthrough]]; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 309 | default: |
| 310 | error = true; |
| 311 | break; |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | if (error) { |
| 316 | fprintf(stderr, "Try 'hwuitest --help' for more information.\n"); |
| 317 | exit(EXIT_FAILURE); |
| 318 | } |
| 319 | |
| 320 | /* Print any remaining command line arguments (not options). */ |
| 321 | if (optind < argc) { |
| 322 | do { |
| 323 | const char* test = argv[optind++]; |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 324 | if (strchr(test, '*')) { |
| 325 | // Glob match |
| 326 | for (auto& iter : TestScene::testMap()) { |
| 327 | if (!fnmatch(test, iter.first.c_str(), 0)) { |
| 328 | gRunTests.push_back(iter.second); |
| 329 | } |
| 330 | } |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 331 | } else { |
John Reck | 66e06d4 | 2021-05-11 17:04:54 -0400 | [diff] [blame^] | 332 | auto pos = TestScene::testMap().find(test); |
| 333 | if (pos == TestScene::testMap().end()) { |
| 334 | fprintf(stderr, "Unknown test '%s'\n", test); |
| 335 | exit(EXIT_FAILURE); |
| 336 | } else { |
| 337 | gRunTests.push_back(pos->second); |
| 338 | } |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 339 | } |
| 340 | } while (optind < argc); |
| 341 | } else { |
sergeyv | 202c10b | 2016-07-11 17:53:45 -0700 | [diff] [blame] | 342 | for (auto& iter : TestScene::testMap()) { |
| 343 | gRunTests.push_back(iter.second); |
| 344 | } |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 348 | int main(int argc, char* argv[]) { |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 349 | Typeface::setRobotoTypefaceForTest(); |
| 350 | |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 351 | parseOptions(argc, argv); |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 352 | if (!gBenchmarkReporter && gOpts.renderOffscreen) { |
| 353 | gBenchmarkReporter.reset(new benchmark::ConsoleReporter()); |
| 354 | } |
| 355 | |
| 356 | if (gBenchmarkReporter) { |
| 357 | size_t name_field_width = 10; |
| 358 | for (auto&& test : gRunTests) { |
| 359 | name_field_width = std::max<size_t>(name_field_width, test.name.size()); |
| 360 | } |
| 361 | // _50th, _90th, etc... |
| 362 | name_field_width += 5; |
| 363 | |
| 364 | benchmark::BenchmarkReporter::Context context; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 365 | context.name_field_width = name_field_width; |
| 366 | gBenchmarkReporter->ReportContext(context); |
| 367 | } |
John Reck | b7dd29e | 2015-10-06 13:28:17 -0700 | [diff] [blame] | 368 | |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 369 | for (auto&& test : gRunTests) { |
| 370 | run(test, gOpts, gBenchmarkReporter.get()); |
Tim Murray | 1a0f1c7 | 2015-05-06 11:37:37 -0700 | [diff] [blame] | 371 | } |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 372 | |
| 373 | if (gBenchmarkReporter) { |
| 374 | gBenchmarkReporter->Finalize(); |
| 375 | } |
| 376 | |
John Reck | 6104cea | 2019-01-10 14:37:17 -0800 | [diff] [blame] | 377 | renderthread::RenderProxy::trimMemory(100); |
| 378 | HardwareBitmapUploader::terminate(); |
| 379 | |
John Reck | a842780 | 2021-05-10 17:47:50 -0400 | [diff] [blame] | 380 | if (gRunLeakCheck) { |
| 381 | LeakChecker::checkForLeaks(); |
| 382 | } |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 383 | return 0; |
| 384 | } |