blob: 37ee8301900fee86c9736bc03df66099b1ddfb2a [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>
Ed Tanousedee0a32025-03-16 17:40:04 -07008#include "test-utils.h"
Ed Tanousa3663052025-03-16 12:54:36 -07009#include <json.h>
10#include <libcper/cper-parse.h>
11#include <libcper/generator/cper-generate.h>
12#include <libcper/generator/sections/gen-section.h>
13#include <libcper/json-schema.h>
14#include <libcper/sections/cper-section.h>
Lawrence Tangd34f2b12022-07-19 15:36:31 +010015
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080016namespace fs = std::filesystem;
17
Lawrence Tangd34f2b12022-07-19 15:36:31 +010018/*
19* Test templates.
20*/
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080021static const GEN_VALID_BITS_TEST_TYPE allValidbitsSet = ALL_VALID;
22static const GEN_VALID_BITS_TEST_TYPE fixedValidbitsSet = SOME_VALID;
23static const int GEN_EXAMPLES = 0;
24
Ed Tanousedee0a32025-03-16 17:40:04 -070025static const char *cper_ext = "cperhex";
26static const char *json_ext = "json";
27
28struct file_info {
29 char *cper_out;
30 char *json_out;
31};
32
33void free_file_info(file_info *info)
34{
35 if (info == NULL) {
36 return;
37 }
38 free(info->cper_out);
39 free(info->json_out);
40 free(info);
41}
42
43file_info *file_info_init(const char *section_name)
44{
45 file_info *info = NULL;
46 char *buf = NULL;
47 size_t size;
48 int ret;
49
50 info = (file_info *)calloc(1, sizeof(file_info));
51 if (info == NULL) {
52 goto fail;
53 }
54
55 size = strlen(LIBCPER_EXAMPLES) + 1 + strlen(section_name) + 1 +
56 strlen(cper_ext) + 1;
57 info->cper_out = (char *)malloc(size);
58 ret = snprintf(info->cper_out, size, "%s/%s.%s", LIBCPER_EXAMPLES,
59 section_name, cper_ext);
60 if (ret != (int)size - 1) {
61 printf("snprintf0 failed\n");
62 goto fail;
63 }
64 size = strlen(LIBCPER_EXAMPLES) + 1 + strlen(section_name) + 1 +
65 strlen(json_ext) + 1;
66 info->json_out = (char *)malloc(size);
67 ret = snprintf(info->json_out, size, "%s/%s.%s", LIBCPER_EXAMPLES,
68 section_name, json_ext);
69 if (ret != (int)size - 1) {
70 printf("snprintf3 failed\n");
71 goto fail;
72 }
73 free(buf);
74 return info;
75
76fail:
77 free(buf);
78 free_file_info(info);
79 return NULL;
80}
81
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080082void cper_create_examples(const char *section_name)
83{
84 //Generate full CPER record for the given type.
Ed Tanousedee0a32025-03-16 17:40:04 -070085 json_object *ir = NULL;
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080086 size_t size;
Ed Tanousedee0a32025-03-16 17:40:04 -070087 size_t file_size;
88 FILE *outFile = NULL;
89 std::vector<unsigned char> file_data;
90 FILE *record = NULL;
91 char *buf = NULL;
92 file_info *info = file_info_init(section_name);
93 if (info == NULL) {
94 goto done;
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080095 }
96
Ed Tanousedee0a32025-03-16 17:40:04 -070097 record = generate_record_memstream(&section_name, 1, &buf, &size, 0,
98 fixedValidbitsSet);
99
100 // Write example CPER to disk
101 outFile = fopen(info->cper_out, "wb");
102 if (outFile == NULL) {
103 std::cerr << "Failed to create/open CPER output file: "
104 << info->cper_out << std::endl;
105 goto done;
106 }
107
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800108 fseek(record, 0, SEEK_END);
Ed Tanousedee0a32025-03-16 17:40:04 -0700109 file_size = ftell(record);
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800110 rewind(record);
111 file_data.resize(file_size);
112 if (fread(file_data.data(), 1, file_data.size(), record) != file_size) {
113 std::cerr << "Failed to read CPER data from memstream."
114 << std::endl;
Ed Tanousedee0a32025-03-16 17:40:04 -0700115 EXPECT_EQ(false, true);
116 fclose(outFile);
117 goto done;
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800118 }
119 for (size_t index = 0; index < file_data.size(); index++) {
Ed Tanousedee0a32025-03-16 17:40:04 -0700120 char hex_str[3];
121 int out = snprintf(hex_str, sizeof(hex_str), "%02x",
122 file_data[index]);
123 if (out != 2) {
124 printf("snprintf1 failed\n");
125 goto done;
126 }
127 fwrite(hex_str, sizeof(char), 2, outFile);
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800128 if (index % 30 == 29) {
Ed Tanousedee0a32025-03-16 17:40:04 -0700129 fwrite("\n", sizeof(char), 1, outFile);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800130 }
131 }
Ed Tanousedee0a32025-03-16 17:40:04 -0700132 fclose(outFile);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800133
134 //Convert to IR, free resources.
135 rewind(record);
Ed Tanousedee0a32025-03-16 17:40:04 -0700136 ir = cper_to_ir(record);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800137 if (ir == NULL) {
138 std::cerr << "Empty JSON from CPER bin" << std::endl;
Ed Tanousedee0a32025-03-16 17:40:04 -0700139 EXPECT_EQ(false, true);
140 goto done;
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800141 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800142
143 //Write json output to disk
Ed Tanousedee0a32025-03-16 17:40:04 -0700144 json_object_to_file_ext(info->json_out, ir, JSON_C_TO_STRING_PRETTY);
Ed Tanousa3663052025-03-16 12:54:36 -0700145 json_object_put(ir);
146
Ed Tanousedee0a32025-03-16 17:40:04 -0700147done:
148 free_file_info(info);
149 if (record != NULL) {
150 fclose(record);
151 }
152 if (outFile != NULL) {
153 fclose(outFile);
154 }
Ed Tanousa3663052025-03-16 12:54:36 -0700155 free(buf);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800156}
157
Ed Tanousedee0a32025-03-16 17:40:04 -0700158int hex2int(char ch)
159{
160 if ((ch >= '0') && (ch <= '9')) {
161 return ch - '0';
162 }
163 if ((ch >= 'A') && (ch <= 'F')) {
164 return ch - 'A' + 10;
165 }
166 if ((ch >= 'a') && (ch <= 'f')) {
167 return ch - 'a' + 10;
168 }
169 return -1;
170}
171
172std::vector<unsigned char> string_to_binary(const char *source, size_t length)
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800173{
174 std::vector<unsigned char> retval;
175 bool uppernibble = true;
Ed Tanousedee0a32025-03-16 17:40:04 -0700176 for (size_t i = 0; i < length; i++) {
177 char c = source[i];
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800178 if (c == '\n') {
179 continue;
180 }
Ed Tanousedee0a32025-03-16 17:40:04 -0700181 int val = hex2int(c);
182 if (val < 0) {
183 printf("Invalid hex character in test file: %c\n", c);
184 return {};
185 }
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800186
187 if (uppernibble) {
Ed Tanousedee0a32025-03-16 17:40:04 -0700188 retval.push_back((unsigned char)(val << 4));
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800189 } else {
Ed Tanousedee0a32025-03-16 17:40:04 -0700190 retval.back() += (unsigned char)val;
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800191 }
192 uppernibble = !uppernibble;
193 }
194 return retval;
195}
196
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800197//Tests fixed CPER sections for IR validity with an example set.
198void cper_example_section_ir_test(const char *section_name)
199{
200 //Open CPER record for the given type.
Ed Tanousedee0a32025-03-16 17:40:04 -0700201 file_info *info = file_info_init(section_name);
202 if (info == NULL) {
203 return;
204 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800205
Ed Tanousedee0a32025-03-16 17:40:04 -0700206 FILE *cper_file = fopen(info->cper_out, "rb");
207 if (cper_file == NULL) {
208 std::cerr << "Failed to open CPER file: " << info->cper_out
209 << std::endl;
210 free_file_info(info);
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800211 FAIL() << "Failed to open CPER file";
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800212 return;
213 }
Ed Tanousedee0a32025-03-16 17:40:04 -0700214 fseek(cper_file, 0, SEEK_END);
215 size_t length = ftell(cper_file);
216 fseek(cper_file, 0, SEEK_SET);
217 char *buffer = (char *)malloc(length);
218 if (!buffer) {
219 free_file_info(info);
220 return;
221 }
222 if (fread(buffer, 1, length, cper_file) != length) {
223 std::cerr << "Failed to read CPER file: " << info->cper_out
224 << std::endl;
225 free(buffer);
226 free_file_info(info);
227 return;
228 }
229 fclose(cper_file);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800230
Ed Tanousedee0a32025-03-16 17:40:04 -0700231 std::vector<unsigned char> cper_bin = string_to_binary(buffer, length);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800232 //Convert to IR, free resources.
Ed Tanousa2dce4b2025-03-05 15:33:06 -0800233 json_object *ir = cper_buf_to_ir(cper_bin.data(), cper_bin.size());
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800234 if (ir == NULL) {
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800235 std::cerr << "Empty JSON from CPER bin" << std::endl;
Ed Tanousedee0a32025-03-16 17:40:04 -0700236 free(buffer);
237 free_file_info(info);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800238 FAIL();
239 return;
240 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800241
Ed Tanousedee0a32025-03-16 17:40:04 -0700242 json_object *expected = json_object_from_file(info->json_out);
243 EXPECT_NE(expected, nullptr);
Ed Tanousa3663052025-03-16 12:54:36 -0700244 if (expected == nullptr) {
Ed Tanousedee0a32025-03-16 17:40:04 -0700245 free(buffer);
246 free_file_info(info);
Ed Tanousa3663052025-03-16 12:54:36 -0700247 const char *str = json_object_to_json_string(ir);
248
249 const char *expected_str = json_object_to_json_string(expected);
250
251 EXPECT_EQ(str, expected_str);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800252 return;
253 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800254
Ed Tanousa3663052025-03-16 12:54:36 -0700255 EXPECT_TRUE(json_object_equal(ir, expected));
Ed Tanousedee0a32025-03-16 17:40:04 -0700256 free(buffer);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800257 json_object_put(ir);
Ed Tanousa3663052025-03-16 12:54:36 -0700258 json_object_put(expected);
Ed Tanousedee0a32025-03-16 17:40:04 -0700259 free_file_info(info);
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800260}
Lawrence Tangcd505202022-07-19 16:55:11 +0100261
262//Tests a single randomly generated CPER section of the given type to ensure CPER-JSON IR validity.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800263void cper_log_section_ir_test(const char *section_name, int single_section,
264 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100265{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100266 //Generate full CPER record for the given type.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100267 char *buf;
268 size_t size;
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100269 FILE *record = generate_record_memstream(&section_name, 1, &buf, &size,
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800270 single_section, validBitsType);
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100271
Lawrence Tange407b4c2022-07-21 13:54:01 +0100272 //Convert to IR, free resources.
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100273 json_object *ir;
John Chungf8fc7052024-05-03 20:05:29 +0800274 if (single_section) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100275 ir = cper_single_section_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800276 } else {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100277 ir = cper_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800278 }
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800279
Lawrence Tange407b4c2022-07-21 13:54:01 +0100280 fclose(record);
281 free(buf);
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100282
Lawrence Tange407b4c2022-07-21 13:54:01 +0100283 //Validate against schema.
Ed Tanousa3663052025-03-16 12:54:36 -0700284 int valid = schema_validate_from_file(ir, single_section,
285 /*all_valid_bits*/ 1);
John Chungf8fc7052024-05-03 20:05:29 +0800286 json_object_put(ir);
Ed Tanousedee0a32025-03-16 17:40:04 -0700287 EXPECT_GE(valid, 0)
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100288 << "IR validation test failed (single section mode = "
Ed Tanousa3663052025-03-16 12:54:36 -0700289 << single_section << ")\n";
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100290}
291
Ed Tanousedee0a32025-03-16 17:40:04 -0700292int to_hex(const unsigned char *input, size_t size, char **out)
Ed Tanous50b966f2025-03-11 09:06:19 -0700293{
Ed Tanousedee0a32025-03-16 17:40:04 -0700294 *out = (char *)malloc(size * 2);
295 if (out == NULL) {
296 return -1;
Ed Tanous50b966f2025-03-11 09:06:19 -0700297 }
Ed Tanousedee0a32025-03-16 17:40:04 -0700298 int out_index = 0;
299 for (size_t i = 0; i < size; i++) {
300 unsigned char c = input[i];
301 char hex_str[3];
302 int n = snprintf(hex_str, sizeof(hex_str), "%02x", c);
303 if (n != 2) {
304 printf("snprintf2 failed with code %d\n", n);
305 return -1;
306 }
307 (*out)[out_index] = hex_str[0];
308 out_index++;
309 (*out)[out_index] = hex_str[1];
310 out_index++;
311 }
312 return out_index;
Ed Tanous50b966f2025-03-11 09:06:19 -0700313}
314
Lawrence Tangcd505202022-07-19 16:55:11 +0100315//Checks for binary round-trip equality for a given randomly generated CPER record.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800316void cper_log_section_binary_test(const char *section_name, int single_section,
317 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangcd505202022-07-19 16:55:11 +0100318{
Lawrence Tange407b4c2022-07-21 13:54:01 +0100319 //Generate CPER record for the given type.
320 char *buf;
321 size_t size;
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100322 FILE *record = generate_record_memstream(&section_name, 1, &buf, &size,
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800323 single_section, validBitsType);
324 if (record == NULL) {
325 std::cerr << "Could not generate memstream for binary test"
326 << std::endl;
327 return;
328 }
Lawrence Tangcd505202022-07-19 16:55:11 +0100329
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100330 //Convert to IR.
331 json_object *ir;
John Chungf8fc7052024-05-03 20:05:29 +0800332 if (single_section) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100333 ir = cper_single_section_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800334 } else {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100335 ir = cper_to_ir(record);
John Chungf8fc7052024-05-03 20:05:29 +0800336 }
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100337
338 //Now convert back to binary, and get a stream out.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100339 char *cper_buf;
340 size_t cper_buf_size;
341 FILE *stream = open_memstream(&cper_buf, &cper_buf_size);
John Chungf8fc7052024-05-03 20:05:29 +0800342 if (single_section) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100343 ir_single_section_to_cper(ir, stream);
John Chungf8fc7052024-05-03 20:05:29 +0800344 } else {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100345 ir_to_cper(ir, stream);
John Chungf8fc7052024-05-03 20:05:29 +0800346 }
Lawrence Tange407b4c2022-07-21 13:54:01 +0100347 fclose(stream);
Lawrence Tangcd505202022-07-19 16:55:11 +0100348
Ed Tanousedee0a32025-03-16 17:40:04 -0700349 printf("size: %zu, cper_buf_size: %zu\n", size, cper_buf_size);
Lawrence Tange407b4c2022-07-21 13:54:01 +0100350
Ed Tanousedee0a32025-03-16 17:40:04 -0700351 char *buf_hex;
352 int buf_hex_len = to_hex((unsigned char *)buf, size, &buf_hex);
353 char *cper_buf_hex;
354 int cper_buf_hex_len =
355 to_hex((unsigned char *)cper_buf, cper_buf_size, &cper_buf_hex);
356
357 EXPECT_EQ(buf_hex_len, cper_buf_hex_len);
358 if (buf_hex_len == cper_buf_hex_len) {
359 EXPECT_EQ(memcmp(buf_hex, cper_buf_hex, buf_hex_len), 0)
360 << "Binary output was not identical to input (single section mode = "
361 << single_section << ").";
362 }
363
364 free(cper_buf_hex);
365 free(buf_hex);
Lawrence Tange407b4c2022-07-21 13:54:01 +0100366 //Free everything up.
367 fclose(record);
368 free(buf);
369 free(cper_buf);
John Chungf8fc7052024-05-03 20:05:29 +0800370 json_object_put(ir);
Lawrence Tangcd505202022-07-19 16:55:11 +0100371}
372
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100373//Tests randomly generated CPER sections for IR validity of a given type, in both single section mode and full CPER log mode.
374void cper_log_section_dual_ir_test(const char *section_name)
375{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800376 cper_log_section_ir_test(section_name, 0, allValidbitsSet);
377 cper_log_section_ir_test(section_name, 1, allValidbitsSet);
378 //Validate against examples
379 cper_example_section_ir_test(section_name);
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100380}
381
382//Tests randomly generated CPER sections for binary compatibility of a given type, in both single section mode and full CPER log mode.
383void cper_log_section_dual_binary_test(const char *section_name)
384{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800385 cper_log_section_binary_test(section_name, 0, allValidbitsSet);
386 cper_log_section_binary_test(section_name, 1, allValidbitsSet);
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100387}
388
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100389/*
Lawrence Tang580423f2022-08-24 09:37:53 +0100390* Non-single section assertions.
391*/
392TEST(CompileTimeAssertions, TwoWayConversion)
393{
John Chungf8fc7052024-05-03 20:05:29 +0800394 for (size_t i = 0; i < section_definitions_len; i++) {
Lawrence Tang580423f2022-08-24 09:37:53 +0100395 //If a conversion one way exists, a conversion the other way must exist.
Ed Tanousedee0a32025-03-16 17:40:04 -0700396 const char *err =
Lawrence Tang40519cb2022-08-24 15:50:08 +0100397 "If a CPER conversion exists one way, there must be an equivalent method in reverse.";
John Chungf8fc7052024-05-03 20:05:29 +0800398 if (section_definitions[i].ToCPER != NULL) {
399 ASSERT_NE(section_definitions[i].ToIR, nullptr) << err;
400 }
401 if (section_definitions[i].ToIR != NULL) {
402 ASSERT_NE(section_definitions[i].ToCPER, nullptr)
403 << err;
404 }
Lawrence Tang580423f2022-08-24 09:37:53 +0100405 }
406}
407
Lawrence Tang40519cb2022-08-24 15:50:08 +0100408TEST(CompileTimeAssertions, ShortcodeNoSpaces)
409{
John Chungf8fc7052024-05-03 20:05:29 +0800410 for (size_t i = 0; i < generator_definitions_len; i++) {
Lawrence Tang40519cb2022-08-24 15:50:08 +0100411 for (int j = 0;
412 generator_definitions[i].ShortName[j + 1] != '\0'; j++) {
413 ASSERT_FALSE(
414 isspace(generator_definitions[i].ShortName[j]))
415 << "Illegal space character detected in shortcode '"
416 << generator_definitions[i].ShortName << "'.";
417 }
418 }
419}
420
Lawrence Tang580423f2022-08-24 09:37:53 +0100421/*
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100422* Single section tests.
423*/
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100424
Lawrence Tangcd505202022-07-19 16:55:11 +0100425//Generic processor tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100426TEST(GenericProcessorTests, IRValid)
427{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100428 cper_log_section_dual_ir_test("generic");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100429}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100430TEST(GenericProcessorTests, BinaryEqual)
431{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100432 cper_log_section_dual_binary_test("generic");
Lawrence Tangcd505202022-07-19 16:55:11 +0100433}
434
435//IA32/x64 tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100436TEST(IA32x64Tests, IRValid)
437{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100438 cper_log_section_dual_ir_test("ia32x64");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100439}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100440TEST(IA32x64Tests, BinaryEqual)
441{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100442 cper_log_section_dual_binary_test("ia32x64");
Lawrence Tangcd505202022-07-19 16:55:11 +0100443}
444
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100445// TEST(IPFTests, IRValid) {
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100446// cper_log_section_dual_ir_test("ipf");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100447// }
Lawrence Tangcd505202022-07-19 16:55:11 +0100448
449//ARM tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100450TEST(ArmTests, IRValid)
451{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100452 cper_log_section_dual_ir_test("arm");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100453}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100454TEST(ArmTests, BinaryEqual)
455{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100456 cper_log_section_dual_binary_test("arm");
Lawrence Tangcd505202022-07-19 16:55:11 +0100457}
458
459//Memory tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100460TEST(MemoryTests, IRValid)
461{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100462 cper_log_section_dual_ir_test("memory");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100463}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100464TEST(MemoryTests, BinaryEqual)
465{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100466 cper_log_section_dual_binary_test("memory");
Lawrence Tangcd505202022-07-19 16:55:11 +0100467}
468
469//Memory 2 tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100470TEST(Memory2Tests, IRValid)
471{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100472 cper_log_section_dual_ir_test("memory2");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100473}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100474TEST(Memory2Tests, BinaryEqual)
475{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100476 cper_log_section_dual_binary_test("memory2");
Lawrence Tangcd505202022-07-19 16:55:11 +0100477}
478
479//PCIe tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100480TEST(PCIeTests, IRValid)
481{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100482 cper_log_section_dual_ir_test("pcie");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100483}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100484TEST(PCIeTests, BinaryEqual)
485{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100486 cper_log_section_dual_binary_test("pcie");
Lawrence Tangcd505202022-07-19 16:55:11 +0100487}
488
489//Firmware tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100490TEST(FirmwareTests, IRValid)
491{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100492 cper_log_section_dual_ir_test("firmware");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100493}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100494TEST(FirmwareTests, BinaryEqual)
495{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100496 cper_log_section_dual_binary_test("firmware");
Lawrence Tangcd505202022-07-19 16:55:11 +0100497}
498
499//PCI Bus tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100500TEST(PCIBusTests, IRValid)
501{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100502 cper_log_section_dual_ir_test("pcibus");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100503}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100504TEST(PCIBusTests, BinaryEqual)
505{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100506 cper_log_section_dual_binary_test("pcibus");
Lawrence Tangcd505202022-07-19 16:55:11 +0100507}
508
509//PCI Device tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100510TEST(PCIDevTests, IRValid)
511{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100512 cper_log_section_dual_ir_test("pcidev");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100513}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100514TEST(PCIDevTests, BinaryEqual)
515{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100516 cper_log_section_dual_binary_test("pcidev");
Lawrence Tangcd505202022-07-19 16:55:11 +0100517}
518
519//Generic DMAr tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100520TEST(DMArGenericTests, IRValid)
521{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100522 cper_log_section_dual_ir_test("dmargeneric");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100523}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100524TEST(DMArGenericTests, BinaryEqual)
525{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100526 cper_log_section_dual_binary_test("dmargeneric");
Lawrence Tangcd505202022-07-19 16:55:11 +0100527}
528
529//VT-d DMAr tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100530TEST(DMArVtdTests, IRValid)
531{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100532 cper_log_section_dual_ir_test("dmarvtd");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100533}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100534TEST(DMArVtdTests, BinaryEqual)
535{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100536 cper_log_section_dual_binary_test("dmarvtd");
Lawrence Tangcd505202022-07-19 16:55:11 +0100537}
538
539//IOMMU DMAr tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100540TEST(DMArIOMMUTests, IRValid)
541{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100542 cper_log_section_dual_ir_test("dmariommu");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100543}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100544TEST(DMArIOMMUTests, BinaryEqual)
545{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100546 cper_log_section_dual_binary_test("dmariommu");
Lawrence Tangcd505202022-07-19 16:55:11 +0100547}
548
549//CCIX PER tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100550TEST(CCIXPERTests, IRValid)
551{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100552 cper_log_section_dual_ir_test("ccixper");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100553}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100554TEST(CCIXPERTests, BinaryEqual)
555{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100556 cper_log_section_dual_binary_test("ccixper");
Lawrence Tangcd505202022-07-19 16:55:11 +0100557}
558
559//CXL Protocol tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100560TEST(CXLProtocolTests, IRValid)
561{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100562 cper_log_section_dual_ir_test("cxlprotocol");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100563}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100564TEST(CXLProtocolTests, BinaryEqual)
565{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100566 cper_log_section_dual_binary_test("cxlprotocol");
Lawrence Tangcd505202022-07-19 16:55:11 +0100567}
568
569//CXL Component tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100570TEST(CXLComponentTests, IRValid)
571{
Lawrence Tang8f977452022-08-24 14:55:07 +0100572 cper_log_section_dual_ir_test("cxlcomponent-media");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100573}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100574TEST(CXLComponentTests, BinaryEqual)
575{
Lawrence Tang8f977452022-08-24 14:55:07 +0100576 cper_log_section_dual_binary_test("cxlcomponent-media");
Lawrence Tangcd505202022-07-19 16:55:11 +0100577}
578
Ed Tanous2d17ace2024-08-27 14:45:38 -0700579//NVIDIA section tests.
580TEST(NVIDIASectionTests, IRValid)
581{
582 cper_log_section_dual_ir_test("nvidia");
583}
584TEST(NVIDIASectionTests, BinaryEqual)
585{
586 cper_log_section_dual_binary_test("nvidia");
587}
588
Lawrence Tangcd505202022-07-19 16:55:11 +0100589//Unknown section tests.
Lawrence Tange407b4c2022-07-21 13:54:01 +0100590TEST(UnknownSectionTests, IRValid)
591{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100592 cper_log_section_dual_ir_test("unknown");
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100593}
Lawrence Tange407b4c2022-07-21 13:54:01 +0100594TEST(UnknownSectionTests, BinaryEqual)
595{
Lawrence Tanga4f662f2022-08-08 14:37:36 +0100596 cper_log_section_dual_binary_test("unknown");
Lawrence Tangcd505202022-07-19 16:55:11 +0100597}
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100598
599//Entrypoint for the testing program.
Erwin Tsaur8870c072025-02-28 12:57:12 -0800600int main(int argc, char **argv)
Lawrence Tangd34f2b12022-07-19 15:36:31 +0100601{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -0800602 if (GEN_EXAMPLES) {
603 cper_create_examples("arm");
604 cper_create_examples("ia32x64");
605 cper_create_examples("memory");
606 cper_create_examples("memory2");
607 cper_create_examples("pcie");
608 cper_create_examples("firmware");
609 cper_create_examples("pcibus");
610 cper_create_examples("pcidev");
611 cper_create_examples("dmargeneric");
612 cper_create_examples("dmarvtd");
613 cper_create_examples("dmariommu");
614 cper_create_examples("ccixper");
615 cper_create_examples("cxlprotocol");
616 cper_create_examples("cxlcomponent-media");
617 cper_create_examples("nvidia");
618 cper_create_examples("unknown");
619 }
Erwin Tsaur8870c072025-02-28 12:57:12 -0800620 testing::InitGoogleTest(&argc, argv);
Lawrence Tange407b4c2022-07-21 13:54:01 +0100621 return RUN_ALL_TESTS();
John Chungf8fc7052024-05-03 20:05:29 +0800622}