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/cper-generate-cli.c b/generator/cper-generate-cli.c
index c9882c2..8c570ab 100644
--- a/generator/cper-generate-cli.c
+++ b/generator/cper-generate-cli.c
@@ -25,6 +25,7 @@
char *out_file = NULL;
char *single_section = NULL;
char **sections = NULL;
+ const GEN_VALID_BITS_TEST_TYPE randomValidbitsSet = RANDOM_VALID;
UINT16 num_sections = 0;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--out") == 0 && i < argc - 1) {
@@ -73,9 +74,11 @@
//Which type are we generating?
if (single_section != NULL && sections == NULL) {
- generate_single_section_record(single_section, cper_file);
+ generate_single_section_record(single_section, cper_file,
+ randomValidbitsSet);
} else if (sections != NULL && single_section == NULL) {
- generate_cper_record(sections, num_sections, cper_file);
+ generate_cper_record(sections, num_sections, cper_file,
+ randomValidbitsSet);
} else {
//Invalid arguments.
printf("Invalid argument. Either both '--sections' and '--single-section' were set, or neither. For command information, refer to 'cper-generate --help'.\n");
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index 7b60848..8675a78 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -16,19 +16,22 @@
const size_t *lengths,
int index,
int num_sections);
-size_t generate_section(void **location, char *type);
+size_t generate_section(void **location, char *type,
+ GEN_VALID_BITS_TEST_TYPE validBitsType);
//Generates a CPER record with the given section types, outputting to the given stream.
-void generate_cper_record(char **types, UINT16 num_sections, FILE *out)
+void generate_cper_record(char **types, UINT16 num_sections, FILE *out,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Initialise randomiser.
- init_random();
+ init_random(0);
//Generate the sections.
void *sections[num_sections];
size_t section_lengths[num_sections];
for (int i = 0; i < num_sections; i++) {
- section_lengths[i] = generate_section(sections + i, types[i]);
+ section_lengths[i] =
+ generate_section(sections + i, types[i], validBitsType);
if (section_lengths[i] == 0) {
//Error encountered, exit.
printf("Error encountered generating section %d of type '%s', length returned zero.\n",
@@ -92,11 +95,12 @@
}
//Generates a single section record for the given section, and outputs to file.
-void generate_single_section_record(char *type, FILE *out)
+void generate_single_section_record(char *type, FILE *out,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Generate a section.
void *section = NULL;
- size_t section_len = generate_section(§ion, type);
+ size_t section_len = generate_section(§ion, type, validBitsType);
//Generate a descriptor, correct the offset.
EFI_ERROR_SECTION_DESCRIPTOR *section_descriptor =
@@ -185,7 +189,8 @@
}
//Generates a single CPER section given the string type.
-size_t generate_section(void **location, char *type)
+size_t generate_section(void **location, char *type,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//The length of the section.
size_t length = 0;
@@ -201,7 +206,7 @@
if (strcmp(type, generator_definitions[i].ShortName) ==
0) {
length = generator_definitions[i].Generate(
- location);
+ location, validBitsType);
section_generated = 1;
break;
}
diff --git a/generator/gen-utils.c b/generator/gen-utils.c
index 03f6b8d..46642b2 100644
--- a/generator/gen-utils.c
+++ b/generator/gen-utils.c
@@ -44,5 +44,5 @@
//Initializes the random seed for rand() using the current time.
void init_random()
{
- srand((unsigned int)time(NULL));
+ srand(1);
}
diff --git a/generator/sections/gen-section-ampere.c b/generator/sections/gen-section-ampere.c
index 3ffe2f5..a28cdf1 100644
--- a/generator/sections/gen-section-ampere.c
+++ b/generator/sections/gen-section-ampere.c
@@ -12,8 +12,10 @@
//Generates a single pseudo-random Ampere error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_ampere(void **location)
+size_t generate_section_ampere(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
+ (void)validBitsType;
//Create random bytes.
size_t size = sizeof(EFI_AMPERE_ERROR_DATA);
UINT8 *section = generate_random_bytes(size);
diff --git a/generator/sections/gen-section-arm.c b/generator/sections/gen-section-arm.c
index 5043741..c181663 100644
--- a/generator/sections/gen-section-arm.c
+++ b/generator/sections/gen-section-arm.c
@@ -5,18 +5,20 @@
**/
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <libcper/BaseTypes.h>
#include <libcper/generator/gen-utils.h>
#include <libcper/generator/sections/gen-section.h>
#define ARM_ERROR_INFO_SIZE 32
-void *generate_arm_error_info();
+void *generate_arm_error_info(GEN_VALID_BITS_TEST_TYPE validBitsType);
size_t generate_arm_context_info(void **location);
//Generates a single pseudo-random ARM processor section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_arm(void **location)
+size_t generate_section_arm(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Set up for generation of error/context structures.
UINT16 error_structure_num = rand() % 4 + 1; //Must be at least 1.
@@ -27,7 +29,7 @@
//Generate the structures.
for (int i = 0; i < error_structure_num; i++) {
- error_structures[i] = generate_arm_error_info();
+ error_structures[i] = generate_arm_error_info(validBitsType);
}
for (int i = 0; i < context_structure_num; i++) {
context_structure_lengths[i] =
@@ -35,7 +37,7 @@
}
//Determine a random amount of vendor specific info.
- int vendor_info_len = rand() % 16;
+ size_t vendor_info_len = rand() % 16 + 4;
//Create the section as a whole.
size_t total_len = 40 + (error_structure_num * ARM_ERROR_INFO_SIZE);
@@ -56,8 +58,13 @@
*(section + 12) = rand() % 4;
//Reserved zero bytes.
- UINT64 *validation = (UINT64 *)section;
- *validation &= 0x7;
+ UINT32 *validation = (UINT32 *)section;
+ *validation &= 0xF;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0xF;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0xA;
+ }
UINT32 *running_state = (UINT32 *)(section + 32);
*running_state &= 0x1;
memset(section + 13, 0, 3);
@@ -76,13 +83,21 @@
cur_pos += context_structure_lengths[i];
}
+ //vendor specific
+ for (size_t i = 0; i < vendor_info_len; i++) {
+ //Ensure only ascii is used so we don't
+ // fail base64E
+ *cur_pos = rand() % 127 + 1;
+ cur_pos += 1;
+ }
+
//Set return values and exit.
*location = section;
return total_len;
}
//Generates a single pseudo-random ARM error info structure. Must be later freed.
-void *generate_arm_error_info()
+void *generate_arm_error_info(GEN_VALID_BITS_TEST_TYPE validBitsType)
{
UINT8 *error_info = generate_random_bytes(ARM_ERROR_INFO_SIZE);
@@ -91,12 +106,17 @@
*(error_info + 1) = ARM_ERROR_INFO_SIZE;
//Type of error.
- UINT8 error_type = rand() % 4;
+ UINT8 error_type = rand() % 3;
*(error_info + 4) = error_type;
//Reserved bits for error information.
UINT16 *validation = (UINT16 *)(error_info + 2);
*validation &= 0x1F;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x1F;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x15;
+ }
//Make sure reserved bits are zero according with the type.
UINT64 *error_subinfo = (UINT64 *)(error_info + 8);
@@ -105,11 +125,25 @@
case 0:
case 1:
*error_subinfo &= 0xFFFFFFF;
+ //Reserved bits for cache/tlb.
+ UINT16 *val_cache = (UINT16 *)(error_info + 8);
+ if (validBitsType == ALL_VALID) {
+ *val_cache = 0x7F;
+ } else if (validBitsType == SOME_VALID) {
+ *val_cache = 0x55;
+ }
break;
//Bus
case 2:
*error_subinfo &= 0xFFFFFFFFFFF;
+ UINT16 *val_bus = (UINT16 *)(error_info + 8);
+ if (validBitsType == ALL_VALID) {
+ *val_bus = 0xFFF;
+ } else if (validBitsType == SOME_VALID) {
+ *val_bus = 0x555;
+ }
+
break;
//Microarch/other.
@@ -117,6 +151,10 @@
break;
}
+ //flags
+ UINT8 *flags = (UINT8 *)(error_info + 7);
+ *flags &= 0xF;
+
return error_info;
}
@@ -175,6 +213,14 @@
int total_size = 8 + reg_size;
UINT16 *context_info = (UINT16 *)generate_random_bytes(total_size);
+ //UEFI spec is not clear about bit 15 in the
+ // reg type 8 section. This sets it to 0 to
+ // avoid confusion for now.
+ if (reg_type == 8) {
+ UINT8 *reg_decode = (UINT8 *)context_info;
+ *(reg_decode + 9) &= 0x7F;
+ }
+
//Set header information.
*(context_info + 1) = reg_type;
*((UINT32 *)(context_info + 2)) = reg_size;
diff --git a/generator/sections/gen-section-ccix-per.c b/generator/sections/gen-section-ccix-per.c
index 0784d34..e648cba 100644
--- a/generator/sections/gen-section-ccix-per.c
+++ b/generator/sections/gen-section-ccix-per.c
@@ -11,7 +11,8 @@
//Generates a single pseudo-random CCIX PER error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_ccix_per(void **location)
+size_t generate_section_ccix_per(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create a random length for the CCIX PER log.
//The log attached here does not necessarily conform to the CCIX specification, and is simply random.
@@ -25,6 +26,11 @@
UINT32 *validation = (UINT32 *)(bytes + 4);
*validation &= 0x7; //Validation bits 3-63.
*(validation + 1) = 0; //Validation bits 3-63.
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x7;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x5;
+ }
*(bytes + 13) &= 0x1F; //CCIX port ID bits 5-7.
UINT16 *reserved = (UINT16 *)(bytes + 14);
*reserved = 0; //Reserved bytes 14-15.
diff --git a/generator/sections/gen-section-cxl-component.c b/generator/sections/gen-section-cxl-component.c
index 395defb..615a152 100644
--- a/generator/sections/gen-section-cxl-component.c
+++ b/generator/sections/gen-section-cxl-component.c
@@ -11,7 +11,8 @@
//Generates a single pseudo-random CXL component error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_cxl_component(void **location)
+size_t generate_section_cxl_component(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create a random length for the CXL component event log.
//The logs attached here do not necessarily conform to the specification, and are simply random.
@@ -24,6 +25,11 @@
//Set reserved areas to zero.
UINT32 *validation = (UINT32 *)(bytes + 4);
*validation &= 0x7;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x7;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x5;
+ }
*(validation + 1) = 0;
UINT8 *slot_number = (UINT8 *)(bytes + 21);
*slot_number &= ~0x7; //Device ID slot number bits 0-2.
diff --git a/generator/sections/gen-section-cxl-protocol.c b/generator/sections/gen-section-cxl-protocol.c
index 5139005..1918d68 100644
--- a/generator/sections/gen-section-cxl-protocol.c
+++ b/generator/sections/gen-section-cxl-protocol.c
@@ -11,7 +11,8 @@
//Generates a single pseudo-random CXL protocol error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_cxl_protocol(void **location)
+size_t generate_section_cxl_protocol(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create a random length for the CXL DVSEC and CXL error log.
//The logs attached here do not necessarily conform to the specification, and are simply random.
@@ -28,7 +29,12 @@
//Set reserved areas to zero.
UINT64 *validation = (UINT64 *)bytes;
- *validation &= 0x3F; //Validation bits 6-63.
+ *validation &= 0x67;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x67;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x25;
+ }
for (int i = 0; i < 7; i++) {
*(bytes + 9 + i) = 0; //Reserved bytes 9-15.
}
@@ -38,6 +44,8 @@
for (int i = 0; i < 3; i++) {
*(bytes + 21 + i) = 0; //CXL agent address bytes 5-7.
}
+ *validation |=
+ 0x18; //Device Serial Number depends on agent type
}
*(bytes + 34) &= ~0x7; //Device ID byte 10 bits 0-2.
diff --git a/generator/sections/gen-section-dmar.c b/generator/sections/gen-section-dmar.c
index dc34696..7c2a85f 100644
--- a/generator/sections/gen-section-dmar.c
+++ b/generator/sections/gen-section-dmar.c
@@ -11,8 +11,10 @@
//Generates a single pseudo-random generic DMAr error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_dmar_generic(void **location)
+size_t generate_section_dmar_generic(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
+ (void)validBitsType;
//Create random bytes.
int size = 32;
UINT8 *bytes = generate_random_bytes(size);
@@ -35,8 +37,10 @@
//Generates a single pseudo-random VT-d DMAr error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_dmar_vtd(void **location)
+size_t generate_section_dmar_vtd(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
+ (void)validBitsType;
//Create random bytes.
int size = 144;
UINT8 *bytes = generate_random_bytes(size);
@@ -59,8 +63,10 @@
//Generates a single pseudo-random IOMMU DMAr error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_dmar_iommu(void **location)
+size_t generate_section_dmar_iommu(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
+ (void)validBitsType;
//Create random bytes.
int size = 144;
UINT8 *bytes = generate_random_bytes(size);
diff --git a/generator/sections/gen-section-firmware.c b/generator/sections/gen-section-firmware.c
index e482a6b..6ec4b88 100644
--- a/generator/sections/gen-section-firmware.c
+++ b/generator/sections/gen-section-firmware.c
@@ -11,8 +11,10 @@
//Generates a single pseudo-random firmware error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_firmware(void **location)
+size_t generate_section_firmware(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
+ (void)validBitsType;
//Create random bytes.
int size = 32;
UINT8 *bytes = generate_random_bytes(size);
diff --git a/generator/sections/gen-section-generic.c b/generator/sections/gen-section-generic.c
index 7baf325..54de52e 100644
--- a/generator/sections/gen-section-generic.c
+++ b/generator/sections/gen-section-generic.c
@@ -11,21 +11,28 @@
//Generates a single pseudo-random generic processor section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_generic(void **location)
+size_t generate_section_generic(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create random bytes.
size_t size = generate_random_section(location, 192);
//Set reserved locations to zero.
UINT8 *start_byte = (UINT8 *)*location;
- *((UINT64 *)start_byte) &= 0xFFF;
+ UINT64 *validation = (UINT64 *)*location;
+ *validation &= 0x1FFF;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x1FFF;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x1555;
+ }
*(start_byte + 12) &= 0x7;
*((UINT16 *)(start_byte + 14)) = 0x0;
//Ensure CPU brand string does not terminate early.
for (int i = 0; i < 128; i++) {
UINT8 *byte = start_byte + 24 + i;
- //CPU brand can only be ASCII
+ //Ensure only ascii is used
*byte = rand() % 127 + 1;
//Null terminate last byte.
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;
}
diff --git a/generator/sections/gen-section-memory.c b/generator/sections/gen-section-memory.c
index 475d6d0..a45f0ce 100644
--- a/generator/sections/gen-section-memory.c
+++ b/generator/sections/gen-section-memory.c
@@ -11,7 +11,8 @@
//Generates a single pseudo-random platform memory error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_memory(void **location)
+size_t generate_section_memory(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create random bytes.
int size = 80;
@@ -19,8 +20,14 @@
//Set reserved areas to zero.
UINT64 *validation = (UINT64 *)bytes;
- *validation &= 0x2FFFFF; //Validation 22-63
- *(bytes + 73) &= ~0x1C; //Extended bits 2-4
+ //Validation 22-63 reserved. 19/20=0 for bank
+ *validation &= 0x27FFFF;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x27FFFF;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x275555;
+ }
+ *(bytes + 73) &= ~0x1C; //Extended bits 2-4
//Fix values that could be above range.
*(bytes + 72) = rand() % 16; //Memory error type
@@ -35,7 +42,8 @@
//Generates a single pseudo-random memory 2 error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_memory2(void **location)
+size_t generate_section_memory2(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create random bytes.
int size = 96;
@@ -43,8 +51,14 @@
//Set reserved areas to zero.
UINT64 *validation = (UINT64 *)bytes;
- *validation &= 0x2FFFFF; //Validation 22-63
- *(bytes + 63) = 0; //Reserved byte 63
+ //Validation 22-63, 20/21 is 0 since 6 is valid
+ *validation &= 0xFFFFF;
+ if (validBitsType == ALL_VALID) {
+ *validation = 0xFFFFF;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x55555;
+ }
+ *(bytes + 63) = 0; //Reserved byte 63
//Fix values that could be above range.
*(bytes + 61) = rand() % 16; //Memory error type
diff --git a/generator/sections/gen-section-nvidia.c b/generator/sections/gen-section-nvidia.c
index 3d2b706..a06f545 100644
--- a/generator/sections/gen-section-nvidia.c
+++ b/generator/sections/gen-section-nvidia.c
@@ -13,8 +13,10 @@
//Generates a single pseudo-random NVIDIA error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_nvidia(void **location)
+size_t generate_section_nvidia(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
+ (void)validBitsType;
const char *signatures[] = {
"DCC-ECC", "DCC-COH", "HSS-BUSY", "HSS-IDLE",
"CLink", "C2C", "C2C-IP-FAIL", "L0 RESET",
diff --git a/generator/sections/gen-section-pci-bus.c b/generator/sections/gen-section-pci-bus.c
index 1e424bf..ca0f255 100644
--- a/generator/sections/gen-section-pci-bus.c
+++ b/generator/sections/gen-section-pci-bus.c
@@ -11,7 +11,8 @@
//Generates a single pseudo-random PCI/PCI-X bus error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_pci_bus(void **location)
+size_t generate_section_pci_bus(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create random bytes.
int size = 72;
@@ -20,6 +21,11 @@
//Set reserved areas to zero.
UINT64 *validation = (UINT64 *)bytes;
*validation &= 0x1FF; //Validation 9-63
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x1FF;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x155;
+ }
UINT32 *reserved = (UINT32 *)(bytes + 20);
*reserved = 0;
UINT64 *bus_command = (UINT64 *)(bytes + 40);
diff --git a/generator/sections/gen-section-pci-dev.c b/generator/sections/gen-section-pci-dev.c
index 999739a..6deac59 100644
--- a/generator/sections/gen-section-pci-dev.c
+++ b/generator/sections/gen-section-pci-dev.c
@@ -11,7 +11,8 @@
//Generates a single pseudo-random PCI component error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_pci_dev(void **location)
+size_t generate_section_pci_dev(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Generate how many register pairs will be attached to this section.
UINT32 num_memory_pairs = rand() % 4;
@@ -24,7 +25,12 @@
//Set reserved areas to zero.
UINT64 *validation = (UINT64 *)bytes;
- *validation &= 0x1F; //Validation 5-63
+ *validation &= 0x1F; //Validation 5-63
+ if (validBitsType == ALL_VALID) {
+ *validation = 0x1F;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x15;
+ }
for (int i = 0; i < 5; i++) {
*(bytes + 27 + i) = 0; //Bytes 11-15 of ID info.
}
diff --git a/generator/sections/gen-section-pcie.c b/generator/sections/gen-section-pcie.c
index eaf050c..db9dfd9 100644
--- a/generator/sections/gen-section-pcie.c
+++ b/generator/sections/gen-section-pcie.c
@@ -13,7 +13,8 @@
//Generates a single pseudo-random PCIe error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
-size_t generate_section_pcie(void **location)
+size_t generate_section_pcie(void **location,
+ GEN_VALID_BITS_TEST_TYPE validBitsType)
{
//Create random bytes.
int size = 208;
@@ -21,7 +22,12 @@
//Set reserved areas to zero.
UINT64 *validation = (UINT64 *)bytes;
- *validation &= 0xFF; //Validation 8-63
+ *validation &= 0xFF; //Validation 8-63
+ if (validBitsType == ALL_VALID) {
+ *validation = 0xFF;
+ } else if (validBitsType == SOME_VALID) {
+ *validation = 0x55;
+ }
UINT32 *version = (UINT32 *)(bytes + 12);
*version &= 0xFFFF; //Version bytes 2-3
UINT32 *reserved = (UINT32 *)(bytes + 20);