Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 2 | /* Test pldm_msgbuf_extract() separately because we can't do _Generic() in C++ |
| 3 | * code, i.e. gtest */ |
| 4 | |
| 5 | #include <endian.h> |
| 6 | #include <float.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | /* We're exercising the implementation so disable the asserts for now */ |
| 11 | #ifndef NDEBUG |
| 12 | #define NDEBUG 1 |
| 13 | #endif |
| 14 | #include "msgbuf.h" |
| 15 | |
| 16 | /* Given we disabled asserts above, set up our own expectation framework */ |
| 17 | #define expect(cond) __expect(__func__, __LINE__, (cond)) |
| 18 | #define __expect(fn, line, cond) \ |
| 19 | do \ |
| 20 | { \ |
| 21 | if (!(cond)) \ |
| 22 | { \ |
| 23 | fprintf(stderr, "%s:%d: failed expectation: %s\n", fn, line, \ |
| 24 | #cond); \ |
| 25 | exit(EXIT_FAILURE); \ |
| 26 | } \ |
| 27 | } while (0) |
| 28 | |
| 29 | static void test_msgbuf_extract_generic_uint8(void) |
| 30 | { |
| 31 | struct pldm_msgbuf _ctx; |
| 32 | struct pldm_msgbuf* ctx = &_ctx; |
| 33 | uint8_t buf[1] = {0xa5}; |
| 34 | uint8_t val; |
| 35 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 36 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 37 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 38 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 39 | expect(val == 0xa5); |
| 40 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 41 | } |
| 42 | |
| 43 | static void test_msgbuf_extract_generic_int8(void) |
| 44 | { |
| 45 | struct pldm_msgbuf _ctx; |
| 46 | struct pldm_msgbuf* ctx = &_ctx; |
| 47 | int8_t buf[1] = {-1}; |
| 48 | int8_t val; |
| 49 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 50 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 51 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 52 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 53 | expect(val == -1); |
| 54 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 55 | } |
| 56 | |
| 57 | static void test_msgbuf_extract_generic_uint16(void) |
| 58 | { |
| 59 | struct pldm_msgbuf _ctx; |
| 60 | struct pldm_msgbuf* ctx = &_ctx; |
| 61 | uint16_t buf[1] = {0x5aa5}; |
| 62 | uint16_t val; |
| 63 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 64 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 65 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 66 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 67 | expect(val == 0x5aa5); |
| 68 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 69 | } |
| 70 | |
| 71 | static void test_msgbuf_extract_generic_int16(void) |
| 72 | { |
| 73 | struct pldm_msgbuf _ctx; |
| 74 | struct pldm_msgbuf* ctx = &_ctx; |
| 75 | int16_t buf[1] = {(int16_t)(htole16((uint16_t)INT16_MIN))}; |
| 76 | int16_t val; |
| 77 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 78 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 79 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 80 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 81 | expect(val == INT16_MIN); |
| 82 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 83 | } |
| 84 | |
| 85 | static void test_msgbuf_extract_generic_uint32(void) |
| 86 | { |
| 87 | struct pldm_msgbuf _ctx; |
| 88 | struct pldm_msgbuf* ctx = &_ctx; |
| 89 | uint32_t buf[1] = {0x5a00ffa5}; |
| 90 | uint32_t val; |
| 91 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 92 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 93 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 94 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 95 | expect(val == 0x5a00ffa5); |
| 96 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 97 | } |
| 98 | |
| 99 | static void test_msgbuf_extract_generic_int32(void) |
| 100 | { |
| 101 | struct pldm_msgbuf _ctx; |
| 102 | struct pldm_msgbuf* ctx = &_ctx; |
| 103 | int32_t buf[1] = {(int32_t)(htole32((uint32_t)INT32_MIN))}; |
| 104 | int32_t val; |
| 105 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 106 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 107 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 108 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 109 | expect(val == INT32_MIN); |
| 110 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 111 | } |
| 112 | |
| 113 | static void test_msgbuf_extract_generic_real32(void) |
| 114 | { |
| 115 | struct pldm_msgbuf _ctx; |
| 116 | struct pldm_msgbuf* ctx = &_ctx; |
| 117 | uint32_t buf[1]; |
| 118 | uint32_t xform; |
| 119 | real32_t val; |
| 120 | |
| 121 | val = FLT_MAX; |
| 122 | memcpy(&xform, &val, sizeof(val)); |
| 123 | buf[0] = htole32(xform); |
| 124 | val = 0; |
| 125 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 126 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 127 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 128 | expect(pldm_msgbuf_extract(ctx, val) == PLDM_SUCCESS); |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 129 | expect(val == FLT_MAX); |
| 130 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 131 | } |
| 132 | |
Andrew Jeffery | 369b121 | 2023-04-20 15:44:48 +0930 | [diff] [blame] | 133 | static void test_msgbuf_extract_array_generic_uint8(void) |
| 134 | { |
| 135 | struct pldm_msgbuf _ctx; |
| 136 | struct pldm_msgbuf* ctx = &_ctx; |
| 137 | uint32_t buf[1] = {0}; |
| 138 | uint8_t arr[1]; |
| 139 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 140 | expect(pldm_msgbuf_init_cc(ctx, sizeof(buf), buf, sizeof(buf)) == |
Andrew Jeffery | 369b121 | 2023-04-20 15:44:48 +0930 | [diff] [blame] | 141 | PLDM_SUCCESS); |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame^] | 142 | expect(pldm_msgbuf_extract_array(ctx, 1, arr, 1) == PLDM_SUCCESS); |
Andrew Jeffery | 369b121 | 2023-04-20 15:44:48 +0930 | [diff] [blame] | 143 | expect(arr[0] == 0); |
| 144 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 145 | } |
| 146 | |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 147 | static void test_msgbuf_insert_generic_int32(void) |
| 148 | { |
| 149 | struct pldm_msgbuf _ctx; |
| 150 | struct pldm_msgbuf* ctx = &_ctx; |
| 151 | int32_t src = -12345; |
| 152 | int32_t checkVal = 0; |
| 153 | uint8_t buf[sizeof(int32_t)] = {0}; |
| 154 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 155 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 156 | expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS); |
| 157 | |
| 158 | struct pldm_msgbuf _ctxExtract; |
| 159 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 160 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 161 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 162 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 163 | expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 164 | |
| 165 | expect(src == checkVal); |
| 166 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 167 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 168 | } |
| 169 | |
| 170 | static void test_msgbuf_insert_generic_uint32(void) |
| 171 | { |
| 172 | struct pldm_msgbuf _ctx; |
| 173 | struct pldm_msgbuf* ctx = &_ctx; |
| 174 | uint32_t src = 0xf1223344; |
| 175 | uint32_t checkVal = 0; |
| 176 | uint8_t buf[sizeof(uint32_t)] = {0}; |
| 177 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 178 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 179 | expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS); |
| 180 | |
| 181 | struct pldm_msgbuf _ctxExtract; |
| 182 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 183 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 184 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 185 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 186 | expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 187 | |
| 188 | expect(src == checkVal); |
| 189 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 190 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 191 | } |
| 192 | |
| 193 | static void test_msgbuf_insert_generic_uint16(void) |
| 194 | { |
| 195 | struct pldm_msgbuf _ctx; |
| 196 | struct pldm_msgbuf* ctx = &_ctx; |
| 197 | uint16_t src = 0xf344; |
| 198 | uint16_t checkVal = 0; |
| 199 | uint8_t buf[sizeof(uint16_t)] = {0}; |
| 200 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 201 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(uint16_t)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 202 | expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS); |
| 203 | |
| 204 | struct pldm_msgbuf _ctxExtract; |
| 205 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 206 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 207 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 208 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 209 | expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 210 | |
| 211 | expect(src == checkVal); |
| 212 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 213 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 214 | } |
| 215 | |
| 216 | static void test_msgbuf_insert_generic_int16(void) |
| 217 | { |
| 218 | struct pldm_msgbuf _ctx; |
| 219 | struct pldm_msgbuf* ctx = &_ctx; |
| 220 | int16_t src = -12; |
| 221 | int16_t checkVal = 0; |
| 222 | uint8_t buf[sizeof(int16_t)] = {0}; |
| 223 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 224 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(uint16_t)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 225 | expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS); |
| 226 | |
| 227 | struct pldm_msgbuf _ctxExtract; |
| 228 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 229 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 230 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 231 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 232 | expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 233 | |
| 234 | expect(src == checkVal); |
| 235 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 236 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 237 | } |
| 238 | |
| 239 | static void test_msgbuf_insert_generic_uint8(void) |
| 240 | { |
| 241 | struct pldm_msgbuf _ctx; |
| 242 | struct pldm_msgbuf* ctx = &_ctx; |
| 243 | uint8_t src = 0xf4; |
| 244 | uint8_t checkVal = 0; |
| 245 | uint8_t buf[sizeof(uint8_t)] = {0}; |
| 246 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 247 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 248 | expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS); |
| 249 | |
| 250 | struct pldm_msgbuf _ctxExtract; |
| 251 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 252 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 253 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 254 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 255 | expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 256 | |
| 257 | expect(src == checkVal); |
| 258 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 259 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 260 | } |
| 261 | |
| 262 | static void test_msgbuf_insert_generic_int8(void) |
| 263 | { |
| 264 | struct pldm_msgbuf _ctx; |
| 265 | struct pldm_msgbuf* ctx = &_ctx; |
| 266 | int8_t src = -4; |
| 267 | int8_t checkVal = 0; |
| 268 | uint8_t buf[sizeof(int8_t)] = {0}; |
| 269 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 270 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 271 | expect(pldm_msgbuf_insert(ctx, src) == PLDM_SUCCESS); |
| 272 | |
| 273 | struct pldm_msgbuf _ctxExtract; |
| 274 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 275 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 276 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 277 | PLDM_SUCCESS); |
Andrew Jeffery | 66c7723 | 2024-04-24 11:42:02 +0930 | [diff] [blame] | 278 | expect(pldm_msgbuf_extract(ctxExtract, checkVal) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 279 | |
| 280 | expect(src == checkVal); |
| 281 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 282 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 283 | } |
| 284 | |
| 285 | static void test_msgbuf_insert_array_generic_uint8(void) |
| 286 | { |
| 287 | struct pldm_msgbuf _ctx; |
| 288 | struct pldm_msgbuf* ctx = &_ctx; |
| 289 | uint8_t src[6] = {0x11, 0x22, 0x44, 0x55, 0x66, 0x77}; |
| 290 | uint8_t buf[6] = {0}; |
| 291 | uint8_t retBuff[6] = {0}; |
| 292 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 293 | expect(pldm_msgbuf_init_cc(ctx, 0, buf, sizeof(buf)) == PLDM_SUCCESS); |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame^] | 294 | expect(pldm_msgbuf_insert_array(ctx, sizeof(src), src, sizeof(src)) == |
| 295 | PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 296 | |
| 297 | struct pldm_msgbuf _ctxExtract; |
| 298 | struct pldm_msgbuf* ctxExtract = &_ctxExtract; |
| 299 | |
Andrew Jeffery | c8df31c | 2024-05-21 16:47:43 +0930 | [diff] [blame] | 300 | expect(pldm_msgbuf_init_cc(ctxExtract, 0, buf, sizeof(buf)) == |
| 301 | PLDM_SUCCESS); |
Andrew Jeffery | 0a1be3c | 2024-08-11 08:34:10 +0000 | [diff] [blame^] | 302 | expect(pldm_msgbuf_extract_array(ctxExtract, sizeof(retBuff), retBuff, |
| 303 | sizeof(retBuff)) == PLDM_SUCCESS); |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 304 | |
| 305 | expect(memcmp(src, retBuff, sizeof(retBuff)) == 0); |
| 306 | expect(pldm_msgbuf_destroy(ctxExtract) == PLDM_SUCCESS); |
| 307 | expect(pldm_msgbuf_destroy(ctx) == PLDM_SUCCESS); |
| 308 | } |
| 309 | |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 310 | typedef void (*testfn)(void); |
| 311 | |
Andrew Jeffery | 369b121 | 2023-04-20 15:44:48 +0930 | [diff] [blame] | 312 | static const testfn tests[] = {test_msgbuf_extract_generic_uint8, |
| 313 | test_msgbuf_extract_generic_int8, |
| 314 | test_msgbuf_extract_generic_uint16, |
| 315 | test_msgbuf_extract_generic_int16, |
| 316 | test_msgbuf_extract_generic_uint32, |
| 317 | test_msgbuf_extract_generic_int32, |
| 318 | test_msgbuf_extract_generic_real32, |
| 319 | test_msgbuf_extract_array_generic_uint8, |
Thu Nguyen | 062c876 | 2023-04-22 20:45:04 +0700 | [diff] [blame] | 320 | test_msgbuf_insert_generic_uint8, |
| 321 | test_msgbuf_insert_generic_int8, |
| 322 | test_msgbuf_insert_generic_uint16, |
| 323 | test_msgbuf_insert_generic_int16, |
| 324 | test_msgbuf_insert_generic_uint32, |
| 325 | test_msgbuf_insert_generic_int32, |
| 326 | test_msgbuf_insert_array_generic_uint8, |
Andrew Jeffery | 369b121 | 2023-04-20 15:44:48 +0930 | [diff] [blame] | 327 | NULL}; |
Andrew Jeffery | c63f63a | 2023-02-24 22:29:33 +1030 | [diff] [blame] | 328 | |
| 329 | int main(void) |
| 330 | { |
| 331 | testfn const* testp = &tests[0]; |
| 332 | |
| 333 | while (*testp) |
| 334 | { |
| 335 | (*testp)(); |
| 336 | testp++; |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |