Switch to modular includes for generator.
Change-Id: Ie2926938912400b86c32733f04d59377c447c66c
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index 3322372..c8819f6 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -9,7 +9,7 @@
#include <string.h>
#include "../edk/Cper.h"
#include "gen-utils.h"
-#include "sections/gen-sections.h"
+#include "sections/gen-section.h"
#include "cper-generate.h"
EFI_ERROR_SECTION_DESCRIPTOR *generate_section_descriptor(char *type,
@@ -150,83 +150,26 @@
descriptor->FruString[i] = 0x0;
}
- //Set section type GUID based on type name.
- if (strcmp(type, "generic") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiProcessorGenericErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ia32x64") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiIa32X64ProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ipf") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiIpfProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "arm") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiArmProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "memory") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiPlatformMemoryErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "memory2") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiPlatformMemoryError2SectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcie") == 0)
- memcpy(&descriptor->SectionType, &gEfiPcieErrorSectionGuid,
- sizeof(EFI_GUID));
- else if (strcmp(type, "firmware") == 0)
- memcpy(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid,
- sizeof(EFI_GUID));
- else if (strcmp(type, "pcibus") == 0)
- memcpy(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid,
- sizeof(EFI_GUID));
- else if (strcmp(type, "pcidev") == 0)
- memcpy(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid,
- sizeof(EFI_GUID));
- else if (strcmp(type, "dmargeneric") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiDMArGenericErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmarvtd") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiDirectedIoDMArErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmariommu") == 0)
- memcpy(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid,
- sizeof(EFI_GUID));
- else if (strcmp(type, "ccixper") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiCcixPerLogErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "cxlprotocol") == 0)
- memcpy(&descriptor->SectionType,
- &gEfiCxlProtocolErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "cxlcomponent") == 0) {
- //Choose between the different CXL component type GUIDs.
- int componentType = rand() % 5;
- switch (componentType) {
- case 0:
- memcpy(&descriptor->SectionType,
- &gEfiCxlGeneralMediaErrorSectionGuid,
- sizeof(EFI_GUID));
- break;
- case 1:
- memcpy(&descriptor->SectionType,
- &gEfiCxlDramEventErrorSectionGuid,
- sizeof(EFI_GUID));
- break;
- case 2:
- memcpy(&descriptor->SectionType,
- &gEfiCxlPhysicalSwitchErrorSectionGuid,
- sizeof(EFI_GUID));
- break;
- case 3:
- memcpy(&descriptor->SectionType,
- &gEfiCxlVirtualSwitchErrorSectionGuid,
- sizeof(EFI_GUID));
- break;
- default:
- memcpy(&descriptor->SectionType,
- &gEfiCxlMldPortErrorSectionGuid,
- sizeof(EFI_GUID));
- break;
+ //If section type is not "unknown", set section type GUID based on type name.
+ int section_guid_found = 0;
+ if (strcmp(type, "unknown") == 0) {
+ section_guid_found = 1;
+ } else {
+ //Find the appropriate GUID for this section name.
+ for (int i = 0; i < generator_definitions_len; i++) {
+ if (strcmp(type, generator_definitions[i].ShortName) ==
+ 0) {
+ memcpy(&descriptor->SectionType,
+ generator_definitions[i].Guid,
+ sizeof(EFI_GUID));
+ section_guid_found = 1;
+ break;
+ }
}
- } else if (strcmp(type, "unknown") != 0) {
+ }
+
+ //Undefined section, show error.
+ if (!section_guid_found) {
//Undefined section, show error.
printf("Undefined section type '%s' provided. See 'cper-generate --help' for command information.\n",
type);
@@ -242,43 +185,26 @@
//The length of the section.
size_t length = 0;
- //Switch on the type, generate accordingly.
- if (strcmp(type, "generic") == 0)
- length = generate_section_generic(location);
- else if (strcmp(type, "ia32x64") == 0)
- length = generate_section_ia32x64(location);
- // else if (strcmp(type, "ipf") == 0)
- // length = generate_section_ipf(location);
- else if (strcmp(type, "arm") == 0)
- length = generate_section_arm(location);
- else if (strcmp(type, "memory") == 0)
- length = generate_section_memory(location);
- else if (strcmp(type, "memory2") == 0)
- length = generate_section_memory2(location);
- else if (strcmp(type, "pcie") == 0)
- length = generate_section_pcie(location);
- else if (strcmp(type, "firmware") == 0)
- length = generate_section_firmware(location);
- else if (strcmp(type, "pcibus") == 0)
- length = generate_section_pci_bus(location);
- else if (strcmp(type, "pcidev") == 0)
- length = generate_section_pci_dev(location);
- else if (strcmp(type, "dmargeneric") == 0)
- length = generate_section_dmar_generic(location);
- else if (strcmp(type, "dmarvtd") == 0)
- length = generate_section_dmar_vtd(location);
- else if (strcmp(type, "dmariommu") == 0)
- length = generate_section_dmar_iommu(location);
- else if (strcmp(type, "ccixper") == 0)
- length = generate_section_ccix_per(location);
- else if (strcmp(type, "cxlprotocol") == 0)
- length = generate_section_cxl_protocol(location);
- else if (strcmp(type, "cxlcomponent") == 0)
- length = generate_section_cxl_component(location);
- else if (strcmp(type, "unknown") == 0)
+ //If the section name is "unknown", simply generate a random bytes section.
+ int section_generated = 0;
+ if (strcmp(type, "unknown") == 0) {
length = generate_random_section(location, rand() % 256);
- else {
- //Undefined section, show error.
+ section_generated = 1;
+ } else {
+ //Function defined section, switch on the type, generate accordingly.
+ for (int i = 0; i < generator_definitions_len; i++) {
+ if (strcmp(type, generator_definitions[i].ShortName) ==
+ 0) {
+ length = generator_definitions[i].Generate(
+ location);
+ section_generated = 1;
+ break;
+ }
+ }
+ }
+
+ //If we didn't find a section generator for the given name, error out.
+ if (!section_generated) {
printf("Undefined section type '%s' given to generate. See 'cper-generate --help' for command information.\n",
type);
return 0;
diff --git a/generator/sections/gen-section-arm.c b/generator/sections/gen-section-arm.c
index 040ad24..7ec94a7 100644
--- a/generator/sections/gen-section-arm.c
+++ b/generator/sections/gen-section-arm.c
@@ -8,7 +8,7 @@
#include <string.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
#define ARM_ERROR_INFO_SIZE 32
void* generate_arm_error_info();
diff --git a/generator/sections/gen-section-ccix-per.c b/generator/sections/gen-section-ccix-per.c
index 72bc1e0..c820d72 100644
--- a/generator/sections/gen-section-ccix-per.c
+++ b/generator/sections/gen-section-ccix-per.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-cxl-component.c b/generator/sections/gen-section-cxl-component.c
index 2b8d18a..5fb6789 100644
--- a/generator/sections/gen-section-cxl-component.c
+++ b/generator/sections/gen-section-cxl-component.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-cxl-protocol.c b/generator/sections/gen-section-cxl-protocol.c
index 3ff6fbb..71a1105 100644
--- a/generator/sections/gen-section-cxl-protocol.c
+++ b/generator/sections/gen-section-cxl-protocol.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-dmar.c b/generator/sections/gen-section-dmar.c
index 91da101..66cc70a 100644
--- a/generator/sections/gen-section-dmar.c
+++ b/generator/sections/gen-section-dmar.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-firmware.c b/generator/sections/gen-section-firmware.c
index 7b47e54..7ba93ee 100644
--- a/generator/sections/gen-section-firmware.c
+++ b/generator/sections/gen-section-firmware.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//Generates a single pseudo-random firmware error section, saving the resulting address to the given
//location. Returns the size of the newly created section.
diff --git a/generator/sections/gen-section-generic.c b/generator/sections/gen-section-generic.c
index 618f9b3..e9a2ea0 100644
--- a/generator/sections/gen-section-generic.c
+++ b/generator/sections/gen-section-generic.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//Generates a single pseudo-random generic processor section, saving the resulting address to the given
//location. Returns the size of the newly created section.
diff --git a/generator/sections/gen-section-ia32x64.c b/generator/sections/gen-section-ia32x64.c
index a78bfcb..a01d2b7 100644
--- a/generator/sections/gen-section-ia32x64.c
+++ b/generator/sections/gen-section-ia32x64.c
@@ -8,7 +8,7 @@
#include <string.h>
#include "../../edk/Cper.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
#define IA32X64_ERROR_STRUCTURE_SIZE 64
void* generate_ia32x64_error_structure();
diff --git a/generator/sections/gen-section-memory.c b/generator/sections/gen-section-memory.c
index 63621da..9d405a4 100644
--- a/generator/sections/gen-section-memory.c
+++ b/generator/sections/gen-section-memory.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-pci-bus.c b/generator/sections/gen-section-pci-bus.c
index dc2381d..1aee19a 100644
--- a/generator/sections/gen-section-pci-bus.c
+++ b/generator/sections/gen-section-pci-bus.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-pci-dev.c b/generator/sections/gen-section-pci-dev.c
index 7913b9a..339f98c 100644
--- a/generator/sections/gen-section-pci-dev.c
+++ b/generator/sections/gen-section-pci-dev.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
//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.
diff --git a/generator/sections/gen-section-pcie.c b/generator/sections/gen-section-pcie.c
index cace516..aa1be6b 100644
--- a/generator/sections/gen-section-pcie.c
+++ b/generator/sections/gen-section-pcie.c
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include "../../edk/BaseTypes.h"
#include "../gen-utils.h"
-#include "gen-sections.h"
+#include "gen-section.h"
#define PCIE_PORT_TYPES (int []){0, 1, 4, 5, 6, 7, 8, 9, 10}
diff --git a/generator/sections/gen-section.c b/generator/sections/gen-section.c
new file mode 100644
index 0000000..012f88f
--- /dev/null
+++ b/generator/sections/gen-section.c
@@ -0,0 +1,30 @@
+/**
+ * Describes available section generators to the CPER generator.
+ *
+ * Author: Lawrence.Tang@arm.com
+ **/
+#include "gen-section.h"
+
+CPER_GENERATOR_DEFINITION generator_definitions[] = {
+ {&gEfiProcessorGenericErrorSectionGuid, "generic", generate_section_generic},
+ {&gEfiIa32X64ProcessorErrorSectionGuid, "ia32x64", generate_section_ia32x64},
+ {&gEfiArmProcessorErrorSectionGuid, "arm", generate_section_arm},
+ {&gEfiPlatformMemoryErrorSectionGuid, "memory", generate_section_memory},
+ {&gEfiPlatformMemoryError2SectionGuid, "memory2", generate_section_memory2},
+ {&gEfiPcieErrorSectionGuid, "pcie", generate_section_pcie},
+ {&gEfiFirmwareErrorSectionGuid, "firmware", generate_section_firmware},
+ {&gEfiPciBusErrorSectionGuid, "pcibus", generate_section_pci_bus},
+ {&gEfiPciDevErrorSectionGuid, "pcidev", generate_section_pci_dev},
+ {&gEfiDMArGenericErrorSectionGuid, "dmargeneric", generate_section_dmar_generic},
+ {&gEfiDirectedIoDMArErrorSectionGuid, "dmarvtd", generate_section_dmar_vtd},
+ {&gEfiIommuDMArErrorSectionGuid, "dmariommu", generate_section_dmar_iommu},
+ {&gEfiCcixPerLogErrorSectionGuid, "ccixper", generate_section_ccix_per},
+ {&gEfiCxlProtocolErrorSectionGuid, "cxlprotocol", generate_section_cxl_protocol},
+ {&gEfiCxlGeneralMediaErrorSectionGuid, "cxlcomponent-media", generate_section_cxl_component},
+ {&gEfiCxlDramEventErrorSectionGuid, "cxlcomponent-dram", generate_section_cxl_component},
+ {&gEfiCxlMemoryModuleErrorSectionGuid, "cxlcomponent-memory", generate_section_cxl_component},
+ {&gEfiCxlPhysicalSwitchErrorSectionGuid, "cxlcomponent-pswitch", generate_section_cxl_component},
+ {&gEfiCxlVirtualSwitchErrorSectionGuid, "cxlcomponent-vswitch", generate_section_cxl_component},
+ {&gEfiCxlMldPortErrorSectionGuid, "cxlcomponent-mld", generate_section_cxl_component},
+};
+const size_t generator_definitions_len = sizeof(generator_definitions) / sizeof(CPER_GENERATOR_DEFINITION);
\ No newline at end of file
diff --git a/generator/sections/gen-sections.h b/generator/sections/gen-section.h
similarity index 69%
rename from generator/sections/gen-sections.h
rename to generator/sections/gen-section.h
index 50f9350..ac0a024 100644
--- a/generator/sections/gen-sections.h
+++ b/generator/sections/gen-section.h
@@ -2,7 +2,9 @@
#define GEN_SECTIONS_H
#include <stdlib.h>
+#include "../../edk/Cper.h"
+//Section generator function predefinitions.
size_t generate_section_generic(void** location);
size_t generate_section_ia32x64(void** location);
size_t generate_section_arm(void** location);
@@ -19,4 +21,14 @@
size_t generate_section_cxl_protocol(void** location);
size_t generate_section_cxl_component(void** location);
+//Definition structure for a single CPER section generator.
+typedef struct {
+ EFI_GUID* Guid;
+ const char* ShortName;
+ size_t (*Generate)(void**);
+} CPER_GENERATOR_DEFINITION;
+
+extern CPER_GENERATOR_DEFINITION generator_definitions[];
+extern const size_t generator_definitions_len;
+
#endif
\ No newline at end of file
diff --git a/tests/ir-tests.cpp b/tests/ir-tests.cpp
index 1017e75..0c9dad8 100644
--- a/tests/ir-tests.cpp
+++ b/tests/ir-tests.cpp
@@ -265,11 +265,11 @@
//CXL Component tests.
TEST(CXLComponentTests, IRValid)
{
- cper_log_section_dual_ir_test("cxlcomponent");
+ cper_log_section_dual_ir_test("cxlcomponent-media");
}
TEST(CXLComponentTests, BinaryEqual)
{
- cper_log_section_dual_binary_test("cxlcomponent");
+ cper_log_section_dual_binary_test("cxlcomponent-media");
}
//Unknown section tests.