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;
}
}
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;
}
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) {
case 'c':
input_filename = optarg;
break;
+ case 'v':
+ verify = true;
+ break;
}
}
}
__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;
}
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" },
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;
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;
}
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) {
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;
}
}
}
__internal_init_once();
- run_tests(input_filename.c_str(), count, choice);
+ run_tests(input_filename.c_str(), verify, count);
return 0;
}