tests: add 'worst case' performance test 23/207223/2
authorAdrian Szyndela <adrian.s@samsung.com>
Wed, 29 May 2019 09:38:33 +0000 (11:38 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Thu, 30 May 2019 12:47:12 +0000 (14:47 +0200)
Change-Id: I4d14eeb5bea1e7054674793ebd8d0861c876eb59

src/stest_performance.cpp

index 2f1c643..bbb60a7 100644 (file)
@@ -145,13 +145,18 @@ struct Test tests[]={
        TC(Decision::ALLOW, "org.tizen.test.dest_prefix.do org.tizen.test.dest_prefix.ao.ao"),
 };
 
+struct Test test_send_to_nonexistent[]={
+       {Decision::DENY, ROOT, ROOT, "User::Shell", "no.such.destination", "/no/such/path",
+       "no.such.interface", "no_such_method", ldp_xml_parser::MessageType::METHOD_CALL}
+};
+
 void test_print(const struct Test* t, Decision result) {
        printf("uid = %lu, gid = %lu, label = %s, destination = %s, expected = %s, result = %s",
                   (unsigned long)t->user, (unsigned long)t->group, t->label, t->destination, DECISIONS[t->expected_result], DECISIONS[result]);
 }
 
-template <typename DB>
-void send_prefix_test(const DB &db)
+template <typename DB, typename Array>
+void send_prefix_test(const DB &db, const Array &tests)
 {
        for (const auto &test : tests) {
                KdbusBusNames names;
@@ -180,7 +185,7 @@ 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) {
+void run_fb(const char *conf_file, bool verify, size_t count, bool worst) {
        Serializer serializer;
        size_t size;
        uint8_t *buff = serializer.serialize(conf_file, size);
@@ -199,11 +204,14 @@ void run_fb(const char *conf_file, bool verify, size_t count) {
        storage.init(file);
 
        printf("FLATBUFFERS:\n");
-       run_x_times([&storage](){ send_prefix_test(storage); }, count);
+       if (!worst)
+               run_x_times([&storage](){ send_prefix_test(storage, tests); }, count);
+       else
+               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) {
-               run_fb(conf_file, verify, c);
+void run_tests(const char *conf_file, bool verify, size_t c, bool worst) {
+       run_fb(conf_file, verify, c, worst);
 }
 
 void print_help(const char *name) {
@@ -216,7 +224,8 @@ void print_help(const char *name) {
 
 static const struct option options[] {
        {"system", no_argument, 0, 0},
-       {"session", no_argument, 0, 0}
+       {"session", no_argument, 0, 0},
+       {nullptr, 0, nullptr, 0}
 };
 
 int main(int argc, char *argv[])
@@ -225,10 +234,11 @@ int main(int argc, char *argv[])
        std::string input_filename = system_bus_conf_file_primary();
        size_t count = 100;
        bool verify = false;
+       bool worst = false;
 
        while (1) {
                int option_index;
-               c = getopt_long(argc, argv, "vc:", options, &option_index);
+               c = getopt_long(argc, argv, "vwc:", options, &option_index);
                if (c == -1)
                        break;
                switch(c) {
@@ -242,6 +252,9 @@ int main(int argc, char *argv[])
                case 'v':
                          verify = true;
                          break;
+               case 'w':
+                         worst = true;
+                         break;
                }
        }
 
@@ -253,7 +266,7 @@ int main(int argc, char *argv[])
        }
 
        tslog::init();
-       run_tests(input_filename.c_str(), verify, count);
+       run_tests(input_filename.c_str(), verify, count, worst);
 
        return 0;
 }