Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Defines tests for validating CPER-JSON IR output from the cper-parse library. |
| 3 | * |
| 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include "gtest/gtest.h" |
| 8 | #include "test-utils.hpp" |
| 9 | extern "C" { |
| 10 | #include "json.h" |
| 11 | #include "../cper-parse.h" |
| 12 | #include "../json-schema.h" |
| 13 | #include "../generator/cper-generate.h" |
| 14 | } |
| 15 | |
| 16 | /* |
| 17 | * Test templates. |
| 18 | */ |
| 19 | void single_section_ir_test(const char* section_name) |
| 20 | { |
| 21 | //Generate CPER record for generic processor. |
| 22 | char* buf; |
| 23 | size_t size; |
| 24 | FILE* record = generate_record_memstream(§ion_name, 1, &buf, &size); |
| 25 | |
| 26 | //Convert to IR, free resources. |
| 27 | json_object* ir = cper_to_ir(record); |
| 28 | fclose(record); |
| 29 | free(buf); |
| 30 | |
| 31 | //Validate against schema. |
| 32 | char error_message[JSON_ERROR_MSG_MAX_LEN] = {0}; |
| 33 | int valid = validate_schema_from_file("./specification/cper-json.json", ir, error_message); |
| 34 | ASSERT_TRUE(valid) << error_message; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * Single section tests. |
| 39 | */ |
| 40 | TEST(GenericProcessorTests, IRValid) { |
| 41 | single_section_ir_test("generic"); |
| 42 | } |
| 43 | TEST(IA32x64Tests, IRValid) { |
| 44 | single_section_ir_test("ia32x64"); |
| 45 | } |
| 46 | // TEST(IPFTests, IRValid) { |
| 47 | // single_section_ir_test("ipf"); |
| 48 | // } |
| 49 | TEST(ArmTests, IRValid) { |
| 50 | single_section_ir_test("arm"); |
| 51 | } |
| 52 | TEST(MemoryTests, IRValid) { |
| 53 | single_section_ir_test("memory"); |
| 54 | } |
| 55 | TEST(Memory2Tests, IRValid) { |
| 56 | single_section_ir_test("memory2"); |
| 57 | } |
| 58 | TEST(PCIeTests, IRValid) { |
| 59 | single_section_ir_test("pcie"); |
| 60 | } |
| 61 | TEST(FirmwareTests, IRValid) { |
| 62 | single_section_ir_test("firmware"); |
| 63 | } |
| 64 | TEST(PCIBusTests, IRValid) { |
| 65 | single_section_ir_test("pcibus"); |
| 66 | } |
| 67 | TEST(PCIDevTests, IRValid) { |
| 68 | single_section_ir_test("pcidev"); |
| 69 | } |
| 70 | TEST(DMArGenericTests, IRValid) { |
| 71 | single_section_ir_test("dmargeneric"); |
| 72 | } |
| 73 | TEST(DMArVtdTests, IRValid) { |
| 74 | single_section_ir_test("dmarvtd"); |
| 75 | } |
| 76 | TEST(DMArIOMMUTests, IRValid) { |
| 77 | single_section_ir_test("dmariommu"); |
| 78 | } |
| 79 | TEST(CCIXPERTests, IRValid) { |
| 80 | single_section_ir_test("ccixper"); |
| 81 | } |
| 82 | TEST(CXLProtocolTests, IRValid) { |
| 83 | single_section_ir_test("cxlprotocol"); |
| 84 | } |
| 85 | TEST(CXLComponentTests, IRValid) { |
| 86 | single_section_ir_test("cxlcomponent"); |
| 87 | } |
| 88 | TEST(UnknownSectionTests, IRValid) { |
| 89 | single_section_ir_test("unknown"); |
| 90 | } |
| 91 | |
| 92 | //Entrypoint for the testing program. |
| 93 | int main() |
| 94 | { |
| 95 | testing::InitGoogleTest(); |
| 96 | return RUN_ALL_TESTS(); |
| 97 | } |