"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<Test> &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 <typename DB, typename Array>
}
}
+template <typename DB>
+void send_performance_test(const DB &db, const std::vector<Test> &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<void(void)> func, size_t times) {
clock_t begin = clock();
for (size_t i = 0; i < times; i++)
std::cout << "run: " << static_cast<double>(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;
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<Test> 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 <config_xml>} <count>" << std::endl;
+ std::cout << "usage: " << name << " [-v] [-r] {--system|--session|-c <config_xml>} <count>" << 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;
}
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) {
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]);
}
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;
}