Remove validation bits
Discard invalid properties from json decode. JSON output should only
contain valid properties. This saves time in preventing post
processing of output for valid fields.
Ensure round trip validity with validation bits removed and required
properties populated.
Fix bugs in json decode.
Overhaul unit tests to use valijson. Add tests with static examples
to validate against schema. Use and nlohmann for better schema
validation over intrinsic libcper validation.
Example json output before:
{
"ValidationBits": {
"LevelValid": false,
"CorrectedValid": true
},
"Level": 1,
"Corrected": true
}
After:
{
"Corrected": true
}
Change-Id: I188bdc2827a57d938c22a431238fadfcdc939ab8
Signed-off-by: Aushim Nagarkatti <anagarkatti@nvidia.com>
diff --git a/generator/sections/gen-section-ia32x64.c b/generator/sections/gen-section-ia32x64.c
index 5415f02..647f77d 100644
--- a/generator/sections/gen-section-ia32x64.c
+++ b/generator/sections/gen-section-ia32x64.c
@@ -11,12 +11,13 @@
#include <libcper/generator/sections/gen-section.h>
#define IA32X64_ERROR_STRUCTURE_SIZE 64
-void *generate_ia32x64_error_structure();
+void *generate_ia32x64_error_structure(GEN_VALID_BITS_TEST_TYPE validBitsType);
size_t generate_ia32x64_context_structure(void **location);
//Generates a single pseudo-random IA32/x64 section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_ia32x64(void **location)
+size_t generate_section_ia32x64(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Set up for generation of error/context structures.
UINT16 error_structure_num = rand() % 4 + 1;
@@ -27,7 +28,8 @@
//Generate the structures.
for (int i = 0; i < error_structure_num; i++) {
- error_structures[i] = generate_ia32x64_error_structure();
+ error_structures[i] =
+ generate_ia32x64_error_structure(validBitsType);
}
for (int i = 0; i < context_structure_num; i++) {
context_structure_lengths[i] =
@@ -51,6 +53,11 @@
//Set header information.
UINT64 *validation = (UINT64 *)section;
*validation &= 0x3;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x3;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x2;
+ }
*validation |= error_structure_num << 2;
*validation |= context_structure_num << 8;
@@ -75,7 +82,7 @@
}
//Generates a single IA32/x64 error structure. Must later be freed.
-void *generate_ia32x64_error_structure()
+void *generate_ia32x64_error_structure(GEN_VALID_BITS_TEST_TYPE validBitsType)
{
UINT8 *error_structure =
generate_random_bytes(IA32X64_ERROR_STRUCTURE_SIZE);
@@ -83,6 +90,11 @@
//Set error structure reserved space to zero.
UINT64 *validation = (UINT64 *)(error_structure + 16);
*validation &= 0x1F;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x1F;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x15;
+ }
//Create a random type of error structure.
EFI_GUID *guid = (EFI_GUID *)error_structure;
@@ -95,7 +107,7 @@
sizeof(EFI_GUID));
//Set reserved space to zero.
- *check_info &= ~0x20FF00;
+ *check_info = ~0x20FF00;
*check_info &= 0x3FFFFFFF;
break;
@@ -105,7 +117,7 @@
sizeof(EFI_GUID));
//Set reserved space to zero.
- *check_info &= ~0x20FF00;
+ *check_info = ~0x20FF00;
*check_info &= 0x3FFFFFFF;
break;
@@ -115,7 +127,7 @@
sizeof(EFI_GUID));
//Set reserved space to zero.
- *check_info &= ~0x20F800;
+ *check_info = ~0x20F800;
*check_info &= 0x7FFFFFFFF;
break;
@@ -125,7 +137,7 @@
sizeof(EFI_GUID));
//Set reserved space to zero.
- *check_info &= ~0xFFE0;
+ *check_info = ~0xFFC0;
*check_info &= 0xFFFFFF;
break;
}