1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Intel Corporation 3 */ 4 5 /* This test is for membership library's simple feature test */ 6 7 #include "test.h" 8 9 #include <rte_memcpy.h> 10 #include <rte_malloc.h> 11 12 #ifdef RTE_EXEC_ENV_WINDOWS 13 static int 14 test_member(void) 15 { 16 printf("member not supported on Windows, skipping test\n"); 17 return TEST_SKIPPED; 18 } 19 20 #else 21 22 #include <rte_member.h> 23 #include <rte_byteorder.h> 24 #include <rte_random.h> 25 #include <rte_debug.h> 26 #include <rte_ip.h> 27 28 struct rte_member_setsum *setsum_ht; 29 struct rte_member_setsum *setsum_cache; 30 struct rte_member_setsum *setsum_vbf; 31 32 /* 5-tuple key type */ 33 struct flow_key { 34 uint32_t ip_src; 35 uint32_t ip_dst; 36 uint16_t port_src; 37 uint16_t port_dst; 38 uint8_t proto; 39 } __rte_packed; 40 41 /* Set ID Macros for multimatch test usage */ 42 #define M_MATCH_S 1 /* Not start with 0 since by default 0 means no match */ 43 #define M_MATCH_E 15 44 #define M_MATCH_STEP 2 45 #define M_MATCH_CNT \ 46 (1 + (M_MATCH_E - M_MATCH_S) / M_MATCH_STEP) 47 48 49 #define NUM_SAMPLES 5 50 #define MAX_MATCH 32 51 52 /* Keys used by unit test functions */ 53 static struct flow_key keys[NUM_SAMPLES] = { 54 { 55 .ip_src = RTE_IPV4(0x03, 0x02, 0x01, 0x00), 56 .ip_dst = RTE_IPV4(0x07, 0x06, 0x05, 0x04), 57 .port_src = 0x0908, 58 .port_dst = 0x0b0a, 59 .proto = 0x0c, 60 }, 61 { 62 .ip_src = RTE_IPV4(0x13, 0x12, 0x11, 0x10), 63 .ip_dst = RTE_IPV4(0x17, 0x16, 0x15, 0x14), 64 .port_src = 0x1918, 65 .port_dst = 0x1b1a, 66 .proto = 0x1c, 67 }, 68 { 69 .ip_src = RTE_IPV4(0x23, 0x22, 0x21, 0x20), 70 .ip_dst = RTE_IPV4(0x27, 0x26, 0x25, 0x24), 71 .port_src = 0x2928, 72 .port_dst = 0x2b2a, 73 .proto = 0x2c, 74 }, 75 { 76 .ip_src = RTE_IPV4(0x33, 0x32, 0x31, 0x30), 77 .ip_dst = RTE_IPV4(0x37, 0x36, 0x35, 0x34), 78 .port_src = 0x3938, 79 .port_dst = 0x3b3a, 80 .proto = 0x3c, 81 }, 82 { 83 .ip_src = RTE_IPV4(0x43, 0x42, 0x41, 0x40), 84 .ip_dst = RTE_IPV4(0x47, 0x46, 0x45, 0x44), 85 .port_src = 0x4948, 86 .port_dst = 0x4b4a, 87 .proto = 0x4c, 88 } 89 }; 90 91 uint32_t test_set[NUM_SAMPLES] = {1, 2, 3, 4, 5}; 92 93 #define ITERATIONS 3 94 #define KEY_SIZE 4 95 96 #define MAX_ENTRIES (1 << 16) 97 uint8_t generated_keys[MAX_ENTRIES][KEY_SIZE]; 98 99 static struct rte_member_parameters params = { 100 .num_keys = MAX_ENTRIES, /* Total hash table entries. */ 101 .key_len = KEY_SIZE, /* Length of hash key. */ 102 103 /* num_set and false_positive_rate only relevant to vBF */ 104 .num_set = 16, 105 .false_positive_rate = 0.03, 106 .prim_hash_seed = 1, 107 .sec_hash_seed = 11, 108 .socket_id = 0 /* NUMA Socket ID for memory. */ 109 }; 110 111 /* 112 * Sequence of operations for find existing setsummary 113 * 114 * - create setsum 115 * - find existing setsum: hit 116 * - find non-existing setsum: miss 117 * 118 */ 119 static int 120 test_member_find_existing(void) 121 { 122 struct rte_member_setsum *tmp_setsum = NULL, *result = NULL; 123 struct rte_member_parameters tmp_params = { 124 .name = "member_find_existing", 125 .num_keys = MAX_ENTRIES, /* Total hash table entries. */ 126 .key_len = KEY_SIZE, /* Length of hash key. */ 127 .type = RTE_MEMBER_TYPE_HT, 128 .num_set = 32, 129 .false_positive_rate = 0.03, 130 .prim_hash_seed = 1, 131 .sec_hash_seed = 11, 132 .socket_id = 0 /* NUMA Socket ID for memory. */ 133 }; 134 135 /* Create */ 136 tmp_setsum = rte_member_create(&tmp_params); 137 TEST_ASSERT(tmp_setsum != NULL, "setsum creation failed"); 138 139 /* Try to find existing hash table */ 140 result = rte_member_find_existing("member_find_existing"); 141 TEST_ASSERT(result == tmp_setsum, "could not find existing setsum"); 142 143 /* Try to find non-existing hash table */ 144 result = rte_member_find_existing("member_find_non_existing"); 145 TEST_ASSERT(result == NULL, "found setsum that shouldn't exist"); 146 147 /* Cleanup. */ 148 rte_member_free(tmp_setsum); 149 150 return 0; 151 } 152 153 /* 154 * Test for bad creating parameters 155 */ 156 static int 157 test_member_create_bad_param(void) 158 { 159 struct rte_member_setsum *bad_setsum = NULL; 160 struct rte_member_parameters bad_params = { 161 .num_keys = MAX_ENTRIES, /* Total hash table entries. */ 162 .key_len = KEY_SIZE, /* Length of hash key. */ 163 .type = RTE_MEMBER_TYPE_HT, 164 .num_set = 32, 165 .false_positive_rate = 0.03, 166 .prim_hash_seed = 1, 167 .sec_hash_seed = 11, 168 .socket_id = 0 /* NUMA Socket ID for memory. */ 169 }; 170 171 printf("Expected error section begin...\n"); 172 bad_params.name = "bad_param1"; 173 bad_params.num_set = 0; 174 bad_params.type = RTE_MEMBER_TYPE_VBF; 175 /* Test with 0 set for vBF should fail */ 176 bad_setsum = rte_member_create(&bad_params); 177 if (bad_setsum != NULL) { 178 rte_member_free(bad_setsum); 179 printf("Impossible creating setsum successfully with invalid " 180 "number of set for vBF\n"); 181 return -1; 182 } 183 184 bad_params.name = "bad_param2"; 185 bad_params.false_positive_rate = 0; 186 bad_params.num_set = 32; 187 /* Test with 0 false positive for vBF should fail */ 188 bad_setsum = rte_member_create(&bad_params); 189 if (bad_setsum != NULL) { 190 rte_member_free(bad_setsum); 191 printf("Impossible creating setsum successfully with invalid " 192 "false positive rate for vBF\n"); 193 return -1; 194 } 195 196 bad_params.name = "bad_param3"; 197 bad_params.false_positive_rate = 0.03; 198 bad_params.num_keys = 0; 199 /* Test with 0 key per BF for vBF should fail */ 200 bad_setsum = rte_member_create(&bad_params); 201 if (bad_setsum != NULL) { 202 rte_member_free(bad_setsum); 203 printf("Impossible creating setsum successfully with invalid " 204 "num_keys for vBF\n"); 205 return -1; 206 } 207 208 bad_params.name = "bad_param4"; 209 bad_params.type = RTE_MEMBER_TYPE_HT; 210 bad_params.num_keys = RTE_MEMBER_BUCKET_ENTRIES / 2; 211 /* Test with less than 1 bucket for HTSS should fail */ 212 bad_setsum = rte_member_create(&bad_params); 213 if (bad_setsum != NULL) { 214 rte_member_free(bad_setsum); 215 printf("Impossible creating setsum successfully with too few " 216 "number of keys(entries) for HT\n"); 217 return -1; 218 } 219 220 bad_params.name = "bad_param5"; 221 bad_params.num_keys = RTE_MEMBER_ENTRIES_MAX + 1; 222 /* Test with more than maximum entries for HTSS should fail */ 223 bad_setsum = rte_member_create(&bad_params); 224 if (bad_setsum != NULL) { 225 rte_member_free(bad_setsum); 226 printf("Impossible creating setsum successfully with to many " 227 "number of keys(entries) for HT\n"); 228 return -1; 229 } 230 231 bad_params.name = "bad_param5"; 232 /* Test with same name should fail */ 233 bad_setsum = rte_member_create(&bad_params); 234 if (bad_setsum != NULL) { 235 rte_member_free(bad_setsum); 236 printf("Impossible creating setsum successfully with existed " 237 "name\n"); 238 return -1; 239 } 240 printf("Expected error section end...\n"); 241 rte_member_free(bad_setsum); 242 return 0; 243 } 244 245 /* Create test setsummaries. */ 246 static int test_member_create(void) 247 { 248 params.key_len = sizeof(struct flow_key); 249 250 params.name = "test_member_ht"; 251 params.is_cache = 0; 252 params.type = RTE_MEMBER_TYPE_HT; 253 setsum_ht = rte_member_create(¶ms); 254 255 params.name = "test_member_cache"; 256 params.is_cache = 1; 257 setsum_cache = rte_member_create(¶ms); 258 259 params.name = "test_member_vbf"; 260 params.type = RTE_MEMBER_TYPE_VBF; 261 setsum_vbf = rte_member_create(¶ms); 262 263 if (setsum_ht == NULL || setsum_cache == NULL || setsum_vbf == NULL) { 264 printf("Creation of setsums fail\n"); 265 return -1; 266 } 267 printf("Creation of setsums success\n"); 268 return 0; 269 } 270 271 static int test_member_insert(void) 272 { 273 int ret_ht, ret_cache, ret_vbf, i; 274 275 for (i = 0; i < NUM_SAMPLES; i++) { 276 ret_ht = rte_member_add(setsum_ht, &keys[i], test_set[i]); 277 ret_cache = rte_member_add(setsum_cache, &keys[i], 278 test_set[i]); 279 ret_vbf = rte_member_add(setsum_vbf, &keys[i], test_set[i]); 280 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0 && ret_vbf >= 0, 281 "insert error"); 282 } 283 printf("insert key success\n"); 284 return 0; 285 } 286 287 static int test_member_lookup(void) 288 { 289 int ret_ht, ret_cache, ret_vbf, i; 290 uint16_t set_ht, set_cache, set_vbf; 291 member_set_t set_ids_ht[NUM_SAMPLES] = {0}; 292 member_set_t set_ids_cache[NUM_SAMPLES] = {0}; 293 member_set_t set_ids_vbf[NUM_SAMPLES] = {0}; 294 295 uint32_t num_key_ht = NUM_SAMPLES; 296 uint32_t num_key_cache = NUM_SAMPLES; 297 uint32_t num_key_vbf = NUM_SAMPLES; 298 299 const void *key_array[NUM_SAMPLES]; 300 301 /* Single lookup test */ 302 for (i = 0; i < NUM_SAMPLES; i++) { 303 ret_ht = rte_member_lookup(setsum_ht, &keys[i], &set_ht); 304 ret_cache = rte_member_lookup(setsum_cache, &keys[i], 305 &set_cache); 306 ret_vbf = rte_member_lookup(setsum_vbf, &keys[i], &set_vbf); 307 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0 && ret_vbf >= 0, 308 "single lookup function error"); 309 310 TEST_ASSERT(set_ht == test_set[i] && 311 set_cache == test_set[i] && 312 set_vbf == test_set[i], 313 "single lookup set value error"); 314 } 315 printf("lookup single key success\n"); 316 317 /* Bulk lookup test */ 318 for (i = 0; i < NUM_SAMPLES; i++) 319 key_array[i] = &keys[i]; 320 321 ret_ht = rte_member_lookup_bulk(setsum_ht, key_array, 322 num_key_ht, set_ids_ht); 323 324 ret_cache = rte_member_lookup_bulk(setsum_cache, key_array, 325 num_key_cache, set_ids_cache); 326 327 ret_vbf = rte_member_lookup_bulk(setsum_vbf, key_array, 328 num_key_vbf, set_ids_vbf); 329 330 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0 && ret_vbf >= 0, 331 "bulk lookup function error"); 332 333 for (i = 0; i < NUM_SAMPLES; i++) { 334 TEST_ASSERT((set_ids_ht[i] == test_set[i]) && 335 (set_ids_cache[i] == test_set[i]) && 336 (set_ids_vbf[i] == test_set[i]), 337 "bulk lookup result error"); 338 } 339 340 return 0; 341 } 342 343 static int test_member_delete(void) 344 { 345 int ret_ht, ret_cache, ret_vbf, i; 346 uint16_t set_ht, set_cache, set_vbf; 347 const void *key_array[NUM_SAMPLES]; 348 member_set_t set_ids_ht[NUM_SAMPLES] = {0}; 349 member_set_t set_ids_cache[NUM_SAMPLES] = {0}; 350 member_set_t set_ids_vbf[NUM_SAMPLES] = {0}; 351 uint32_t num_key_ht = NUM_SAMPLES; 352 uint32_t num_key_cache = NUM_SAMPLES; 353 uint32_t num_key_vbf = NUM_SAMPLES; 354 355 /* Delete part of all inserted keys */ 356 for (i = 0; i < NUM_SAMPLES / 2; i++) { 357 ret_ht = rte_member_delete(setsum_ht, &keys[i], test_set[i]); 358 ret_cache = rte_member_delete(setsum_cache, &keys[i], 359 test_set[i]); 360 ret_vbf = rte_member_delete(setsum_vbf, &keys[i], test_set[i]); 361 /* VBF does not support delete yet, so return error code */ 362 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0, 363 "key deletion function error"); 364 TEST_ASSERT(ret_vbf < 0, 365 "vbf does not support deletion, error"); 366 } 367 368 for (i = 0; i < NUM_SAMPLES; i++) 369 key_array[i] = &keys[i]; 370 371 ret_ht = rte_member_lookup_bulk(setsum_ht, key_array, 372 num_key_ht, set_ids_ht); 373 374 ret_cache = rte_member_lookup_bulk(setsum_cache, key_array, 375 num_key_cache, set_ids_cache); 376 377 ret_vbf = rte_member_lookup_bulk(setsum_vbf, key_array, 378 num_key_vbf, set_ids_vbf); 379 380 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0 && ret_vbf >= 0, 381 "bulk lookup function error"); 382 383 for (i = 0; i < NUM_SAMPLES / 2; i++) { 384 TEST_ASSERT((set_ids_ht[i] == RTE_MEMBER_NO_MATCH) && 385 (set_ids_cache[i] == RTE_MEMBER_NO_MATCH), 386 "bulk lookup result error"); 387 } 388 389 for (i = NUM_SAMPLES / 2; i < NUM_SAMPLES; i++) { 390 TEST_ASSERT((set_ids_ht[i] == test_set[i]) && 391 (set_ids_cache[i] == test_set[i]) && 392 (set_ids_vbf[i] == test_set[i]), 393 "bulk lookup result error"); 394 } 395 396 /* Delete the left of inserted keys */ 397 for (i = NUM_SAMPLES / 2; i < NUM_SAMPLES; i++) { 398 ret_ht = rte_member_delete(setsum_ht, &keys[i], test_set[i]); 399 ret_cache = rte_member_delete(setsum_cache, &keys[i], 400 test_set[i]); 401 ret_vbf = rte_member_delete(setsum_vbf, &keys[i], test_set[i]); 402 /* VBF does not support delete yet, so return error code */ 403 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0, 404 "key deletion function error"); 405 TEST_ASSERT(ret_vbf < 0, 406 "vbf does not support deletion, error"); 407 } 408 409 for (i = 0; i < NUM_SAMPLES; i++) { 410 ret_ht = rte_member_lookup(setsum_ht, &keys[i], &set_ht); 411 ret_cache = rte_member_lookup(setsum_cache, &keys[i], 412 &set_cache); 413 ret_vbf = rte_member_lookup(setsum_vbf, &keys[i], &set_vbf); 414 TEST_ASSERT(ret_ht >= 0 && ret_cache >= 0, 415 "key lookup function error"); 416 TEST_ASSERT(set_ht == RTE_MEMBER_NO_MATCH && 417 ret_cache == RTE_MEMBER_NO_MATCH, 418 "key deletion failed"); 419 } 420 /* Reset vbf for other following tests */ 421 rte_member_reset(setsum_vbf); 422 423 printf("delete success\n"); 424 return 0; 425 } 426 427 static int test_member_multimatch(void) 428 { 429 int ret_ht, ret_vbf, ret_cache; 430 member_set_t set_ids_ht[MAX_MATCH] = {0}; 431 member_set_t set_ids_vbf[MAX_MATCH] = {0}; 432 member_set_t set_ids_cache[MAX_MATCH] = {0}; 433 434 member_set_t set_ids_ht_m[NUM_SAMPLES][MAX_MATCH] = {{0} }; 435 member_set_t set_ids_vbf_m[NUM_SAMPLES][MAX_MATCH] = {{0} }; 436 member_set_t set_ids_cache_m[NUM_SAMPLES][MAX_MATCH] = {{0} }; 437 438 uint32_t match_count_ht[NUM_SAMPLES]; 439 uint32_t match_count_vbf[NUM_SAMPLES]; 440 uint32_t match_count_cache[NUM_SAMPLES]; 441 442 uint32_t num_key_ht = NUM_SAMPLES; 443 uint32_t num_key_vbf = NUM_SAMPLES; 444 uint32_t num_key_cache = NUM_SAMPLES; 445 446 const void *key_array[NUM_SAMPLES]; 447 448 uint32_t i, j; 449 450 /* Same key at most inserted 2*entry_per_bucket times for HT mode */ 451 for (i = M_MATCH_S; i <= M_MATCH_E; i += M_MATCH_STEP) { 452 for (j = 0; j < NUM_SAMPLES; j++) { 453 ret_ht = rte_member_add(setsum_ht, &keys[j], i); 454 ret_vbf = rte_member_add(setsum_vbf, &keys[j], i); 455 ret_cache = rte_member_add(setsum_cache, &keys[j], i); 456 457 TEST_ASSERT(ret_ht >= 0 && ret_vbf >= 0 && 458 ret_cache >= 0, 459 "insert function error"); 460 } 461 } 462 463 /* Single multimatch test */ 464 for (i = 0; i < NUM_SAMPLES; i++) { 465 ret_vbf = rte_member_lookup_multi(setsum_vbf, &keys[i], 466 MAX_MATCH, set_ids_vbf); 467 ret_ht = rte_member_lookup_multi(setsum_ht, &keys[i], 468 MAX_MATCH, set_ids_ht); 469 ret_cache = rte_member_lookup_multi(setsum_cache, &keys[i], 470 MAX_MATCH, set_ids_cache); 471 /* 472 * For cache mode, keys overwrite when signature same. 473 * the multimatch should work like single match. 474 */ 475 TEST_ASSERT(ret_ht == M_MATCH_CNT && ret_vbf == M_MATCH_CNT && 476 ret_cache == 1, 477 "single lookup_multi error"); 478 TEST_ASSERT(set_ids_cache[0] == M_MATCH_E, 479 "single lookup_multi cache error"); 480 481 for (j = 1; j <= M_MATCH_CNT; j++) { 482 TEST_ASSERT(set_ids_ht[j-1] == j * M_MATCH_STEP - 1 && 483 set_ids_vbf[j-1] == 484 j * M_MATCH_STEP - 1, 485 "single multimatch lookup error"); 486 } 487 } 488 printf("lookup single key for multimatch success\n"); 489 490 /* Bulk multimatch test */ 491 for (i = 0; i < NUM_SAMPLES; i++) 492 key_array[i] = &keys[i]; 493 ret_vbf = rte_member_lookup_multi_bulk(setsum_vbf, 494 &key_array[0], num_key_ht, MAX_MATCH, match_count_vbf, 495 (member_set_t *)set_ids_vbf_m); 496 497 ret_ht = rte_member_lookup_multi_bulk(setsum_ht, 498 &key_array[0], num_key_vbf, MAX_MATCH, match_count_ht, 499 (member_set_t *)set_ids_ht_m); 500 501 ret_cache = rte_member_lookup_multi_bulk(setsum_cache, 502 &key_array[0], num_key_cache, MAX_MATCH, 503 match_count_cache, (member_set_t *)set_ids_cache_m); 504 505 506 for (j = 0; j < NUM_SAMPLES; j++) { 507 TEST_ASSERT(match_count_ht[j] == M_MATCH_CNT, 508 "bulk multimatch lookup HT match count error"); 509 TEST_ASSERT(match_count_vbf[j] == M_MATCH_CNT, 510 "bulk multimatch lookup vBF match count error"); 511 TEST_ASSERT(match_count_cache[j] == 1, 512 "bulk multimatch lookup CACHE match count error"); 513 TEST_ASSERT(set_ids_cache_m[j][0] == M_MATCH_E, 514 "bulk multimatch lookup CACHE set value error"); 515 516 for (i = 1; i <= M_MATCH_CNT; i++) { 517 TEST_ASSERT(set_ids_ht_m[j][i-1] == 518 i * M_MATCH_STEP - 1, 519 "bulk multimatch lookup HT set value error"); 520 TEST_ASSERT(set_ids_vbf_m[j][i-1] == 521 i * M_MATCH_STEP - 1, 522 "bulk multimatch lookup vBF set value error"); 523 } 524 } 525 526 printf("lookup for bulk multimatch success\n"); 527 528 return 0; 529 } 530 531 static int key_compare(const void *key1, const void *key2) 532 { 533 return memcmp(key1, key2, KEY_SIZE); 534 } 535 536 static void 537 setup_keys_and_data(void) 538 { 539 unsigned int i, j; 540 int num_duplicates; 541 542 /* Reset all arrays */ 543 for (i = 0; i < KEY_SIZE; i++) 544 generated_keys[0][i] = 0; 545 546 /* Generate a list of keys, some of which may be duplicates */ 547 for (i = 0; i < MAX_ENTRIES; i++) { 548 for (j = 0; j < KEY_SIZE; j++) 549 generated_keys[i][j] = rte_rand() & 0xFF; 550 } 551 552 /* Remove duplicates from the keys array */ 553 do { 554 num_duplicates = 0; 555 /* Sort the list of keys to make it easier to find duplicates */ 556 qsort(generated_keys, MAX_ENTRIES, KEY_SIZE, key_compare); 557 558 /* Sift through the list of keys and look for duplicates */ 559 int num_duplicates = 0; 560 for (i = 0; i < MAX_ENTRIES - 1; i++) { 561 if (memcmp(generated_keys[i], generated_keys[i + 1], 562 KEY_SIZE) == 0) { 563 /* This key already exists, try again */ 564 num_duplicates++; 565 for (j = 0; j < KEY_SIZE; j++) 566 generated_keys[i][j] = 567 rte_rand() & 0xFF; 568 } 569 } 570 } while (num_duplicates != 0); 571 } 572 573 static inline int 574 add_generated_keys(struct rte_member_setsum *setsum, unsigned int *added_keys) 575 { 576 int ret = 0; 577 578 for (*added_keys = 0; ret >= 0 && *added_keys < MAX_ENTRIES; 579 (*added_keys)++) { 580 uint16_t set = (rte_rand() & 0xf) + 1; 581 ret = rte_member_add(setsum, &generated_keys[*added_keys], set); 582 } 583 return ret; 584 } 585 586 static inline int 587 add_generated_keys_cache(struct rte_member_setsum *setsum, 588 unsigned int *added_keys) 589 { 590 int ret = 0; 591 592 for (*added_keys = 0; ret == 0 && *added_keys < MAX_ENTRIES; 593 (*added_keys)++) { 594 uint16_t set = (rte_rand() & 0xf) + 1; 595 ret = rte_member_add(setsum, &generated_keys[*added_keys], set); 596 } 597 return ret; 598 } 599 600 static int 601 test_member_loadfactor(void) 602 { 603 unsigned int j; 604 unsigned int added_keys, average_keys_added = 0; 605 int ret; 606 607 setup_keys_and_data(); 608 609 rte_member_free(setsum_ht); 610 rte_member_free(setsum_cache); 611 rte_member_free(setsum_vbf); 612 613 params.key_len = KEY_SIZE; 614 params.name = "test_member_ht"; 615 params.is_cache = 0; 616 params.type = RTE_MEMBER_TYPE_HT; 617 setsum_ht = rte_member_create(¶ms); 618 619 params.name = "test_member_cache"; 620 params.is_cache = 1; 621 setsum_cache = rte_member_create(¶ms); 622 623 624 if (setsum_ht == NULL || setsum_cache == NULL) { 625 printf("Creation of setsums fail\n"); 626 return -1; 627 } 628 /* Test HT non-cache mode */ 629 for (j = 0; j < ITERATIONS; j++) { 630 /* Add random entries until key cannot be added */ 631 ret = add_generated_keys(setsum_ht, &added_keys); 632 if (ret != -ENOSPC) { 633 printf("Unexpected error when adding keys\n"); 634 return -1; 635 } 636 average_keys_added += added_keys; 637 638 /* Reset the table */ 639 rte_member_reset(setsum_ht); 640 641 /* Print a dot to show progress on operations */ 642 printf("."); 643 fflush(stdout); 644 } 645 646 average_keys_added /= ITERATIONS; 647 648 printf("\nKeys inserted when no space(non-cache) = %.2f%% (%u/%u)\n", 649 ((double) average_keys_added / params.num_keys * 100), 650 average_keys_added, params.num_keys); 651 652 /* Test cache mode */ 653 added_keys = average_keys_added = 0; 654 for (j = 0; j < ITERATIONS; j++) { 655 /* Add random entries until key cannot be added */ 656 ret = add_generated_keys_cache(setsum_cache, &added_keys); 657 if (ret != 1) { 658 printf("Unexpected error when adding keys\n"); 659 return -1; 660 } 661 average_keys_added += added_keys; 662 663 /* Reset the table */ 664 rte_member_reset(setsum_cache); 665 666 /* Print a dot to show progress on operations */ 667 printf("."); 668 fflush(stdout); 669 } 670 671 average_keys_added /= ITERATIONS; 672 673 printf("\nKeys inserted when eviction happens(cache)= %.2f%% (%u/%u)\n", 674 ((double) average_keys_added / params.num_keys * 100), 675 average_keys_added, params.num_keys); 676 return 0; 677 } 678 679 static void 680 perform_free(void) 681 { 682 rte_member_free(setsum_ht); 683 rte_member_free(setsum_cache); 684 rte_member_free(setsum_vbf); 685 } 686 687 static int 688 test_member(void) 689 { 690 if (test_member_create_bad_param() < 0) 691 return -1; 692 693 if (test_member_find_existing() < 0) 694 return -1; 695 696 if (test_member_create() < 0) { 697 perform_free(); 698 return -1; 699 } 700 if (test_member_insert() < 0) { 701 perform_free(); 702 return -1; 703 } 704 if (test_member_lookup() < 0) { 705 perform_free(); 706 return -1; 707 } 708 if (test_member_delete() < 0) { 709 perform_free(); 710 return -1; 711 } 712 if (test_member_multimatch() < 0) { 713 perform_free(); 714 return -1; 715 } 716 if (test_member_loadfactor() < 0) { 717 rte_member_free(setsum_ht); 718 rte_member_free(setsum_cache); 719 return -1; 720 } 721 722 perform_free(); 723 return 0; 724 } 725 726 #endif /* !RTE_EXEC_ENV_WINDOWS */ 727 728 REGISTER_TEST_COMMAND(member_autotest, test_member); 729