Update to odulow per maintenance bronze
[o-du/phy.git] / fhi_lib / test / common / xranlib_unit_test_main.cc
1 /*******************************************************************************
2  *
3  * <COPYRIGHT_TAG>
4  *
5  *******************************************************************************/
6 #include <rte_config.h>
7 #include <rte_eal.h>
8 #include <rte_debug.h>
9
10 #include "common.hpp"
11 #include "xran_lib_wrap.hpp"
12
13 static int parse_input_parameter(std::string executable, std::string option)
14 {
15     std::size_t delim_pos = option.find("=");
16     std::string param = option.substr(delim_pos + 1);
17
18     try
19     {
20         return std::stoi(param);
21     }
22     catch(std::logic_error &e)
23     {
24         std::cout << executable << ": invalid argument '"<< param << "' for '" << option  << "'" << std::endl;
25         std::cout << "Try '" << executable << " --usage' for more information." << std::endl;
26         exit(-1);
27     }
28 }
29
30 //xranLibWraper xranlib;
31 xranLibWraper *xranlib;
32
33 int main(int argc, char** argv) {
34     int all_test_ret = 0;
35
36     /* Enable xml output by default */
37     ::testing::GTEST_FLAG(output) = "xml:test_results.xml";
38
39     ::testing::InitGoogleTest(&argc, argv);
40
41     const std::string executable = argv[0];
42
43     for(int index = 1; index < argc; index++) {
44
45         const std::string option = argv[index];
46
47         if (option.find("--nb_repetitions=") != std::string::npos)
48         {
49             BenchmarkParameters::repetition = parse_input_parameter(executable, option);
50         }
51         else if (option.find("--nb_loops=") != std::string::npos)
52         {
53             BenchmarkParameters::loop = parse_input_parameter(executable, option);
54         }
55         else if (option.find("--cpu_nb=") != std::string::npos)
56         {
57             BenchmarkParameters::cpu_id = (unsigned) parse_input_parameter(executable, option);
58
59             if (BenchmarkParameters::cpu_id == 0)
60                 std::cout << std::endl << "Warning: Core #0 is running the VM's OS. "
61                           << "Measurements won't be accurate. It shouldn't be used!"
62                           << std::endl << std::endl;
63         }
64         /* --usage used instead of --help to avoid conflict with gtest --help */
65         else if (!option.compare("--usage"))
66         {
67             std::cout << "Usage: " << executable << " [GTEST_OPTION]... [OPTION]..." << std::endl;
68             std::cout << "Runs unittests with given gtest options." << std::endl;
69             std::cout << std::endl;
70             std::cout << "Available options: " << std::endl;
71             std::cout << "--nb_repetitions=NUMBER Sets how many times results are measured" << std::endl;
72             std::cout << "--nb_loops=NUMBER Sets how many times function is called per repetition"
73                       << std::endl;
74             std::cout << "--cpu_nb=NUMBER Sets core number to run tests on" << std::endl;
75             std::cout << "--usage Prints this message" << std::endl;
76
77             return 0;
78         }
79         else
80         {
81             std::cout << executable << ": inavlid option " << option << std::endl;
82             std::cout << "Try '" << executable << " --usage' for more information." << std::endl;
83
84             return -1;
85         }
86     }
87
88     xranlib = new xranLibWraper;
89
90     if(xranlib->SetUp() < 0) {
91         return (-1);
92         }
93
94     all_test_ret = RUN_ALL_TESTS();
95
96     xranlib->TearDown();
97
98     if(xranlib != nullptr) {
99         delete xranlib;
100         xranlib == nullptr;
101         }
102
103     return all_test_ret;
104 }
105
106
107