blob: 1344379136230609d887cad44a7bb0d397656ac3 [file] [log] [blame]
Lawrence Tangd34f2b12022-07-19 15:36:31 +01001/**
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"
9extern "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*/
19void 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(&section_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*/
40TEST(GenericProcessorTests, IRValid) {
41 single_section_ir_test("generic");
42}
43TEST(IA32x64Tests, IRValid) {
44 single_section_ir_test("ia32x64");
45}
46// TEST(IPFTests, IRValid) {
47// single_section_ir_test("ipf");
48// }
49TEST(ArmTests, IRValid) {
50 single_section_ir_test("arm");
51}
52TEST(MemoryTests, IRValid) {
53 single_section_ir_test("memory");
54}
55TEST(Memory2Tests, IRValid) {
56 single_section_ir_test("memory2");
57}
58TEST(PCIeTests, IRValid) {
59 single_section_ir_test("pcie");
60}
61TEST(FirmwareTests, IRValid) {
62 single_section_ir_test("firmware");
63}
64TEST(PCIBusTests, IRValid) {
65 single_section_ir_test("pcibus");
66}
67TEST(PCIDevTests, IRValid) {
68 single_section_ir_test("pcidev");
69}
70TEST(DMArGenericTests, IRValid) {
71 single_section_ir_test("dmargeneric");
72}
73TEST(DMArVtdTests, IRValid) {
74 single_section_ir_test("dmarvtd");
75}
76TEST(DMArIOMMUTests, IRValid) {
77 single_section_ir_test("dmariommu");
78}
79TEST(CCIXPERTests, IRValid) {
80 single_section_ir_test("ccixper");
81}
82TEST(CXLProtocolTests, IRValid) {
83 single_section_ir_test("cxlprotocol");
84}
85TEST(CXLComponentTests, IRValid) {
86 single_section_ir_test("cxlcomponent");
87}
88TEST(UnknownSectionTests, IRValid) {
89 single_section_ir_test("unknown");
90}
91
92//Entrypoint for the testing program.
93int main()
94{
95 testing::InitGoogleTest();
96 return RUN_ALL_TESTS();
97}