blob: d5e8f5b55c2aab5a1d4292241eacb7c66b09b5b3 [file] [log] [blame]
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01001#include <stdio.h>
Lawrence Tang368e0b42022-07-07 14:31:06 +01002#include "../cper-parse.h"
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01003#include "json.h"
Lawrence Tang8a2d7372022-07-12 16:44:49 +01004#include "../json-schema.h"
Lawrence Tang1b0b00e2022-07-05 10:33:10 +01005
6int main(int argc, char* argv[]) {
Lawrence Tangf0f95572022-07-07 16:56:22 +01007
8 //Get a handle for the log file.
9 FILE* cper_file = fopen(argv[1], "r");
10 if (cper_file == NULL) {
11 printf("Could not open CPER record, file handle returned null.");
12 return -1;
13 }
14
15 json_object* ir = cper_to_ir(cper_file);
16 fclose(cper_file);
17
Lawrence Tang8a2d7372022-07-12 16:44:49 +010018 const char* json_output = json_object_to_json_string(ir);
19 printf("\n%s\n", json_output);
20
21 //Test JSON validator.
22 if (argc >= 3)
23 {
24 printf("Validating output with specification %s...\n", argv[2]);
Lawrence Tang8f793ac2022-07-13 10:17:09 +010025 validate_schema_debug_enable();
26 char* error_message = malloc(JSON_ERROR_MSG_MAX_LEN);
Lawrence Tang8a2d7372022-07-12 16:44:49 +010027 if (!validate_schema_from_file(argv[2], ir, error_message))
28 {
29 printf("Validation failed: %s\n", error_message);
30 }
31 else
32 {
33 printf("Validation passed!\n");
34 }
35 }
Lawrence Tang1b0b00e2022-07-05 10:33:10 +010036}