From: Kushagra K Date: Thu, 29 Apr 2021 11:00:00 +0000 (+0530) Subject: tests: add generated performance tests X-Git-Tag: accepted/tizen/7.0/unified/20221110.060304~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F89%2F257689%2F4;p=platform%2Fcore%2Fsystem%2Flibdbuspolicy.git tests: add generated performance tests Enhancing performance test by incorporating VD Tizen image specific Item Send rules in default context to performance test at runtime. Verification Results: sh-3.2# ./stest_performance --system -r 10 SERIALIZED: Default ItemSend Rule Count: 578 run: 0.001137 Change-Id: I7050d19a3ef50119254e417a2ef05b5bf4ecd911 --- diff --git a/src/stest_performance.cpp b/src/stest_performance.cpp index 410cbc7..d4dce04 100644 --- a/src/stest_performance.cpp +++ b/src/stest_performance.cpp @@ -173,9 +173,28 @@ struct Test test_send_to_nonexistent[]={ "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]); +void create_test(const StorageBackendSerialized &storage, std::vector &tests) { + const auto &backend = storage.getBackend(); + const auto &file = backend.getFile(); + const auto &send_set = backend.fileGetSendSet(file); + const auto &context_default = backend.setGetContextDefault(send_set); + const auto &items = backend.policyGetItems(context_default); + for (auto iterator = backend.containerGetIterator(items); + iterator != backend.containerGetIteratorEnd(items); + iterator++) { + const auto &item = *iterator; + backend.itemSrGetName(item); + Test t{backend.decisionItemGetDecision(backend.itemGetDecisionItem(item)), + 0, 0, "User::Shell", + backend.stringGetCStr(backend.itemSrGetName(item)), + backend.stringGetCStr(backend.itemSrGetPath(item)), + backend.stringGetCStr(backend.itemSrGetInterface(item)), + backend.stringGetCStr(backend.itemSrGetMember(item)), + backend.itemSrGetMessageType(item)}; + tests.push_back(t); + } + + std::cout << "Default ItemSend Rule Count: " << tests.size() << std::endl; } template @@ -199,6 +218,19 @@ void send_prefix_test(const DB &db, const Array &tests) } } +template +void send_performance_test(const DB &db, const std::vector &r_tests) +{ + for (const auto &test : r_tests) { + KdbusBusNames names; + MatchItemSend m_item(test.interface, test.member, test.path, test.type, + names.addSpaceSeparatedNames(test.destination)); + + /* Just find the decision from the default context, no need to check for validity */ + db.getDecisionItemContextDefault(m_item); + } +} + void run_x_times(std::function func, size_t times) { clock_t begin = clock(); for (size_t i = 0; i < times; i++) @@ -208,7 +240,7 @@ 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, const std::string &serialized, bool verify, size_t count, bool worst) { +void run_tests(const char *conf_file, const std::string &serialized, bool real, bool verify, size_t count, bool worst) { Serializer serializer; StorageBackendSerialized storage; @@ -224,22 +256,24 @@ void run_fb(const char *conf_file, const std::string &serialized, bool verify, s storage.init(serialized.c_str(), verify); } - printf("SERIALIZED:\n"); - if (!worst) - run_x_times([&storage](){ send_prefix_test(storage, tests); }, count); - else + std::cout << "SERIALIZED:" << std::endl; + if (worst) { run_x_times([&storage](){ send_prefix_test(storage, test_send_to_nonexistent); }, count); -} - -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); + } else if (real) { + std::vector r_tests; + create_test(storage, r_tests); + run_x_times([&storage, &r_tests](){ send_performance_test(storage, r_tests); }, count); + } else { + run_x_times([&storage](){ send_prefix_test(storage, tests); }, count); + } } void print_help(const char *name) { std::cout << std::endl; - std::cout << "usage: " << name << " [-v] {--system|--session|-c } " << std::endl; + std::cout << "usage: " << name << " [-v] [-r] {--system|--session|-c } " << std::endl; std::cout << std::endl; std::cout << " -v - Verify" << std::endl; + std::cout << " -r - Generate test from the actual policy rules" << std::endl; std::cout << std::endl; } @@ -257,10 +291,11 @@ int main(int argc, char *argv[]) size_t count = 100; bool verify = false; bool worst = false; + bool real = false; while (1) { int option_index; - c = getopt_long(argc, argv, "vwc:i:", options, &option_index); + c = getopt_long(argc, argv, "rvwc:i:", options, &option_index); if (c == -1) break; switch(c) { @@ -269,21 +304,24 @@ int main(int argc, char *argv[]) input_filename = session_bus_conf_file_primary(); break; case 'c': - input_filename = optarg; - break; + input_filename = optarg; + break; case 'v': - verify = true; - break; + verify = true; + break; case 'w': - worst = true; - break; + worst = true; + break; case 'i': - input_filename_serialized = optarg; - break; + input_filename_serialized = optarg; + break; + case 'r': + real = true; + break; } } - if (optind < argc) { + if (optind < argc && !(real && worst)) { count = std::stoi(argv[optind]); } else { print_help(argv[0]); @@ -291,7 +329,7 @@ int main(int argc, char *argv[]) } tslog::init(); - run_tests(input_filename.c_str(), input_filename_serialized, verify, count, worst); + run_tests(input_filename.c_str(), input_filename_serialized, real, verify, count, worst); return 0; }