1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation
11 #include <sys/queue.h>
13 #include <rte_common.h>
14 #include <rte_malloc.h>
15 #include <rte_cycles.h>
16 #include <rte_random.h>
17 #include <rte_memory.h>
20 #include <rte_string_fns.h>
25 #include <rte_fbk_hash.h>
26 #include <rte_jhash.h>
27 #include <rte_hash_crc.h>
29 /*******************************************************************************
30 * Hash function performance test configuration section. Each performance test
31 * will be performed HASHTEST_ITERATIONS times.
33 * The five arrays below control what tests are performed. Every combination
34 * from the array entries is tested.
36 static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc};
37 static uint32_t hashtest_initvals[] = {0};
38 static uint32_t hashtest_key_lens[] = {0, 2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21, 31, 32, 33, 63, 64};
39 #define MAX_KEYSIZE 64
40 /******************************************************************************/
41 #define LOCAL_FBK_HASH_ENTRIES_MAX (1 << 15)
44 * Check condition and return an error if true. Assumes that "handle" is the
45 * name of the hash structure pointer to be freed.
47 #define RETURN_IF_ERROR(cond, str, ...) do { \
49 printf("ERROR line %d: " str "\n", __LINE__, ##__VA_ARGS__); \
50 if (handle) rte_hash_free(handle); \
55 #define RETURN_IF_ERROR_FBK(cond, str, ...) do { \
57 printf("ERROR line %d: " str "\n", __LINE__, ##__VA_ARGS__); \
58 if (handle) rte_fbk_hash_free(handle); \
63 /* 5-tuple key type */
70 } __attribute__((packed));
73 * Hash function that always returns the same value, to easily test what
74 * happens when a bucket is full.
76 static uint32_t pseudo_hash(__attribute__((unused)) const void *keys,
77 __attribute__((unused)) uint32_t key_len,
78 __attribute__((unused)) uint32_t init_val)
84 * Print out result of unit test hash operation.
86 #if defined(UNIT_TEST_HASH_VERBOSE)
87 static void print_key_info(const char *msg, const struct flow_key *key,
90 uint8_t *p = (uint8_t *)key;
93 printf("%s key:0x", msg);
94 for (i = 0; i < sizeof(struct flow_key); i++) {
97 printf(" @ pos %d\n", pos);
100 static void print_key_info(__attribute__((unused)) const char *msg,
101 __attribute__((unused)) const struct flow_key *key,
102 __attribute__((unused)) int32_t pos)
107 /* Keys used by unit test functions */
108 static struct flow_key keys[5] = { {
109 .ip_src = IPv4(0x03, 0x02, 0x01, 0x00),
110 .ip_dst = IPv4(0x07, 0x06, 0x05, 0x04),
115 .ip_src = IPv4(0x13, 0x12, 0x11, 0x10),
116 .ip_dst = IPv4(0x17, 0x16, 0x15, 0x14),
121 .ip_src = IPv4(0x23, 0x22, 0x21, 0x20),
122 .ip_dst = IPv4(0x27, 0x26, 0x25, 0x24),
127 .ip_src = IPv4(0x33, 0x32, 0x31, 0x30),
128 .ip_dst = IPv4(0x37, 0x36, 0x35, 0x34),
133 .ip_src = IPv4(0x43, 0x42, 0x41, 0x40),
134 .ip_dst = IPv4(0x47, 0x46, 0x45, 0x44),
140 /* Parameters used for hash table in unit test functions. Name set later. */
141 static struct rte_hash_parameters ut_params = {
143 .key_len = sizeof(struct flow_key), /* 13 */
144 .hash_func = rte_jhash,
145 .hash_func_init_val = 0,
149 #define CRC32_ITERATIONS (1U << 10)
150 #define CRC32_DWORDS (1U << 6)
152 * Test if all CRC32 implementations yield the same hash value
155 test_crc32_hash_alg_equiv(void)
159 uint64_t data64[CRC32_DWORDS];
163 printf("\n# CRC32 implementations equivalence test\n");
164 for (i = 0; i < CRC32_ITERATIONS; i++) {
165 /* Randomizing data_len of data set */
166 data_len = (size_t) ((rte_rand() % sizeof(data64)) + 1);
167 init_val = (uint32_t) rte_rand();
169 /* Fill the data set */
170 for (j = 0; j < CRC32_DWORDS; j++)
171 data64[j] = rte_rand();
173 /* Calculate software CRC32 */
174 rte_hash_crc_set_alg(CRC32_SW);
175 hash_val = rte_hash_crc(data64, data_len, init_val);
177 /* Check against 4-byte-operand sse4.2 CRC32 if available */
178 rte_hash_crc_set_alg(CRC32_SSE42);
179 if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
180 printf("Failed checking CRC32_SW against CRC32_SSE42\n");
184 /* Check against 8-byte-operand sse4.2 CRC32 if available */
185 rte_hash_crc_set_alg(CRC32_SSE42_x64);
186 if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
187 printf("Failed checking CRC32_SW against CRC32_SSE42_x64\n");
191 /* Check against 8-byte-operand ARM64 CRC32 if available */
192 rte_hash_crc_set_alg(CRC32_ARM64);
193 if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
194 printf("Failed checking CRC32_SW against CRC32_ARM64\n");
199 /* Resetting to best available algorithm */
200 rte_hash_crc_set_alg(CRC32_SSE42_x64);
202 if (i == CRC32_ITERATIONS)
205 printf("Failed test data (hex, %zu bytes total):\n", data_len);
206 for (j = 0; j < data_len; j++)
207 printf("%02X%c", ((uint8_t *)data64)[j],
208 ((j+1) % 16 == 0 || j == data_len - 1) ? '\n' : ' ');
214 * Test a hash function.
216 static void run_hash_func_test(rte_hash_function f, uint32_t init_val,
219 static uint8_t key[MAX_KEYSIZE];
223 for (i = 0; i < key_len; i++)
224 key[i] = (uint8_t) rte_rand();
226 /* just to be on the safe side */
230 f(key, key_len, init_val);
234 * Test all hash functions.
236 static void run_hash_func_tests(void)
241 i < sizeof(hashtest_funcs) / sizeof(rte_hash_function);
244 j < sizeof(hashtest_initvals) / sizeof(uint32_t);
247 k < sizeof(hashtest_key_lens) / sizeof(uint32_t);
249 run_hash_func_test(hashtest_funcs[i],
250 hashtest_initvals[j],
251 hashtest_key_lens[k]);
258 * Basic sequence of operations for a single key:
264 static int test_add_delete(void)
266 struct rte_hash *handle;
267 /* test with standard add/lookup/delete functions */
268 int pos0, expectedPos0;
270 ut_params.name = "test1";
271 handle = rte_hash_create(&ut_params);
272 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
274 pos0 = rte_hash_add_key(handle, &keys[0]);
275 print_key_info("Add", &keys[0], pos0);
276 RETURN_IF_ERROR(pos0 < 0, "failed to add key (pos0=%d)", pos0);
279 pos0 = rte_hash_lookup(handle, &keys[0]);
280 print_key_info("Lkp", &keys[0], pos0);
281 RETURN_IF_ERROR(pos0 != expectedPos0,
282 "failed to find key (pos0=%d)", pos0);
284 pos0 = rte_hash_del_key(handle, &keys[0]);
285 print_key_info("Del", &keys[0], pos0);
286 RETURN_IF_ERROR(pos0 != expectedPos0,
287 "failed to delete key (pos0=%d)", pos0);
289 pos0 = rte_hash_lookup(handle, &keys[0]);
290 print_key_info("Lkp", &keys[0], pos0);
291 RETURN_IF_ERROR(pos0 != -ENOENT,
292 "fail: found key after deleting! (pos0=%d)", pos0);
294 rte_hash_free(handle);
296 /* repeat test with precomputed hash functions */
297 hash_sig_t hash_value;
298 int pos1, expectedPos1;
300 handle = rte_hash_create(&ut_params);
301 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
303 hash_value = rte_hash_hash(handle, &keys[0]);
304 pos1 = rte_hash_add_key_with_hash(handle, &keys[0], hash_value);
305 print_key_info("Add", &keys[0], pos1);
306 RETURN_IF_ERROR(pos1 < 0, "failed to add key (pos1=%d)", pos1);
309 pos1 = rte_hash_lookup_with_hash(handle, &keys[0], hash_value);
310 print_key_info("Lkp", &keys[0], pos1);
311 RETURN_IF_ERROR(pos1 != expectedPos1,
312 "failed to find key (pos1=%d)", pos1);
314 pos1 = rte_hash_del_key_with_hash(handle, &keys[0], hash_value);
315 print_key_info("Del", &keys[0], pos1);
316 RETURN_IF_ERROR(pos1 != expectedPos1,
317 "failed to delete key (pos1=%d)", pos1);
319 pos1 = rte_hash_lookup_with_hash(handle, &keys[0], hash_value);
320 print_key_info("Lkp", &keys[0], pos1);
321 RETURN_IF_ERROR(pos1 != -ENOENT,
322 "fail: found key after deleting! (pos1=%d)", pos1);
324 rte_hash_free(handle);
330 * Sequence of operations for a single key:
335 * - lookup: hit (updated data)
340 static int test_add_update_delete(void)
342 struct rte_hash *handle;
343 int pos0, expectedPos0;
345 ut_params.name = "test2";
346 handle = rte_hash_create(&ut_params);
347 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
349 pos0 = rte_hash_del_key(handle, &keys[0]);
350 print_key_info("Del", &keys[0], pos0);
351 RETURN_IF_ERROR(pos0 != -ENOENT,
352 "fail: found non-existent key (pos0=%d)", pos0);
354 pos0 = rte_hash_add_key(handle, &keys[0]);
355 print_key_info("Add", &keys[0], pos0);
356 RETURN_IF_ERROR(pos0 < 0, "failed to add key (pos0=%d)", pos0);
359 pos0 = rte_hash_lookup(handle, &keys[0]);
360 print_key_info("Lkp", &keys[0], pos0);
361 RETURN_IF_ERROR(pos0 != expectedPos0,
362 "failed to find key (pos0=%d)", pos0);
364 pos0 = rte_hash_add_key(handle, &keys[0]);
365 print_key_info("Add", &keys[0], pos0);
366 RETURN_IF_ERROR(pos0 != expectedPos0,
367 "failed to re-add key (pos0=%d)", pos0);
369 pos0 = rte_hash_lookup(handle, &keys[0]);
370 print_key_info("Lkp", &keys[0], pos0);
371 RETURN_IF_ERROR(pos0 != expectedPos0,
372 "failed to find key (pos0=%d)", pos0);
374 pos0 = rte_hash_del_key(handle, &keys[0]);
375 print_key_info("Del", &keys[0], pos0);
376 RETURN_IF_ERROR(pos0 != expectedPos0,
377 "failed to delete key (pos0=%d)", pos0);
379 pos0 = rte_hash_del_key(handle, &keys[0]);
380 print_key_info("Del", &keys[0], pos0);
381 RETURN_IF_ERROR(pos0 != -ENOENT,
382 "fail: deleted already deleted key (pos0=%d)", pos0);
384 pos0 = rte_hash_lookup(handle, &keys[0]);
385 print_key_info("Lkp", &keys[0], pos0);
386 RETURN_IF_ERROR(pos0 != -ENOENT,
387 "fail: found key after deleting! (pos0=%d)", pos0);
389 rte_hash_free(handle);
394 * Sequence of operations for retrieving a key with its position
398 * - get the key with its position: hit
400 * - try to get the deleted key: miss
403 static int test_hash_get_key_with_position(void)
405 struct rte_hash *handle = NULL;
406 int pos, expectedPos, result;
409 ut_params.name = "hash_get_key_w_pos";
410 handle = rte_hash_create(&ut_params);
411 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
413 pos = rte_hash_add_key(handle, &keys[0]);
414 print_key_info("Add", &keys[0], pos);
415 RETURN_IF_ERROR(pos < 0, "failed to add key (pos0=%d)", pos);
418 result = rte_hash_get_key_with_position(handle, pos, &key);
419 RETURN_IF_ERROR(result != 0, "error retrieving a key");
421 pos = rte_hash_del_key(handle, &keys[0]);
422 print_key_info("Del", &keys[0], pos);
423 RETURN_IF_ERROR(pos != expectedPos,
424 "failed to delete key (pos0=%d)", pos);
426 result = rte_hash_get_key_with_position(handle, pos, &key);
427 RETURN_IF_ERROR(result != -ENOENT, "non valid key retrieved");
429 rte_hash_free(handle);
434 * Sequence of operations for find existing hash table
437 * - find existing table: hit
438 * - find non-existing table: miss
441 static int test_hash_find_existing(void)
443 struct rte_hash *handle = NULL, *result = NULL;
445 /* Create hash table. */
446 ut_params.name = "hash_find_existing";
447 handle = rte_hash_create(&ut_params);
448 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
450 /* Try to find existing hash table */
451 result = rte_hash_find_existing("hash_find_existing");
452 RETURN_IF_ERROR(result != handle, "could not find existing hash table");
454 /* Try to find non-existing hash table */
455 result = rte_hash_find_existing("hash_find_non_existing");
456 RETURN_IF_ERROR(!(result == NULL), "found table that shouldn't exist");
459 rte_hash_free(handle);
465 * Sequence of operations for 5 keys
468 * - add keys (update)
469 * - lookup keys: hit (updated data)
470 * - delete keys : hit
471 * - lookup keys: miss
473 static int test_five_keys(void)
475 struct rte_hash *handle;
476 const void *key_array[5] = {0};
482 ut_params.name = "test3";
483 handle = rte_hash_create(&ut_params);
484 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
487 for (i = 0; i < 5; i++) {
488 pos[i] = rte_hash_add_key(handle, &keys[i]);
489 print_key_info("Add", &keys[i], pos[i]);
490 RETURN_IF_ERROR(pos[i] < 0,
491 "failed to add key (pos[%u]=%d)", i, pos[i]);
492 expected_pos[i] = pos[i];
496 for(i = 0; i < 5; i++)
497 key_array[i] = &keys[i];
499 ret = rte_hash_lookup_bulk(handle, &key_array[0], 5, (int32_t *)pos);
501 for(i = 0; i < 5; i++) {
502 print_key_info("Lkp", key_array[i], pos[i]);
503 RETURN_IF_ERROR(pos[i] != expected_pos[i],
504 "failed to find key (pos[%u]=%d)", i, pos[i]);
508 for (i = 0; i < 5; i++) {
509 pos[i] = rte_hash_add_key(handle, &keys[i]);
510 print_key_info("Add", &keys[i], pos[i]);
511 RETURN_IF_ERROR(pos[i] != expected_pos[i],
512 "failed to add key (pos[%u]=%d)", i, pos[i]);
516 for (i = 0; i < 5; i++) {
517 pos[i] = rte_hash_lookup(handle, &keys[i]);
518 print_key_info("Lkp", &keys[i], pos[i]);
519 RETURN_IF_ERROR(pos[i] != expected_pos[i],
520 "failed to find key (pos[%u]=%d)", i, pos[i]);
524 for (i = 0; i < 5; i++) {
525 pos[i] = rte_hash_del_key(handle, &keys[i]);
526 print_key_info("Del", &keys[i], pos[i]);
527 RETURN_IF_ERROR(pos[i] != expected_pos[i],
528 "failed to delete key (pos[%u]=%d)", i, pos[i]);
532 for (i = 0; i < 5; i++) {
533 pos[i] = rte_hash_lookup(handle, &keys[i]);
534 print_key_info("Lkp", &keys[i], pos[i]);
535 RETURN_IF_ERROR(pos[i] != -ENOENT,
536 "found non-existent key (pos[%u]=%d)", i, pos[i]);
540 ret = rte_hash_lookup_bulk(handle, &key_array[0], 5, (int32_t *)pos);
542 for (i = 0; i < 5; i++) {
543 print_key_info("Lkp", key_array[i], pos[i]);
544 RETURN_IF_ERROR(pos[i] != -ENOENT,
545 "found not-existent key (pos[%u]=%d)", i, pos[i]);
548 rte_hash_free(handle);
554 * Add keys to the same bucket until bucket full.
555 * - add 5 keys to the same bucket (hash created with 4 keys per bucket):
556 * first 4 successful, 5th successful, pushing existing item in bucket
557 * - lookup the 5 keys: 5 hits
558 * - add the 5 keys again: 5 OK
559 * - lookup the 5 keys: 5 hits (updated data)
560 * - delete the 5 keys: 5 OK
561 * - lookup the 5 keys: 5 misses
563 static int test_full_bucket(void)
565 struct rte_hash_parameters params_pseudo_hash = {
568 .key_len = sizeof(struct flow_key), /* 13 */
569 .hash_func = pseudo_hash,
570 .hash_func_init_val = 0,
573 struct rte_hash *handle;
578 handle = rte_hash_create(¶ms_pseudo_hash);
579 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
582 for (i = 0; i < 4; i++) {
583 pos[i] = rte_hash_add_key(handle, &keys[i]);
584 print_key_info("Add", &keys[i], pos[i]);
585 RETURN_IF_ERROR(pos[i] < 0,
586 "failed to add key (pos[%u]=%d)", i, pos[i]);
587 expected_pos[i] = pos[i];
590 * This should work and will push one of the items
591 * in the bucket because it is full
593 pos[4] = rte_hash_add_key(handle, &keys[4]);
594 print_key_info("Add", &keys[4], pos[4]);
595 RETURN_IF_ERROR(pos[4] < 0,
596 "failed to add key (pos[4]=%d)", pos[4]);
597 expected_pos[4] = pos[4];
600 for (i = 0; i < 5; i++) {
601 pos[i] = rte_hash_lookup(handle, &keys[i]);
602 print_key_info("Lkp", &keys[i], pos[i]);
603 RETURN_IF_ERROR(pos[i] != expected_pos[i],
604 "failed to find key (pos[%u]=%d)", i, pos[i]);
608 for (i = 0; i < 5; i++) {
609 pos[i] = rte_hash_add_key(handle, &keys[i]);
610 print_key_info("Add", &keys[i], pos[i]);
611 RETURN_IF_ERROR(pos[i] != expected_pos[i],
612 "failed to add key (pos[%u]=%d)", i, pos[i]);
616 for (i = 0; i < 5; i++) {
617 pos[i] = rte_hash_lookup(handle, &keys[i]);
618 print_key_info("Lkp", &keys[i], pos[i]);
619 RETURN_IF_ERROR(pos[i] != expected_pos[i],
620 "failed to find key (pos[%u]=%d)", i, pos[i]);
623 /* Delete 1 key, check other keys are still found */
624 pos[1] = rte_hash_del_key(handle, &keys[1]);
625 print_key_info("Del", &keys[1], pos[1]);
626 RETURN_IF_ERROR(pos[1] != expected_pos[1],
627 "failed to delete key (pos[1]=%d)", pos[1]);
628 pos[3] = rte_hash_lookup(handle, &keys[3]);
629 print_key_info("Lkp", &keys[3], pos[3]);
630 RETURN_IF_ERROR(pos[3] != expected_pos[3],
631 "failed lookup after deleting key from same bucket "
632 "(pos[3]=%d)", pos[3]);
634 /* Go back to previous state */
635 pos[1] = rte_hash_add_key(handle, &keys[1]);
636 print_key_info("Add", &keys[1], pos[1]);
637 expected_pos[1] = pos[1];
638 RETURN_IF_ERROR(pos[1] < 0, "failed to add key (pos[1]=%d)", pos[1]);
641 for (i = 0; i < 5; i++) {
642 pos[i] = rte_hash_del_key(handle, &keys[i]);
643 print_key_info("Del", &keys[i], pos[i]);
644 RETURN_IF_ERROR(pos[i] != expected_pos[i],
645 "failed to delete key (pos[%u]=%d)", i, pos[i]);
649 for (i = 0; i < 5; i++) {
650 pos[i] = rte_hash_lookup(handle, &keys[i]);
651 print_key_info("Lkp", &keys[i], pos[i]);
652 RETURN_IF_ERROR(pos[i] != -ENOENT,
653 "fail: found non-existent key (pos[%u]=%d)", i, pos[i]);
656 rte_hash_free(handle);
658 /* Cover the NULL case. */
664 * Similar to the test above (full bucket test), but for extendable buckets.
666 static int test_extendable_bucket(void)
668 struct rte_hash_parameters params_pseudo_hash = {
671 .key_len = sizeof(struct flow_key), /* 13 */
672 .hash_func = pseudo_hash,
673 .hash_func_init_val = 0,
675 .extra_flag = RTE_HASH_EXTRA_FLAGS_EXT_TABLE
677 struct rte_hash *handle;
679 int expected_pos[64];
681 struct flow_key rand_keys[64];
683 for (i = 0; i < 64; i++) {
684 rand_keys[i].port_dst = i;
685 rand_keys[i].port_src = i+1;
688 handle = rte_hash_create(¶ms_pseudo_hash);
689 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
692 for (i = 0; i < 64; i++) {
693 pos[i] = rte_hash_add_key(handle, &rand_keys[i]);
694 print_key_info("Add", &rand_keys[i], pos[i]);
695 RETURN_IF_ERROR(pos[i] < 0,
696 "failed to add key (pos[%u]=%d)", i, pos[i]);
697 expected_pos[i] = pos[i];
701 for (i = 0; i < 64; i++) {
702 pos[i] = rte_hash_lookup(handle, &rand_keys[i]);
703 print_key_info("Lkp", &rand_keys[i], pos[i]);
704 RETURN_IF_ERROR(pos[i] != expected_pos[i],
705 "failed to find key (pos[%u]=%d)", i, pos[i]);
709 for (i = 0; i < 64; i++) {
710 pos[i] = rte_hash_add_key(handle, &rand_keys[i]);
711 print_key_info("Add", &rand_keys[i], pos[i]);
712 RETURN_IF_ERROR(pos[i] != expected_pos[i],
713 "failed to add key (pos[%u]=%d)", i, pos[i]);
717 for (i = 0; i < 64; i++) {
718 pos[i] = rte_hash_lookup(handle, &rand_keys[i]);
719 print_key_info("Lkp", &rand_keys[i], pos[i]);
720 RETURN_IF_ERROR(pos[i] != expected_pos[i],
721 "failed to find key (pos[%u]=%d)", i, pos[i]);
724 /* Delete 1 key, check other keys are still found */
725 pos[35] = rte_hash_del_key(handle, &rand_keys[35]);
726 print_key_info("Del", &rand_keys[35], pos[35]);
727 RETURN_IF_ERROR(pos[35] != expected_pos[35],
728 "failed to delete key (pos[1]=%d)", pos[35]);
729 pos[20] = rte_hash_lookup(handle, &rand_keys[20]);
730 print_key_info("Lkp", &rand_keys[20], pos[20]);
731 RETURN_IF_ERROR(pos[20] != expected_pos[20],
732 "failed lookup after deleting key from same bucket "
733 "(pos[20]=%d)", pos[20]);
735 /* Go back to previous state */
736 pos[35] = rte_hash_add_key(handle, &rand_keys[35]);
737 print_key_info("Add", &rand_keys[35], pos[35]);
738 expected_pos[35] = pos[35];
739 RETURN_IF_ERROR(pos[35] < 0, "failed to add key (pos[1]=%d)", pos[35]);
742 for (i = 0; i < 64; i++) {
743 pos[i] = rte_hash_del_key(handle, &rand_keys[i]);
744 print_key_info("Del", &rand_keys[i], pos[i]);
745 RETURN_IF_ERROR(pos[i] != expected_pos[i],
746 "failed to delete key (pos[%u]=%d)", i, pos[i]);
750 for (i = 0; i < 64; i++) {
751 pos[i] = rte_hash_lookup(handle, &rand_keys[i]);
752 print_key_info("Lkp", &rand_keys[i], pos[i]);
753 RETURN_IF_ERROR(pos[i] != -ENOENT,
754 "fail: found non-existent key (pos[%u]=%d)", i, pos[i]);
758 for (i = 0; i < 64; i++) {
759 pos[i] = rte_hash_add_key(handle, &rand_keys[i]);
760 print_key_info("Add", &rand_keys[i], pos[i]);
761 RETURN_IF_ERROR(pos[i] < 0,
762 "failed to add key (pos[%u]=%d)", i, pos[i]);
763 expected_pos[i] = pos[i];
766 rte_hash_free(handle);
768 /* Cover the NULL case. */
773 /******************************************************************************/
775 fbk_hash_unit_test(void)
777 struct rte_fbk_hash_params params = {
778 .name = "fbk_hash_test",
779 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
780 .entries_per_bucket = 4,
784 struct rte_fbk_hash_params invalid_params_1 = {
786 .entries = LOCAL_FBK_HASH_ENTRIES_MAX + 1, /* Not power of 2 */
787 .entries_per_bucket = 4,
791 struct rte_fbk_hash_params invalid_params_2 = {
794 .entries_per_bucket = 3, /* Not power of 2 */
798 struct rte_fbk_hash_params invalid_params_3 = {
800 .entries = 0, /* Entries is 0 */
801 .entries_per_bucket = 4,
805 struct rte_fbk_hash_params invalid_params_4 = {
807 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
808 .entries_per_bucket = 0, /* Entries per bucket is 0 */
812 struct rte_fbk_hash_params invalid_params_5 = {
815 .entries_per_bucket = 8, /* Entries per bucket > entries */
819 struct rte_fbk_hash_params invalid_params_6 = {
821 .entries = RTE_FBK_HASH_ENTRIES_MAX * 2, /* Entries > max allowed */
822 .entries_per_bucket = 4,
826 struct rte_fbk_hash_params invalid_params_7 = {
828 .entries = RTE_FBK_HASH_ENTRIES_MAX,
829 .entries_per_bucket = RTE_FBK_HASH_ENTRIES_PER_BUCKET_MAX * 2, /* Entries > max allowed */
833 struct rte_fbk_hash_params invalid_params_8 = {
835 .entries = RTE_FBK_HASH_ENTRIES_MAX,
836 .entries_per_bucket = 4,
837 .socket_id = RTE_MAX_NUMA_NODES + 1, /* invalid socket */
840 /* try to create two hashes with identical names
841 * in this case, trying to create a second one will not
842 * fail but will simply return pointer to the existing
843 * hash with that name. sort of like a "find hash by name" :-)
845 struct rte_fbk_hash_params invalid_params_same_name_1 = {
846 .name = "same_name", /* hash with identical name */
848 .entries_per_bucket = 2,
852 /* trying to create this hash should return a pointer to an existing hash */
853 struct rte_fbk_hash_params invalid_params_same_name_2 = {
854 .name = "same_name", /* hash with identical name */
855 .entries = RTE_FBK_HASH_ENTRIES_MAX,
856 .entries_per_bucket = 4,
860 /* this is a sanity check for "same name" test
861 * creating this hash will check if we are actually able to create
862 * multiple hashes with different names (instead of having just one).
864 struct rte_fbk_hash_params different_name = {
865 .name = "different_name", /* different name */
866 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
867 .entries_per_bucket = 4,
871 struct rte_fbk_hash_params params_jhash = {
873 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
874 .entries_per_bucket = 4,
876 .hash_func = rte_jhash_1word, /* Tests for different hash_func */
877 .init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT,
880 struct rte_fbk_hash_params params_nohash = {
881 .name = "valid nohash",
882 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
883 .entries_per_bucket = 4,
885 .hash_func = NULL, /* Tests for null hash_func */
886 .init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT,
889 struct rte_fbk_hash_table *handle, *tmp;
891 {0xc6e18639, 0xe67c201c, 0xd4c8cffd, 0x44728691, 0xd5430fa9};
892 uint16_t vals[5] = {28108, 5699, 38490, 2166, 61571};
897 /* Try creating hashes with invalid parameters */
898 printf("# Testing hash creation with invalid parameters "
899 "- expect error msgs\n");
900 handle = rte_fbk_hash_create(&invalid_params_1);
901 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
903 handle = rte_fbk_hash_create(&invalid_params_2);
904 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
906 handle = rte_fbk_hash_create(&invalid_params_3);
907 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
909 handle = rte_fbk_hash_create(&invalid_params_4);
910 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
912 handle = rte_fbk_hash_create(&invalid_params_5);
913 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
915 handle = rte_fbk_hash_create(&invalid_params_6);
916 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
918 handle = rte_fbk_hash_create(&invalid_params_7);
919 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
921 handle = rte_fbk_hash_create(&invalid_params_8);
922 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
924 handle = rte_fbk_hash_create(&invalid_params_same_name_1);
925 RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation should have succeeded");
927 tmp = rte_fbk_hash_create(&invalid_params_same_name_2);
929 rte_fbk_hash_free(tmp);
930 RETURN_IF_ERROR_FBK(tmp != NULL, "fbk hash creation should have failed");
932 /* we are not freeing handle here because we need a hash list
933 * to be not empty for the next test */
935 /* create a hash in non-empty list - good for coverage */
936 tmp = rte_fbk_hash_create(&different_name);
937 RETURN_IF_ERROR_FBK(tmp == NULL, "fbk hash creation should have succeeded");
939 /* free both hashes */
940 rte_fbk_hash_free(handle);
941 rte_fbk_hash_free(tmp);
943 /* Create empty jhash hash. */
944 handle = rte_fbk_hash_create(¶ms_jhash);
945 RETURN_IF_ERROR_FBK(handle == NULL, "fbk jhash hash creation failed");
948 rte_fbk_hash_free(handle);
950 /* Create empty jhash hash. */
951 handle = rte_fbk_hash_create(¶ms_nohash);
952 RETURN_IF_ERROR_FBK(handle == NULL, "fbk nohash hash creation failed");
955 rte_fbk_hash_free(handle);
957 /* Create empty hash. */
958 handle = rte_fbk_hash_create(¶ms);
959 RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation failed");
961 used_entries = rte_fbk_hash_get_load_factor(handle) * LOCAL_FBK_HASH_ENTRIES_MAX;
962 RETURN_IF_ERROR_FBK((unsigned)used_entries != 0, \
963 "load factor right after creation is not zero but it should be");
965 for (i = 0; i < 5; i++) {
966 status = rte_fbk_hash_add_key(handle, keys[i], vals[i]);
967 RETURN_IF_ERROR_FBK(status != 0, "fbk hash add failed");
970 used_entries = rte_fbk_hash_get_load_factor(handle) * LOCAL_FBK_HASH_ENTRIES_MAX;
971 RETURN_IF_ERROR_FBK((unsigned)used_entries != (unsigned)((((double)5)/LOCAL_FBK_HASH_ENTRIES_MAX)*LOCAL_FBK_HASH_ENTRIES_MAX), \
972 "load factor now is not as expected");
973 /* Find value of added keys. */
974 for (i = 0; i < 5; i++) {
975 status = rte_fbk_hash_lookup(handle, keys[i]);
976 RETURN_IF_ERROR_FBK(status != vals[i],
977 "fbk hash lookup failed");
980 /* Change value of added keys. */
981 for (i = 0; i < 5; i++) {
982 status = rte_fbk_hash_add_key(handle, keys[i], vals[4 - i]);
983 RETURN_IF_ERROR_FBK(status != 0, "fbk hash update failed");
986 /* Find new values. */
987 for (i = 0; i < 5; i++) {
988 status = rte_fbk_hash_lookup(handle, keys[i]);
989 RETURN_IF_ERROR_FBK(status != vals[4-i],
990 "fbk hash lookup failed");
993 /* Delete keys individually. */
994 for (i = 0; i < 5; i++) {
995 status = rte_fbk_hash_delete_key(handle, keys[i]);
996 RETURN_IF_ERROR_FBK(status != 0, "fbk hash delete failed");
999 used_entries = rte_fbk_hash_get_load_factor(handle) * LOCAL_FBK_HASH_ENTRIES_MAX;
1000 RETURN_IF_ERROR_FBK((unsigned)used_entries != 0, \
1001 "load factor right after deletion is not zero but it should be");
1002 /* Lookup should now fail. */
1003 for (i = 0; i < 5; i++) {
1004 status = rte_fbk_hash_lookup(handle, keys[i]);
1005 RETURN_IF_ERROR_FBK(status == 0,
1006 "fbk hash lookup should have failed");
1009 /* Add keys again. */
1010 for (i = 0; i < 5; i++) {
1011 status = rte_fbk_hash_add_key(handle, keys[i], vals[i]);
1012 RETURN_IF_ERROR_FBK(status != 0, "fbk hash add failed");
1015 /* Make sure they were added. */
1016 for (i = 0; i < 5; i++) {
1017 status = rte_fbk_hash_lookup(handle, keys[i]);
1018 RETURN_IF_ERROR_FBK(status != vals[i],
1019 "fbk hash lookup failed");
1022 /* Clear all entries. */
1023 rte_fbk_hash_clear_all(handle);
1025 /* Lookup should fail. */
1026 for (i = 0; i < 5; i++) {
1027 status = rte_fbk_hash_lookup(handle, keys[i]);
1028 RETURN_IF_ERROR_FBK(status == 0,
1029 "fbk hash lookup should have failed");
1034 /* fill up the hash_table */
1035 for (i = 0; i < RTE_FBK_HASH_ENTRIES_MAX + 1; i++)
1036 rte_fbk_hash_add_key(handle, i, (uint16_t) i);
1038 /* Find non-existent key in a full hashtable */
1039 status = rte_fbk_hash_lookup(handle, RTE_FBK_HASH_ENTRIES_MAX + 1);
1040 RETURN_IF_ERROR_FBK(status != -ENOENT,
1041 "fbk hash lookup succeeded");
1043 /* Delete non-existent key in a full hashtable */
1044 status = rte_fbk_hash_delete_key(handle, RTE_FBK_HASH_ENTRIES_MAX + 1);
1045 RETURN_IF_ERROR_FBK(status != -ENOENT,
1046 "fbk hash delete succeeded");
1048 /* Delete one key from a full hashtable */
1049 status = rte_fbk_hash_delete_key(handle, 1);
1050 RETURN_IF_ERROR_FBK(status != 0,
1051 "fbk hash delete failed");
1053 /* Clear all entries. */
1054 rte_fbk_hash_clear_all(handle);
1057 rte_fbk_hash_free(handle);
1059 /* Cover the NULL case. */
1060 rte_fbk_hash_free(0);
1066 * Sequence of operations for find existing fbk hash table
1069 * - find existing table: hit
1070 * - find non-existing table: miss
1073 static int test_fbk_hash_find_existing(void)
1075 struct rte_fbk_hash_params params = {
1076 .name = "fbk_hash_find_existing",
1077 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1078 .entries_per_bucket = 4,
1081 struct rte_fbk_hash_table *handle = NULL, *result = NULL;
1083 /* Create hash table. */
1084 handle = rte_fbk_hash_create(¶ms);
1085 RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation failed");
1087 /* Try to find existing fbk hash table */
1088 result = rte_fbk_hash_find_existing("fbk_hash_find_existing");
1089 RETURN_IF_ERROR_FBK(result != handle, "could not find existing fbk hash table");
1091 /* Try to find non-existing fbk hash table */
1092 result = rte_fbk_hash_find_existing("fbk_hash_find_non_existing");
1093 RETURN_IF_ERROR_FBK(!(result == NULL), "found fbk table that shouldn't exist");
1096 rte_fbk_hash_free(handle);
1101 #define BUCKET_ENTRIES 4
1103 * Do tests for hash creation with bad parameters.
1105 static int test_hash_creation_with_bad_parameters(void)
1107 struct rte_hash *handle, *tmp;
1108 struct rte_hash_parameters params;
1110 handle = rte_hash_create(NULL);
1111 if (handle != NULL) {
1112 rte_hash_free(handle);
1113 printf("Impossible creating hash successfully without any parameter\n");
1117 memcpy(¶ms, &ut_params, sizeof(params));
1118 params.name = "creation_with_bad_parameters_0";
1119 params.entries = RTE_HASH_ENTRIES_MAX + 1;
1120 handle = rte_hash_create(¶ms);
1121 if (handle != NULL) {
1122 rte_hash_free(handle);
1123 printf("Impossible creating hash successfully with entries in parameter exceeded\n");
1127 memcpy(¶ms, &ut_params, sizeof(params));
1128 params.name = "creation_with_bad_parameters_2";
1129 params.entries = BUCKET_ENTRIES - 1;
1130 handle = rte_hash_create(¶ms);
1131 if (handle != NULL) {
1132 rte_hash_free(handle);
1133 printf("Impossible creating hash successfully if entries less than bucket_entries in parameter\n");
1137 memcpy(¶ms, &ut_params, sizeof(params));
1138 params.name = "creation_with_bad_parameters_3";
1140 handle = rte_hash_create(¶ms);
1141 if (handle != NULL) {
1142 rte_hash_free(handle);
1143 printf("Impossible creating hash successfully if key_len in parameter is zero\n");
1147 memcpy(¶ms, &ut_params, sizeof(params));
1148 params.name = "creation_with_bad_parameters_4";
1149 params.socket_id = RTE_MAX_NUMA_NODES + 1;
1150 handle = rte_hash_create(¶ms);
1151 if (handle != NULL) {
1152 rte_hash_free(handle);
1153 printf("Impossible creating hash successfully with invalid socket\n");
1157 /* test with same name should fail */
1158 memcpy(¶ms, &ut_params, sizeof(params));
1159 params.name = "same_name";
1160 handle = rte_hash_create(¶ms);
1161 if (handle == NULL) {
1162 printf("Cannot create first hash table with 'same_name'\n");
1165 tmp = rte_hash_create(¶ms);
1167 printf("Creation of hash table with same name should fail\n");
1168 rte_hash_free(handle);
1172 rte_hash_free(handle);
1174 printf("# Test successful. No more errors expected\n");
1180 * Do tests for hash creation with parameters that look incorrect
1181 * but are actually valid.
1184 test_hash_creation_with_good_parameters(void)
1186 struct rte_hash *handle;
1187 struct rte_hash_parameters params;
1189 /* create with null hash function - should choose DEFAULT_HASH_FUNC */
1190 memcpy(¶ms, &ut_params, sizeof(params));
1191 params.name = "name";
1192 params.hash_func = NULL;
1193 handle = rte_hash_create(¶ms);
1194 if (handle == NULL) {
1195 printf("Creating hash with null hash_func failed\n");
1199 rte_hash_free(handle);
1204 #define ITERATIONS 3
1206 * Test to see the average table utilization (entries added/max entries)
1207 * before hitting a random entry that cannot be added
1209 static int test_average_table_utilization(uint32_t ext_table)
1211 struct rte_hash *handle;
1212 uint8_t simple_key[MAX_KEYSIZE];
1214 unsigned added_keys, average_keys_added = 0;
1218 printf("\n# Running test to determine average utilization"
1219 "\n before adding elements begins to fail\n");
1221 printf("ext table is enabled\n");
1223 printf("ext table is disabled\n");
1225 printf("Measuring performance, please wait");
1227 ut_params.entries = 1 << 16;
1228 ut_params.name = "test_average_utilization";
1229 ut_params.hash_func = rte_jhash;
1231 ut_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1233 ut_params.extra_flag &= ~RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1235 handle = rte_hash_create(&ut_params);
1237 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
1239 for (j = 0; j < ITERATIONS; j++) {
1241 /* Add random entries until key cannot be added */
1242 for (added_keys = 0; ret >= 0; added_keys++) {
1243 for (i = 0; i < ut_params.key_len; i++)
1244 simple_key[i] = rte_rand() % 255;
1245 ret = rte_hash_add_key(handle, simple_key);
1250 if (ret != -ENOSPC) {
1251 printf("Unexpected error when adding keys\n");
1252 rte_hash_free(handle);
1256 cnt = rte_hash_count(handle);
1257 if (cnt != added_keys) {
1258 printf("rte_hash_count returned wrong value %u, %u,"
1259 "%u\n", j, added_keys, cnt);
1260 rte_hash_free(handle);
1264 if (cnt != ut_params.entries) {
1265 printf("rte_hash_count returned wrong value "
1266 "%u, %u, %u\n", j, added_keys, cnt);
1267 rte_hash_free(handle);
1272 average_keys_added += added_keys;
1274 /* Reset the table */
1275 rte_hash_reset(handle);
1277 /* Print a dot to show progress on operations */
1282 average_keys_added /= ITERATIONS;
1284 printf("\nAverage table utilization = %.2f%% (%u/%u)\n",
1285 ((double) average_keys_added / ut_params.entries * 100),
1286 average_keys_added, ut_params.entries);
1287 rte_hash_free(handle);
1292 #define NUM_ENTRIES 256
1293 static int test_hash_iteration(uint32_t ext_table)
1295 struct rte_hash *handle;
1297 uint8_t keys[NUM_ENTRIES][MAX_KEYSIZE];
1298 const void *next_key;
1300 void *data[NUM_ENTRIES];
1301 unsigned added_keys;
1305 ut_params.entries = NUM_ENTRIES;
1306 ut_params.name = "test_hash_iteration";
1307 ut_params.hash_func = rte_jhash;
1308 ut_params.key_len = 16;
1310 ut_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1312 ut_params.extra_flag &= ~RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1314 handle = rte_hash_create(&ut_params);
1315 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
1317 /* Add random entries until key cannot be added */
1318 for (added_keys = 0; added_keys < NUM_ENTRIES; added_keys++) {
1319 data[added_keys] = (void *) ((uintptr_t) rte_rand());
1320 for (i = 0; i < ut_params.key_len; i++)
1321 keys[added_keys][i] = rte_rand() % 255;
1322 ret = rte_hash_add_key_data(handle, keys[added_keys], data[added_keys]);
1325 printf("Insertion failed for ext table\n");
1332 /* Iterate through the hash table */
1333 while (rte_hash_iterate(handle, &next_key, &next_data, &iter) >= 0) {
1334 /* Search for the key in the list of keys added */
1335 for (i = 0; i < NUM_ENTRIES; i++) {
1336 if (memcmp(next_key, keys[i], ut_params.key_len) == 0) {
1337 if (next_data != data[i]) {
1338 printf("Data found in the hash table is"
1339 "not the data added with the key\n");
1346 if (i == NUM_ENTRIES) {
1347 printf("Key found in the hash table was not added\n");
1352 /* Check if all keys have been iterated */
1353 if (added_keys != 0) {
1354 printf("There were still %u keys to iterate\n", added_keys);
1358 rte_hash_free(handle);
1362 rte_hash_free(handle);
1366 static uint8_t key[16] = {0x00, 0x01, 0x02, 0x03,
1367 0x04, 0x05, 0x06, 0x07,
1368 0x08, 0x09, 0x0a, 0x0b,
1369 0x0c, 0x0d, 0x0e, 0x0f};
1370 static struct rte_hash_parameters hash_params_ex = {
1375 .hash_func_init_val = 0,
1380 * add/delete key with jhash2
1383 test_hash_add_delete_jhash2(void)
1386 struct rte_hash *handle;
1389 hash_params_ex.name = "hash_test_jhash2";
1390 hash_params_ex.key_len = 4;
1391 hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
1393 handle = rte_hash_create(&hash_params_ex);
1394 if (handle == NULL) {
1395 printf("test_hash_add_delete_jhash2 fail to create hash\n");
1398 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1400 printf("test_hash_add_delete_jhash2 fail to add hash key\n");
1404 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1405 if (pos2 < 0 || pos1 != pos2) {
1406 printf("test_hash_add_delete_jhash2 delete different key from being added\n");
1413 rte_hash_free(handle);
1419 * add/delete (2) key with jhash2
1422 test_hash_add_delete_2_jhash2(void)
1425 struct rte_hash *handle;
1428 hash_params_ex.name = "hash_test_2_jhash2";
1429 hash_params_ex.key_len = 8;
1430 hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
1432 handle = rte_hash_create(&hash_params_ex);
1436 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1440 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1441 if (pos2 < 0 || pos1 != pos2)
1448 rte_hash_free(handle);
1454 test_hash_jhash_1word(const void *key, uint32_t length, uint32_t initval)
1456 const uint32_t *k = key;
1458 RTE_SET_USED(length);
1460 return rte_jhash_1word(k[0], initval);
1464 test_hash_jhash_2word(const void *key, uint32_t length, uint32_t initval)
1466 const uint32_t *k = key;
1468 RTE_SET_USED(length);
1470 return rte_jhash_2words(k[0], k[1], initval);
1474 test_hash_jhash_3word(const void *key, uint32_t length, uint32_t initval)
1476 const uint32_t *k = key;
1478 RTE_SET_USED(length);
1480 return rte_jhash_3words(k[0], k[1], k[2], initval);
1484 * add/delete key with jhash 1word
1487 test_hash_add_delete_jhash_1word(void)
1490 struct rte_hash *handle;
1493 hash_params_ex.name = "hash_test_jhash_1word";
1494 hash_params_ex.key_len = 4;
1495 hash_params_ex.hash_func = test_hash_jhash_1word;
1497 handle = rte_hash_create(&hash_params_ex);
1499 goto fail_jhash_1word;
1501 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1503 goto fail_jhash_1word;
1505 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1506 if (pos2 < 0 || pos1 != pos2)
1507 goto fail_jhash_1word;
1513 rte_hash_free(handle);
1519 * add/delete key with jhash 2word
1522 test_hash_add_delete_jhash_2word(void)
1525 struct rte_hash *handle;
1528 hash_params_ex.name = "hash_test_jhash_2word";
1529 hash_params_ex.key_len = 8;
1530 hash_params_ex.hash_func = test_hash_jhash_2word;
1532 handle = rte_hash_create(&hash_params_ex);
1534 goto fail_jhash_2word;
1536 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1538 goto fail_jhash_2word;
1540 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1541 if (pos2 < 0 || pos1 != pos2)
1542 goto fail_jhash_2word;
1548 rte_hash_free(handle);
1554 * add/delete key with jhash 3word
1557 test_hash_add_delete_jhash_3word(void)
1560 struct rte_hash *handle;
1563 hash_params_ex.name = "hash_test_jhash_3word";
1564 hash_params_ex.key_len = 12;
1565 hash_params_ex.hash_func = test_hash_jhash_3word;
1567 handle = rte_hash_create(&hash_params_ex);
1569 goto fail_jhash_3word;
1571 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1573 goto fail_jhash_3word;
1575 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1576 if (pos2 < 0 || pos1 != pos2)
1577 goto fail_jhash_3word;
1583 rte_hash_free(handle);
1589 * Do all unit and performance tests.
1594 if (test_add_delete() < 0)
1596 if (test_hash_add_delete_jhash2() < 0)
1598 if (test_hash_add_delete_2_jhash2() < 0)
1600 if (test_hash_add_delete_jhash_1word() < 0)
1602 if (test_hash_add_delete_jhash_2word() < 0)
1604 if (test_hash_add_delete_jhash_3word() < 0)
1606 if (test_hash_get_key_with_position() < 0)
1608 if (test_hash_find_existing() < 0)
1610 if (test_add_update_delete() < 0)
1612 if (test_five_keys() < 0)
1614 if (test_full_bucket() < 0)
1616 if (test_extendable_bucket() < 0)
1619 if (test_fbk_hash_find_existing() < 0)
1621 if (fbk_hash_unit_test() < 0)
1623 if (test_hash_creation_with_bad_parameters() < 0)
1625 if (test_hash_creation_with_good_parameters() < 0)
1628 /* ext table disabled */
1629 if (test_average_table_utilization(0) < 0)
1631 if (test_hash_iteration(0) < 0)
1634 /* ext table enabled */
1635 if (test_average_table_utilization(1) < 0)
1637 if (test_hash_iteration(1) < 0)
1640 run_hash_func_tests();
1642 if (test_crc32_hash_alg_equiv() < 0)
1648 REGISTER_TEST_COMMAND(hash_autotest, test_hash);