tests: allow reading from file in perf test 28/249428/1
authorAdrian Szyndela <adrian.s@samsung.com>
Tue, 8 Dec 2020 14:52:12 +0000 (15:52 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 11 Dec 2020 09:12:21 +0000 (10:12 +0100)
Change-Id: I1660ed2a0248efe139590ac278fbf29d4db2d44c

src/stest_performance.cpp

index 1fe6635..bda50f8 100644 (file)
@@ -208,16 +208,17 @@ void run_x_times(std::function<void(void)> func, size_t times) {
        std::cout << "run: " << static_cast<double>(end - begin)/CLOCKS_PER_SEC << std::endl;
 }
 
-void run_fb(const char *conf_file, bool verify, size_t count, bool worst) {
+void run_fb(const char *conf_file, const std::string &serialized, bool verify, size_t count, bool worst) {
        Serializer serializer;
-       size_t size;
-       auto buff = serializer.serialize(conf_file, size);
-
-       if (verify)
-               std::cerr << "verification not supported at the moment" << std::endl;
 
        StorageBackendSerialized storage;
-       storage.initFromData(buff, size);
+       if (serialized.empty()) {
+               size_t size;
+               auto buff = serializer.serialize(conf_file, size);
+               storage.initFromData(buff, size, verify);
+       } else {
+               storage.init(serialized.c_str(), verify);
+       }
 
        printf("SERIALIZED:\n");
        if (!worst)
@@ -226,8 +227,8 @@ void run_fb(const char *conf_file, bool verify, size_t count, bool worst) {
                run_x_times([&storage](){ send_prefix_test(storage, test_send_to_nonexistent); }, count);
 }
 
-void run_tests(const char *conf_file, bool verify, size_t c, bool worst) {
-       run_fb(conf_file, verify, c, worst);
+void run_tests(const char *conf_file, const std::string &serialized, bool verify, size_t c, bool worst) {
+       run_fb(conf_file, serialized, verify, c, worst);
 }
 
 void print_help(const char *name) {
@@ -248,13 +249,14 @@ int main(int argc, char *argv[])
 {
        int c;
        std::string input_filename = system_bus_conf_file_primary();
+       std::string input_filename_serialized;
        size_t count = 100;
        bool verify = false;
        bool worst = false;
 
        while (1) {
                int option_index;
-               c = getopt_long(argc, argv, "vwc:", options, &option_index);
+               c = getopt_long(argc, argv, "vwc:i:", options, &option_index);
                if (c == -1)
                        break;
                switch(c) {
@@ -271,6 +273,9 @@ int main(int argc, char *argv[])
                case 'w':
                          worst = true;
                          break;
+               case 'i':
+                         input_filename_serialized = optarg;
+                         break;
                }
        }
 
@@ -282,7 +287,7 @@ int main(int argc, char *argv[])
        }
 
        tslog::init();
-       run_tests(input_filename.c_str(), verify, count, worst);
+       run_tests(input_filename.c_str(), input_filename_serialized, verify, count, worst);
 
        return 0;
 }