From 55af0a46c935aabc7e8bfcd6822135910fc75085 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 8 Dec 2020 15:52:12 +0100 Subject: [PATCH] tests: allow reading from file in perf test Change-Id: I1660ed2a0248efe139590ac278fbf29d4db2d44c --- src/stest_performance.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 1fe6635..bda50f8 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -208,16 +208,17 @@ void run_x_times(std::function func, size_t times) { std::cout << "run: " << static_cast(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; } -- 2.7.4