tests: add -v (verify) command line parameter 43/201043/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 7 Mar 2019 11:22:36 +0000 (12:22 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 7 Mar 2019 14:22:42 +0000 (15:22 +0100)
Change-Id: Iaf03cab80eecc12839610121786abfb3a1d102c9

src/stest_load_perf.cpp
src/stest_performance.cpp

index 2794a15..13f3b58 100644 (file)
@@ -40,35 +40,43 @@ bool run_xml(const char *conf_file) {
        return __internal_init(SYSTEM_BUS, conf_file) == 0;
 }
 
-bool run_xml_plus_fb(const char *conf_file) {
+bool run_xml_plus_fb(const char *conf_file, bool verify) {
        Serializer serializer;
        size_t size;
        uint8_t *buff = serializer.serialize(conf_file, size);
 
+       if (verify) {
+               auto verifier = flatbuffers::Verifier(buff, size);
+               if (!FB::VerifyFileBuffer(verifier)) {
+                       std::cout << "verification of serialized data: failed" << std::endl;
+                       return false;
+               }
+       }
+
        const FB::File *file = FB::GetFile(buff);
 
        StorageBackendSerialized storage;
        return storage.init(file);
 }
 
-bool run_fb(const char *conf_file) {
+bool run_fb(const char *conf_file, bool verify) {
        StorageBackendSerialized sbs;
-       return sbs.init(conf_file, true);
+       return sbs.init(conf_file, verify);
 }
 
-void run_tests(const char *conf_file, const char *conf_bin, size_t c, Choice ch) {
+void run_tests(const char *conf_file, const char *conf_bin, size_t c, Choice ch, bool verify) {
        if (ch == Choice::ALL || ch == Choice::XML) {
                if (!measure([&conf_file, c]() { return run_xml(conf_file); }, c, "XML")) {
                        std::cout << "ERROR" << std::endl;
                }
        }
        if (ch == Choice::ALL || ch == Choice::FB) {
-               if (!measure([&conf_bin, c]() { return run_fb(conf_bin); }, c, "FB")) {
+               if (!measure([&conf_bin, c, verify]() { return run_fb(conf_bin, verify); }, c, "FB")) {
                        std::cout << "ERROR" << std::endl;
                }
        }
        if (ch == Choice::ALL || ch == Choice::XMLplusFB)
-               if (!measure([&conf_file, c]() { return run_xml_plus_fb(conf_file); }, c, "FB after XML")) {
+               if (!measure([&conf_file, c, verify]() { return run_xml_plus_fb(conf_file, verify); }, c, "FB after XML")) {
                        std::cout << "ERROR" << std::endl;
                }
 }
@@ -81,6 +89,7 @@ void print_help(const char *name) {
        std::cout << "       -x              - XML" << std::endl;
        std::cout << "       -d              - FB after XML" << std::endl;
        std::cout << "       -a <config_bin> - All tests" << std::endl;
+       std::cout << "       -v              - Verify" << std::endl;
        std::cout << std::endl;
 }
 
@@ -96,10 +105,11 @@ int main(int argc, char *argv[])
        std::string binary_file = "";
        size_t count = 100;
        Choice choice = Choice::NONE;
+       bool verify = false;
 
        while (1) {
                int option_index;
-               c = getopt_long(argc, argv, "f:xda:c:", options, &option_index);
+               c = getopt_long(argc, argv, "f:xda:c:v", options, &option_index);
                if (c == -1)
                        break;
                switch(c) {
@@ -140,6 +150,9 @@ int main(int argc, char *argv[])
                case 'c':
                        input_filename = optarg;
                        break;
+               case 'v':
+                       verify = true;
+                       break;
                }
        }
 
@@ -151,7 +164,7 @@ int main(int argc, char *argv[])
        }
 
        __internal_init_once();
-       run_tests(input_filename.c_str(), binary_file.c_str(), count, choice);
+       run_tests(input_filename.c_str(), binary_file.c_str(), count, choice, verify);
 
        return 0;
 }
index a98f139..75221c6 100644 (file)
 using namespace ldp_xml_parser;
 using namespace ldp_serialized;
 
-enum class Choice {
-       ALL,
-       XML,
-       FB,
-};
-
 std::map<Decision, const char*> DECISIONS {
        { Decision::ANY,   "ANY"   },
        { Decision::ALLOW, "ALLOW" },
@@ -187,19 +181,19 @@ 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_policy_db(const char *conf_file, size_t count) {
-       __internal_init(SYSTEM_BUS, conf_file);
-       auto &db = policy_checker_system().getPolicyDb();
-
-       printf("XML:\n");
-       run_x_times([&db](){ send_prefix_test(db); }, count);
-}
-
-void run_fb(const char *conf_file, size_t count) {
+void run_fb(const char *conf_file, bool verify, size_t count) {
        Serializer serializer;
        size_t size;
        uint8_t *buff = serializer.serialize(conf_file, size);
 
+       if (verify) {
+               auto verifier = flatbuffers::Verifier(buff, size);
+               if (!FB::VerifyFileBuffer(verifier)) {
+                       std::cout << "verification of serialized data: failed" << std::endl;
+                       return;
+               }
+       }
+
        const FB::File *file = FB::GetFile(buff);
 
        StorageBackendSerialized storage;
@@ -209,21 +203,15 @@ void run_fb(const char *conf_file, size_t count) {
        run_x_times([&storage](){ send_prefix_test(storage); }, count);
 }
 
-void run_tests(const char *conf_file, size_t c, Choice ch) {
-       if (ch == Choice::ALL || ch == Choice::XML)
-               run_policy_db(conf_file, c);
-
-       if (ch == Choice::ALL || ch == Choice::FB)
-               run_fb(conf_file, c);
+void run_tests(const char *conf_file, bool verify, size_t c) {
+               run_fb(conf_file, verify, c);
 }
 
 void print_help(const char *name) {
        std::cout << std::endl;
-       std::cout << "usage: " << name << " {-f|-x|-a} {--system|--session|-c <config_xml>} <count>" << std::endl;
+       std::cout << "usage: " << name << " [-v] {--system|--session|-c <config_xml>} <count>" << std::endl;
        std::cout << std::endl;
-       std::cout << "       -f - Flatbuffers" << std::endl;
-       std::cout << "       -x - XML" << std::endl;
-       std::cout << "       -a - Flatbuffers and XML" << std::endl;
+       std::cout << "       -v - Verify" << std::endl;
        std::cout << std::endl;
 }
 
@@ -237,11 +225,11 @@ int main(int argc, char *argv[])
        int c;
        std::string input_filename = system_bus_conf_file_primary();
        size_t count = 100;
-       Choice choice = Choice::ALL;
+       bool verify = false;
 
        while (1) {
                int option_index;
-               c = getopt_long(argc, argv, "fxac:", options, &option_index);
+               c = getopt_long(argc, argv, "vc:", options, &option_index);
                if (c == -1)
                        break;
                switch(c) {
@@ -249,15 +237,12 @@ int main(int argc, char *argv[])
                        if (option_index == 1)
                                input_filename = session_bus_conf_file_primary();
                        break;
-               case 'f':
-                         choice = Choice::FB;
-                         break;
-               case 'x':
-                         choice = Choice::XML;
-                         break;
                case 'c':
                          input_filename = optarg;
                          break;
+               case 'v':
+                         verify = true;
+                         break;
                }
        }
 
@@ -269,7 +254,7 @@ int main(int argc, char *argv[])
        }
 
        __internal_init_once();
-       run_tests(input_filename.c_str(), count, choice);
+       run_tests(input_filename.c_str(), verify, count);
 
        return 0;
 }