blob: b30e2ecea9f46a3db387d689470738196152fedb [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.
Ed Tanousfedd4572024-07-12 13:56:00 -07003 *
Lawrence Tangd34f2b12022-07-19 15:36:31 +01004 * Author: Lawrence.Tang@arm.com
5 **/
6
Ed Tanousa3663052025-03-16 12:54:36 -07007#include <gtest/gtest.h>
Lawrence Tangd34f2b12022-07-19 15:36:31 +01008#include "test-utils.hpp"
Ed Tanousa3663052025-03-16 12:54:36 -07009#include <cctype>
Ed Tanousa2dce4b2025-03-05 15:33:06 -080010#include <charconv>
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080011#include <filesystem>
Ed Tanousa2dce4b2025-03-05 15:33:06 -080012#include <format>
Ed Tanousa3663052025-03-16 12:54:36 -070013#include <fstream>
14#include <json.h>
15#include <libcper/cper-parse.h>
16#include <libcper/generator/cper-generate.h>
17#include <libcper/generator/sections/gen-section.h>
18#include <libcper/json-schema.h>
19#include <libcper/sections/cper-section.h>
Lawrence Tangd34f2b12022-07-19 15:36:31 +010020
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080021namespace fs = std::filesystem;
22
Lawrence Tangd34f2b12022-07-19 15:36:31 +010023/*
24* Test templates.
25*/
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080026static const GEN_VALID_BITS_TEST_TYPE allValidbitsSet = ALL_VALID;
27static const GEN_VALID_BITS_TEST_TYPE fixedValidbitsSet = SOME_VALID;
28static const int GEN_EXAMPLES = 0;
29
30void cper_create_examples(const char *section_name)
31{
32 //Generate full CPER record for the given type.
33 fs::path file_path = LIBCPER_EXAMPLES;
34 file_path /= section_name;
Ed Tanousa2dce4b2025-03-05 15:33:06 -080035 fs::path cper_out = file_path.replace_extension("cperhex");
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080036 fs::path json_out = file_path.replace_extension("json");
37
38 char *buf;
39 size_t size;
40 FILE *record = generate_record_memstream(&section_name, 1, &buf, &size,
41 0, fixedValidbitsSet);
42
43 // Write example CPER to disk
44 std::ofstream outFile(cper_out, std::ios::binary);
45 if (!outFile.is_open()) {
46 std::cerr << "Failed to create/open CPER output file: "
47 << cper_out << std::endl;
48 return;
49 }
50
Ed Tanousa2dce4b2025-03-05 15:33:06 -080051 std::vector<unsigned char> file_data;
52 fseek(record, 0, SEEK_END);
53 size_t file_size = ftell(record);
54 rewind(record);
55 file_data.resize(file_size);
56 if (fread(file_data.data(), 1, file_data.size(), record) != file_size) {
57 std::cerr << "Failed to read CPER data from memstream."
58 << std::endl;
59 FAIL();
60 return;
61 }
62 for (size_t index = 0; index < file_data.size(); index++) {
63 outFile << std::format("{:02x}", file_data[index]);
64 if (index % 30 == 29) {
65 outFile << "\n";
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080066 }
67 }
68 outFile.close();
69
70 //Convert to IR, free resources.
71 rewind(record);
72 json_object *ir = cper_to_ir(record);
73 if (ir == NULL) {
74 std::cerr << "Empty JSON from CPER bin" << std::endl;
75 FAIL();
76 return;
77 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080078
79 //Write json output to disk
Ed Tanousa3663052025-03-16 12:54:36 -070080 json_object_to_file_ext(json_out.c_str(), ir, JSON_C_TO_STRING_PRETTY);
81 json_object_put(ir);
82
83 fclose(record);
84 free(buf);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080085}
86
Ed Tanousa2dce4b2025-03-05 15:33:06 -080087std::vector<unsigned char> string_to_binary(const std::string &source)
88{
89 std::vector<unsigned char> retval;
90 bool uppernibble = true;
91 for (const char c : source) {
92 unsigned char val = 0;
93 if (c == '\n') {
94 continue;
95 }
96 std::from_chars_result r = std::from_chars(&c, &c + 1, val, 16);
97 EXPECT_TRUE(r.ec == std::error_code())
98 << "Invalid hex character in test file: " << c;
99
100 if (uppernibble) {
101 retval.push_back(val << 4);
102 } else {
103 retval.back() += val;
104 }
105 uppernibble = !uppernibble;
106 }
107 return retval;
108}
109
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800110//Tests fixed CPER sections for IR validity with an example set.
111void cper_example_section_ir_test(const char *section_name)
112{
113 //Open CPER record for the given type.
114 fs::path fpath = LIBCPER_EXAMPLES;
115 fpath /= section_name;
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800116 fs::path cper = fpath.replace_extension("cperhex");
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800117 fs::path json = fpath.replace_extension("json");
118
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800119 std::ifstream cper_file(cper, std::ios::binary);
120 if (!cper_file.is_open()) {
121 std::cerr << "Failed to open CPER file: " << cper << std::endl;
122 FAIL() << "Failed to open CPER file";
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800123 return;
124 }
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800125 std::string cper_str((std::istreambuf_iterator<char>(cper_file)),
126 std::istreambuf_iterator<char>());
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800127
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800128 std::vector<unsigned char> cper_bin = string_to_binary(cper_str);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800129 //Convert to IR, free resources.
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800130 json_object *ir = cper_buf_to_ir(cper_bin.data(), cper_bin.size());
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800131 if (ir == NULL) {
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800132 std::cerr << "Empty JSON from CPER bin" << std::endl;
133 FAIL();
134 return;
135 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800136
Ed Tanousa3663052025-03-16 12:54:36 -0700137 json_object *expected = json_object_from_file(json.c_str());
138 ASSERT_NE(expected, nullptr);
139 if (expected == nullptr) {
140 const char *str = json_object_to_json_string(ir);
141
142 const char *expected_str = json_object_to_json_string(expected);
143
144 EXPECT_EQ(str, expected_str);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800145 return;
146 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800147
Ed Tanousa3663052025-03-16 12:54:36 -0700148 EXPECT_TRUE(json_object_equal(ir, expected));
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800149
150 json_object_put(ir);
Ed Tanousa3663052025-03-16 12:54:36 -0700151 json_object_put(expected);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800152}
Lawrence Tangcd505202022-07-19 16:55:11 +0100153
154//Tests a single randomly generated CPER section of the given type to ensure CPER-JSON IR validity.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800155void cper_log_section_ir_test(const char *section_name, int single_section,
156 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100157{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100158 //Generate full CPER record for the given type.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100159 char *buf;
160 size_t size;
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100161 FILE *record = generate_record_memstream(&section_name, 1, &buf, &size,
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800162 single_section, validBitsType);
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100163
Lawrence Tange407b4c2022-07-21 13:54:01 +0100164 //Convert to IR, free resources.
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100165 json_object *ir;
John Chungf8fc7052024-05-03 20:05:29 +0800166 if (single_section) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100167 ir = cper_single_section_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800168 } else {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100169 ir = cper_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800170 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800171
Lawrence Tange407b4c2022-07-21 13:54:01 +0100172 fclose(record);
173 free(buf);
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100174
Lawrence Tange407b4c2022-07-21 13:54:01 +0100175 //Validate against schema.
Ed Tanousa3663052025-03-16 12:54:36 -0700176 int valid = schema_validate_from_file(ir, single_section,
177 /*all_valid_bits*/ 1);
John Chungf8fc7052024-05-03 20:05:29 +0800178 json_object_put(ir);
Ed Tanousa3663052025-03-16 12:54:36 -0700179 EXPECT_TRUE(valid)
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100180 << "IR validation test failed (single section mode = "
Ed Tanousa3663052025-03-16 12:54:36 -0700181 << single_section << ")\n";
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100182}
183
Ed Tanous50b966f2025-03-11 09:06:19 -0700184std::string to_hex(char *input, size_t size)
185{
186 std::string out;
187 for (char c : std::span<unsigned char>((unsigned char *)input, size)) {
188 out += std::format("{:02x}", static_cast<unsigned char>(c));
189 }
190 return out;
191}
192
Lawrence Tangcd505202022-07-19 16:55:11 +0100193//Checks for binary round-trip equality for a given randomly generated CPER record.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800194void cper_log_section_binary_test(const char *section_name, int single_section,
195 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangcd505202022-07-19 16:55:11 +0100196{
Lawrence Tange407b4c2022-07-21 13:54:01 +0100197 //Generate CPER record for the given type.
198 char *buf;
199 size_t size;
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100200 FILE *record = generate_record_memstream(&section_name, 1, &buf, &size,
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800201 single_section, validBitsType);
202 if (record == NULL) {
203 std::cerr << "Could not generate memstream for binary test"
204 << std::endl;
205 return;
206 }
Lawrence Tangcd505202022-07-19 16:55:11 +0100207
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100208 //Convert to IR.
209 json_object *ir;
John Chungf8fc7052024-05-03 20:05:29 +0800210 if (single_section) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100211 ir = cper_single_section_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800212 } else {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100213 ir = cper_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800214 }
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100215
216 //Now convert back to binary, and get a stream out.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100217 char *cper_buf;
218 size_t cper_buf_size;
219 FILE *stream = open_memstream(&cper_buf, &cper_buf_size);
John Chungf8fc7052024-05-03 20:05:29 +0800220 if (single_section) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100221 ir_single_section_to_cper(ir, stream);
John Chungf8fc7052024-05-03 20:05:29 +0800222 } else {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100223 ir_to_cper(ir, stream);
John Chungf8fc7052024-05-03 20:05:29 +0800224 }
Lawrence Tange407b4c2022-07-21 13:54:01 +0100225 fclose(stream);
Lawrence Tangcd505202022-07-19 16:55:11 +0100226
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800227 std::cout << "size: " << size << ", cper_buf_size: " << cper_buf_size
228 << std::endl;
Ed Tanous50b966f2025-03-11 09:06:19 -0700229 EXPECT_EQ(to_hex(buf, size),
230 to_hex(cper_buf, std::min(size, cper_buf_size)))
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100231 << "Binary output was not identical to input (single section mode = "
232 << single_section << ").";
Lawrence Tange407b4c2022-07-21 13:54:01 +0100233
234 //Free everything up.
235 fclose(record);
236 free(buf);
237 free(cper_buf);
John Chungf8fc7052024-05-03 20:05:29 +0800238 json_object_put(ir);
Lawrence Tangcd505202022-07-19 16:55:11 +0100239}
240
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100241//Tests randomly generated CPER sections for IR validity of a given type, in both single section mode and full CPER log mode.
242void cper_log_section_dual_ir_test(const char *section_name)
243{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800244 cper_log_section_ir_test(section_name, 0, allValidbitsSet);
245 cper_log_section_ir_test(section_name, 1, allValidbitsSet);
246 //Validate against examples
247 cper_example_section_ir_test(section_name);
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100248}
249
250//Tests randomly generated CPER sections for binary compatibility of a given type, in both single section mode and full CPER log mode.
251void cper_log_section_dual_binary_test(const char *section_name)
252{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800253 cper_log_section_binary_test(section_name, 0, allValidbitsSet);
254 cper_log_section_binary_test(section_name, 1, allValidbitsSet);
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100255}
256
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100257/*
Lawrence Tang580423f2022-08-24 09:37:53 +0100258* Non-single section assertions.
259*/
260TEST(CompileTimeAssertions, TwoWayConversion)
261{
John Chungf8fc7052024-05-03 20:05:29 +0800262 for (size_t i = 0; i < section_definitions_len; i++) {
Lawrence Tang580423f2022-08-24 09:37:53 +0100263 //If a conversion one way exists, a conversion the other way must exist.
Lawrence Tang40519cb2022-08-24 15:50:08 +0100264 std::string err =
265 "If a CPER conversion exists one way, there must be an equivalent method in reverse.";
John Chungf8fc7052024-05-03 20:05:29 +0800266 if (section_definitions[i].ToCPER != NULL) {
267 ASSERT_NE(section_definitions[i].ToIR, nullptr) << err;
268 }
269 if (section_definitions[i].ToIR != NULL) {
270 ASSERT_NE(section_definitions[i].ToCPER, nullptr)
271 << err;
272 }
Lawrence Tang580423f2022-08-24 09:37:53 +0100273 }
274}
275
Lawrence Tang40519cb2022-08-24 15:50:08 +0100276TEST(CompileTimeAssertions, ShortcodeNoSpaces)
277{
John Chungf8fc7052024-05-03 20:05:29 +0800278 for (size_t i = 0; i < generator_definitions_len; i++) {
Lawrence Tang40519cb2022-08-24 15:50:08 +0100279 for (int j = 0;
280 generator_definitions[i].ShortName[j + 1] != '\0'; j++) {
281 ASSERT_FALSE(
282 isspace(generator_definitions[i].ShortName[j]))
283 << "Illegal space character detected in shortcode '"
284 << generator_definitions[i].ShortName << "'.";
285 }
286 }
287}
288
Lawrence Tang580423f2022-08-24 09:37:53 +0100289/*
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100290* Single section tests.
291*/
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100292
Lawrence Tangcd505202022-07-19 16:55:11 +0100293//Generic processor tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100294TEST(GenericProcessorTests, IRValid)
295{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100296 cper_log_section_dual_ir_test("generic");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100297}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100298TEST(GenericProcessorTests, BinaryEqual)
299{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100300 cper_log_section_dual_binary_test("generic");
Lawrence Tangcd505202022-07-19 16:55:11 +0100301}
302
303//IA32/x64 tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100304TEST(IA32x64Tests, IRValid)
305{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100306 cper_log_section_dual_ir_test("ia32x64");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100307}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100308TEST(IA32x64Tests, BinaryEqual)
309{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100310 cper_log_section_dual_binary_test("ia32x64");
Lawrence Tangcd505202022-07-19 16:55:11 +0100311}
312
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100313// TEST(IPFTests, IRValid) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100314// cper_log_section_dual_ir_test("ipf");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100315// }
Lawrence Tangcd505202022-07-19 16:55:11 +0100316
317//ARM tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100318TEST(ArmTests, IRValid)
319{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100320 cper_log_section_dual_ir_test("arm");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100321}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100322TEST(ArmTests, BinaryEqual)
323{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100324 cper_log_section_dual_binary_test("arm");
Lawrence Tangcd505202022-07-19 16:55:11 +0100325}
326
327//Memory tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100328TEST(MemoryTests, IRValid)
329{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100330 cper_log_section_dual_ir_test("memory");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100331}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100332TEST(MemoryTests, BinaryEqual)
333{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100334 cper_log_section_dual_binary_test("memory");
Lawrence Tangcd505202022-07-19 16:55:11 +0100335}
336
337//Memory 2 tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100338TEST(Memory2Tests, IRValid)
339{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100340 cper_log_section_dual_ir_test("memory2");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100341}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100342TEST(Memory2Tests, BinaryEqual)
343{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100344 cper_log_section_dual_binary_test("memory2");
Lawrence Tangcd505202022-07-19 16:55:11 +0100345}
346
347//PCIe tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100348TEST(PCIeTests, IRValid)
349{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100350 cper_log_section_dual_ir_test("pcie");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100351}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100352TEST(PCIeTests, BinaryEqual)
353{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100354 cper_log_section_dual_binary_test("pcie");
Lawrence Tangcd505202022-07-19 16:55:11 +0100355}
356
357//Firmware tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100358TEST(FirmwareTests, IRValid)
359{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100360 cper_log_section_dual_ir_test("firmware");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100361}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100362TEST(FirmwareTests, BinaryEqual)
363{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100364 cper_log_section_dual_binary_test("firmware");
Lawrence Tangcd505202022-07-19 16:55:11 +0100365}
366
367//PCI Bus tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100368TEST(PCIBusTests, IRValid)
369{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100370 cper_log_section_dual_ir_test("pcibus");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100371}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100372TEST(PCIBusTests, BinaryEqual)
373{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100374 cper_log_section_dual_binary_test("pcibus");
Lawrence Tangcd505202022-07-19 16:55:11 +0100375}
376
377//PCI Device tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100378TEST(PCIDevTests, IRValid)
379{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100380 cper_log_section_dual_ir_test("pcidev");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100381}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100382TEST(PCIDevTests, BinaryEqual)
383{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100384 cper_log_section_dual_binary_test("pcidev");
Lawrence Tangcd505202022-07-19 16:55:11 +0100385}
386
387//Generic DMAr tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100388TEST(DMArGenericTests, IRValid)
389{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100390 cper_log_section_dual_ir_test("dmargeneric");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100391}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100392TEST(DMArGenericTests, BinaryEqual)
393{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100394 cper_log_section_dual_binary_test("dmargeneric");
Lawrence Tangcd505202022-07-19 16:55:11 +0100395}
396
397//VT-d DMAr tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100398TEST(DMArVtdTests, IRValid)
399{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100400 cper_log_section_dual_ir_test("dmarvtd");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100401}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100402TEST(DMArVtdTests, BinaryEqual)
403{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100404 cper_log_section_dual_binary_test("dmarvtd");
Lawrence Tangcd505202022-07-19 16:55:11 +0100405}
406
407//IOMMU DMAr tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100408TEST(DMArIOMMUTests, IRValid)
409{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100410 cper_log_section_dual_ir_test("dmariommu");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100411}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100412TEST(DMArIOMMUTests, BinaryEqual)
413{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100414 cper_log_section_dual_binary_test("dmariommu");
Lawrence Tangcd505202022-07-19 16:55:11 +0100415}
416
417//CCIX PER tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100418TEST(CCIXPERTests, IRValid)
419{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100420 cper_log_section_dual_ir_test("ccixper");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100421}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100422TEST(CCIXPERTests, BinaryEqual)
423{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100424 cper_log_section_dual_binary_test("ccixper");
Lawrence Tangcd505202022-07-19 16:55:11 +0100425}
426
427//CXL Protocol tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100428TEST(CXLProtocolTests, IRValid)
429{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100430 cper_log_section_dual_ir_test("cxlprotocol");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100431}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100432TEST(CXLProtocolTests, BinaryEqual)
433{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100434 cper_log_section_dual_binary_test("cxlprotocol");
Lawrence Tangcd505202022-07-19 16:55:11 +0100435}
436
437//CXL Component tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100438TEST(CXLComponentTests, IRValid)
439{
Lawrence Tang8f977452022-08-24 14:55:07 +0100440 cper_log_section_dual_ir_test("cxlcomponent-media");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100441}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100442TEST(CXLComponentTests, BinaryEqual)
443{
Lawrence Tang8f977452022-08-24 14:55:07 +0100444 cper_log_section_dual_binary_test("cxlcomponent-media");
Lawrence Tangcd505202022-07-19 16:55:11 +0100445}
446
Ed Tanous2d17ace2024-08-27 14:45:38 -0700447//NVIDIA section tests.
448TEST(NVIDIASectionTests, IRValid)
449{
450 cper_log_section_dual_ir_test("nvidia");
451}
452TEST(NVIDIASectionTests, BinaryEqual)
453{
454 cper_log_section_dual_binary_test("nvidia");
455}
456
Lawrence Tangcd505202022-07-19 16:55:11 +0100457//Unknown section tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100458TEST(UnknownSectionTests, IRValid)
459{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100460 cper_log_section_dual_ir_test("unknown");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100461}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100462TEST(UnknownSectionTests, BinaryEqual)
463{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100464 cper_log_section_dual_binary_test("unknown");
Lawrence Tangcd505202022-07-19 16:55:11 +0100465}
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100466
467//Entrypoint for the testing program.
Erwin Tsaur8870c072025-02-28 12:57:12 -0800468int main(int argc, char **argv)
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100469{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800470 if (GEN_EXAMPLES) {
471 cper_create_examples("arm");
472 cper_create_examples("ia32x64");
473 cper_create_examples("memory");
474 cper_create_examples("memory2");
475 cper_create_examples("pcie");
476 cper_create_examples("firmware");
477 cper_create_examples("pcibus");
478 cper_create_examples("pcidev");
479 cper_create_examples("dmargeneric");
480 cper_create_examples("dmarvtd");
481 cper_create_examples("dmariommu");
482 cper_create_examples("ccixper");
483 cper_create_examples("cxlprotocol");
484 cper_create_examples("cxlcomponent-media");
485 cper_create_examples("nvidia");
486 cper_create_examples("unknown");
487 }
Erwin Tsaur8870c072025-02-28 12:57:12 -0800488 testing::InitGoogleTest(&argc, argv);
Lawrence Tange407b4c2022-07-21 13:54:01 +0100489 return RUN_ALL_TESTS();
John Chungf8fc7052024-05-03 20:05:29 +0800490}