Json daccor
json daccor is a json-schema validation library that accepts json-c
objects as input, and seems to be designed for openwrt, a system
with very similar requirements to BMCs.
Using this library has several motivations. First, it keeps
libcper as a C application so integrations aren't required to provide
a c++ toolchain to be able to run unit tests.
Next, it means that we avoid an "expensive" conversion in unit tests
from json-c -> nlohmann just so we can use a third library, valijson
In terms of dependency count, it drops one dependency.
(nlohmann+valijson) to (json daccor)
Finally, it means that in the future versions of the library, we
can allow json-schema verification as an option in the library
itself, which would allow us to give a CLI option for verifying
schema on any arbitrary output (helping in debugging).
Testing to see if it will work and what improvements it makes
Change-Id: I1c00bf2ef9b898b2e5decd90b749c784fb4de109
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/tests/fuzz_cper_buf_to_ir.cpp b/tests/fuzz_cper_buf_to_ir.cpp
index 4baef7b..b947782 100644
--- a/tests/fuzz_cper_buf_to_ir.cpp
+++ b/tests/fuzz_cper_buf_to_ir.cpp
@@ -1,3 +1,4 @@
+#include <cassert>
#include "libcper/cper-parse.h"
#include "test-utils.hpp"
@@ -7,19 +8,11 @@
if (ir == NULL) {
return 0;
}
- char *str = strdup(json_object_to_json_string(ir));
- nlohmann::json jsonData = nlohmann::json::parse(str, nullptr, false);
- free(str);
- assert(jsonData.is_discarded() == false);
- std::string error_message;
- static std::unique_ptr<valijson::Schema> schema =
- load_schema(AddRequiredProps::NO, 0);
-
- int valid = schema_validate_from_file(*schema, jsonData, error_message);
+ int valid = schema_validate_from_file(ir, 0 /* single_section */,
+ /*all_valid_bits*/ 0);
if (!valid) {
- std::cout << "JSON: " << jsonData.dump(4) << std::endl;
- std::cout << "Error: " << error_message << std::endl;
+ printf("JSON: %s\n", json_object_to_json_string(ir));
}
assert(valid);
json_object_put(ir);