1 // Copyright (C) 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <getopt.h>
16 #include <unistd.h>
17
18 #include <cstring>
19 #include <string>
20
21 #include <ditto/arg_parser.h>
22 #include <ditto/instruction.h>
23 #include <ditto/logger.h>
24 #include <ditto/parser.h>
25 #include <ditto/tracer.h>
26
main(int argc,char ** argv)27 int main(int argc, char** argv) {
28 dittosuite::Tracer tracer;
29 dittosuite::CmdArguments arguments = dittosuite::ParseArguments(argc, argv);
30 dittosuite::Instruction::SetArgv(argv);
31 dittosuite::Instruction::SetArgc(argc);
32 auto& parser = dittosuite::Parser::GetParser();
33
34 auto benchmark = arguments.embedded_benchmark.size()
35 ? parser.ParseEmbedded(arguments.embedded_benchmark, arguments.parameters)
36 : parser.ParseFile(arguments.file_path, arguments.parameters);
37 tracer.StartSession(std::move(benchmark));
38
39 auto init = dittosuite::Parser::GetParser().GetInit();
40 if (init != nullptr) {
41 init->SetUp();
42 init->Run();
43 init->TearDown();
44 }
45
46 auto main = dittosuite::Parser::GetParser().GetMain();
47 main->SetUp();
48 tracer.Start("Benchmark");
49 main->Run();
50 tracer.End("Benchmark");
51 main->TearDown();
52
53 auto result = main->CollectResults("");
54 result->Print(arguments.results_output, "");
55
56 auto clean_up = dittosuite::Parser::GetParser().GetCleanUp();
57 if (clean_up != nullptr) {
58 clean_up->SetUp();
59 clean_up->Run();
60 clean_up->TearDown();
61 }
62 return 0;
63 }
64