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