1 // SPDX-License-Identifier: BSD-3-Clause 2 /* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries. 3 * Microchip VCAP API kunit test suite 4 */ 5 6 #include <kunit/test.h> 7 #include "vcap_api.h" 8 #include "vcap_api_client.h" 9 #include "vcap_model_kunit.h" 10 11 /* First we have the test infrastructure that emulates the platform 12 * implementation 13 */ 14 #define TEST_BUF_CNT 100 15 #define TEST_BUF_SZ 350 16 #define STREAMWSIZE 64 17 18 static u32 test_updateaddr[STREAMWSIZE] = {}; 19 static int test_updateaddridx; 20 static int test_cache_erase_count; 21 static u32 test_init_start; 22 static u32 test_init_count; 23 static u32 test_hw_counter_id; 24 static struct vcap_cache_data test_hw_cache; 25 static struct net_device test_netdev = {}; 26 27 /* Callback used by the VCAP API */ 28 static enum vcap_keyfield_set test_val_keyset(struct net_device *ndev, 29 struct vcap_admin *admin, 30 struct vcap_rule *rule, 31 struct vcap_keyset_list *kslist, 32 u16 l3_proto) 33 { 34 int idx; 35 36 if (kslist->cnt > 0) { 37 switch (admin->vtype) { 38 case VCAP_TYPE_IS0: 39 for (idx = 0; idx < kslist->cnt; idx++) { 40 if (kslist->keysets[idx] == VCAP_KFS_ETAG) 41 return kslist->keysets[idx]; 42 if (kslist->keysets[idx] == VCAP_KFS_PURE_5TUPLE_IP4) 43 return kslist->keysets[idx]; 44 if (kslist->keysets[idx] == VCAP_KFS_NORMAL_5TUPLE_IP4) 45 return kslist->keysets[idx]; 46 if (kslist->keysets[idx] == VCAP_KFS_NORMAL_7TUPLE) 47 return kslist->keysets[idx]; 48 } 49 break; 50 case VCAP_TYPE_IS2: 51 for (idx = 0; idx < kslist->cnt; idx++) { 52 if (kslist->keysets[idx] == VCAP_KFS_MAC_ETYPE) 53 return kslist->keysets[idx]; 54 if (kslist->keysets[idx] == VCAP_KFS_ARP) 55 return kslist->keysets[idx]; 56 if (kslist->keysets[idx] == VCAP_KFS_IP_7TUPLE) 57 return kslist->keysets[idx]; 58 } 59 break; 60 default: 61 pr_info("%s:%d: no validation for VCAP %d\n", 62 __func__, __LINE__, admin->vtype); 63 break; 64 } 65 } 66 return -EINVAL; 67 } 68 69 /* Callback used by the VCAP API */ 70 static void test_add_def_fields(struct net_device *ndev, 71 struct vcap_admin *admin, 72 struct vcap_rule *rule) 73 { 74 if (admin->vinst == 0 || admin->vinst == 2) 75 vcap_rule_add_key_bit(rule, VCAP_KF_LOOKUP_FIRST_IS, VCAP_BIT_1); 76 else 77 vcap_rule_add_key_bit(rule, VCAP_KF_LOOKUP_FIRST_IS, VCAP_BIT_0); 78 } 79 80 /* Callback used by the VCAP API */ 81 static void test_cache_erase(struct vcap_admin *admin) 82 { 83 if (test_cache_erase_count) { 84 memset(admin->cache.keystream, 0, test_cache_erase_count); 85 memset(admin->cache.maskstream, 0, test_cache_erase_count); 86 memset(admin->cache.actionstream, 0, test_cache_erase_count); 87 test_cache_erase_count = 0; 88 } 89 } 90 91 /* Callback used by the VCAP API */ 92 static void test_cache_init(struct net_device *ndev, struct vcap_admin *admin, 93 u32 start, u32 count) 94 { 95 test_init_start = start; 96 test_init_count = count; 97 } 98 99 /* Callback used by the VCAP API */ 100 static void test_cache_read(struct net_device *ndev, struct vcap_admin *admin, 101 enum vcap_selection sel, u32 start, u32 count) 102 { 103 u32 *keystr, *mskstr, *actstr; 104 int idx; 105 106 pr_debug("%s:%d: %d %d\n", __func__, __LINE__, start, count); 107 switch (sel) { 108 case VCAP_SEL_ENTRY: 109 keystr = &admin->cache.keystream[start]; 110 mskstr = &admin->cache.maskstream[start]; 111 for (idx = 0; idx < count; ++idx) { 112 pr_debug("%s:%d: keydata[%02d]: 0x%08x\n", __func__, 113 __LINE__, start + idx, keystr[idx]); 114 } 115 for (idx = 0; idx < count; ++idx) { 116 /* Invert the mask before decoding starts */ 117 mskstr[idx] = ~mskstr[idx]; 118 pr_debug("%s:%d: mskdata[%02d]: 0x%08x\n", __func__, 119 __LINE__, start + idx, mskstr[idx]); 120 } 121 break; 122 case VCAP_SEL_ACTION: 123 actstr = &admin->cache.actionstream[start]; 124 for (idx = 0; idx < count; ++idx) { 125 pr_debug("%s:%d: actdata[%02d]: 0x%08x\n", __func__, 126 __LINE__, start + idx, actstr[idx]); 127 } 128 break; 129 case VCAP_SEL_COUNTER: 130 pr_debug("%s:%d\n", __func__, __LINE__); 131 test_hw_counter_id = start; 132 admin->cache.counter = test_hw_cache.counter; 133 admin->cache.sticky = test_hw_cache.sticky; 134 break; 135 case VCAP_SEL_ALL: 136 pr_debug("%s:%d\n", __func__, __LINE__); 137 break; 138 } 139 } 140 141 /* Callback used by the VCAP API */ 142 static void test_cache_write(struct net_device *ndev, struct vcap_admin *admin, 143 enum vcap_selection sel, u32 start, u32 count) 144 { 145 u32 *keystr, *mskstr, *actstr; 146 int idx; 147 148 switch (sel) { 149 case VCAP_SEL_ENTRY: 150 keystr = &admin->cache.keystream[start]; 151 mskstr = &admin->cache.maskstream[start]; 152 for (idx = 0; idx < count; ++idx) { 153 pr_debug("%s:%d: keydata[%02d]: 0x%08x\n", __func__, 154 __LINE__, start + idx, keystr[idx]); 155 } 156 for (idx = 0; idx < count; ++idx) { 157 /* Invert the mask before encoding starts */ 158 mskstr[idx] = ~mskstr[idx]; 159 pr_debug("%s:%d: mskdata[%02d]: 0x%08x\n", __func__, 160 __LINE__, start + idx, mskstr[idx]); 161 } 162 break; 163 case VCAP_SEL_ACTION: 164 actstr = &admin->cache.actionstream[start]; 165 for (idx = 0; idx < count; ++idx) { 166 pr_debug("%s:%d: actdata[%02d]: 0x%08x\n", __func__, 167 __LINE__, start + idx, actstr[idx]); 168 } 169 break; 170 case VCAP_SEL_COUNTER: 171 pr_debug("%s:%d\n", __func__, __LINE__); 172 test_hw_counter_id = start; 173 test_hw_cache.counter = admin->cache.counter; 174 test_hw_cache.sticky = admin->cache.sticky; 175 break; 176 case VCAP_SEL_ALL: 177 pr_err("%s:%d: cannot write all streams at once\n", 178 __func__, __LINE__); 179 break; 180 } 181 } 182 183 /* Callback used by the VCAP API */ 184 static void test_cache_update(struct net_device *ndev, struct vcap_admin *admin, 185 enum vcap_command cmd, 186 enum vcap_selection sel, u32 addr) 187 { 188 if (test_updateaddridx < ARRAY_SIZE(test_updateaddr)) 189 test_updateaddr[test_updateaddridx] = addr; 190 else 191 pr_err("%s:%d: overflow: %d\n", __func__, __LINE__, test_updateaddridx); 192 test_updateaddridx++; 193 } 194 195 static void test_cache_move(struct net_device *ndev, struct vcap_admin *admin, 196 u32 addr, int offset, int count) 197 { 198 } 199 200 /* Provide port information via a callback interface */ 201 static int vcap_test_port_info(struct net_device *ndev, enum vcap_type vtype, 202 int (*pf)(void *out, int arg, const char *fmt, ...), 203 void *out, int arg) 204 { 205 return 0; 206 } 207 208 static int vcap_test_enable(struct net_device *ndev, 209 struct vcap_admin *admin, 210 bool enable) 211 { 212 return 0; 213 } 214 215 static struct vcap_operations test_callbacks = { 216 .validate_keyset = test_val_keyset, 217 .add_default_fields = test_add_def_fields, 218 .cache_erase = test_cache_erase, 219 .cache_write = test_cache_write, 220 .cache_read = test_cache_read, 221 .init = test_cache_init, 222 .update = test_cache_update, 223 .move = test_cache_move, 224 .port_info = vcap_test_port_info, 225 .enable = vcap_test_enable, 226 }; 227 228 static struct vcap_control test_vctrl = { 229 .vcaps = kunit_test_vcaps, 230 .stats = &kunit_test_vcap_stats, 231 .ops = &test_callbacks, 232 }; 233 234 static void vcap_test_api_init(struct vcap_admin *admin) 235 { 236 /* Initialize the shared objects */ 237 INIT_LIST_HEAD(&test_vctrl.list); 238 INIT_LIST_HEAD(&admin->list); 239 INIT_LIST_HEAD(&admin->rules); 240 list_add_tail(&admin->list, &test_vctrl.list); 241 memset(test_updateaddr, 0, sizeof(test_updateaddr)); 242 test_updateaddridx = 0; 243 } 244 245 /* Define the test cases. */ 246 247 static void vcap_api_set_bit_1_test(struct kunit *test) 248 { 249 struct vcap_stream_iter iter = { 250 .offset = 35, 251 .sw_width = 52, 252 .reg_idx = 1, 253 .reg_bitpos = 20, 254 .tg = 0 255 }; 256 u32 stream[2] = {0}; 257 258 vcap_set_bit(stream, &iter, 1); 259 260 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[0]); 261 KUNIT_EXPECT_EQ(test, (u32)BIT(20), stream[1]); 262 } 263 264 static void vcap_api_set_bit_0_test(struct kunit *test) 265 { 266 struct vcap_stream_iter iter = { 267 .offset = 35, 268 .sw_width = 52, 269 .reg_idx = 2, 270 .reg_bitpos = 11, 271 .tg = 0 272 }; 273 u32 stream[3] = {~0, ~0, ~0}; 274 275 vcap_set_bit(stream, &iter, 0); 276 277 KUNIT_EXPECT_EQ(test, (u32)~0, stream[0]); 278 KUNIT_EXPECT_EQ(test, (u32)~0, stream[1]); 279 KUNIT_EXPECT_EQ(test, (u32)~BIT(11), stream[2]); 280 } 281 282 static void vcap_api_iterator_init_test(struct kunit *test) 283 { 284 struct vcap_stream_iter iter; 285 struct vcap_typegroup typegroups[] = { 286 { .offset = 0, .width = 2, .value = 2, }, 287 { .offset = 156, .width = 1, .value = 0, }, 288 { .offset = 0, .width = 0, .value = 0, }, 289 }; 290 struct vcap_typegroup typegroups2[] = { 291 { .offset = 0, .width = 3, .value = 4, }, 292 { .offset = 49, .width = 2, .value = 0, }, 293 { .offset = 98, .width = 2, .value = 0, }, 294 }; 295 296 vcap_iter_init(&iter, 52, typegroups, 86); 297 298 KUNIT_EXPECT_EQ(test, 52, iter.sw_width); 299 KUNIT_EXPECT_EQ(test, 86 + 2, iter.offset); 300 KUNIT_EXPECT_EQ(test, 3, iter.reg_idx); 301 KUNIT_EXPECT_EQ(test, 4, iter.reg_bitpos); 302 303 vcap_iter_init(&iter, 49, typegroups2, 134); 304 305 KUNIT_EXPECT_EQ(test, 49, iter.sw_width); 306 KUNIT_EXPECT_EQ(test, 134 + 7, iter.offset); 307 KUNIT_EXPECT_EQ(test, 5, iter.reg_idx); 308 KUNIT_EXPECT_EQ(test, 11, iter.reg_bitpos); 309 } 310 311 static void vcap_api_iterator_next_test(struct kunit *test) 312 { 313 struct vcap_stream_iter iter; 314 struct vcap_typegroup typegroups[] = { 315 { .offset = 0, .width = 4, .value = 8, }, 316 { .offset = 49, .width = 1, .value = 0, }, 317 { .offset = 98, .width = 2, .value = 0, }, 318 { .offset = 147, .width = 3, .value = 0, }, 319 { .offset = 196, .width = 2, .value = 0, }, 320 { .offset = 245, .width = 1, .value = 0, }, 321 }; 322 int idx; 323 324 vcap_iter_init(&iter, 49, typegroups, 86); 325 326 KUNIT_EXPECT_EQ(test, 49, iter.sw_width); 327 KUNIT_EXPECT_EQ(test, 86 + 5, iter.offset); 328 KUNIT_EXPECT_EQ(test, 3, iter.reg_idx); 329 KUNIT_EXPECT_EQ(test, 10, iter.reg_bitpos); 330 331 vcap_iter_next(&iter); 332 333 KUNIT_EXPECT_EQ(test, 91 + 1, iter.offset); 334 KUNIT_EXPECT_EQ(test, 3, iter.reg_idx); 335 KUNIT_EXPECT_EQ(test, 11, iter.reg_bitpos); 336 337 for (idx = 0; idx < 6; idx++) 338 vcap_iter_next(&iter); 339 340 KUNIT_EXPECT_EQ(test, 92 + 6 + 2, iter.offset); 341 KUNIT_EXPECT_EQ(test, 4, iter.reg_idx); 342 KUNIT_EXPECT_EQ(test, 2, iter.reg_bitpos); 343 } 344 345 static void vcap_api_encode_typegroups_test(struct kunit *test) 346 { 347 u32 stream[12] = {0}; 348 struct vcap_typegroup typegroups[] = { 349 { .offset = 0, .width = 4, .value = 8, }, 350 { .offset = 49, .width = 1, .value = 1, }, 351 { .offset = 98, .width = 2, .value = 3, }, 352 { .offset = 147, .width = 3, .value = 5, }, 353 { .offset = 196, .width = 2, .value = 2, }, 354 { .offset = 245, .width = 5, .value = 27, }, 355 { .offset = 0, .width = 0, .value = 0, }, 356 }; 357 358 vcap_encode_typegroups(stream, 49, typegroups, false); 359 360 KUNIT_EXPECT_EQ(test, (u32)0x8, stream[0]); 361 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[1]); 362 KUNIT_EXPECT_EQ(test, (u32)0x1, stream[2]); 363 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[3]); 364 KUNIT_EXPECT_EQ(test, (u32)0x3, stream[4]); 365 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[5]); 366 KUNIT_EXPECT_EQ(test, (u32)0x5, stream[6]); 367 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[7]); 368 KUNIT_EXPECT_EQ(test, (u32)0x2, stream[8]); 369 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[9]); 370 KUNIT_EXPECT_EQ(test, (u32)27, stream[10]); 371 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[11]); 372 } 373 374 static void vcap_api_encode_bit_test(struct kunit *test) 375 { 376 struct vcap_stream_iter iter; 377 u32 stream[4] = {0}; 378 struct vcap_typegroup typegroups[] = { 379 { .offset = 0, .width = 4, .value = 8, }, 380 { .offset = 49, .width = 1, .value = 1, }, 381 { .offset = 98, .width = 2, .value = 3, }, 382 { .offset = 147, .width = 3, .value = 5, }, 383 { .offset = 196, .width = 2, .value = 2, }, 384 { .offset = 245, .width = 1, .value = 0, }, 385 }; 386 387 vcap_iter_init(&iter, 49, typegroups, 44); 388 389 KUNIT_EXPECT_EQ(test, 48, iter.offset); 390 KUNIT_EXPECT_EQ(test, 1, iter.reg_idx); 391 KUNIT_EXPECT_EQ(test, 16, iter.reg_bitpos); 392 393 vcap_encode_bit(stream, &iter, 1); 394 395 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[0]); 396 KUNIT_EXPECT_EQ(test, (u32)BIT(16), stream[1]); 397 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[2]); 398 } 399 400 static void vcap_api_encode_field_test(struct kunit *test) 401 { 402 struct vcap_stream_iter iter; 403 u32 stream[16] = {0}; 404 struct vcap_typegroup typegroups[] = { 405 { .offset = 0, .width = 4, .value = 8, }, 406 { .offset = 49, .width = 1, .value = 1, }, 407 { .offset = 98, .width = 2, .value = 3, }, 408 { .offset = 147, .width = 3, .value = 5, }, 409 { .offset = 196, .width = 2, .value = 2, }, 410 { .offset = 245, .width = 5, .value = 27, }, 411 { .offset = 0, .width = 0, .value = 0, }, 412 }; 413 struct vcap_field rf = { 414 .type = VCAP_FIELD_U32, 415 .offset = 86, 416 .width = 4, 417 }; 418 u8 value[] = {0x5}; 419 420 vcap_iter_init(&iter, 49, typegroups, rf.offset); 421 422 KUNIT_EXPECT_EQ(test, 91, iter.offset); 423 KUNIT_EXPECT_EQ(test, 3, iter.reg_idx); 424 KUNIT_EXPECT_EQ(test, 10, iter.reg_bitpos); 425 426 vcap_encode_field(stream, &iter, rf.width, value); 427 428 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[0]); 429 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[1]); 430 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[2]); 431 KUNIT_EXPECT_EQ(test, (u32)(0x5 << 10), stream[3]); 432 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[4]); 433 434 vcap_encode_typegroups(stream, 49, typegroups, false); 435 436 KUNIT_EXPECT_EQ(test, (u32)0x8, stream[0]); 437 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[1]); 438 KUNIT_EXPECT_EQ(test, (u32)0x1, stream[2]); 439 KUNIT_EXPECT_EQ(test, (u32)(0x5 << 10), stream[3]); 440 KUNIT_EXPECT_EQ(test, (u32)0x3, stream[4]); 441 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[5]); 442 KUNIT_EXPECT_EQ(test, (u32)0x5, stream[6]); 443 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[7]); 444 KUNIT_EXPECT_EQ(test, (u32)0x2, stream[8]); 445 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[9]); 446 KUNIT_EXPECT_EQ(test, (u32)27, stream[10]); 447 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[11]); 448 } 449 450 /* In this testcase the subword is smaller than a register */ 451 static void vcap_api_encode_short_field_test(struct kunit *test) 452 { 453 struct vcap_stream_iter iter; 454 int sw_width = 21; 455 u32 stream[6] = {0}; 456 struct vcap_typegroup tgt[] = { 457 { .offset = 0, .width = 3, .value = 7, }, 458 { .offset = 21, .width = 2, .value = 3, }, 459 { .offset = 42, .width = 1, .value = 1, }, 460 { .offset = 0, .width = 0, .value = 0, }, 461 }; 462 struct vcap_field rf = { 463 .type = VCAP_FIELD_U32, 464 .offset = 25, 465 .width = 4, 466 }; 467 u8 value[] = {0x5}; 468 469 vcap_iter_init(&iter, sw_width, tgt, rf.offset); 470 471 KUNIT_EXPECT_EQ(test, 1, iter.regs_per_sw); 472 KUNIT_EXPECT_EQ(test, 21, iter.sw_width); 473 KUNIT_EXPECT_EQ(test, 25 + 3 + 2, iter.offset); 474 KUNIT_EXPECT_EQ(test, 1, iter.reg_idx); 475 KUNIT_EXPECT_EQ(test, 25 + 3 + 2 - sw_width, iter.reg_bitpos); 476 477 vcap_encode_field(stream, &iter, rf.width, value); 478 479 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[0]); 480 KUNIT_EXPECT_EQ(test, (u32)(0x5 << (25 + 3 + 2 - sw_width)), stream[1]); 481 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[2]); 482 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[3]); 483 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[4]); 484 KUNIT_EXPECT_EQ(test, (u32)0x0, stream[5]); 485 486 vcap_encode_typegroups(stream, sw_width, tgt, false); 487 488 KUNIT_EXPECT_EQ(test, (u32)7, stream[0]); 489 KUNIT_EXPECT_EQ(test, (u32)((0x5 << (25 + 3 + 2 - sw_width)) + 3), stream[1]); 490 KUNIT_EXPECT_EQ(test, (u32)1, stream[2]); 491 KUNIT_EXPECT_EQ(test, (u32)0, stream[3]); 492 KUNIT_EXPECT_EQ(test, (u32)0, stream[4]); 493 KUNIT_EXPECT_EQ(test, (u32)0, stream[5]); 494 } 495 496 static void vcap_api_encode_keyfield_test(struct kunit *test) 497 { 498 u32 keywords[16] = {0}; 499 u32 maskwords[16] = {0}; 500 struct vcap_admin admin = { 501 .vtype = VCAP_TYPE_IS2, 502 .cache = { 503 .keystream = keywords, 504 .maskstream = maskwords, 505 .actionstream = keywords, 506 }, 507 }; 508 struct vcap_rule_internal rule = { 509 .admin = &admin, 510 .data = { 511 .keyset = VCAP_KFS_MAC_ETYPE, 512 }, 513 .vctrl = &test_vctrl, 514 }; 515 struct vcap_client_keyfield ckf = { 516 .ctrl.list = {}, 517 .ctrl.key = VCAP_KF_ISDX_CLS, 518 .ctrl.type = VCAP_FIELD_U32, 519 .data.u32.value = 0xeef014a1, 520 .data.u32.mask = 0xfff, 521 }; 522 struct vcap_field rf = { 523 .type = VCAP_FIELD_U32, 524 .offset = 56, 525 .width = 12, 526 }; 527 struct vcap_typegroup tgt[] = { 528 { .offset = 0, .width = 2, .value = 2, }, 529 { .offset = 156, .width = 1, .value = 1, }, 530 { .offset = 0, .width = 0, .value = 0, }, 531 }; 532 533 vcap_test_api_init(&admin); 534 vcap_encode_keyfield(&rule, &ckf, &rf, tgt); 535 536 /* Key */ 537 KUNIT_EXPECT_EQ(test, (u32)0x0, keywords[0]); 538 KUNIT_EXPECT_EQ(test, (u32)0x0, keywords[1]); 539 KUNIT_EXPECT_EQ(test, (u32)(0x04a1 << 6), keywords[2]); 540 KUNIT_EXPECT_EQ(test, (u32)0x0, keywords[3]); 541 KUNIT_EXPECT_EQ(test, (u32)0x0, keywords[4]); 542 KUNIT_EXPECT_EQ(test, (u32)0x0, keywords[5]); 543 KUNIT_EXPECT_EQ(test, (u32)0x0, keywords[6]); 544 545 /* Mask */ 546 KUNIT_EXPECT_EQ(test, (u32)0x0, maskwords[0]); 547 KUNIT_EXPECT_EQ(test, (u32)0x0, maskwords[1]); 548 KUNIT_EXPECT_EQ(test, (u32)(0x0fff << 6), maskwords[2]); 549 KUNIT_EXPECT_EQ(test, (u32)0x0, maskwords[3]); 550 KUNIT_EXPECT_EQ(test, (u32)0x0, maskwords[4]); 551 KUNIT_EXPECT_EQ(test, (u32)0x0, maskwords[5]); 552 KUNIT_EXPECT_EQ(test, (u32)0x0, maskwords[6]); 553 } 554 555 static void vcap_api_encode_max_keyfield_test(struct kunit *test) 556 { 557 int idx; 558 u32 keywords[6] = {0}; 559 u32 maskwords[6] = {0}; 560 struct vcap_admin admin = { 561 .vtype = VCAP_TYPE_IS2, 562 /* IS2 sw_width = 52 bit */ 563 .cache = { 564 .keystream = keywords, 565 .maskstream = maskwords, 566 .actionstream = keywords, 567 }, 568 }; 569 struct vcap_rule_internal rule = { 570 .admin = &admin, 571 .data = { 572 .keyset = VCAP_KFS_IP_7TUPLE, 573 }, 574 .vctrl = &test_vctrl, 575 }; 576 struct vcap_client_keyfield ckf = { 577 .ctrl.list = {}, 578 .ctrl.key = VCAP_KF_L3_IP6_DIP, 579 .ctrl.type = VCAP_FIELD_U128, 580 .data.u128.value = { 0xa1, 0xa2, 0xa3, 0xa4, 0, 0, 0x43, 0, 581 0, 0, 0, 0, 0, 0, 0x78, 0x8e, }, 582 .data.u128.mask = { 0xff, 0xff, 0xff, 0xff, 0, 0, 0xff, 0, 583 0, 0, 0, 0, 0, 0, 0xff, 0xff }, 584 }; 585 struct vcap_field rf = { 586 .type = VCAP_FIELD_U128, 587 .offset = 0, 588 .width = 128, 589 }; 590 struct vcap_typegroup tgt[] = { 591 { .offset = 0, .width = 2, .value = 2, }, 592 { .offset = 156, .width = 1, .value = 1, }, 593 { .offset = 0, .width = 0, .value = 0, }, 594 }; 595 u32 keyres[] = { 596 0x928e8a84, 597 0x000c0002, 598 0x00000010, 599 0x00000000, 600 0x0239e000, 601 0x00000000, 602 }; 603 u32 mskres[] = { 604 0xfffffffc, 605 0x000c0003, 606 0x0000003f, 607 0x00000000, 608 0x03fffc00, 609 0x00000000, 610 }; 611 612 vcap_encode_keyfield(&rule, &ckf, &rf, tgt); 613 614 /* Key */ 615 for (idx = 0; idx < ARRAY_SIZE(keyres); ++idx) 616 KUNIT_EXPECT_EQ(test, keyres[idx], keywords[idx]); 617 /* Mask */ 618 for (idx = 0; idx < ARRAY_SIZE(mskres); ++idx) 619 KUNIT_EXPECT_EQ(test, mskres[idx], maskwords[idx]); 620 } 621 622 static void vcap_api_encode_actionfield_test(struct kunit *test) 623 { 624 u32 actwords[16] = {0}; 625 int sw_width = 21; 626 struct vcap_admin admin = { 627 .vtype = VCAP_TYPE_ES2, /* act_width = 21 */ 628 .cache = { 629 .actionstream = actwords, 630 }, 631 }; 632 struct vcap_rule_internal rule = { 633 .admin = &admin, 634 .data = { 635 .actionset = VCAP_AFS_BASE_TYPE, 636 }, 637 .vctrl = &test_vctrl, 638 }; 639 struct vcap_client_actionfield caf = { 640 .ctrl.list = {}, 641 .ctrl.action = VCAP_AF_POLICE_IDX, 642 .ctrl.type = VCAP_FIELD_U32, 643 .data.u32.value = 0x67908032, 644 }; 645 struct vcap_field rf = { 646 .type = VCAP_FIELD_U32, 647 .offset = 35, 648 .width = 6, 649 }; 650 struct vcap_typegroup tgt[] = { 651 { .offset = 0, .width = 2, .value = 2, }, 652 { .offset = 21, .width = 1, .value = 1, }, 653 { .offset = 42, .width = 1, .value = 0, }, 654 { .offset = 0, .width = 0, .value = 0, }, 655 }; 656 657 vcap_encode_actionfield(&rule, &caf, &rf, tgt); 658 659 /* Action */ 660 KUNIT_EXPECT_EQ(test, (u32)0x0, actwords[0]); 661 KUNIT_EXPECT_EQ(test, (u32)((0x32 << (35 + 2 + 1 - sw_width)) & 0x1fffff), actwords[1]); 662 KUNIT_EXPECT_EQ(test, (u32)((0x32 >> ((2 * sw_width) - 38 - 1))), actwords[2]); 663 KUNIT_EXPECT_EQ(test, (u32)0x0, actwords[3]); 664 KUNIT_EXPECT_EQ(test, (u32)0x0, actwords[4]); 665 KUNIT_EXPECT_EQ(test, (u32)0x0, actwords[5]); 666 KUNIT_EXPECT_EQ(test, (u32)0x0, actwords[6]); 667 } 668 669 static void vcap_api_keyfield_typegroup_test(struct kunit *test) 670 { 671 const struct vcap_typegroup *tg; 672 673 tg = vcap_keyfield_typegroup(&test_vctrl, VCAP_TYPE_IS2, VCAP_KFS_MAC_ETYPE); 674 KUNIT_EXPECT_PTR_NE(test, NULL, tg); 675 KUNIT_EXPECT_EQ(test, 0, tg[0].offset); 676 KUNIT_EXPECT_EQ(test, 2, tg[0].width); 677 KUNIT_EXPECT_EQ(test, 2, tg[0].value); 678 KUNIT_EXPECT_EQ(test, 156, tg[1].offset); 679 KUNIT_EXPECT_EQ(test, 1, tg[1].width); 680 KUNIT_EXPECT_EQ(test, 0, tg[1].value); 681 KUNIT_EXPECT_EQ(test, 0, tg[2].offset); 682 KUNIT_EXPECT_EQ(test, 0, tg[2].width); 683 KUNIT_EXPECT_EQ(test, 0, tg[2].value); 684 685 tg = vcap_keyfield_typegroup(&test_vctrl, VCAP_TYPE_ES2, VCAP_KFS_LL_FULL); 686 KUNIT_EXPECT_PTR_EQ(test, NULL, tg); 687 } 688 689 static void vcap_api_actionfield_typegroup_test(struct kunit *test) 690 { 691 const struct vcap_typegroup *tg; 692 693 tg = vcap_actionfield_typegroup(&test_vctrl, VCAP_TYPE_IS0, VCAP_AFS_FULL); 694 KUNIT_EXPECT_PTR_NE(test, NULL, tg); 695 KUNIT_EXPECT_EQ(test, 0, tg[0].offset); 696 KUNIT_EXPECT_EQ(test, 3, tg[0].width); 697 KUNIT_EXPECT_EQ(test, 4, tg[0].value); 698 KUNIT_EXPECT_EQ(test, 110, tg[1].offset); 699 KUNIT_EXPECT_EQ(test, 2, tg[1].width); 700 KUNIT_EXPECT_EQ(test, 0, tg[1].value); 701 KUNIT_EXPECT_EQ(test, 220, tg[2].offset); 702 KUNIT_EXPECT_EQ(test, 2, tg[2].width); 703 KUNIT_EXPECT_EQ(test, 0, tg[2].value); 704 KUNIT_EXPECT_EQ(test, 0, tg[3].offset); 705 KUNIT_EXPECT_EQ(test, 0, tg[3].width); 706 KUNIT_EXPECT_EQ(test, 0, tg[3].value); 707 708 tg = vcap_actionfield_typegroup(&test_vctrl, VCAP_TYPE_IS2, VCAP_AFS_CLASSIFICATION); 709 KUNIT_EXPECT_PTR_EQ(test, NULL, tg); 710 } 711 712 static void vcap_api_vcap_keyfields_test(struct kunit *test) 713 { 714 const struct vcap_field *ft; 715 716 ft = vcap_keyfields(&test_vctrl, VCAP_TYPE_IS2, VCAP_KFS_MAC_ETYPE); 717 KUNIT_EXPECT_PTR_NE(test, NULL, ft); 718 719 /* Keyset that is not available and within the maximum keyset enum value */ 720 ft = vcap_keyfields(&test_vctrl, VCAP_TYPE_ES2, VCAP_KFS_PURE_5TUPLE_IP4); 721 KUNIT_EXPECT_PTR_EQ(test, NULL, ft); 722 723 /* Keyset that is not available and beyond the maximum keyset enum value */ 724 ft = vcap_keyfields(&test_vctrl, VCAP_TYPE_ES2, VCAP_KFS_LL_FULL); 725 KUNIT_EXPECT_PTR_EQ(test, NULL, ft); 726 } 727 728 static void vcap_api_vcap_actionfields_test(struct kunit *test) 729 { 730 const struct vcap_field *ft; 731 732 ft = vcap_actionfields(&test_vctrl, VCAP_TYPE_IS0, VCAP_AFS_FULL); 733 KUNIT_EXPECT_PTR_NE(test, NULL, ft); 734 735 ft = vcap_actionfields(&test_vctrl, VCAP_TYPE_IS2, VCAP_AFS_FULL); 736 KUNIT_EXPECT_PTR_EQ(test, NULL, ft); 737 738 ft = vcap_actionfields(&test_vctrl, VCAP_TYPE_IS2, VCAP_AFS_CLASSIFICATION); 739 KUNIT_EXPECT_PTR_EQ(test, NULL, ft); 740 } 741 742 static void vcap_api_encode_rule_keyset_test(struct kunit *test) 743 { 744 u32 keywords[16] = {0}; 745 u32 maskwords[16] = {0}; 746 struct vcap_admin admin = { 747 .vtype = VCAP_TYPE_IS2, 748 .cache = { 749 .keystream = keywords, 750 .maskstream = maskwords, 751 }, 752 }; 753 struct vcap_rule_internal rule = { 754 .admin = &admin, 755 .data = { 756 .keyset = VCAP_KFS_MAC_ETYPE, 757 }, 758 .vctrl = &test_vctrl, 759 }; 760 struct vcap_client_keyfield ckf[] = { 761 { 762 .ctrl.key = VCAP_KF_TYPE, 763 .ctrl.type = VCAP_FIELD_U32, 764 .data.u32.value = 0x00, 765 .data.u32.mask = 0x0f, 766 }, 767 { 768 .ctrl.key = VCAP_KF_LOOKUP_FIRST_IS, 769 .ctrl.type = VCAP_FIELD_BIT, 770 .data.u1.value = 0x01, 771 .data.u1.mask = 0x01, 772 }, 773 { 774 .ctrl.key = VCAP_KF_IF_IGR_PORT_MASK_L3, 775 .ctrl.type = VCAP_FIELD_BIT, 776 .data.u1.value = 0x00, 777 .data.u1.mask = 0x01, 778 }, 779 { 780 .ctrl.key = VCAP_KF_IF_IGR_PORT_MASK_RNG, 781 .ctrl.type = VCAP_FIELD_U32, 782 .data.u32.value = 0x00, 783 .data.u32.mask = 0x0f, 784 }, 785 { 786 .ctrl.key = VCAP_KF_IF_IGR_PORT_MASK, 787 .ctrl.type = VCAP_FIELD_U72, 788 .data.u72.value = {0x0, 0x00, 0x00, 0x00}, 789 .data.u72.mask = {0xfd, 0xff, 0xff, 0xff}, 790 }, 791 { 792 .ctrl.key = VCAP_KF_L2_DMAC, 793 .ctrl.type = VCAP_FIELD_U48, 794 /* Opposite endianness */ 795 .data.u48.value = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, 796 .data.u48.mask = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 797 }, 798 { 799 .ctrl.key = VCAP_KF_ETYPE_LEN_IS, 800 .ctrl.type = VCAP_FIELD_BIT, 801 .data.u1.value = 0x01, 802 .data.u1.mask = 0x01, 803 }, 804 { 805 .ctrl.key = VCAP_KF_ETYPE, 806 .ctrl.type = VCAP_FIELD_U32, 807 .data.u32.value = 0xaabb, 808 .data.u32.mask = 0xffff, 809 }, 810 }; 811 int idx; 812 int ret; 813 814 /* Empty entry list */ 815 INIT_LIST_HEAD(&rule.data.keyfields); 816 ret = vcap_encode_rule_keyset(&rule); 817 KUNIT_EXPECT_EQ(test, -EINVAL, ret); 818 819 for (idx = 0; idx < ARRAY_SIZE(ckf); idx++) 820 list_add_tail(&ckf[idx].ctrl.list, &rule.data.keyfields); 821 ret = vcap_encode_rule_keyset(&rule); 822 KUNIT_EXPECT_EQ(test, 0, ret); 823 824 /* The key and mask values below are from an actual Sparx5 rule config */ 825 /* Key */ 826 KUNIT_EXPECT_EQ(test, (u32)0x00000042, keywords[0]); 827 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[1]); 828 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[2]); 829 KUNIT_EXPECT_EQ(test, (u32)0x00020100, keywords[3]); 830 KUNIT_EXPECT_EQ(test, (u32)0x60504030, keywords[4]); 831 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[5]); 832 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[6]); 833 KUNIT_EXPECT_EQ(test, (u32)0x0002aaee, keywords[7]); 834 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[8]); 835 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[9]); 836 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[10]); 837 KUNIT_EXPECT_EQ(test, (u32)0x00000000, keywords[11]); 838 839 /* Mask: they will be inverted when applied to the register */ 840 KUNIT_EXPECT_EQ(test, (u32)~0x00b07f80, maskwords[0]); 841 KUNIT_EXPECT_EQ(test, (u32)~0xfff00000, maskwords[1]); 842 KUNIT_EXPECT_EQ(test, (u32)~0xfffffffc, maskwords[2]); 843 KUNIT_EXPECT_EQ(test, (u32)~0xfff000ff, maskwords[3]); 844 KUNIT_EXPECT_EQ(test, (u32)~0x00000000, maskwords[4]); 845 KUNIT_EXPECT_EQ(test, (u32)~0xfffffff0, maskwords[5]); 846 KUNIT_EXPECT_EQ(test, (u32)~0xfffffffe, maskwords[6]); 847 KUNIT_EXPECT_EQ(test, (u32)~0xfffc0001, maskwords[7]); 848 KUNIT_EXPECT_EQ(test, (u32)~0xffffffff, maskwords[8]); 849 KUNIT_EXPECT_EQ(test, (u32)~0xffffffff, maskwords[9]); 850 KUNIT_EXPECT_EQ(test, (u32)~0xffffffff, maskwords[10]); 851 KUNIT_EXPECT_EQ(test, (u32)~0xffffffff, maskwords[11]); 852 } 853 854 static void vcap_api_encode_rule_actionset_test(struct kunit *test) 855 { 856 u32 actwords[16] = {0}; 857 struct vcap_admin admin = { 858 .vtype = VCAP_TYPE_IS2, 859 .cache = { 860 .actionstream = actwords, 861 }, 862 }; 863 struct vcap_rule_internal rule = { 864 .admin = &admin, 865 .data = { 866 .actionset = VCAP_AFS_BASE_TYPE, 867 }, 868 .vctrl = &test_vctrl, 869 }; 870 struct vcap_client_actionfield caf[] = { 871 { 872 .ctrl.action = VCAP_AF_MATCH_ID, 873 .ctrl.type = VCAP_FIELD_U32, 874 .data.u32.value = 0x01, 875 }, 876 { 877 .ctrl.action = VCAP_AF_MATCH_ID_MASK, 878 .ctrl.type = VCAP_FIELD_U32, 879 .data.u32.value = 0x01, 880 }, 881 { 882 .ctrl.action = VCAP_AF_CNT_ID, 883 .ctrl.type = VCAP_FIELD_U32, 884 .data.u32.value = 0x64, 885 }, 886 }; 887 int idx; 888 int ret; 889 890 /* Empty entry list */ 891 INIT_LIST_HEAD(&rule.data.actionfields); 892 ret = vcap_encode_rule_actionset(&rule); 893 /* We allow rules with no actions */ 894 KUNIT_EXPECT_EQ(test, 0, ret); 895 896 for (idx = 0; idx < ARRAY_SIZE(caf); idx++) 897 list_add_tail(&caf[idx].ctrl.list, &rule.data.actionfields); 898 ret = vcap_encode_rule_actionset(&rule); 899 KUNIT_EXPECT_EQ(test, 0, ret); 900 901 /* The action values below are from an actual Sparx5 rule config */ 902 KUNIT_EXPECT_EQ(test, (u32)0x00000002, actwords[0]); 903 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[1]); 904 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[2]); 905 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[3]); 906 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[4]); 907 KUNIT_EXPECT_EQ(test, (u32)0x00100000, actwords[5]); 908 KUNIT_EXPECT_EQ(test, (u32)0x06400010, actwords[6]); 909 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[7]); 910 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[8]); 911 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[9]); 912 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[10]); 913 KUNIT_EXPECT_EQ(test, (u32)0x00000000, actwords[11]); 914 } 915 916 static void vcap_api_rule_add_keyvalue_test(struct kunit *test) 917 { 918 struct vcap_admin admin = { 919 .vtype = VCAP_TYPE_IS2, 920 }; 921 struct vcap_rule_internal ri = { 922 .admin = &admin, 923 .data = { 924 .keyset = VCAP_KFS_NO_VALUE, 925 }, 926 .vctrl = &test_vctrl, 927 }; 928 struct vcap_rule *rule = (struct vcap_rule *)&ri; 929 struct vcap_client_keyfield *kf; 930 int ret; 931 struct vcap_u128_key dip = { 932 .value = {0x17, 0x26, 0x35, 0x44, 0x63, 0x62, 0x71}, 933 .mask = {0xf1, 0xf2, 0xf3, 0xf4, 0x4f, 0x3f, 0x2f, 0x1f}, 934 }; 935 int idx; 936 937 INIT_LIST_HEAD(&rule->keyfields); 938 ret = vcap_rule_add_key_bit(rule, VCAP_KF_LOOKUP_FIRST_IS, VCAP_BIT_0); 939 KUNIT_EXPECT_EQ(test, 0, ret); 940 ret = list_empty(&rule->keyfields); 941 KUNIT_EXPECT_EQ(test, false, ret); 942 kf = list_first_entry(&rule->keyfields, struct vcap_client_keyfield, 943 ctrl.list); 944 KUNIT_EXPECT_EQ(test, VCAP_KF_LOOKUP_FIRST_IS, kf->ctrl.key); 945 KUNIT_EXPECT_EQ(test, VCAP_FIELD_BIT, kf->ctrl.type); 946 KUNIT_EXPECT_EQ(test, 0x0, kf->data.u1.value); 947 KUNIT_EXPECT_EQ(test, 0x1, kf->data.u1.mask); 948 949 INIT_LIST_HEAD(&rule->keyfields); 950 ret = vcap_rule_add_key_bit(rule, VCAP_KF_LOOKUP_FIRST_IS, VCAP_BIT_1); 951 KUNIT_EXPECT_EQ(test, 0, ret); 952 ret = list_empty(&rule->keyfields); 953 KUNIT_EXPECT_EQ(test, false, ret); 954 kf = list_first_entry(&rule->keyfields, struct vcap_client_keyfield, 955 ctrl.list); 956 KUNIT_EXPECT_EQ(test, VCAP_KF_LOOKUP_FIRST_IS, kf->ctrl.key); 957 KUNIT_EXPECT_EQ(test, VCAP_FIELD_BIT, kf->ctrl.type); 958 KUNIT_EXPECT_EQ(test, 0x1, kf->data.u1.value); 959 KUNIT_EXPECT_EQ(test, 0x1, kf->data.u1.mask); 960 961 INIT_LIST_HEAD(&rule->keyfields); 962 ret = vcap_rule_add_key_bit(rule, VCAP_KF_LOOKUP_FIRST_IS, 963 VCAP_BIT_ANY); 964 KUNIT_EXPECT_EQ(test, 0, ret); 965 ret = list_empty(&rule->keyfields); 966 KUNIT_EXPECT_EQ(test, false, ret); 967 kf = list_first_entry(&rule->keyfields, struct vcap_client_keyfield, 968 ctrl.list); 969 KUNIT_EXPECT_EQ(test, VCAP_KF_LOOKUP_FIRST_IS, kf->ctrl.key); 970 KUNIT_EXPECT_EQ(test, VCAP_FIELD_BIT, kf->ctrl.type); 971 KUNIT_EXPECT_EQ(test, 0x0, kf->data.u1.value); 972 KUNIT_EXPECT_EQ(test, 0x0, kf->data.u1.mask); 973 974 INIT_LIST_HEAD(&rule->keyfields); 975 ret = vcap_rule_add_key_u32(rule, VCAP_KF_TYPE, 0x98765432, 0xff00ffab); 976 KUNIT_EXPECT_EQ(test, 0, ret); 977 ret = list_empty(&rule->keyfields); 978 KUNIT_EXPECT_EQ(test, false, ret); 979 kf = list_first_entry(&rule->keyfields, struct vcap_client_keyfield, 980 ctrl.list); 981 KUNIT_EXPECT_EQ(test, VCAP_KF_TYPE, kf->ctrl.key); 982 KUNIT_EXPECT_EQ(test, VCAP_FIELD_U32, kf->ctrl.type); 983 KUNIT_EXPECT_EQ(test, 0x98765432, kf->data.u32.value); 984 KUNIT_EXPECT_EQ(test, 0xff00ffab, kf->data.u32.mask); 985 986 INIT_LIST_HEAD(&rule->keyfields); 987 ret = vcap_rule_add_key_u128(rule, VCAP_KF_L3_IP6_SIP, &dip); 988 KUNIT_EXPECT_EQ(test, 0, ret); 989 ret = list_empty(&rule->keyfields); 990 KUNIT_EXPECT_EQ(test, false, ret); 991 kf = list_first_entry(&rule->keyfields, struct vcap_client_keyfield, 992 ctrl.list); 993 KUNIT_EXPECT_EQ(test, VCAP_KF_L3_IP6_SIP, kf->ctrl.key); 994 KUNIT_EXPECT_EQ(test, VCAP_FIELD_U128, kf->ctrl.type); 995 for (idx = 0; idx < ARRAY_SIZE(dip.value); ++idx) 996 KUNIT_EXPECT_EQ(test, dip.value[idx], kf->data.u128.value[idx]); 997 for (idx = 0; idx < ARRAY_SIZE(dip.mask); ++idx) 998 KUNIT_EXPECT_EQ(test, dip.mask[idx], kf->data.u128.mask[idx]); 999 } 1000 1001 static void vcap_api_rule_add_actionvalue_test(struct kunit *test) 1002 { 1003 struct vcap_admin admin = { 1004 .vtype = VCAP_TYPE_IS2, 1005 }; 1006 struct vcap_rule_internal ri = { 1007 .admin = &admin, 1008 .data = { 1009 .actionset = VCAP_AFS_NO_VALUE, 1010 }, 1011 }; 1012 struct vcap_rule *rule = (struct vcap_rule *)&ri; 1013 struct vcap_client_actionfield *af; 1014 int ret; 1015 1016 INIT_LIST_HEAD(&rule->actionfields); 1017 ret = vcap_rule_add_action_bit(rule, VCAP_AF_POLICE_ENA, VCAP_BIT_0); 1018 KUNIT_EXPECT_EQ(test, 0, ret); 1019 ret = list_empty(&rule->actionfields); 1020 KUNIT_EXPECT_EQ(test, false, ret); 1021 af = list_first_entry(&rule->actionfields, 1022 struct vcap_client_actionfield, ctrl.list); 1023 KUNIT_EXPECT_EQ(test, VCAP_AF_POLICE_ENA, af->ctrl.action); 1024 KUNIT_EXPECT_EQ(test, VCAP_FIELD_BIT, af->ctrl.type); 1025 KUNIT_EXPECT_EQ(test, 0x0, af->data.u1.value); 1026 1027 INIT_LIST_HEAD(&rule->actionfields); 1028 ret = vcap_rule_add_action_bit(rule, VCAP_AF_POLICE_ENA, VCAP_BIT_1); 1029 KUNIT_EXPECT_EQ(test, 0, ret); 1030 ret = list_empty(&rule->actionfields); 1031 KUNIT_EXPECT_EQ(test, false, ret); 1032 af = list_first_entry(&rule->actionfields, 1033 struct vcap_client_actionfield, ctrl.list); 1034 KUNIT_EXPECT_EQ(test, VCAP_AF_POLICE_ENA, af->ctrl.action); 1035 KUNIT_EXPECT_EQ(test, VCAP_FIELD_BIT, af->ctrl.type); 1036 KUNIT_EXPECT_EQ(test, 0x1, af->data.u1.value); 1037 1038 INIT_LIST_HEAD(&rule->actionfields); 1039 ret = vcap_rule_add_action_bit(rule, VCAP_AF_POLICE_ENA, VCAP_BIT_ANY); 1040 KUNIT_EXPECT_EQ(test, 0, ret); 1041 ret = list_empty(&rule->actionfields); 1042 KUNIT_EXPECT_EQ(test, false, ret); 1043 af = list_first_entry(&rule->actionfields, 1044 struct vcap_client_actionfield, ctrl.list); 1045 KUNIT_EXPECT_EQ(test, VCAP_AF_POLICE_ENA, af->ctrl.action); 1046 KUNIT_EXPECT_EQ(test, VCAP_FIELD_BIT, af->ctrl.type); 1047 KUNIT_EXPECT_EQ(test, 0x0, af->data.u1.value); 1048 1049 INIT_LIST_HEAD(&rule->actionfields); 1050 ret = vcap_rule_add_action_u32(rule, VCAP_AF_TYPE, 0x98765432); 1051 KUNIT_EXPECT_EQ(test, 0, ret); 1052 ret = list_empty(&rule->actionfields); 1053 KUNIT_EXPECT_EQ(test, false, ret); 1054 af = list_first_entry(&rule->actionfields, 1055 struct vcap_client_actionfield, ctrl.list); 1056 KUNIT_EXPECT_EQ(test, VCAP_AF_TYPE, af->ctrl.action); 1057 KUNIT_EXPECT_EQ(test, VCAP_FIELD_U32, af->ctrl.type); 1058 KUNIT_EXPECT_EQ(test, 0x98765432, af->data.u32.value); 1059 1060 INIT_LIST_HEAD(&rule->actionfields); 1061 ret = vcap_rule_add_action_u32(rule, VCAP_AF_MASK_MODE, 0xaabbccdd); 1062 KUNIT_EXPECT_EQ(test, 0, ret); 1063 ret = list_empty(&rule->actionfields); 1064 KUNIT_EXPECT_EQ(test, false, ret); 1065 af = list_first_entry(&rule->actionfields, 1066 struct vcap_client_actionfield, ctrl.list); 1067 KUNIT_EXPECT_EQ(test, VCAP_AF_MASK_MODE, af->ctrl.action); 1068 KUNIT_EXPECT_EQ(test, VCAP_FIELD_U32, af->ctrl.type); 1069 KUNIT_EXPECT_EQ(test, 0xaabbccdd, af->data.u32.value); 1070 } 1071 1072 static void vcap_api_rule_find_keyset_basic_test(struct kunit *test) 1073 { 1074 struct vcap_keyset_list matches = {}; 1075 struct vcap_admin admin = { 1076 .vtype = VCAP_TYPE_IS2, 1077 }; 1078 struct vcap_rule_internal ri = { 1079 .admin = &admin, 1080 .vctrl = &test_vctrl, 1081 }; 1082 struct vcap_client_keyfield ckf[] = { 1083 { 1084 .ctrl.key = VCAP_KF_TYPE, 1085 }, { 1086 .ctrl.key = VCAP_KF_LOOKUP_FIRST_IS, 1087 }, { 1088 .ctrl.key = VCAP_KF_IF_IGR_PORT_MASK_L3, 1089 }, { 1090 .ctrl.key = VCAP_KF_IF_IGR_PORT_MASK_RNG, 1091 }, { 1092 .ctrl.key = VCAP_KF_IF_IGR_PORT_MASK, 1093 }, { 1094 .ctrl.key = VCAP_KF_L2_DMAC, 1095 }, { 1096 .ctrl.key = VCAP_KF_ETYPE_LEN_IS, 1097 }, { 1098 .ctrl.key = VCAP_KF_ETYPE, 1099 }, 1100 }; 1101 int idx; 1102 bool ret; 1103 enum vcap_keyfield_set keysets[10] = {}; 1104 1105 matches.keysets = keysets; 1106 matches.max = ARRAY_SIZE(keysets); 1107 1108 INIT_LIST_HEAD(&ri.data.keyfields); 1109 for (idx = 0; idx < ARRAY_SIZE(ckf); idx++) 1110 list_add_tail(&ckf[idx].ctrl.list, &ri.data.keyfields); 1111 1112 ret = vcap_rule_find_keysets(&ri, &matches); 1113 1114 KUNIT_EXPECT_EQ(test, true, ret); 1115 KUNIT_EXPECT_EQ(test, 1, matches.cnt); 1116 KUNIT_EXPECT_EQ(test, VCAP_KFS_MAC_ETYPE, matches.keysets[0]); 1117 } 1118 1119 static void vcap_api_rule_find_keyset_failed_test(struct kunit *test) 1120 { 1121 struct vcap_keyset_list matches = {}; 1122 struct vcap_admin admin = { 1123 .vtype = VCAP_TYPE_IS2, 1124 }; 1125 struct vcap_rule_internal ri = { 1126 .admin = &admin, 1127 .vctrl = &test_vctrl, 1128 }; 1129 struct vcap_client_keyfield ckf[] = { 1130 { 1131 .ctrl.key = VCAP_KF_TYPE, 1132 }, { 1133 .ctrl.key = VCAP_KF_LOOKUP_FIRST_IS, 1134 }, { 1135 .ctrl.key = VCAP_KF_ARP_OPCODE, 1136 }, { 1137 .ctrl.key = VCAP_KF_L3_IP4_SIP, 1138 }, { 1139 .ctrl.key = VCAP_KF_L3_IP4_DIP, 1140 }, { 1141 .ctrl.key = VCAP_KF_8021Q_PCP_CLS, 1142 }, { 1143 .ctrl.key = VCAP_KF_ETYPE_LEN_IS, /* Not with ARP */ 1144 }, { 1145 .ctrl.key = VCAP_KF_ETYPE, /* Not with ARP */ 1146 }, 1147 }; 1148 int idx; 1149 bool ret; 1150 enum vcap_keyfield_set keysets[10] = {}; 1151 1152 matches.keysets = keysets; 1153 matches.max = ARRAY_SIZE(keysets); 1154 1155 INIT_LIST_HEAD(&ri.data.keyfields); 1156 for (idx = 0; idx < ARRAY_SIZE(ckf); idx++) 1157 list_add_tail(&ckf[idx].ctrl.list, &ri.data.keyfields); 1158 1159 ret = vcap_rule_find_keysets(&ri, &matches); 1160 1161 KUNIT_EXPECT_EQ(test, false, ret); 1162 KUNIT_EXPECT_EQ(test, 0, matches.cnt); 1163 KUNIT_EXPECT_EQ(test, VCAP_KFS_NO_VALUE, matches.keysets[0]); 1164 } 1165 1166 static void vcap_api_rule_find_keyset_many_test(struct kunit *test) 1167 { 1168 struct vcap_keyset_list matches = {}; 1169 struct vcap_admin admin = { 1170 .vtype = VCAP_TYPE_IS2, 1171 }; 1172 struct vcap_rule_internal ri = { 1173 .admin = &admin, 1174 .vctrl = &test_vctrl, 1175 }; 1176 struct vcap_client_keyfield ckf[] = { 1177 { 1178 .ctrl.key = VCAP_KF_TYPE, 1179 }, { 1180 .ctrl.key = VCAP_KF_LOOKUP_FIRST_IS, 1181 }, { 1182 .ctrl.key = VCAP_KF_8021Q_DEI_CLS, 1183 }, { 1184 .ctrl.key = VCAP_KF_8021Q_PCP_CLS, 1185 }, { 1186 .ctrl.key = VCAP_KF_8021Q_VID_CLS, 1187 }, { 1188 .ctrl.key = VCAP_KF_ISDX_CLS, 1189 }, { 1190 .ctrl.key = VCAP_KF_L2_MC_IS, 1191 }, { 1192 .ctrl.key = VCAP_KF_L2_BC_IS, 1193 }, 1194 }; 1195 int idx; 1196 bool ret; 1197 enum vcap_keyfield_set keysets[10] = {}; 1198 1199 matches.keysets = keysets; 1200 matches.max = ARRAY_SIZE(keysets); 1201 1202 INIT_LIST_HEAD(&ri.data.keyfields); 1203 for (idx = 0; idx < ARRAY_SIZE(ckf); idx++) 1204 list_add_tail(&ckf[idx].ctrl.list, &ri.data.keyfields); 1205 1206 ret = vcap_rule_find_keysets(&ri, &matches); 1207 1208 KUNIT_EXPECT_EQ(test, true, ret); 1209 KUNIT_EXPECT_EQ(test, 6, matches.cnt); 1210 KUNIT_EXPECT_EQ(test, VCAP_KFS_ARP, matches.keysets[0]); 1211 KUNIT_EXPECT_EQ(test, VCAP_KFS_IP4_OTHER, matches.keysets[1]); 1212 KUNIT_EXPECT_EQ(test, VCAP_KFS_IP4_TCP_UDP, matches.keysets[2]); 1213 KUNIT_EXPECT_EQ(test, VCAP_KFS_IP6_STD, matches.keysets[3]); 1214 KUNIT_EXPECT_EQ(test, VCAP_KFS_IP_7TUPLE, matches.keysets[4]); 1215 KUNIT_EXPECT_EQ(test, VCAP_KFS_MAC_ETYPE, matches.keysets[5]); 1216 } 1217 1218 static void vcap_api_encode_rule_test(struct kunit *test) 1219 { 1220 /* Data used by VCAP Library callback */ 1221 static u32 keydata[32] = {}; 1222 static u32 mskdata[32] = {}; 1223 static u32 actdata[32] = {}; 1224 1225 struct vcap_admin is2_admin = { 1226 .vtype = VCAP_TYPE_IS2, 1227 .first_cid = 10000, 1228 .last_cid = 19999, 1229 .lookups = 4, 1230 .last_valid_addr = 3071, 1231 .first_valid_addr = 0, 1232 .last_used_addr = 800, 1233 .cache = { 1234 .keystream = keydata, 1235 .maskstream = mskdata, 1236 .actionstream = actdata, 1237 }, 1238 }; 1239 struct vcap_rule *rule = 0; 1240 struct vcap_rule_internal *ri = 0; 1241 int vcap_chain_id = 10005; 1242 enum vcap_user user = VCAP_USER_VCAP_UTIL; 1243 u16 priority = 10; 1244 int id = 100; 1245 int ret; 1246 struct vcap_u48_key smac = { 1247 .value = { 0x88, 0x75, 0x32, 0x34, 0x9e, 0xb1 }, 1248 .mask = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } 1249 }; 1250 struct vcap_u48_key dmac = { 1251 .value = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }, 1252 .mask = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } 1253 }; 1254 u32 port_mask_rng_value = 0x05; 1255 u32 port_mask_rng_mask = 0x0f; 1256 u32 igr_port_mask_value = 0xffabcd01; 1257 u32 igr_port_mask_mask = ~0; 1258 /* counter is not written yet, so it is not in expwriteaddr */ 1259 u32 expwriteaddr[] = {792, 793, 794, 795, 796, 797, 0}; 1260 int idx; 1261 1262 vcap_test_api_init(&is2_admin); 1263 1264 /* Allocate the rule */ 1265 rule = vcap_alloc_rule(&test_vctrl, &test_netdev, vcap_chain_id, user, 1266 priority, id); 1267 KUNIT_EXPECT_PTR_NE(test, NULL, rule); 1268 ri = (struct vcap_rule_internal *)rule; 1269 1270 /* Add rule keys */ 1271 ret = vcap_rule_add_key_u48(rule, VCAP_KF_L2_DMAC, &dmac); 1272 KUNIT_EXPECT_EQ(test, 0, ret); 1273 ret = vcap_rule_add_key_u48(rule, VCAP_KF_L2_SMAC, &smac); 1274 KUNIT_EXPECT_EQ(test, 0, ret); 1275 ret = vcap_rule_add_key_bit(rule, VCAP_KF_ETYPE_LEN_IS, VCAP_BIT_1); 1276 KUNIT_EXPECT_EQ(test, 0, ret); 1277 /* Cannot add the same field twice */ 1278 ret = vcap_rule_add_key_bit(rule, VCAP_KF_ETYPE_LEN_IS, VCAP_BIT_1); 1279 KUNIT_EXPECT_EQ(test, -EINVAL, ret); 1280 ret = vcap_rule_add_key_bit(rule, VCAP_KF_IF_IGR_PORT_MASK_L3, 1281 VCAP_BIT_ANY); 1282 KUNIT_EXPECT_EQ(test, 0, ret); 1283 ret = vcap_rule_add_key_u32(rule, VCAP_KF_IF_IGR_PORT_MASK_RNG, 1284 port_mask_rng_value, port_mask_rng_mask); 1285 KUNIT_EXPECT_EQ(test, 0, ret); 1286 ret = vcap_rule_add_key_u32(rule, VCAP_KF_IF_IGR_PORT_MASK, 1287 igr_port_mask_value, igr_port_mask_mask); 1288 KUNIT_EXPECT_EQ(test, 0, ret); 1289 1290 /* Add rule actions */ 1291 ret = vcap_rule_add_action_bit(rule, VCAP_AF_POLICE_ENA, VCAP_BIT_1); 1292 KUNIT_EXPECT_EQ(test, 0, ret); 1293 ret = vcap_rule_add_action_u32(rule, VCAP_AF_CNT_ID, id); 1294 KUNIT_EXPECT_EQ(test, 0, ret); 1295 ret = vcap_rule_add_action_u32(rule, VCAP_AF_MATCH_ID, 1); 1296 KUNIT_EXPECT_EQ(test, 0, ret); 1297 ret = vcap_rule_add_action_u32(rule, VCAP_AF_MATCH_ID_MASK, 1); 1298 KUNIT_EXPECT_EQ(test, 0, ret); 1299 1300 /* For now the actionset is hardcoded */ 1301 ret = vcap_set_rule_set_actionset(rule, VCAP_AFS_BASE_TYPE); 1302 KUNIT_EXPECT_EQ(test, 0, ret); 1303 1304 /* Validation with validate keyset callback */ 1305 ret = vcap_val_rule(rule, ETH_P_ALL); 1306 KUNIT_EXPECT_EQ(test, 0, ret); 1307 KUNIT_EXPECT_EQ(test, VCAP_KFS_MAC_ETYPE, rule->keyset); 1308 KUNIT_EXPECT_EQ(test, VCAP_AFS_BASE_TYPE, rule->actionset); 1309 KUNIT_EXPECT_EQ(test, 6, ri->size); 1310 KUNIT_EXPECT_EQ(test, 2, ri->keyset_sw_regs); 1311 KUNIT_EXPECT_EQ(test, 4, ri->actionset_sw_regs); 1312 1313 /* Add rule with write callback */ 1314 ret = vcap_add_rule(rule); 1315 KUNIT_EXPECT_EQ(test, 0, ret); 1316 KUNIT_EXPECT_EQ(test, 792, is2_admin.last_used_addr); 1317 for (idx = 0; idx < ARRAY_SIZE(expwriteaddr); ++idx) 1318 KUNIT_EXPECT_EQ(test, expwriteaddr[idx], test_updateaddr[idx]); 1319 1320 /* Check that the rule has been added */ 1321 ret = list_empty(&is2_admin.rules); 1322 KUNIT_EXPECT_EQ(test, false, ret); 1323 KUNIT_EXPECT_EQ(test, 0, ret); 1324 vcap_free_rule(rule); 1325 1326 /* Check that the rule has been freed: tricky to access since this 1327 * memory should not be accessible anymore 1328 */ 1329 KUNIT_EXPECT_PTR_NE(test, NULL, rule); 1330 ret = list_empty(&rule->keyfields); 1331 KUNIT_EXPECT_EQ(test, true, ret); 1332 ret = list_empty(&rule->actionfields); 1333 KUNIT_EXPECT_EQ(test, true, ret); 1334 } 1335 1336 static void vcap_api_next_lookup_basic_test(struct kunit *test) 1337 { 1338 struct vcap_admin admin1 = { 1339 .vtype = VCAP_TYPE_IS2, 1340 .vinst = 0, 1341 .first_cid = 8000000, 1342 .last_cid = 8199999, 1343 .lookups = 4, 1344 .lookups_per_instance = 2, 1345 }; 1346 struct vcap_admin admin2 = { 1347 .vtype = VCAP_TYPE_IS2, 1348 .vinst = 1, 1349 .first_cid = 8200000, 1350 .last_cid = 8399999, 1351 .lookups = 4, 1352 .lookups_per_instance = 2, 1353 }; 1354 bool ret; 1355 1356 vcap_test_api_init(&admin1); 1357 list_add_tail(&admin2.list, &test_vctrl.list); 1358 1359 ret = vcap_is_next_lookup(&test_vctrl, 8000000, 1001000); 1360 KUNIT_EXPECT_EQ(test, false, ret); 1361 ret = vcap_is_next_lookup(&test_vctrl, 8000000, 8001000); 1362 KUNIT_EXPECT_EQ(test, false, ret); 1363 ret = vcap_is_next_lookup(&test_vctrl, 8000000, 8101000); 1364 KUNIT_EXPECT_EQ(test, true, ret); 1365 1366 ret = vcap_is_next_lookup(&test_vctrl, 8100000, 8101000); 1367 KUNIT_EXPECT_EQ(test, false, ret); 1368 ret = vcap_is_next_lookup(&test_vctrl, 8100000, 8201000); 1369 KUNIT_EXPECT_EQ(test, true, ret); 1370 1371 ret = vcap_is_next_lookup(&test_vctrl, 8200000, 8201000); 1372 KUNIT_EXPECT_EQ(test, false, ret); 1373 ret = vcap_is_next_lookup(&test_vctrl, 8200000, 8301000); 1374 KUNIT_EXPECT_EQ(test, true, ret); 1375 1376 ret = vcap_is_next_lookup(&test_vctrl, 8300000, 8301000); 1377 KUNIT_EXPECT_EQ(test, false, ret); 1378 ret = vcap_is_next_lookup(&test_vctrl, 8300000, 8401000); 1379 KUNIT_EXPECT_EQ(test, true, ret); 1380 } 1381 1382 static void vcap_api_next_lookup_advanced_test(struct kunit *test) 1383 { 1384 struct vcap_admin admin1 = { 1385 .vtype = VCAP_TYPE_IS0, 1386 .vinst = 0, 1387 .first_cid = 1000000, 1388 .last_cid = 1199999, 1389 .lookups = 6, 1390 .lookups_per_instance = 2, 1391 }; 1392 struct vcap_admin admin2 = { 1393 .vtype = VCAP_TYPE_IS0, 1394 .vinst = 1, 1395 .first_cid = 1200000, 1396 .last_cid = 1399999, 1397 .lookups = 6, 1398 .lookups_per_instance = 2, 1399 }; 1400 struct vcap_admin admin3 = { 1401 .vtype = VCAP_TYPE_IS0, 1402 .vinst = 2, 1403 .first_cid = 1400000, 1404 .last_cid = 1599999, 1405 .lookups = 6, 1406 .lookups_per_instance = 2, 1407 }; 1408 struct vcap_admin admin4 = { 1409 .vtype = VCAP_TYPE_IS2, 1410 .vinst = 0, 1411 .first_cid = 8000000, 1412 .last_cid = 8199999, 1413 .lookups = 4, 1414 .lookups_per_instance = 2, 1415 }; 1416 struct vcap_admin admin5 = { 1417 .vtype = VCAP_TYPE_IS2, 1418 .vinst = 1, 1419 .first_cid = 8200000, 1420 .last_cid = 8399999, 1421 .lookups = 4, 1422 .lookups_per_instance = 2, 1423 }; 1424 bool ret; 1425 1426 vcap_test_api_init(&admin1); 1427 list_add_tail(&admin2.list, &test_vctrl.list); 1428 list_add_tail(&admin3.list, &test_vctrl.list); 1429 list_add_tail(&admin4.list, &test_vctrl.list); 1430 list_add_tail(&admin5.list, &test_vctrl.list); 1431 1432 ret = vcap_is_next_lookup(&test_vctrl, 1000000, 1001000); 1433 KUNIT_EXPECT_EQ(test, false, ret); 1434 ret = vcap_is_next_lookup(&test_vctrl, 1000000, 1101000); 1435 KUNIT_EXPECT_EQ(test, true, ret); 1436 1437 ret = vcap_is_next_lookup(&test_vctrl, 1100000, 1201000); 1438 KUNIT_EXPECT_EQ(test, true, ret); 1439 ret = vcap_is_next_lookup(&test_vctrl, 1100000, 1301000); 1440 KUNIT_EXPECT_EQ(test, false, ret); 1441 ret = vcap_is_next_lookup(&test_vctrl, 1100000, 8101000); 1442 KUNIT_EXPECT_EQ(test, false, ret); 1443 ret = vcap_is_next_lookup(&test_vctrl, 1300000, 1401000); 1444 KUNIT_EXPECT_EQ(test, true, ret); 1445 ret = vcap_is_next_lookup(&test_vctrl, 1400000, 1501000); 1446 KUNIT_EXPECT_EQ(test, true, ret); 1447 ret = vcap_is_next_lookup(&test_vctrl, 1500000, 8001000); 1448 KUNIT_EXPECT_EQ(test, true, ret); 1449 1450 ret = vcap_is_next_lookup(&test_vctrl, 8000000, 8001000); 1451 KUNIT_EXPECT_EQ(test, false, ret); 1452 ret = vcap_is_next_lookup(&test_vctrl, 8000000, 8101000); 1453 KUNIT_EXPECT_EQ(test, true, ret); 1454 1455 ret = vcap_is_next_lookup(&test_vctrl, 8300000, 8301000); 1456 KUNIT_EXPECT_EQ(test, false, ret); 1457 ret = vcap_is_next_lookup(&test_vctrl, 8300000, 8401000); 1458 KUNIT_EXPECT_EQ(test, true, ret); 1459 } 1460 1461 static struct kunit_case vcap_api_support_test_cases[] = { 1462 KUNIT_CASE(vcap_api_next_lookup_basic_test), 1463 KUNIT_CASE(vcap_api_next_lookup_advanced_test), 1464 {} 1465 }; 1466 1467 static struct kunit_suite vcap_api_support_test_suite = { 1468 .name = "VCAP_API_Support_Testsuite", 1469 .test_cases = vcap_api_support_test_cases, 1470 }; 1471 1472 static struct kunit_case vcap_api_full_rule_test_cases[] = { 1473 KUNIT_CASE(vcap_api_rule_find_keyset_basic_test), 1474 KUNIT_CASE(vcap_api_rule_find_keyset_failed_test), 1475 KUNIT_CASE(vcap_api_rule_find_keyset_many_test), 1476 KUNIT_CASE(vcap_api_encode_rule_test), 1477 {} 1478 }; 1479 1480 static struct kunit_suite vcap_api_full_rule_test_suite = { 1481 .name = "VCAP_API_Full_Rule_Testsuite", 1482 .test_cases = vcap_api_full_rule_test_cases, 1483 }; 1484 1485 static struct kunit_case vcap_api_rule_value_test_cases[] = { 1486 KUNIT_CASE(vcap_api_rule_add_keyvalue_test), 1487 KUNIT_CASE(vcap_api_rule_add_actionvalue_test), 1488 {} 1489 }; 1490 1491 static struct kunit_suite vcap_api_rule_value_test_suite = { 1492 .name = "VCAP_API_Rule_Value_Testsuite", 1493 .test_cases = vcap_api_rule_value_test_cases, 1494 }; 1495 1496 static struct kunit_case vcap_api_encoding_test_cases[] = { 1497 KUNIT_CASE(vcap_api_set_bit_1_test), 1498 KUNIT_CASE(vcap_api_set_bit_0_test), 1499 KUNIT_CASE(vcap_api_iterator_init_test), 1500 KUNIT_CASE(vcap_api_iterator_next_test), 1501 KUNIT_CASE(vcap_api_encode_typegroups_test), 1502 KUNIT_CASE(vcap_api_encode_bit_test), 1503 KUNIT_CASE(vcap_api_encode_field_test), 1504 KUNIT_CASE(vcap_api_encode_short_field_test), 1505 KUNIT_CASE(vcap_api_encode_keyfield_test), 1506 KUNIT_CASE(vcap_api_encode_max_keyfield_test), 1507 KUNIT_CASE(vcap_api_encode_actionfield_test), 1508 KUNIT_CASE(vcap_api_keyfield_typegroup_test), 1509 KUNIT_CASE(vcap_api_actionfield_typegroup_test), 1510 KUNIT_CASE(vcap_api_vcap_keyfields_test), 1511 KUNIT_CASE(vcap_api_vcap_actionfields_test), 1512 KUNIT_CASE(vcap_api_encode_rule_keyset_test), 1513 KUNIT_CASE(vcap_api_encode_rule_actionset_test), 1514 {} 1515 }; 1516 1517 static struct kunit_suite vcap_api_encoding_test_suite = { 1518 .name = "VCAP_API_Encoding_Testsuite", 1519 .test_cases = vcap_api_encoding_test_cases, 1520 }; 1521 1522 kunit_test_suite(vcap_api_support_test_suite); 1523 kunit_test_suite(vcap_api_full_rule_test_suite); 1524 kunit_test_suite(vcap_api_rule_value_test_suite); 1525 kunit_test_suite(vcap_api_encoding_test_suite); 1526