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. |
Ed Tanous | fedd457 | 2024-07-12 13:56:00 -0700 | [diff] [blame] | 3 | * |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 7 | #include "test-utils.h" |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 8 | #include "string.h" |
| 9 | #include "assert.h" |
| 10 | #include <ctype.h> |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 11 | #include <json.h> |
| 12 | #include <libcper/cper-parse.h> |
| 13 | #include <libcper/generator/cper-generate.h> |
| 14 | #include <libcper/generator/sections/gen-section.h> |
| 15 | #include <libcper/json-schema.h> |
| 16 | #include <libcper/sections/cper-section.h> |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 17 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 18 | #include "base64_test.h" |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 19 | |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 20 | /* |
| 21 | * Test templates. |
| 22 | */ |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 23 | static const GEN_VALID_BITS_TEST_TYPE allValidbitsSet = ALL_VALID; |
| 24 | static const GEN_VALID_BITS_TEST_TYPE fixedValidbitsSet = SOME_VALID; |
| 25 | static const int GEN_EXAMPLES = 0; |
| 26 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 27 | static const char *cper_ext = "cperhex"; |
| 28 | static const char *json_ext = "json"; |
| 29 | |
| 30 | struct file_info { |
| 31 | char *cper_out; |
| 32 | char *json_out; |
| 33 | }; |
| 34 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 35 | void free_file_info(struct file_info *info) |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 36 | { |
| 37 | if (info == NULL) { |
| 38 | return; |
| 39 | } |
| 40 | free(info->cper_out); |
| 41 | free(info->json_out); |
| 42 | free(info); |
| 43 | } |
| 44 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 45 | struct file_info *file_info_init(const char *section_name) |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 46 | { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 47 | struct file_info *info = NULL; |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 48 | char *buf = NULL; |
| 49 | size_t size; |
| 50 | int ret; |
| 51 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 52 | info = (struct file_info *)calloc(1, sizeof(struct file_info)); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 53 | if (info == NULL) { |
| 54 | goto fail; |
| 55 | } |
| 56 | |
| 57 | size = strlen(LIBCPER_EXAMPLES) + 1 + strlen(section_name) + 1 + |
| 58 | strlen(cper_ext) + 1; |
| 59 | info->cper_out = (char *)malloc(size); |
| 60 | ret = snprintf(info->cper_out, size, "%s/%s.%s", LIBCPER_EXAMPLES, |
| 61 | section_name, cper_ext); |
| 62 | if (ret != (int)size - 1) { |
| 63 | printf("snprintf0 failed\n"); |
| 64 | goto fail; |
| 65 | } |
| 66 | size = strlen(LIBCPER_EXAMPLES) + 1 + strlen(section_name) + 1 + |
| 67 | strlen(json_ext) + 1; |
| 68 | info->json_out = (char *)malloc(size); |
| 69 | ret = snprintf(info->json_out, size, "%s/%s.%s", LIBCPER_EXAMPLES, |
| 70 | section_name, json_ext); |
| 71 | if (ret != (int)size - 1) { |
| 72 | printf("snprintf3 failed\n"); |
| 73 | goto fail; |
| 74 | } |
| 75 | free(buf); |
| 76 | return info; |
| 77 | |
| 78 | fail: |
| 79 | free(buf); |
| 80 | free_file_info(info); |
| 81 | return NULL; |
| 82 | } |
| 83 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 84 | void cper_create_examples(const char *section_name) |
| 85 | { |
| 86 | //Generate full CPER record for the given type. |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 87 | json_object *ir = NULL; |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 88 | size_t size; |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 89 | size_t file_size; |
| 90 | FILE *outFile = NULL; |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 91 | unsigned char *file_data; |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 92 | FILE *record = NULL; |
| 93 | char *buf = NULL; |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 94 | struct file_info *info = file_info_init(section_name); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 95 | if (info == NULL) { |
| 96 | goto done; |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 99 | record = generate_record_memstream(§ion_name, 1, &buf, &size, 0, |
| 100 | fixedValidbitsSet); |
| 101 | |
| 102 | // Write example CPER to disk |
| 103 | outFile = fopen(info->cper_out, "wb"); |
| 104 | if (outFile == NULL) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 105 | printf("Failed to create/open CPER output file: %s\n", |
| 106 | info->cper_out); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 107 | goto done; |
| 108 | } |
| 109 | |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 110 | fseek(record, 0, SEEK_END); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 111 | file_size = ftell(record); |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 112 | rewind(record); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 113 | file_data = malloc(file_size); |
| 114 | if (fread(file_data, 1, file_size, record) != file_size) { |
| 115 | printf("Failed to read CPER data from memstream."); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 116 | fclose(outFile); |
Aushim Nagarkatti | c1e38a1 | 2025-06-26 11:59:41 -0700 | [diff] [blame^] | 117 | outFile = NULL; |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 118 | assert(0); |
| 119 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 120 | goto done; |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 121 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 122 | for (size_t index = 0; index < file_size; index++) { |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 123 | char hex_str[3]; |
| 124 | int out = snprintf(hex_str, sizeof(hex_str), "%02x", |
| 125 | file_data[index]); |
| 126 | if (out != 2) { |
| 127 | printf("snprintf1 failed\n"); |
| 128 | goto done; |
| 129 | } |
| 130 | fwrite(hex_str, sizeof(char), 2, outFile); |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 131 | if (index % 30 == 29) { |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 132 | fwrite("\n", sizeof(char), 1, outFile); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 135 | fclose(outFile); |
Aushim Nagarkatti | c1e38a1 | 2025-06-26 11:59:41 -0700 | [diff] [blame^] | 136 | outFile = NULL; |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 137 | |
| 138 | //Convert to IR, free resources. |
| 139 | rewind(record); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 140 | ir = cper_to_ir(record); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 141 | if (ir == NULL) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 142 | printf("Empty JSON from CPER bin2\n"); |
| 143 | assert(0); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 144 | goto done; |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 145 | } |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 146 | |
| 147 | //Write json output to disk |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 148 | json_object_to_file_ext(info->json_out, ir, JSON_C_TO_STRING_PRETTY); |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 149 | json_object_put(ir); |
| 150 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 151 | done: |
| 152 | free_file_info(info); |
| 153 | if (record != NULL) { |
| 154 | fclose(record); |
| 155 | } |
| 156 | if (outFile != NULL) { |
| 157 | fclose(outFile); |
| 158 | } |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 159 | free(buf); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 162 | int hex2int(char ch) |
| 163 | { |
| 164 | if ((ch >= '0') && (ch <= '9')) { |
| 165 | return ch - '0'; |
| 166 | } |
| 167 | if ((ch >= 'A') && (ch <= 'F')) { |
| 168 | return ch - 'A' + 10; |
| 169 | } |
| 170 | if ((ch >= 'a') && (ch <= 'f')) { |
| 171 | return ch - 'a' + 10; |
| 172 | } |
| 173 | return -1; |
| 174 | } |
| 175 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 176 | int string_to_binary(const char *source, size_t length, unsigned char **retval) |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 177 | { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 178 | size_t retval_size = length * 2; |
| 179 | *retval = malloc(retval_size); |
| 180 | int uppernibble = 1; |
| 181 | |
| 182 | size_t ret_index = 0; |
| 183 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 184 | for (size_t i = 0; i < length; i++) { |
| 185 | char c = source[i]; |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 186 | if (c == '\n') { |
| 187 | continue; |
| 188 | } |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 189 | int val = hex2int(c); |
| 190 | if (val < 0) { |
| 191 | printf("Invalid hex character in test file: %c\n", c); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 192 | return -1; |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 193 | } |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 194 | |
| 195 | if (uppernibble) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 196 | (*retval)[ret_index] = (unsigned char)(val << 4); |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 197 | } else { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 198 | (*retval)[ret_index] += (unsigned char)val; |
| 199 | ret_index++; |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 200 | } |
| 201 | uppernibble = !uppernibble; |
| 202 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 203 | return ret_index; |
Ed Tanous | a2dce4b | 2025-03-05 15:33:06 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 206 | //Tests fixed CPER sections for IR validity with an example set. |
| 207 | void cper_example_section_ir_test(const char *section_name) |
| 208 | { |
| 209 | //Open CPER record for the given type. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 210 | struct file_info *info = file_info_init(section_name); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 211 | if (info == NULL) { |
| 212 | return; |
| 213 | } |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 214 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 215 | FILE *cper_file = fopen(info->cper_out, "rb"); |
| 216 | if (cper_file == NULL) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 217 | printf("Failed to open CPER file: %s\n", info->cper_out); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 218 | free_file_info(info); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 219 | assert(0); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 220 | return; |
| 221 | } |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 222 | fseek(cper_file, 0, SEEK_END); |
| 223 | size_t length = ftell(cper_file); |
| 224 | fseek(cper_file, 0, SEEK_SET); |
| 225 | char *buffer = (char *)malloc(length); |
| 226 | if (!buffer) { |
| 227 | free_file_info(info); |
| 228 | return; |
| 229 | } |
| 230 | if (fread(buffer, 1, length, cper_file) != length) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 231 | printf("Failed to read CPER file: %s\n", info->cper_out); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 232 | free(buffer); |
| 233 | free_file_info(info); |
| 234 | return; |
| 235 | } |
| 236 | fclose(cper_file); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 237 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 238 | unsigned char *cper_bin; |
| 239 | int cper_bin_len = string_to_binary(buffer, length, &cper_bin); |
| 240 | if (cper_bin_len <= 0) { |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 241 | free(buffer); |
| 242 | free_file_info(info); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 243 | assert(0); |
| 244 | return; |
| 245 | } |
| 246 | printf("cper_bin: %s\n", cper_bin); |
| 247 | printf("cper_bin_len: %d\n", cper_bin_len); |
| 248 | |
| 249 | //Convert to IR, free resources. |
| 250 | json_object *ir = cper_buf_to_ir(cper_bin, cper_bin_len); |
| 251 | if (ir == NULL) { |
| 252 | printf("Empty JSON from CPER bin3\n"); |
| 253 | free(cper_bin); |
| 254 | free(buffer); |
| 255 | free_file_info(info); |
| 256 | assert(0); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 257 | return; |
| 258 | } |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 259 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 260 | json_object *expected = json_object_from_file(info->json_out); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 261 | assert(expected != NULL); |
| 262 | if (expected == NULL) { |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 263 | free(buffer); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 264 | free(cper_bin); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 265 | free_file_info(info); |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 266 | const char *str = json_object_to_json_string(ir); |
| 267 | |
| 268 | const char *expected_str = json_object_to_json_string(expected); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 269 | assert(strcmp(str, expected_str) == 0); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 270 | return; |
| 271 | } |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 272 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 273 | assert(json_object_equal(ir, expected)); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 274 | free(buffer); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 275 | free(cper_bin); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 276 | json_object_put(ir); |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 277 | json_object_put(expected); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 278 | free_file_info(info); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 279 | } |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 280 | |
| 281 | //Tests a single randomly generated CPER section of the given type to ensure CPER-JSON IR validity. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 282 | void cper_log_section_ir_test(const char *section_name, int single_section, |
| 283 | GEN_VALID_BITS_TEST_TYPE validBitsType) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 284 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 285 | //Generate full CPER record for the given type. |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 286 | char *buf; |
| 287 | size_t size; |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 288 | FILE *record = generate_record_memstream(§ion_name, 1, &buf, &size, |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 289 | single_section, validBitsType); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 290 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 291 | //Convert to IR, free resources. |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 292 | json_object *ir; |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 293 | if (single_section) { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 294 | ir = cper_single_section_to_ir(record); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 295 | } else { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 296 | ir = cper_to_ir(record); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 297 | } |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 298 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 299 | fclose(record); |
| 300 | free(buf); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 301 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 302 | //Validate against schema. |
Ed Tanous | a366305 | 2025-03-16 12:54:36 -0700 | [diff] [blame] | 303 | int valid = schema_validate_from_file(ir, single_section, |
| 304 | /*all_valid_bits*/ 1); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 305 | json_object_put(ir); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 306 | |
| 307 | if (valid < 0) { |
| 308 | printf("IR validation test failed (single section mode = %d)\n", |
| 309 | single_section); |
| 310 | assert(0); |
| 311 | } |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 314 | int to_hex(const unsigned char *input, size_t size, char **out) |
Ed Tanous | 50b966f | 2025-03-11 09:06:19 -0700 | [diff] [blame] | 315 | { |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 316 | *out = (char *)malloc(size * 2); |
| 317 | if (out == NULL) { |
| 318 | return -1; |
Ed Tanous | 50b966f | 2025-03-11 09:06:19 -0700 | [diff] [blame] | 319 | } |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 320 | int out_index = 0; |
| 321 | for (size_t i = 0; i < size; i++) { |
| 322 | unsigned char c = input[i]; |
| 323 | char hex_str[3]; |
| 324 | int n = snprintf(hex_str, sizeof(hex_str), "%02x", c); |
| 325 | if (n != 2) { |
| 326 | printf("snprintf2 failed with code %d\n", n); |
| 327 | return -1; |
| 328 | } |
| 329 | (*out)[out_index] = hex_str[0]; |
| 330 | out_index++; |
| 331 | (*out)[out_index] = hex_str[1]; |
| 332 | out_index++; |
| 333 | } |
| 334 | return out_index; |
Ed Tanous | 50b966f | 2025-03-11 09:06:19 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 337 | //Checks for binary round-trip equality for a given randomly generated CPER record. |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 338 | void cper_log_section_binary_test(const char *section_name, int single_section, |
| 339 | GEN_VALID_BITS_TEST_TYPE validBitsType) |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 340 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 341 | //Generate CPER record for the given type. |
| 342 | char *buf; |
| 343 | size_t size; |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 344 | FILE *record = generate_record_memstream(§ion_name, 1, &buf, &size, |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 345 | single_section, validBitsType); |
| 346 | if (record == NULL) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 347 | printf("Could not generate memstream for binary test"); |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 348 | return; |
| 349 | } |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 350 | |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 351 | //Convert to IR. |
| 352 | json_object *ir; |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 353 | if (single_section) { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 354 | ir = cper_single_section_to_ir(record); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 355 | } else { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 356 | ir = cper_to_ir(record); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 357 | } |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 358 | |
| 359 | //Now convert back to binary, and get a stream out. |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 360 | char *cper_buf; |
| 361 | size_t cper_buf_size; |
| 362 | FILE *stream = open_memstream(&cper_buf, &cper_buf_size); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 363 | if (single_section) { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 364 | ir_single_section_to_cper(ir, stream); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 365 | } else { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 366 | ir_to_cper(ir, stream); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 367 | } |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 368 | fclose(stream); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 369 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 370 | printf("size: %zu, cper_buf_size: %zu\n", size, cper_buf_size); |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 371 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 372 | char *buf_hex; |
| 373 | int buf_hex_len = to_hex((unsigned char *)buf, size, &buf_hex); |
| 374 | char *cper_buf_hex; |
| 375 | int cper_buf_hex_len = |
| 376 | to_hex((unsigned char *)cper_buf, cper_buf_size, &cper_buf_hex); |
| 377 | |
Ed Tanous | 9f260e5 | 2025-04-24 09:37:59 -0700 | [diff] [blame] | 378 | printf("%.*s\n", cper_buf_hex_len, cper_buf_hex); |
| 379 | printf("%.*s\n", buf_hex_len, buf_hex); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 380 | assert(buf_hex_len == cper_buf_hex_len); |
| 381 | assert(memcmp(buf_hex, cper_buf_hex, buf_hex_len) == 0); |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 382 | |
Ed Tanous | edee0a3 | 2025-03-16 17:40:04 -0700 | [diff] [blame] | 383 | free(buf_hex); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 384 | free(cper_buf_hex); |
| 385 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 386 | //Free everything up. |
| 387 | fclose(record); |
| 388 | free(buf); |
| 389 | free(cper_buf); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 390 | json_object_put(ir); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 393 | //Tests randomly generated CPER sections for IR validity of a given type, in both single section mode and full CPER log mode. |
| 394 | void cper_log_section_dual_ir_test(const char *section_name) |
| 395 | { |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 396 | cper_log_section_ir_test(section_name, 0, allValidbitsSet); |
| 397 | cper_log_section_ir_test(section_name, 1, allValidbitsSet); |
| 398 | //Validate against examples |
| 399 | cper_example_section_ir_test(section_name); |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | //Tests randomly generated CPER sections for binary compatibility of a given type, in both single section mode and full CPER log mode. |
| 403 | void cper_log_section_dual_binary_test(const char *section_name) |
| 404 | { |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 405 | cper_log_section_binary_test(section_name, 0, allValidbitsSet); |
| 406 | cper_log_section_binary_test(section_name, 1, allValidbitsSet); |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 409 | /* |
Lawrence Tang | 580423f | 2022-08-24 09:37:53 +0100 | [diff] [blame] | 410 | * Non-single section assertions. |
| 411 | */ |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 412 | void CompileTimeAssertions_TwoWayConversion() |
Lawrence Tang | 580423f | 2022-08-24 09:37:53 +0100 | [diff] [blame] | 413 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 414 | for (size_t i = 0; i < section_definitions_len; i++) { |
Lawrence Tang | 580423f | 2022-08-24 09:37:53 +0100 | [diff] [blame] | 415 | //If a conversion one way exists, a conversion the other way must exist. |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 416 | if (section_definitions[i].ToCPER != NULL) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 417 | assert(section_definitions[i].ToIR != NULL); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 418 | } |
| 419 | if (section_definitions[i].ToIR != NULL) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 420 | assert(section_definitions[i].ToCPER != NULL); |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 421 | } |
Lawrence Tang | 580423f | 2022-08-24 09:37:53 +0100 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 425 | void CompileTimeAssertions_ShortcodeNoSpaces() |
Lawrence Tang | 40519cb | 2022-08-24 15:50:08 +0100 | [diff] [blame] | 426 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 427 | for (size_t i = 0; i < generator_definitions_len; i++) { |
Lawrence Tang | 40519cb | 2022-08-24 15:50:08 +0100 | [diff] [blame] | 428 | for (int j = 0; |
| 429 | generator_definitions[i].ShortName[j + 1] != '\0'; j++) { |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 430 | assert(isspace(generator_definitions[i].ShortName[j]) == |
| 431 | 0); |
Lawrence Tang | 40519cb | 2022-08-24 15:50:08 +0100 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
Lawrence Tang | 580423f | 2022-08-24 09:37:53 +0100 | [diff] [blame] | 436 | /* |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 437 | * Single section tests. |
| 438 | */ |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 439 | |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 440 | //Generic processor tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 441 | void GenericProcessorTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 442 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 443 | cper_log_section_dual_ir_test("generic"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 444 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 445 | void GenericProcessorTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 446 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 447 | cper_log_section_dual_binary_test("generic"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | //IA32/x64 tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 451 | void IA32x64Tests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 452 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 453 | cper_log_section_dual_ir_test("ia32x64"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 454 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 455 | void IA32x64Tests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 456 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 457 | cper_log_section_dual_binary_test("ia32x64"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 458 | } |
| 459 | |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 460 | // void IPFTests_IRValid() { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 461 | // cper_log_section_dual_ir_test("ipf"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 462 | // } |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 463 | |
| 464 | //ARM tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 465 | void ArmTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 466 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 467 | cper_log_section_dual_ir_test("arm"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 468 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 469 | void ArmTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 470 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 471 | cper_log_section_dual_binary_test("arm"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | //Memory tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 475 | void MemoryTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 476 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 477 | cper_log_section_dual_ir_test("memory"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 478 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 479 | void MemoryTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 480 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 481 | cper_log_section_dual_binary_test("memory"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | //Memory 2 tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 485 | void Memory2Tests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 486 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 487 | cper_log_section_dual_ir_test("memory2"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 488 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 489 | void Memory2Tests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 490 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 491 | cper_log_section_dual_binary_test("memory2"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | //PCIe tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 495 | void PCIeTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 496 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 497 | cper_log_section_dual_ir_test("pcie"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 498 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 499 | void PCIeTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 500 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 501 | cper_log_section_dual_binary_test("pcie"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | //Firmware tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 505 | void FirmwareTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 506 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 507 | cper_log_section_dual_ir_test("firmware"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 508 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 509 | void FirmwareTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 510 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 511 | cper_log_section_dual_binary_test("firmware"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | //PCI Bus tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 515 | void PCIBusTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 516 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 517 | cper_log_section_dual_ir_test("pcibus"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 518 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 519 | void PCIBusTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 520 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 521 | cper_log_section_dual_binary_test("pcibus"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | //PCI Device tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 525 | void PCIDevTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 526 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 527 | cper_log_section_dual_ir_test("pcidev"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 528 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 529 | void PCIDevTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 530 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 531 | cper_log_section_dual_binary_test("pcidev"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | //Generic DMAr tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 535 | void DMArGenericTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 536 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 537 | cper_log_section_dual_ir_test("dmargeneric"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 538 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 539 | void DMArGenericTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 540 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 541 | cper_log_section_dual_binary_test("dmargeneric"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | //VT-d DMAr tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 545 | void DMArVtdTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 546 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 547 | cper_log_section_dual_ir_test("dmarvtd"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 548 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 549 | void DMArVtdTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 550 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 551 | cper_log_section_dual_binary_test("dmarvtd"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | //IOMMU DMAr tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 555 | void DMArIOMMUTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 556 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 557 | cper_log_section_dual_ir_test("dmariommu"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 558 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 559 | void DMArIOMMUTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 560 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 561 | cper_log_section_dual_binary_test("dmariommu"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | //CCIX PER tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 565 | void CCIXPERTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 566 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 567 | cper_log_section_dual_ir_test("ccixper"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 568 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 569 | void CCIXPERTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 570 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 571 | cper_log_section_dual_binary_test("ccixper"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | //CXL Protocol tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 575 | void CXLProtocolTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 576 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 577 | cper_log_section_dual_ir_test("cxlprotocol"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 578 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 579 | void CXLProtocolTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 580 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 581 | cper_log_section_dual_binary_test("cxlprotocol"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | //CXL Component tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 585 | void CXLComponentTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 586 | { |
Lawrence Tang | 8f97745 | 2022-08-24 14:55:07 +0100 | [diff] [blame] | 587 | cper_log_section_dual_ir_test("cxlcomponent-media"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 588 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 589 | void CXLComponentTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 590 | { |
Lawrence Tang | 8f97745 | 2022-08-24 14:55:07 +0100 | [diff] [blame] | 591 | cper_log_section_dual_binary_test("cxlcomponent-media"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Ed Tanous | 2d17ace | 2024-08-27 14:45:38 -0700 | [diff] [blame] | 594 | //NVIDIA section tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 595 | void NVIDIASectionTests_IRValid() |
Ed Tanous | 2d17ace | 2024-08-27 14:45:38 -0700 | [diff] [blame] | 596 | { |
| 597 | cper_log_section_dual_ir_test("nvidia"); |
| 598 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 599 | void NVIDIASectionTests_BinaryEqual() |
Ed Tanous | 2d17ace | 2024-08-27 14:45:38 -0700 | [diff] [blame] | 600 | { |
| 601 | cper_log_section_dual_binary_test("nvidia"); |
| 602 | } |
| 603 | |
Ed Tanous | 55968b1 | 2025-05-06 21:04:52 -0700 | [diff] [blame] | 604 | void NVIDIACMETSectionTests_IRValid() |
| 605 | { |
| 606 | cper_example_section_ir_test("nvidia_cmet_info"); |
| 607 | } |
| 608 | |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 609 | //Unknown section tests. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 610 | void UnknownSectionTests_IRValid() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 611 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 612 | cper_log_section_dual_ir_test("unknown"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 613 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 614 | void UnknownSectionTests_BinaryEqual() |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame] | 615 | { |
Lawrence Tang | a4f662f | 2022-08-08 14:37:36 +0100 | [diff] [blame] | 616 | cper_log_section_dual_binary_test("unknown"); |
Lawrence Tang | cd50520 | 2022-07-19 16:55:11 +0100 | [diff] [blame] | 617 | } |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 618 | |
| 619 | //Entrypoint for the testing program. |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 620 | int main() |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 621 | { |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 622 | if (GEN_EXAMPLES) { |
| 623 | cper_create_examples("arm"); |
| 624 | cper_create_examples("ia32x64"); |
| 625 | cper_create_examples("memory"); |
| 626 | cper_create_examples("memory2"); |
| 627 | cper_create_examples("pcie"); |
| 628 | cper_create_examples("firmware"); |
| 629 | cper_create_examples("pcibus"); |
| 630 | cper_create_examples("pcidev"); |
| 631 | cper_create_examples("dmargeneric"); |
| 632 | cper_create_examples("dmarvtd"); |
| 633 | cper_create_examples("dmariommu"); |
| 634 | cper_create_examples("ccixper"); |
| 635 | cper_create_examples("cxlprotocol"); |
| 636 | cper_create_examples("cxlcomponent-media"); |
| 637 | cper_create_examples("nvidia"); |
| 638 | cper_create_examples("unknown"); |
| 639 | } |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 640 | test_base64_encode_good(); |
| 641 | test_base64_decode_good(); |
| 642 | GenericProcessorTests_IRValid(); |
| 643 | GenericProcessorTests_BinaryEqual(); |
| 644 | IA32x64Tests_IRValid(); |
| 645 | IA32x64Tests_BinaryEqual(); |
| 646 | ArmTests_IRValid(); |
| 647 | ArmTests_BinaryEqual(); |
| 648 | MemoryTests_IRValid(); |
| 649 | MemoryTests_BinaryEqual(); |
| 650 | Memory2Tests_IRValid(); |
| 651 | Memory2Tests_BinaryEqual(); |
| 652 | PCIeTests_IRValid(); |
| 653 | PCIeTests_BinaryEqual(); |
| 654 | FirmwareTests_IRValid(); |
| 655 | FirmwareTests_BinaryEqual(); |
| 656 | PCIBusTests_IRValid(); |
| 657 | PCIBusTests_BinaryEqual(); |
| 658 | PCIDevTests_IRValid(); |
| 659 | PCIDevTests_BinaryEqual(); |
| 660 | DMArGenericTests_IRValid(); |
| 661 | DMArGenericTests_BinaryEqual(); |
| 662 | DMArVtdTests_IRValid(); |
| 663 | DMArVtdTests_BinaryEqual(); |
| 664 | DMArIOMMUTests_IRValid(); |
| 665 | DMArIOMMUTests_BinaryEqual(); |
| 666 | CCIXPERTests_IRValid(); |
| 667 | CCIXPERTests_BinaryEqual(); |
| 668 | CXLProtocolTests_IRValid(); |
| 669 | CXLProtocolTests_BinaryEqual(); |
| 670 | CXLComponentTests_IRValid(); |
| 671 | CXLComponentTests_BinaryEqual(); |
| 672 | NVIDIASectionTests_IRValid(); |
| 673 | NVIDIASectionTests_BinaryEqual(); |
Ed Tanous | 55968b1 | 2025-05-06 21:04:52 -0700 | [diff] [blame] | 674 | NVIDIACMETSectionTests_IRValid(); |
Ed Tanous | 5464029 | 2025-03-17 20:55:20 -0700 | [diff] [blame] | 675 | UnknownSectionTests_IRValid(); |
| 676 | UnknownSectionTests_BinaryEqual(); |
| 677 | CompileTimeAssertions_TwoWayConversion(); |
| 678 | CompileTimeAssertions_ShortcodeNoSpaces(); |
| 679 | |
| 680 | printf("\n\nTest completed successfully.\n"); |
| 681 | |
| 682 | return 0; |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 683 | } |