Tom Cherry | cb0f9bb | 2017-09-12 15:58:47 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #include "subcontext.h" |
| 18 | |
| 19 | #include <benchmark/benchmark.h> |
| 20 | |
| 21 | #include "test_function_map.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace init { |
| 25 | |
| 26 | static void BenchmarkSuccess(benchmark::State& state) { |
| 27 | auto subcontext = Subcontext("path", kVendorContext); |
| 28 | auto subcontext_killer = SubcontextKiller(subcontext); |
| 29 | |
| 30 | while (state.KeepRunning()) { |
| 31 | subcontext.Execute(std::vector<std::string>{"return_success"}); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | BENCHMARK(BenchmarkSuccess); |
| 36 | |
| 37 | TestFunctionMap BuildTestFunctionMap() { |
| 38 | TestFunctionMap test_function_map; |
| 39 | test_function_map.Add("return_success", 0, 0, true, |
| 40 | [](const BuiltinArguments& args) { return Success(); }); |
| 41 | |
| 42 | return test_function_map; |
| 43 | } |
| 44 | |
| 45 | } // namespace init |
| 46 | } // namespace android |
| 47 | |
| 48 | int main(int argc, char** argv) { |
| 49 | if (argc > 1 && !strcmp(basename(argv[1]), "subcontext")) { |
| 50 | auto test_function_map = android::init::BuildTestFunctionMap(); |
| 51 | return android::init::SubcontextMain(argc, argv, &test_function_map); |
| 52 | } |
| 53 | |
| 54 | ::benchmark::Initialize(&argc, argv); |
| 55 | if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; |
| 56 | ::benchmark::RunSpecifiedBenchmarks(); |
| 57 | } |