1 /******************************************************************************
\r
3 * Copyright (c) 2019 Intel.
\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
9 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 *******************************************************************************/
\r
19 #include <rte_config.h>
\r
20 #include <rte_eal.h>
\r
21 #include <rte_debug.h>
\r
23 #include "common.hpp"
\r
24 #include "xran_lib_wrap.hpp"
\r
26 static int parse_input_parameter(std::string executable, std::string option)
\r
28 std::size_t delim_pos = option.find("=");
\r
29 std::string param = option.substr(delim_pos + 1);
\r
33 return std::stoi(param);
\r
35 catch(std::logic_error &e)
\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
43 //xranLibWraper xranlib;
\r
44 xranLibWraper *xranlib;
\r
46 int main(int argc, char** argv) {
\r
47 int all_test_ret = 0;
\r
49 /* Enable xml output by default */
\r
50 ::testing::GTEST_FLAG(output) = "xml:test_results.xml";
\r
52 ::testing::InitGoogleTest(&argc, argv);
\r
54 const std::string executable = argv[0];
\r
56 for(int index = 1; index < argc; index++) {
\r
58 const std::string option = argv[index];
\r
60 if (option.find("--nb_repetitions=") != std::string::npos)
\r
62 BenchmarkParameters::repetition = parse_input_parameter(executable, option);
\r
64 else if (option.find("--nb_loops=") != std::string::npos)
\r
66 BenchmarkParameters::loop = parse_input_parameter(executable, option);
\r
68 else if (option.find("--cpu_nb=") != std::string::npos)
\r
70 BenchmarkParameters::cpu_id = (unsigned) parse_input_parameter(executable, option);
\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
77 /* --usage used instead of --help to avoid conflict with gtest --help */
\r
78 else if (!option.compare("--usage"))
\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
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
94 std::cout << executable << ": inavlid option " << option << std::endl;
\r
95 std::cout << "Try '" << executable << " --usage' for more information." << std::endl;
\r
101 xranlib = new xranLibWraper;
\r
103 if(xranlib->SetUp() < 0) {
\r
107 all_test_ret = RUN_ALL_TESTS();
\r
109 xranlib->TearDown();
\r
111 if(xranlib != nullptr) {
\r
113 xranlib == nullptr;
\r
116 return all_test_ret;
\r