f245034425c9201b0fd5e55670432bbd1e1202c2
[o-du/phy.git] / fhi_lib / test / common / xranlib_unit_test_main.cc
1 /******************************************************************************\r
2 *\r
3 *   Copyright (c) 2019 Intel.\r
4 *\r
5 *   Licensed under the Apache License, Version 2.0 (the "License");\r
6 *   you may not use this file except in compliance with the License.\r
7 *   You may obtain a copy of the License at\r
8 *\r
9 *       http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 *   Unless required by applicable law or agreed to in writing, software\r
12 *   distributed under the License is distributed on an "AS IS" BASIS,\r
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 *   See the License for the specific language governing permissions and\r
15 *   limitations under the License.\r
16 *\r
17 *******************************************************************************/\r
18 \r
19 #include <rte_config.h>\r
20 #include <rte_eal.h>\r
21 #include <rte_debug.h>\r
22 \r
23 #include "common.hpp"\r
24 #include "xran_lib_wrap.hpp"\r
25 \r
26 static int parse_input_parameter(std::string executable, std::string option)\r
27 {\r
28     std::size_t delim_pos = option.find("=");\r
29     std::string param = option.substr(delim_pos + 1);\r
30 \r
31     try\r
32     {\r
33         return std::stoi(param);\r
34     }\r
35     catch(std::logic_error &e)\r
36     {\r
37         std::cout << executable << ": invalid argument '"<< param << "' for '" << option  << "'" << std::endl;\r
38         std::cout << "Try '" << executable << " --usage' for more information." << std::endl;\r
39         exit(-1);\r
40     }\r
41 }\r
42 \r
43 //xranLibWraper xranlib;\r
44 xranLibWraper *xranlib;\r
45 \r
46 int main(int argc, char** argv) {\r
47     int all_test_ret = 0;\r
48 \r
49     /* Enable xml output by default */\r
50     ::testing::GTEST_FLAG(output) = "xml:test_results.xml";\r
51 \r
52     ::testing::InitGoogleTest(&argc, argv);\r
53 \r
54     const std::string executable = argv[0];\r
55 \r
56     for(int index = 1; index < argc; index++) {\r
57 \r
58         const std::string option = argv[index];\r
59 \r
60         if (option.find("--nb_repetitions=") != std::string::npos)\r
61         {\r
62             BenchmarkParameters::repetition = parse_input_parameter(executable, option);\r
63         }\r
64         else if (option.find("--nb_loops=") != std::string::npos)\r
65         {\r
66             BenchmarkParameters::loop = parse_input_parameter(executable, option);\r
67         }\r
68         else if (option.find("--cpu_nb=") != std::string::npos)\r
69         {\r
70             BenchmarkParameters::cpu_id = (unsigned) parse_input_parameter(executable, option);\r
71 \r
72             if (BenchmarkParameters::cpu_id == 0)\r
73                 std::cout << std::endl << "Warning: Core #0 is running the VM's OS. "\r
74                           << "Measurements won't be accurate. It shouldn't be used!"\r
75                           << std::endl << std::endl;\r
76         }\r
77         /* --usage used instead of --help to avoid conflict with gtest --help */\r
78         else if (!option.compare("--usage"))\r
79         {\r
80             std::cout << "Usage: " << executable << " [GTEST_OPTION]... [OPTION]..." << std::endl;\r
81             std::cout << "Runs unittests with given gtest options." << std::endl;\r
82             std::cout << std::endl;\r
83             std::cout << "Available options: " << std::endl;\r
84             std::cout << "--nb_repetitions=NUMBER Sets how many times results are measured" << std::endl;\r
85             std::cout << "--nb_loops=NUMBER Sets how many times function is called per repetition"\r
86                       << std::endl;\r
87             std::cout << "--cpu_nb=NUMBER Sets core number to run tests on" << std::endl;\r
88             std::cout << "--usage Prints this message" << std::endl;\r
89 \r
90             return 0;\r
91         }\r
92         else\r
93         {\r
94             std::cout << executable << ": inavlid option " << option << std::endl;\r
95             std::cout << "Try '" << executable << " --usage' for more information." << std::endl;\r
96 \r
97             return -1;\r
98         }\r
99     }\r
100 \r
101     xranlib = new xranLibWraper;\r
102 \r
103     if(xranlib->SetUp() < 0) {\r
104         return (-1);\r
105         }\r
106 \r
107     all_test_ret = RUN_ALL_TESTS();\r
108 \r
109     xranlib->TearDown();\r
110 \r
111     if(xranlib != nullptr) {\r
112         delete xranlib;\r
113         xranlib == nullptr;\r
114         }\r
115 \r
116     return all_test_ret;\r
117 }\r
118 \r
119 \r
120 \r