| Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2012 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 |  | 
|  | 17 |  | 
|  | 18 | #include <regex.h> | 
|  | 19 | #include <stdio.h> | 
|  | 20 | #include <stdlib.h> | 
|  | 21 |  | 
|  | 22 | #include <vector> | 
|  | 23 |  | 
|  | 24 | #include <benchmark/Benchmark.h> | 
|  | 25 |  | 
|  | 26 | int main(int argc, char* argv[]) { | 
|  | 27 | if (::testing::Benchmark::List().empty()) { | 
|  | 28 | fprintf(stderr, "No benchmarks registered!\n"); | 
|  | 29 | exit(EXIT_FAILURE); | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | std::vector<regex_t*> regs; | 
|  | 33 | for (int i = 1; i < argc; i++) { | 
|  | 34 | regex_t* re = new regex_t; | 
|  | 35 | int errcode = regcomp(re, argv[i], 0); | 
|  | 36 | if (errcode != 0) { | 
|  | 37 | size_t errbuf_size = regerror(errcode, re, NULL, 0); | 
|  | 38 | if (errbuf_size > 0) { | 
|  | 39 | char* errbuf = new char[errbuf_size]; | 
|  | 40 | regerror(errcode, re, errbuf, errbuf_size); | 
|  | 41 | fprintf(stderr, "Couldn't compile \"%s\" as a regular expression: %s\n", | 
|  | 42 | argv[i], errbuf); | 
|  | 43 | } else { | 
|  | 44 | fprintf(stderr, "Unknown compile error for \"%s\" as a regular expression!\n", argv[i]); | 
|  | 45 | } | 
|  | 46 | exit(EXIT_FAILURE); | 
|  | 47 | } | 
|  | 48 | regs.push_back(re); | 
|  | 49 | } | 
|  | 50 |  | 
| Christopher Ferris | 339ac37 | 2015-02-20 18:31:06 -0800 | [diff] [blame] | 51 | if (::testing::Benchmark::RunAll(regs) == 0) { | 
| Christopher Ferris | df4942c | 2015-02-17 19:58:53 -0800 | [diff] [blame] | 52 | fprintf(stderr, "No matching benchmarks!\n"); | 
|  | 53 | fprintf(stderr, "Available benchmarks:\n"); | 
|  | 54 | for (const auto& benchmark : ::testing::Benchmark::List()) { | 
|  | 55 | fprintf(stderr, "  %s\n", benchmark->Name().c_str()); | 
|  | 56 | } | 
|  | 57 | exit(EXIT_FAILURE); | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | return 0; | 
|  | 61 | } |