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 #define RETURN_IF_ERROR_RCU_QSBR(cond, str, ...) do { \
65 printf("ERROR line %d: " str "\n", __LINE__, ##__VA_ARGS__); \
66 if (rcu_cfg.mode == RTE_HASH_QSBR_MODE_SYNC) { \
68 /* Wait until reader exited. */ \
69 rte_eal_mp_wait_lcore(); \
71 rte_hash_free(g_handle); \
77 /* 5-tuple key type */
87 * Hash function that always returns the same value, to easily test what
88 * happens when a bucket is full.
90 static uint32_t pseudo_hash(__rte_unused const void *keys,
91 __rte_unused uint32_t key_len,
92 __rte_unused uint32_t init_val)
97 RTE_LOG_REGISTER(hash_logtype_test, test.hash, INFO);
100 * Print out result of unit test hash operation.
102 static void print_key_info(const char *msg, const struct flow_key *key,
105 const uint8_t *p = (const uint8_t *)key;
108 rte_log(RTE_LOG_DEBUG, hash_logtype_test, "%s key:0x", msg);
109 for (i = 0; i < sizeof(struct flow_key); i++)
110 rte_log(RTE_LOG_DEBUG, hash_logtype_test, "%02X", p[i]);
111 rte_log(RTE_LOG_DEBUG, hash_logtype_test, " @ pos %d\n", pos);
114 /* Keys used by unit test functions */
115 static struct flow_key keys[5] = { {
116 .ip_src = RTE_IPV4(0x03, 0x02, 0x01, 0x00),
117 .ip_dst = RTE_IPV4(0x07, 0x06, 0x05, 0x04),
122 .ip_src = RTE_IPV4(0x13, 0x12, 0x11, 0x10),
123 .ip_dst = RTE_IPV4(0x17, 0x16, 0x15, 0x14),
128 .ip_src = RTE_IPV4(0x23, 0x22, 0x21, 0x20),
129 .ip_dst = RTE_IPV4(0x27, 0x26, 0x25, 0x24),
134 .ip_src = RTE_IPV4(0x33, 0x32, 0x31, 0x30),
135 .ip_dst = RTE_IPV4(0x37, 0x36, 0x35, 0x34),
140 .ip_src = RTE_IPV4(0x43, 0x42, 0x41, 0x40),
141 .ip_dst = RTE_IPV4(0x47, 0x46, 0x45, 0x44),
147 /* Parameters used for hash table in unit test functions. Name set later. */
148 static struct rte_hash_parameters ut_params = {
150 .key_len = sizeof(struct flow_key), /* 13 */
151 .hash_func = rte_jhash,
152 .hash_func_init_val = 0,
156 #define CRC32_ITERATIONS (1U << 10)
157 #define CRC32_DWORDS (1U << 6)
159 * Test if all CRC32 implementations yield the same hash value
162 test_crc32_hash_alg_equiv(void)
166 uint64_t data64[CRC32_DWORDS];
170 printf("\n# CRC32 implementations equivalence test\n");
171 for (i = 0; i < CRC32_ITERATIONS; i++) {
172 /* Randomizing data_len of data set */
173 data_len = (size_t) ((rte_rand() % sizeof(data64)) + 1);
174 init_val = (uint32_t) rte_rand();
176 /* Fill the data set */
177 for (j = 0; j < CRC32_DWORDS; j++)
178 data64[j] = rte_rand();
180 /* Calculate software CRC32 */
181 rte_hash_crc_set_alg(CRC32_SW);
182 hash_val = rte_hash_crc(data64, data_len, init_val);
184 /* Check against 4-byte-operand sse4.2 CRC32 if available */
185 rte_hash_crc_set_alg(CRC32_SSE42);
186 if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
187 printf("Failed checking CRC32_SW against CRC32_SSE42\n");
191 /* Check against 8-byte-operand sse4.2 CRC32 if available */
192 rte_hash_crc_set_alg(CRC32_SSE42_x64);
193 if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
194 printf("Failed checking CRC32_SW against CRC32_SSE42_x64\n");
198 /* Check against 8-byte-operand ARM64 CRC32 if available */
199 rte_hash_crc_set_alg(CRC32_ARM64);
200 if (hash_val != rte_hash_crc(data64, data_len, init_val)) {
201 printf("Failed checking CRC32_SW against CRC32_ARM64\n");
206 /* Resetting to best available algorithm */
207 rte_hash_crc_set_alg(CRC32_SSE42_x64);
209 if (i == CRC32_ITERATIONS)
212 printf("Failed test data (hex, %zu bytes total):\n", data_len);
213 for (j = 0; j < data_len; j++)
214 printf("%02X%c", ((uint8_t *)data64)[j],
215 ((j+1) % 16 == 0 || j == data_len - 1) ? '\n' : ' ');
221 * Test a hash function.
223 static void run_hash_func_test(rte_hash_function f, uint32_t init_val,
226 static uint8_t key[MAX_KEYSIZE];
230 for (i = 0; i < key_len; i++)
231 key[i] = (uint8_t) rte_rand();
233 /* just to be on the safe side */
237 f(key, key_len, init_val);
241 * Test all hash functions.
243 static void run_hash_func_tests(void)
247 for (i = 0; i < RTE_DIM(hashtest_funcs); i++) {
248 for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
249 for (k = 0; k < RTE_DIM(hashtest_key_lens); k++) {
250 run_hash_func_test(hashtest_funcs[i],
251 hashtest_initvals[j],
252 hashtest_key_lens[k]);
259 * Basic sequence of operations for a single key:
265 * Repeat the test case when 'free on delete' is disabled.
272 static int test_add_delete(void)
274 struct rte_hash *handle;
275 /* test with standard add/lookup/delete functions */
276 int pos0, expectedPos0;
278 ut_params.name = "test1";
279 handle = rte_hash_create(&ut_params);
280 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
282 pos0 = rte_hash_add_key(handle, &keys[0]);
283 print_key_info("Add", &keys[0], pos0);
284 RETURN_IF_ERROR(pos0 < 0, "failed to add key (pos0=%d)", pos0);
287 pos0 = rte_hash_lookup(handle, &keys[0]);
288 print_key_info("Lkp", &keys[0], pos0);
289 RETURN_IF_ERROR(pos0 != expectedPos0,
290 "failed to find key (pos0=%d)", pos0);
292 pos0 = rte_hash_del_key(handle, &keys[0]);
293 print_key_info("Del", &keys[0], pos0);
294 RETURN_IF_ERROR(pos0 != expectedPos0,
295 "failed to delete key (pos0=%d)", pos0);
297 pos0 = rte_hash_lookup(handle, &keys[0]);
298 print_key_info("Lkp", &keys[0], pos0);
299 RETURN_IF_ERROR(pos0 != -ENOENT,
300 "fail: found key after deleting! (pos0=%d)", pos0);
302 rte_hash_free(handle);
304 /* repeat test with precomputed hash functions */
305 hash_sig_t hash_value;
306 int pos1, expectedPos1, delPos1;
308 ut_params.extra_flag = RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL;
309 handle = rte_hash_create(&ut_params);
310 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
311 ut_params.extra_flag = 0;
313 hash_value = rte_hash_hash(handle, &keys[0]);
314 pos1 = rte_hash_add_key_with_hash(handle, &keys[0], hash_value);
315 print_key_info("Add", &keys[0], pos1);
316 RETURN_IF_ERROR(pos1 < 0, "failed to add 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 != expectedPos1,
322 "failed to find key (pos1=%d)", pos1);
324 pos1 = rte_hash_del_key_with_hash(handle, &keys[0], hash_value);
325 print_key_info("Del", &keys[0], pos1);
326 RETURN_IF_ERROR(pos1 != expectedPos1,
327 "failed to delete key (pos1=%d)", pos1);
330 pos1 = rte_hash_lookup_with_hash(handle, &keys[0], hash_value);
331 print_key_info("Lkp", &keys[0], pos1);
332 RETURN_IF_ERROR(pos1 != -ENOENT,
333 "fail: found key after deleting! (pos1=%d)", pos1);
335 pos1 = rte_hash_free_key_with_position(handle, delPos1);
336 print_key_info("Free", &keys[0], delPos1);
337 RETURN_IF_ERROR(pos1 != 0,
338 "failed to free key (pos1=%d)", delPos1);
340 rte_hash_free(handle);
346 * Sequence of operations for a single key:
351 * - lookup: hit (updated data)
356 static int test_add_update_delete(void)
358 struct rte_hash *handle;
359 int pos0, expectedPos0;
361 ut_params.name = "test2";
362 handle = rte_hash_create(&ut_params);
363 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
365 pos0 = rte_hash_del_key(handle, &keys[0]);
366 print_key_info("Del", &keys[0], pos0);
367 RETURN_IF_ERROR(pos0 != -ENOENT,
368 "fail: found non-existent key (pos0=%d)", pos0);
370 pos0 = rte_hash_add_key(handle, &keys[0]);
371 print_key_info("Add", &keys[0], pos0);
372 RETURN_IF_ERROR(pos0 < 0, "failed to add key (pos0=%d)", pos0);
375 pos0 = rte_hash_lookup(handle, &keys[0]);
376 print_key_info("Lkp", &keys[0], pos0);
377 RETURN_IF_ERROR(pos0 != expectedPos0,
378 "failed to find key (pos0=%d)", pos0);
380 pos0 = rte_hash_add_key(handle, &keys[0]);
381 print_key_info("Add", &keys[0], pos0);
382 RETURN_IF_ERROR(pos0 != expectedPos0,
383 "failed to re-add key (pos0=%d)", pos0);
385 pos0 = rte_hash_lookup(handle, &keys[0]);
386 print_key_info("Lkp", &keys[0], pos0);
387 RETURN_IF_ERROR(pos0 != expectedPos0,
388 "failed to find key (pos0=%d)", pos0);
390 pos0 = rte_hash_del_key(handle, &keys[0]);
391 print_key_info("Del", &keys[0], pos0);
392 RETURN_IF_ERROR(pos0 != expectedPos0,
393 "failed to delete key (pos0=%d)", pos0);
395 pos0 = rte_hash_del_key(handle, &keys[0]);
396 print_key_info("Del", &keys[0], pos0);
397 RETURN_IF_ERROR(pos0 != -ENOENT,
398 "fail: deleted already deleted key (pos0=%d)", pos0);
400 pos0 = rte_hash_lookup(handle, &keys[0]);
401 print_key_info("Lkp", &keys[0], pos0);
402 RETURN_IF_ERROR(pos0 != -ENOENT,
403 "fail: found key after deleting! (pos0=%d)", pos0);
405 rte_hash_free(handle);
410 * Sequence of operations for a single key with 'disable free on del' set:
415 * - lookup: hit (updated data)
422 static int test_add_update_delete_free(void)
424 struct rte_hash *handle;
425 int pos0, expectedPos0, delPos0, result;
427 ut_params.name = "test2";
428 ut_params.extra_flag = RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL;
429 handle = rte_hash_create(&ut_params);
430 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
431 ut_params.extra_flag = 0;
433 pos0 = rte_hash_del_key(handle, &keys[0]);
434 print_key_info("Del", &keys[0], pos0);
435 RETURN_IF_ERROR(pos0 != -ENOENT,
436 "fail: found non-existent key (pos0=%d)", pos0);
438 pos0 = rte_hash_add_key(handle, &keys[0]);
439 print_key_info("Add", &keys[0], pos0);
440 RETURN_IF_ERROR(pos0 < 0, "failed to add key (pos0=%d)", pos0);
443 pos0 = rte_hash_lookup(handle, &keys[0]);
444 print_key_info("Lkp", &keys[0], pos0);
445 RETURN_IF_ERROR(pos0 != expectedPos0,
446 "failed to find key (pos0=%d)", pos0);
448 pos0 = rte_hash_add_key(handle, &keys[0]);
449 print_key_info("Add", &keys[0], pos0);
450 RETURN_IF_ERROR(pos0 != expectedPos0,
451 "failed to re-add key (pos0=%d)", pos0);
453 pos0 = rte_hash_lookup(handle, &keys[0]);
454 print_key_info("Lkp", &keys[0], pos0);
455 RETURN_IF_ERROR(pos0 != expectedPos0,
456 "failed to find key (pos0=%d)", pos0);
458 delPos0 = rte_hash_del_key(handle, &keys[0]);
459 print_key_info("Del", &keys[0], delPos0);
460 RETURN_IF_ERROR(delPos0 != expectedPos0,
461 "failed to delete key (pos0=%d)", delPos0);
463 pos0 = rte_hash_del_key(handle, &keys[0]);
464 print_key_info("Del", &keys[0], pos0);
465 RETURN_IF_ERROR(pos0 != -ENOENT,
466 "fail: deleted already deleted key (pos0=%d)", pos0);
468 pos0 = rte_hash_lookup(handle, &keys[0]);
469 print_key_info("Lkp", &keys[0], pos0);
470 RETURN_IF_ERROR(pos0 != -ENOENT,
471 "fail: found key after deleting! (pos0=%d)", pos0);
473 result = rte_hash_free_key_with_position(handle, delPos0);
474 print_key_info("Free", &keys[0], delPos0);
475 RETURN_IF_ERROR(result != 0,
476 "failed to free key (pos1=%d)", delPos0);
478 pos0 = rte_hash_lookup(handle, &keys[0]);
479 print_key_info("Lkp", &keys[0], pos0);
480 RETURN_IF_ERROR(pos0 != -ENOENT,
481 "fail: found key after deleting! (pos0=%d)", pos0);
483 rte_hash_free(handle);
488 * Sequence of operations for a single key with 'rw concurrency lock free' set:
492 * Repeat the test case when 'multi writer add' is enabled.
497 static int test_add_delete_free_lf(void)
499 /* Should match the #define LCORE_CACHE_SIZE value in rte_cuckoo_hash.h */
500 #define LCORE_CACHE_SIZE 64
501 struct rte_hash *handle;
502 hash_sig_t hash_value;
503 int pos, expectedPos, delPos;
507 extra_flag = ut_params.extra_flag;
508 ut_params.extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF;
509 handle = rte_hash_create(&ut_params);
510 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
511 ut_params.extra_flag = extra_flag;
514 * The number of iterations is at least the same as the number of slots
515 * rte_hash allocates internally. This is to reveal potential issues of
516 * not freeing keys successfully.
518 for (i = 0; i < ut_params.entries + 1; i++) {
519 hash_value = rte_hash_hash(handle, &keys[0]);
520 pos = rte_hash_add_key_with_hash(handle, &keys[0], hash_value);
521 print_key_info("Add", &keys[0], pos);
522 RETURN_IF_ERROR(pos < 0, "failed to add key (pos=%d)", pos);
525 pos = rte_hash_del_key_with_hash(handle, &keys[0], hash_value);
526 print_key_info("Del", &keys[0], pos);
527 RETURN_IF_ERROR(pos != expectedPos,
528 "failed to delete key (pos=%d)", pos);
531 pos = rte_hash_free_key_with_position(handle, delPos);
532 print_key_info("Free", &keys[0], delPos);
533 RETURN_IF_ERROR(pos != 0,
534 "failed to free key (pos=%d)", delPos);
537 rte_hash_free(handle);
539 extra_flag = ut_params.extra_flag;
540 ut_params.extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF |
541 RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
542 handle = rte_hash_create(&ut_params);
543 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
544 ut_params.extra_flag = extra_flag;
546 ip_src = keys[0].ip_src;
548 * The number of iterations is at least the same as the number of slots
549 * rte_hash allocates internally. This is to reveal potential issues of
550 * not freeing keys successfully.
552 for (i = 0; i < ut_params.entries + (RTE_MAX_LCORE - 1) *
553 (LCORE_CACHE_SIZE - 1) + 1; i++) {
555 hash_value = rte_hash_hash(handle, &keys[0]);
556 pos = rte_hash_add_key_with_hash(handle, &keys[0], hash_value);
557 print_key_info("Add", &keys[0], pos);
558 RETURN_IF_ERROR(pos < 0, "failed to add key (pos=%d)", pos);
561 pos = rte_hash_del_key_with_hash(handle, &keys[0], hash_value);
562 print_key_info("Del", &keys[0], pos);
563 RETURN_IF_ERROR(pos != expectedPos,
564 "failed to delete key (pos=%d)", pos);
567 pos = rte_hash_free_key_with_position(handle, delPos);
568 print_key_info("Free", &keys[0], delPos);
569 RETURN_IF_ERROR(pos != 0,
570 "failed to free key (pos=%d)", delPos);
572 keys[0].ip_src = ip_src;
574 rte_hash_free(handle);
580 * Sequence of operations for retrieving a key with its position
584 * - get the key with its position: hit
586 * - try to get the deleted key: miss
588 * Repeat the test case when 'free on delete' is disabled.
591 * - get the key with its position: hit
593 * - try to get the deleted key: hit
595 * - try to get the deleted key: miss
598 static int test_hash_get_key_with_position(void)
600 struct rte_hash *handle = NULL;
601 int pos, expectedPos, delPos, result;
604 ut_params.name = "hash_get_key_w_pos";
605 handle = rte_hash_create(&ut_params);
606 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
608 pos = rte_hash_add_key(handle, &keys[0]);
609 print_key_info("Add", &keys[0], pos);
610 RETURN_IF_ERROR(pos < 0, "failed to add key (pos0=%d)", pos);
613 result = rte_hash_get_key_with_position(handle, pos, &key);
614 RETURN_IF_ERROR(result != 0, "error retrieving a key");
616 pos = rte_hash_del_key(handle, &keys[0]);
617 print_key_info("Del", &keys[0], pos);
618 RETURN_IF_ERROR(pos != expectedPos,
619 "failed to delete key (pos0=%d)", pos);
621 result = rte_hash_get_key_with_position(handle, pos, &key);
622 RETURN_IF_ERROR(result != -ENOENT, "non valid key retrieved");
624 rte_hash_free(handle);
626 ut_params.name = "hash_get_key_w_pos";
627 ut_params.extra_flag = RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL;
628 handle = rte_hash_create(&ut_params);
629 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
630 ut_params.extra_flag = 0;
632 pos = rte_hash_add_key(handle, &keys[0]);
633 print_key_info("Add", &keys[0], pos);
634 RETURN_IF_ERROR(pos < 0, "failed to add key (pos0=%d)", pos);
637 result = rte_hash_get_key_with_position(handle, pos, &key);
638 RETURN_IF_ERROR(result != 0, "error retrieving a key");
640 delPos = rte_hash_del_key(handle, &keys[0]);
641 print_key_info("Del", &keys[0], delPos);
642 RETURN_IF_ERROR(delPos != expectedPos,
643 "failed to delete key (pos0=%d)", delPos);
645 result = rte_hash_get_key_with_position(handle, delPos, &key);
646 RETURN_IF_ERROR(result != -ENOENT, "non valid key retrieved");
648 result = rte_hash_free_key_with_position(handle, delPos);
649 print_key_info("Free", &keys[0], delPos);
650 RETURN_IF_ERROR(result != 0,
651 "failed to free key (pos1=%d)", delPos);
653 result = rte_hash_get_key_with_position(handle, delPos, &key);
654 RETURN_IF_ERROR(result != -ENOENT, "non valid key retrieved");
656 rte_hash_free(handle);
661 * Sequence of operations for find existing hash table
664 * - find existing table: hit
665 * - find non-existing table: miss
668 static int test_hash_find_existing(void)
670 struct rte_hash *handle = NULL, *result = NULL;
672 /* Create hash table. */
673 ut_params.name = "hash_find_existing";
674 handle = rte_hash_create(&ut_params);
675 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
677 /* Try to find existing hash table */
678 result = rte_hash_find_existing("hash_find_existing");
679 RETURN_IF_ERROR(result != handle, "could not find existing hash table");
681 /* Try to find non-existing hash table */
682 result = rte_hash_find_existing("hash_find_non_existing");
683 RETURN_IF_ERROR(!(result == NULL), "found table that shouldn't exist");
686 rte_hash_free(handle);
692 * Sequence of operations for 5 keys
695 * - add keys (update)
696 * - lookup keys: hit (updated data)
697 * - delete keys : hit
698 * - lookup keys: miss
700 static int test_five_keys(void)
702 struct rte_hash *handle;
703 const void *key_array[5] = {0};
709 ut_params.name = "test3";
710 handle = rte_hash_create(&ut_params);
711 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
714 for (i = 0; i < 5; i++) {
715 pos[i] = rte_hash_add_key(handle, &keys[i]);
716 print_key_info("Add", &keys[i], pos[i]);
717 RETURN_IF_ERROR(pos[i] < 0,
718 "failed to add key (pos[%u]=%d)", i, pos[i]);
719 expected_pos[i] = pos[i];
723 for(i = 0; i < 5; i++)
724 key_array[i] = &keys[i];
726 ret = rte_hash_lookup_bulk(handle, &key_array[0], 5, (int32_t *)pos);
728 for(i = 0; i < 5; i++) {
729 print_key_info("Lkp", key_array[i], pos[i]);
730 RETURN_IF_ERROR(pos[i] != expected_pos[i],
731 "failed to find key (pos[%u]=%d)", i, pos[i]);
735 for (i = 0; i < 5; i++) {
736 pos[i] = rte_hash_add_key(handle, &keys[i]);
737 print_key_info("Add", &keys[i], pos[i]);
738 RETURN_IF_ERROR(pos[i] != expected_pos[i],
739 "failed to add key (pos[%u]=%d)", i, pos[i]);
743 for (i = 0; i < 5; i++) {
744 pos[i] = rte_hash_lookup(handle, &keys[i]);
745 print_key_info("Lkp", &keys[i], pos[i]);
746 RETURN_IF_ERROR(pos[i] != expected_pos[i],
747 "failed to find key (pos[%u]=%d)", i, pos[i]);
751 for (i = 0; i < 5; i++) {
752 pos[i] = rte_hash_del_key(handle, &keys[i]);
753 print_key_info("Del", &keys[i], pos[i]);
754 RETURN_IF_ERROR(pos[i] != expected_pos[i],
755 "failed to delete key (pos[%u]=%d)", i, pos[i]);
759 for (i = 0; i < 5; i++) {
760 pos[i] = rte_hash_lookup(handle, &keys[i]);
761 print_key_info("Lkp", &keys[i], pos[i]);
762 RETURN_IF_ERROR(pos[i] != -ENOENT,
763 "found non-existent key (pos[%u]=%d)", i, pos[i]);
767 ret = rte_hash_lookup_bulk(handle, &key_array[0], 5, (int32_t *)pos);
769 for (i = 0; i < 5; i++) {
770 print_key_info("Lkp", key_array[i], pos[i]);
771 RETURN_IF_ERROR(pos[i] != -ENOENT,
772 "found not-existent key (pos[%u]=%d)", i, pos[i]);
775 rte_hash_free(handle);
781 * Add keys to the same bucket until bucket full.
782 * - add 5 keys to the same bucket (hash created with 4 keys per bucket):
783 * first 4 successful, 5th successful, pushing existing item in bucket
784 * - lookup the 5 keys: 5 hits
785 * - add the 5 keys again: 5 OK
786 * - lookup the 5 keys: 5 hits (updated data)
787 * - delete the 5 keys: 5 OK
788 * - lookup the 5 keys: 5 misses
790 static int test_full_bucket(void)
792 struct rte_hash_parameters params_pseudo_hash = {
795 .key_len = sizeof(struct flow_key), /* 13 */
796 .hash_func = pseudo_hash,
797 .hash_func_init_val = 0,
800 struct rte_hash *handle;
805 handle = rte_hash_create(¶ms_pseudo_hash);
806 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
809 for (i = 0; i < 4; i++) {
810 pos[i] = rte_hash_add_key(handle, &keys[i]);
811 print_key_info("Add", &keys[i], pos[i]);
812 RETURN_IF_ERROR(pos[i] < 0,
813 "failed to add key (pos[%u]=%d)", i, pos[i]);
814 expected_pos[i] = pos[i];
817 * This should work and will push one of the items
818 * in the bucket because it is full
820 pos[4] = rte_hash_add_key(handle, &keys[4]);
821 print_key_info("Add", &keys[4], pos[4]);
822 RETURN_IF_ERROR(pos[4] < 0,
823 "failed to add key (pos[4]=%d)", pos[4]);
824 expected_pos[4] = pos[4];
827 for (i = 0; i < 5; i++) {
828 pos[i] = rte_hash_lookup(handle, &keys[i]);
829 print_key_info("Lkp", &keys[i], pos[i]);
830 RETURN_IF_ERROR(pos[i] != expected_pos[i],
831 "failed to find key (pos[%u]=%d)", i, pos[i]);
835 for (i = 0; i < 5; i++) {
836 pos[i] = rte_hash_add_key(handle, &keys[i]);
837 print_key_info("Add", &keys[i], pos[i]);
838 RETURN_IF_ERROR(pos[i] != expected_pos[i],
839 "failed to add key (pos[%u]=%d)", i, pos[i]);
843 for (i = 0; i < 5; i++) {
844 pos[i] = rte_hash_lookup(handle, &keys[i]);
845 print_key_info("Lkp", &keys[i], pos[i]);
846 RETURN_IF_ERROR(pos[i] != expected_pos[i],
847 "failed to find key (pos[%u]=%d)", i, pos[i]);
850 /* Delete 1 key, check other keys are still found */
851 pos[1] = rte_hash_del_key(handle, &keys[1]);
852 print_key_info("Del", &keys[1], pos[1]);
853 RETURN_IF_ERROR(pos[1] != expected_pos[1],
854 "failed to delete key (pos[1]=%d)", pos[1]);
855 pos[3] = rte_hash_lookup(handle, &keys[3]);
856 print_key_info("Lkp", &keys[3], pos[3]);
857 RETURN_IF_ERROR(pos[3] != expected_pos[3],
858 "failed lookup after deleting key from same bucket "
859 "(pos[3]=%d)", pos[3]);
861 /* Go back to previous state */
862 pos[1] = rte_hash_add_key(handle, &keys[1]);
863 print_key_info("Add", &keys[1], pos[1]);
864 expected_pos[1] = pos[1];
865 RETURN_IF_ERROR(pos[1] < 0, "failed to add key (pos[1]=%d)", pos[1]);
868 for (i = 0; i < 5; i++) {
869 pos[i] = rte_hash_del_key(handle, &keys[i]);
870 print_key_info("Del", &keys[i], pos[i]);
871 RETURN_IF_ERROR(pos[i] != expected_pos[i],
872 "failed to delete key (pos[%u]=%d)", i, pos[i]);
876 for (i = 0; i < 5; i++) {
877 pos[i] = rte_hash_lookup(handle, &keys[i]);
878 print_key_info("Lkp", &keys[i], pos[i]);
879 RETURN_IF_ERROR(pos[i] != -ENOENT,
880 "fail: found non-existent key (pos[%u]=%d)", i, pos[i]);
883 rte_hash_free(handle);
885 /* Cover the NULL case. */
891 * Similar to the test above (full bucket test), but for extendable buckets.
893 static int test_extendable_bucket(void)
895 struct rte_hash_parameters params_pseudo_hash = {
898 .key_len = sizeof(struct flow_key), /* 13 */
899 .hash_func = pseudo_hash,
900 .hash_func_init_val = 0,
902 .extra_flag = RTE_HASH_EXTRA_FLAGS_EXT_TABLE
904 struct rte_hash *handle;
906 int expected_pos[64];
908 struct flow_key rand_keys[64];
910 for (i = 0; i < 64; i++) {
911 rand_keys[i].port_dst = i;
912 rand_keys[i].port_src = i+1;
915 handle = rte_hash_create(¶ms_pseudo_hash);
916 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
919 for (i = 0; i < 64; i++) {
920 pos[i] = rte_hash_add_key(handle, &rand_keys[i]);
921 print_key_info("Add", &rand_keys[i], pos[i]);
922 RETURN_IF_ERROR(pos[i] < 0,
923 "failed to add key (pos[%u]=%d)", i, pos[i]);
924 expected_pos[i] = pos[i];
928 for (i = 0; i < 64; i++) {
929 pos[i] = rte_hash_lookup(handle, &rand_keys[i]);
930 print_key_info("Lkp", &rand_keys[i], pos[i]);
931 RETURN_IF_ERROR(pos[i] != expected_pos[i],
932 "failed to find key (pos[%u]=%d)", i, pos[i]);
936 for (i = 0; i < 64; i++) {
937 pos[i] = rte_hash_add_key(handle, &rand_keys[i]);
938 print_key_info("Add", &rand_keys[i], pos[i]);
939 RETURN_IF_ERROR(pos[i] != expected_pos[i],
940 "failed to add key (pos[%u]=%d)", i, pos[i]);
944 for (i = 0; i < 64; i++) {
945 pos[i] = rte_hash_lookup(handle, &rand_keys[i]);
946 print_key_info("Lkp", &rand_keys[i], pos[i]);
947 RETURN_IF_ERROR(pos[i] != expected_pos[i],
948 "failed to find key (pos[%u]=%d)", i, pos[i]);
951 /* Delete 1 key, check other keys are still found */
952 pos[35] = rte_hash_del_key(handle, &rand_keys[35]);
953 print_key_info("Del", &rand_keys[35], pos[35]);
954 RETURN_IF_ERROR(pos[35] != expected_pos[35],
955 "failed to delete key (pos[1]=%d)", pos[35]);
956 pos[20] = rte_hash_lookup(handle, &rand_keys[20]);
957 print_key_info("Lkp", &rand_keys[20], pos[20]);
958 RETURN_IF_ERROR(pos[20] != expected_pos[20],
959 "failed lookup after deleting key from same bucket "
960 "(pos[20]=%d)", pos[20]);
962 /* Go back to previous state */
963 pos[35] = rte_hash_add_key(handle, &rand_keys[35]);
964 print_key_info("Add", &rand_keys[35], pos[35]);
965 expected_pos[35] = pos[35];
966 RETURN_IF_ERROR(pos[35] < 0, "failed to add key (pos[1]=%d)", pos[35]);
969 for (i = 0; i < 64; i++) {
970 pos[i] = rte_hash_del_key(handle, &rand_keys[i]);
971 print_key_info("Del", &rand_keys[i], pos[i]);
972 RETURN_IF_ERROR(pos[i] != expected_pos[i],
973 "failed to delete key (pos[%u]=%d)", i, pos[i]);
977 for (i = 0; i < 64; i++) {
978 pos[i] = rte_hash_lookup(handle, &rand_keys[i]);
979 print_key_info("Lkp", &rand_keys[i], pos[i]);
980 RETURN_IF_ERROR(pos[i] != -ENOENT,
981 "fail: found non-existent key (pos[%u]=%d)", i, pos[i]);
985 for (i = 0; i < 64; i++) {
986 pos[i] = rte_hash_add_key(handle, &rand_keys[i]);
987 print_key_info("Add", &rand_keys[i], pos[i]);
988 RETURN_IF_ERROR(pos[i] < 0,
989 "failed to add key (pos[%u]=%d)", i, pos[i]);
990 expected_pos[i] = pos[i];
993 rte_hash_free(handle);
995 /* Cover the NULL case. */
1000 /******************************************************************************/
1002 fbk_hash_unit_test(void)
1004 struct rte_fbk_hash_params params = {
1005 .name = "fbk_hash_test",
1006 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1007 .entries_per_bucket = 4,
1011 struct rte_fbk_hash_params invalid_params_1 = {
1012 .name = "invalid_1",
1013 .entries = LOCAL_FBK_HASH_ENTRIES_MAX + 1, /* Not power of 2 */
1014 .entries_per_bucket = 4,
1018 struct rte_fbk_hash_params invalid_params_2 = {
1019 .name = "invalid_2",
1021 .entries_per_bucket = 3, /* Not power of 2 */
1025 struct rte_fbk_hash_params invalid_params_3 = {
1026 .name = "invalid_3",
1027 .entries = 0, /* Entries is 0 */
1028 .entries_per_bucket = 4,
1032 struct rte_fbk_hash_params invalid_params_4 = {
1033 .name = "invalid_4",
1034 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1035 .entries_per_bucket = 0, /* Entries per bucket is 0 */
1039 struct rte_fbk_hash_params invalid_params_5 = {
1040 .name = "invalid_5",
1042 .entries_per_bucket = 8, /* Entries per bucket > entries */
1046 struct rte_fbk_hash_params invalid_params_6 = {
1047 .name = "invalid_6",
1048 .entries = RTE_FBK_HASH_ENTRIES_MAX * 2, /* Entries > max allowed */
1049 .entries_per_bucket = 4,
1053 struct rte_fbk_hash_params invalid_params_7 = {
1054 .name = "invalid_7",
1055 .entries = RTE_FBK_HASH_ENTRIES_MAX,
1056 .entries_per_bucket = RTE_FBK_HASH_ENTRIES_PER_BUCKET_MAX * 2, /* Entries > max allowed */
1060 struct rte_fbk_hash_params invalid_params_8 = {
1061 .name = "invalid_7",
1062 .entries = RTE_FBK_HASH_ENTRIES_MAX,
1063 .entries_per_bucket = 4,
1064 .socket_id = RTE_MAX_NUMA_NODES + 1, /* invalid socket */
1067 /* try to create two hashes with identical names
1068 * in this case, trying to create a second one will not
1069 * fail but will simply return pointer to the existing
1070 * hash with that name. sort of like a "find hash by name" :-)
1072 struct rte_fbk_hash_params invalid_params_same_name_1 = {
1073 .name = "same_name", /* hash with identical name */
1075 .entries_per_bucket = 2,
1079 /* trying to create this hash should return a pointer to an existing hash */
1080 struct rte_fbk_hash_params invalid_params_same_name_2 = {
1081 .name = "same_name", /* hash with identical name */
1082 .entries = RTE_FBK_HASH_ENTRIES_MAX,
1083 .entries_per_bucket = 4,
1087 /* this is a sanity check for "same name" test
1088 * creating this hash will check if we are actually able to create
1089 * multiple hashes with different names (instead of having just one).
1091 struct rte_fbk_hash_params different_name = {
1092 .name = "different_name", /* different name */
1093 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1094 .entries_per_bucket = 4,
1098 struct rte_fbk_hash_params params_jhash = {
1100 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1101 .entries_per_bucket = 4,
1103 .hash_func = rte_jhash_1word, /* Tests for different hash_func */
1104 .init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT,
1107 struct rte_fbk_hash_params params_nohash = {
1108 .name = "valid nohash",
1109 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1110 .entries_per_bucket = 4,
1112 .hash_func = NULL, /* Tests for null hash_func */
1113 .init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT,
1116 struct rte_fbk_hash_table *handle, *tmp;
1118 {0xc6e18639, 0xe67c201c, 0xd4c8cffd, 0x44728691, 0xd5430fa9};
1119 uint16_t vals[5] = {28108, 5699, 38490, 2166, 61571};
1122 double used_entries;
1124 /* Try creating hashes with invalid parameters */
1125 printf("# Testing hash creation with invalid parameters "
1126 "- expect error msgs\n");
1127 handle = rte_fbk_hash_create(&invalid_params_1);
1128 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1130 handle = rte_fbk_hash_create(&invalid_params_2);
1131 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1133 handle = rte_fbk_hash_create(&invalid_params_3);
1134 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1136 handle = rte_fbk_hash_create(&invalid_params_4);
1137 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1139 handle = rte_fbk_hash_create(&invalid_params_5);
1140 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1142 handle = rte_fbk_hash_create(&invalid_params_6);
1143 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1145 handle = rte_fbk_hash_create(&invalid_params_7);
1146 RETURN_IF_ERROR_FBK(handle != NULL, "fbk hash creation should have failed");
1148 if (rte_eal_has_hugepages()) {
1149 handle = rte_fbk_hash_create(&invalid_params_8);
1150 RETURN_IF_ERROR_FBK(handle != NULL,
1151 "fbk hash creation should have failed");
1154 handle = rte_fbk_hash_create(&invalid_params_same_name_1);
1155 RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation should have succeeded");
1157 tmp = rte_fbk_hash_create(&invalid_params_same_name_2);
1159 rte_fbk_hash_free(tmp);
1160 RETURN_IF_ERROR_FBK(tmp != NULL, "fbk hash creation should have failed");
1162 /* we are not freeing handle here because we need a hash list
1163 * to be not empty for the next test */
1165 /* create a hash in non-empty list - good for coverage */
1166 tmp = rte_fbk_hash_create(&different_name);
1167 RETURN_IF_ERROR_FBK(tmp == NULL, "fbk hash creation should have succeeded");
1169 /* free both hashes */
1170 rte_fbk_hash_free(handle);
1171 rte_fbk_hash_free(tmp);
1173 /* Create empty jhash hash. */
1174 handle = rte_fbk_hash_create(¶ms_jhash);
1175 RETURN_IF_ERROR_FBK(handle == NULL, "fbk jhash hash creation failed");
1178 rte_fbk_hash_free(handle);
1180 /* Create empty jhash hash. */
1181 handle = rte_fbk_hash_create(¶ms_nohash);
1182 RETURN_IF_ERROR_FBK(handle == NULL, "fbk nohash hash creation failed");
1185 rte_fbk_hash_free(handle);
1187 /* Create empty hash. */
1188 handle = rte_fbk_hash_create(¶ms);
1189 RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation failed");
1191 used_entries = rte_fbk_hash_get_load_factor(handle) * LOCAL_FBK_HASH_ENTRIES_MAX;
1192 RETURN_IF_ERROR_FBK((unsigned)used_entries != 0, \
1193 "load factor right after creation is not zero but it should be");
1195 for (i = 0; i < 5; i++) {
1196 status = rte_fbk_hash_add_key(handle, keys[i], vals[i]);
1197 RETURN_IF_ERROR_FBK(status != 0, "fbk hash add failed");
1200 used_entries = rte_fbk_hash_get_load_factor(handle) * LOCAL_FBK_HASH_ENTRIES_MAX;
1201 RETURN_IF_ERROR_FBK((unsigned)used_entries != (unsigned)((((double)5)/LOCAL_FBK_HASH_ENTRIES_MAX)*LOCAL_FBK_HASH_ENTRIES_MAX), \
1202 "load factor now is not as expected");
1203 /* Find value of added keys. */
1204 for (i = 0; i < 5; i++) {
1205 status = rte_fbk_hash_lookup(handle, keys[i]);
1206 RETURN_IF_ERROR_FBK(status != vals[i],
1207 "fbk hash lookup failed");
1210 /* Change value of added keys. */
1211 for (i = 0; i < 5; i++) {
1212 status = rte_fbk_hash_add_key(handle, keys[i], vals[4 - i]);
1213 RETURN_IF_ERROR_FBK(status != 0, "fbk hash update failed");
1216 /* Find new values. */
1217 for (i = 0; i < 5; i++) {
1218 status = rte_fbk_hash_lookup(handle, keys[i]);
1219 RETURN_IF_ERROR_FBK(status != vals[4-i],
1220 "fbk hash lookup failed");
1223 /* Delete keys individually. */
1224 for (i = 0; i < 5; i++) {
1225 status = rte_fbk_hash_delete_key(handle, keys[i]);
1226 RETURN_IF_ERROR_FBK(status != 0, "fbk hash delete failed");
1229 used_entries = rte_fbk_hash_get_load_factor(handle) * LOCAL_FBK_HASH_ENTRIES_MAX;
1230 RETURN_IF_ERROR_FBK((unsigned)used_entries != 0, \
1231 "load factor right after deletion is not zero but it should be");
1232 /* Lookup should now fail. */
1233 for (i = 0; i < 5; i++) {
1234 status = rte_fbk_hash_lookup(handle, keys[i]);
1235 RETURN_IF_ERROR_FBK(status == 0,
1236 "fbk hash lookup should have failed");
1239 /* Add keys again. */
1240 for (i = 0; i < 5; i++) {
1241 status = rte_fbk_hash_add_key(handle, keys[i], vals[i]);
1242 RETURN_IF_ERROR_FBK(status != 0, "fbk hash add failed");
1245 /* Make sure they were added. */
1246 for (i = 0; i < 5; i++) {
1247 status = rte_fbk_hash_lookup(handle, keys[i]);
1248 RETURN_IF_ERROR_FBK(status != vals[i],
1249 "fbk hash lookup failed");
1252 /* Clear all entries. */
1253 rte_fbk_hash_clear_all(handle);
1255 /* Lookup should fail. */
1256 for (i = 0; i < 5; i++) {
1257 status = rte_fbk_hash_lookup(handle, keys[i]);
1258 RETURN_IF_ERROR_FBK(status == 0,
1259 "fbk hash lookup should have failed");
1264 /* fill up the hash_table */
1265 for (i = 0; i < RTE_FBK_HASH_ENTRIES_MAX + 1; i++)
1266 rte_fbk_hash_add_key(handle, i, (uint16_t) i);
1268 /* Find non-existent key in a full hashtable */
1269 status = rte_fbk_hash_lookup(handle, RTE_FBK_HASH_ENTRIES_MAX + 1);
1270 RETURN_IF_ERROR_FBK(status != -ENOENT,
1271 "fbk hash lookup succeeded");
1273 /* Delete non-existent key in a full hashtable */
1274 status = rte_fbk_hash_delete_key(handle, RTE_FBK_HASH_ENTRIES_MAX + 1);
1275 RETURN_IF_ERROR_FBK(status != -ENOENT,
1276 "fbk hash delete succeeded");
1278 /* Delete one key from a full hashtable */
1279 status = rte_fbk_hash_delete_key(handle, 1);
1280 RETURN_IF_ERROR_FBK(status != 0,
1281 "fbk hash delete failed");
1283 /* Clear all entries. */
1284 rte_fbk_hash_clear_all(handle);
1287 rte_fbk_hash_free(handle);
1289 /* Cover the NULL case. */
1290 rte_fbk_hash_free(0);
1296 * Sequence of operations for find existing fbk hash table
1299 * - find existing table: hit
1300 * - find non-existing table: miss
1303 static int test_fbk_hash_find_existing(void)
1305 struct rte_fbk_hash_params params = {
1306 .name = "fbk_hash_find_existing",
1307 .entries = LOCAL_FBK_HASH_ENTRIES_MAX,
1308 .entries_per_bucket = 4,
1311 struct rte_fbk_hash_table *handle = NULL, *result = NULL;
1313 /* Create hash table. */
1314 handle = rte_fbk_hash_create(¶ms);
1315 RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation failed");
1317 /* Try to find existing fbk hash table */
1318 result = rte_fbk_hash_find_existing("fbk_hash_find_existing");
1319 RETURN_IF_ERROR_FBK(result != handle, "could not find existing fbk hash table");
1321 /* Try to find non-existing fbk hash table */
1322 result = rte_fbk_hash_find_existing("fbk_hash_find_non_existing");
1323 RETURN_IF_ERROR_FBK(!(result == NULL), "found fbk table that shouldn't exist");
1326 rte_fbk_hash_free(handle);
1331 #define BUCKET_ENTRIES 4
1333 * Do tests for hash creation with bad parameters.
1335 static int test_hash_creation_with_bad_parameters(void)
1337 struct rte_hash *handle, *tmp;
1338 struct rte_hash_parameters params;
1340 handle = rte_hash_create(NULL);
1341 if (handle != NULL) {
1342 rte_hash_free(handle);
1343 printf("Impossible creating hash successfully without any parameter\n");
1347 memcpy(¶ms, &ut_params, sizeof(params));
1348 params.name = "creation_with_bad_parameters_0";
1349 params.entries = RTE_HASH_ENTRIES_MAX + 1;
1350 handle = rte_hash_create(¶ms);
1351 if (handle != NULL) {
1352 rte_hash_free(handle);
1353 printf("Impossible creating hash successfully with entries in parameter exceeded\n");
1357 memcpy(¶ms, &ut_params, sizeof(params));
1358 params.name = "creation_with_bad_parameters_2";
1359 params.entries = BUCKET_ENTRIES - 1;
1360 handle = rte_hash_create(¶ms);
1361 if (handle != NULL) {
1362 rte_hash_free(handle);
1363 printf("Impossible creating hash successfully if entries less than bucket_entries in parameter\n");
1367 memcpy(¶ms, &ut_params, sizeof(params));
1368 params.name = "creation_with_bad_parameters_3";
1370 handle = rte_hash_create(¶ms);
1371 if (handle != NULL) {
1372 rte_hash_free(handle);
1373 printf("Impossible creating hash successfully if key_len in parameter is zero\n");
1377 memcpy(¶ms, &ut_params, sizeof(params));
1378 params.name = "creation_with_bad_parameters_4";
1379 params.socket_id = RTE_MAX_NUMA_NODES + 1;
1380 handle = rte_hash_create(¶ms);
1381 if (handle != NULL) {
1382 rte_hash_free(handle);
1383 printf("Impossible creating hash successfully with invalid socket\n");
1387 /* test with same name should fail */
1388 memcpy(¶ms, &ut_params, sizeof(params));
1389 params.name = "same_name";
1390 handle = rte_hash_create(¶ms);
1391 if (handle == NULL) {
1392 printf("Cannot create first hash table with 'same_name'\n");
1395 tmp = rte_hash_create(¶ms);
1397 printf("Creation of hash table with same name should fail\n");
1398 rte_hash_free(handle);
1402 rte_hash_free(handle);
1404 printf("# Test successful. No more errors expected\n");
1410 * Do tests for hash creation with parameters that look incorrect
1411 * but are actually valid.
1414 test_hash_creation_with_good_parameters(void)
1416 struct rte_hash *handle;
1417 struct rte_hash_parameters params;
1419 /* create with null hash function - should choose DEFAULT_HASH_FUNC */
1420 memcpy(¶ms, &ut_params, sizeof(params));
1421 params.name = "name";
1422 params.hash_func = NULL;
1423 handle = rte_hash_create(¶ms);
1424 if (handle == NULL) {
1425 printf("Creating hash with null hash_func failed\n");
1429 rte_hash_free(handle);
1434 #define ITERATIONS 3
1436 * Test to see the average table utilization (entries added/max entries)
1437 * before hitting a random entry that cannot be added
1439 static int test_average_table_utilization(uint32_t ext_table)
1441 struct rte_hash *handle;
1442 uint8_t simple_key[MAX_KEYSIZE];
1444 unsigned added_keys, average_keys_added = 0;
1448 printf("\n# Running test to determine average utilization"
1449 "\n before adding elements begins to fail\n");
1451 printf("ext table is enabled\n");
1453 printf("ext table is disabled\n");
1455 printf("Measuring performance, please wait");
1457 ut_params.entries = 1 << 16;
1458 ut_params.name = "test_average_utilization";
1459 ut_params.hash_func = rte_jhash;
1461 ut_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1463 ut_params.extra_flag &= ~RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1465 handle = rte_hash_create(&ut_params);
1467 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
1469 for (j = 0; j < ITERATIONS; j++) {
1471 /* Add random entries until key cannot be added */
1472 for (added_keys = 0; ret >= 0; added_keys++) {
1473 for (i = 0; i < ut_params.key_len; i++)
1474 simple_key[i] = rte_rand() % 255;
1475 ret = rte_hash_add_key(handle, simple_key);
1480 if (ret != -ENOSPC) {
1481 printf("Unexpected error when adding keys\n");
1482 rte_hash_free(handle);
1486 cnt = rte_hash_count(handle);
1487 if (cnt != added_keys) {
1488 printf("rte_hash_count returned wrong value %u, %u,"
1489 "%u\n", j, added_keys, cnt);
1490 rte_hash_free(handle);
1494 if (cnt != ut_params.entries) {
1495 printf("rte_hash_count returned wrong value "
1496 "%u, %u, %u\n", j, added_keys, cnt);
1497 rte_hash_free(handle);
1502 average_keys_added += added_keys;
1504 /* Reset the table */
1505 rte_hash_reset(handle);
1507 /* Print a dot to show progress on operations */
1512 average_keys_added /= ITERATIONS;
1514 printf("\nAverage table utilization = %.2f%% (%u/%u)\n",
1515 ((double) average_keys_added / ut_params.entries * 100),
1516 average_keys_added, ut_params.entries);
1517 rte_hash_free(handle);
1522 #define NUM_ENTRIES 256
1523 static int test_hash_iteration(uint32_t ext_table)
1525 struct rte_hash *handle;
1527 uint8_t keys[NUM_ENTRIES][MAX_KEYSIZE];
1528 const void *next_key;
1530 void *data[NUM_ENTRIES];
1531 unsigned added_keys;
1535 ut_params.entries = NUM_ENTRIES;
1536 ut_params.name = "test_hash_iteration";
1537 ut_params.hash_func = rte_jhash;
1538 ut_params.key_len = 16;
1540 ut_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1542 ut_params.extra_flag &= ~RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1544 handle = rte_hash_create(&ut_params);
1545 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
1547 /* Add random entries until key cannot be added */
1548 for (added_keys = 0; added_keys < NUM_ENTRIES; added_keys++) {
1549 data[added_keys] = (void *) ((uintptr_t) rte_rand());
1550 for (i = 0; i < ut_params.key_len; i++)
1551 keys[added_keys][i] = rte_rand() % 255;
1552 ret = rte_hash_add_key_data(handle, keys[added_keys], data[added_keys]);
1555 printf("Insertion failed for ext table\n");
1562 /* Iterate through the hash table */
1563 while (rte_hash_iterate(handle, &next_key, &next_data, &iter) >= 0) {
1564 /* Search for the key in the list of keys added */
1565 for (i = 0; i < NUM_ENTRIES; i++) {
1566 if (memcmp(next_key, keys[i], ut_params.key_len) == 0) {
1567 if (next_data != data[i]) {
1568 printf("Data found in the hash table is"
1569 "not the data added with the key\n");
1576 if (i == NUM_ENTRIES) {
1577 printf("Key found in the hash table was not added\n");
1582 /* Check if all keys have been iterated */
1583 if (added_keys != 0) {
1584 printf("There were still %u keys to iterate\n", added_keys);
1588 rte_hash_free(handle);
1592 rte_hash_free(handle);
1596 static uint8_t key[16] = {0x00, 0x01, 0x02, 0x03,
1597 0x04, 0x05, 0x06, 0x07,
1598 0x08, 0x09, 0x0a, 0x0b,
1599 0x0c, 0x0d, 0x0e, 0x0f};
1600 static struct rte_hash_parameters hash_params_ex = {
1605 .hash_func_init_val = 0,
1610 * add/delete key with jhash2
1613 test_hash_add_delete_jhash2(void)
1616 struct rte_hash *handle;
1619 hash_params_ex.name = "hash_test_jhash2";
1620 hash_params_ex.key_len = 4;
1621 hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
1623 handle = rte_hash_create(&hash_params_ex);
1624 if (handle == NULL) {
1625 printf("test_hash_add_delete_jhash2 fail to create hash\n");
1628 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1630 printf("test_hash_add_delete_jhash2 fail to add hash key\n");
1634 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1635 if (pos2 < 0 || pos1 != pos2) {
1636 printf("test_hash_add_delete_jhash2 delete different key from being added\n");
1643 rte_hash_free(handle);
1649 * add/delete (2) key with jhash2
1652 test_hash_add_delete_2_jhash2(void)
1655 struct rte_hash *handle;
1658 hash_params_ex.name = "hash_test_2_jhash2";
1659 hash_params_ex.key_len = 8;
1660 hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
1662 handle = rte_hash_create(&hash_params_ex);
1666 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1670 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1671 if (pos2 < 0 || pos1 != pos2)
1678 rte_hash_free(handle);
1684 test_hash_jhash_1word(const void *key, uint32_t length, uint32_t initval)
1686 const uint32_t *k = key;
1688 RTE_SET_USED(length);
1690 return rte_jhash_1word(k[0], initval);
1694 test_hash_jhash_2word(const void *key, uint32_t length, uint32_t initval)
1696 const uint32_t *k = key;
1698 RTE_SET_USED(length);
1700 return rte_jhash_2words(k[0], k[1], initval);
1704 test_hash_jhash_3word(const void *key, uint32_t length, uint32_t initval)
1706 const uint32_t *k = key;
1708 RTE_SET_USED(length);
1710 return rte_jhash_3words(k[0], k[1], k[2], initval);
1714 * add/delete key with jhash 1word
1717 test_hash_add_delete_jhash_1word(void)
1720 struct rte_hash *handle;
1723 hash_params_ex.name = "hash_test_jhash_1word";
1724 hash_params_ex.key_len = 4;
1725 hash_params_ex.hash_func = test_hash_jhash_1word;
1727 handle = rte_hash_create(&hash_params_ex);
1729 goto fail_jhash_1word;
1731 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1733 goto fail_jhash_1word;
1735 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1736 if (pos2 < 0 || pos1 != pos2)
1737 goto fail_jhash_1word;
1743 rte_hash_free(handle);
1749 * add/delete key with jhash 2word
1752 test_hash_add_delete_jhash_2word(void)
1755 struct rte_hash *handle;
1758 hash_params_ex.name = "hash_test_jhash_2word";
1759 hash_params_ex.key_len = 8;
1760 hash_params_ex.hash_func = test_hash_jhash_2word;
1762 handle = rte_hash_create(&hash_params_ex);
1764 goto fail_jhash_2word;
1766 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1768 goto fail_jhash_2word;
1770 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1771 if (pos2 < 0 || pos1 != pos2)
1772 goto fail_jhash_2word;
1778 rte_hash_free(handle);
1784 * add/delete key with jhash 3word
1787 test_hash_add_delete_jhash_3word(void)
1790 struct rte_hash *handle;
1793 hash_params_ex.name = "hash_test_jhash_3word";
1794 hash_params_ex.key_len = 12;
1795 hash_params_ex.hash_func = test_hash_jhash_3word;
1797 handle = rte_hash_create(&hash_params_ex);
1799 goto fail_jhash_3word;
1801 pos1 = rte_hash_add_key(handle, (void *)&key[0]);
1803 goto fail_jhash_3word;
1805 pos2 = rte_hash_del_key(handle, (void *)&key[0]);
1806 if (pos2 < 0 || pos1 != pos2)
1807 goto fail_jhash_3word;
1813 rte_hash_free(handle);
1818 static struct rte_hash *g_handle;
1819 static struct rte_rcu_qsbr *g_qsv;
1820 static volatile uint8_t writer_done;
1821 struct flow_key g_rand_keys[9];
1824 * rte_hash_rcu_qsbr_add positive and negative tests.
1825 * - Add RCU QSBR variable to Hash
1826 * - Add another RCU QSBR variable to Hash
1830 test_hash_rcu_qsbr_add(void)
1833 struct rte_rcu_qsbr *qsv2 = NULL;
1835 struct rte_hash_rcu_config rcu_cfg = {0};
1836 struct rte_hash_parameters params;
1838 printf("\n# Running RCU QSBR add tests\n");
1839 memcpy(¶ms, &ut_params, sizeof(params));
1840 params.name = "test_hash_rcu_qsbr_add";
1841 params.extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF |
1842 RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
1843 g_handle = rte_hash_create(¶ms);
1844 RETURN_IF_ERROR_RCU_QSBR(g_handle == NULL, "Hash creation failed");
1846 /* Create RCU QSBR variable */
1847 sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
1848 g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1849 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1850 RETURN_IF_ERROR_RCU_QSBR(g_qsv == NULL,
1851 "RCU QSBR variable creation failed");
1853 status = rte_rcu_qsbr_init(g_qsv, RTE_MAX_LCORE);
1854 RETURN_IF_ERROR_RCU_QSBR(status != 0,
1855 "RCU QSBR variable initialization failed");
1858 /* Invalid QSBR mode */
1859 rcu_cfg.mode = 0xff;
1860 status = rte_hash_rcu_qsbr_add(g_handle, &rcu_cfg);
1861 RETURN_IF_ERROR_RCU_QSBR(status == 0, "Invalid QSBR mode test failed");
1863 rcu_cfg.mode = RTE_HASH_QSBR_MODE_DQ;
1864 /* Attach RCU QSBR to hash table */
1865 status = rte_hash_rcu_qsbr_add(g_handle, &rcu_cfg);
1866 RETURN_IF_ERROR_RCU_QSBR(status != 0,
1867 "Attach RCU QSBR to hash table failed");
1869 /* Create and attach another RCU QSBR to hash table */
1870 qsv2 = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1871 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1872 RETURN_IF_ERROR_RCU_QSBR(qsv2 == NULL,
1873 "RCU QSBR variable creation failed");
1876 rcu_cfg.mode = RTE_HASH_QSBR_MODE_SYNC;
1877 status = rte_hash_rcu_qsbr_add(g_handle, &rcu_cfg);
1879 RETURN_IF_ERROR_RCU_QSBR(status == 0,
1880 "Attach RCU QSBR to hash table succeeded where failure"
1883 rte_hash_free(g_handle);
1890 * rte_hash_rcu_qsbr_add DQ mode functional test.
1891 * Reader and writer are in the same thread in this test.
1892 * - Create hash which supports maximum 8 (9 if ext bkt is enabled) entries
1893 * - Add RCU QSBR variable to hash
1894 * - Add 8 hash entries and fill the bucket
1895 * - If ext bkt is enabled, add 1 extra entry that is available in the ext bkt
1896 * - Register a reader thread (not a real thread)
1897 * - Reader lookup existing entry
1898 * - Writer deletes the entry
1899 * - Reader lookup the entry
1900 * - Writer re-add the entry (no available free index)
1901 * - Reader report quiescent state and unregister
1902 * - Writer re-add the entry
1903 * - Reader lookup the entry
1906 test_hash_rcu_qsbr_dq_mode(uint8_t ext_bkt)
1908 uint32_t total_entries = (ext_bkt == 0) ? 8 : 9;
1910 uint8_t hash_extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF;
1913 hash_extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1915 struct rte_hash_parameters params_pseudo_hash = {
1916 .name = "test_hash_rcu_qsbr_dq_mode",
1917 .entries = total_entries,
1918 .key_len = sizeof(struct flow_key), /* 13 */
1919 .hash_func = pseudo_hash,
1920 .hash_func_init_val = 0,
1922 .extra_flag = hash_extra_flag,
1924 int pos[total_entries];
1925 int expected_pos[total_entries];
1929 struct rte_hash_rcu_config rcu_cfg = {0};
1934 for (i = 0; i < total_entries; i++) {
1935 g_rand_keys[i].port_dst = i;
1936 g_rand_keys[i].port_src = i+1;
1940 printf("\n# Running RCU QSBR DQ mode functional test with"
1943 printf("\n# Running RCU QSBR DQ mode functional test\n");
1945 g_handle = rte_hash_create(¶ms_pseudo_hash);
1946 RETURN_IF_ERROR_RCU_QSBR(g_handle == NULL, "Hash creation failed");
1948 /* Create RCU QSBR variable */
1949 sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
1950 g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1951 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1952 RETURN_IF_ERROR_RCU_QSBR(g_qsv == NULL,
1953 "RCU QSBR variable creation failed");
1955 status = rte_rcu_qsbr_init(g_qsv, RTE_MAX_LCORE);
1956 RETURN_IF_ERROR_RCU_QSBR(status != 0,
1957 "RCU QSBR variable initialization failed");
1960 rcu_cfg.mode = RTE_HASH_QSBR_MODE_DQ;
1961 /* Attach RCU QSBR to hash table */
1962 status = rte_hash_rcu_qsbr_add(g_handle, &rcu_cfg);
1963 RETURN_IF_ERROR_RCU_QSBR(status != 0,
1964 "Attach RCU QSBR to hash table failed");
1967 for (i = 0; i < total_entries; i++) {
1968 pos[i] = rte_hash_add_key(g_handle, &g_rand_keys[i]);
1969 print_key_info("Add", &g_rand_keys[i], pos[i]);
1970 RETURN_IF_ERROR_RCU_QSBR(pos[i] < 0,
1971 "failed to add key (pos[%u]=%d)", i,
1973 expected_pos[i] = pos[i];
1976 /* Register pseudo reader */
1977 status = rte_rcu_qsbr_thread_register(g_qsv, 0);
1978 RETURN_IF_ERROR_RCU_QSBR(status != 0,
1979 "RCU QSBR thread registration failed");
1980 rte_rcu_qsbr_thread_online(g_qsv, 0);
1983 pos[0] = rte_hash_lookup(g_handle, &g_rand_keys[0]);
1984 print_key_info("Lkp", &g_rand_keys[0], pos[0]);
1985 RETURN_IF_ERROR_RCU_QSBR(pos[0] != expected_pos[0],
1986 "failed to find correct key (pos[%u]=%d)", 0,
1990 pos[0] = rte_hash_del_key(g_handle, &g_rand_keys[0]);
1991 print_key_info("Del", &g_rand_keys[0], pos[0]);
1992 RETURN_IF_ERROR_RCU_QSBR(pos[0] != expected_pos[0],
1993 "failed to del correct key (pos[%u]=%d)", 0,
1997 pos[0] = rte_hash_lookup(g_handle, &g_rand_keys[0]);
1998 print_key_info("Lkp", &g_rand_keys[0], pos[0]);
1999 RETURN_IF_ERROR_RCU_QSBR(pos[0] != -ENOENT,
2000 "found deleted key (pos[%u]=%d)", 0, pos[0]);
2003 pos[0] = rte_hash_add_key(g_handle, &g_rand_keys[0]);
2004 print_key_info("Add", &g_rand_keys[0], pos[0]);
2005 RETURN_IF_ERROR_RCU_QSBR(pos[0] != -ENOSPC,
2006 "Added key successfully (pos[%u]=%d)", 0, pos[0]);
2008 /* Reader quiescent */
2009 rte_rcu_qsbr_quiescent(g_qsv, 0);
2012 pos[0] = rte_hash_add_key(g_handle, &g_rand_keys[0]);
2013 print_key_info("Add", &g_rand_keys[0], pos[0]);
2014 RETURN_IF_ERROR_RCU_QSBR(pos[0] < 0,
2015 "failed to add key (pos[%u]=%d)", 0, pos[0]);
2016 expected_pos[0] = pos[0];
2018 rte_rcu_qsbr_thread_offline(g_qsv, 0);
2019 (void)rte_rcu_qsbr_thread_unregister(g_qsv, 0);
2022 pos[0] = rte_hash_lookup(g_handle, &g_rand_keys[0]);
2023 print_key_info("Lkp", &g_rand_keys[0], pos[0]);
2024 RETURN_IF_ERROR_RCU_QSBR(pos[0] != expected_pos[0],
2025 "failed to find correct key (pos[%u]=%d)", 0,
2028 rte_hash_free(g_handle);
2034 /* Report quiescent state interval every 1024 lookups. Larger critical
2035 * sections in reader will result in writer polling multiple times.
2037 #define QSBR_REPORTING_INTERVAL 1024
2038 #define WRITER_ITERATIONS 512
2041 * Reader thread using rte_hash data structure with RCU.
2044 test_hash_rcu_qsbr_reader(void *arg)
2049 /* Register this thread to report quiescent state */
2050 (void)rte_rcu_qsbr_thread_register(g_qsv, 0);
2051 rte_rcu_qsbr_thread_online(g_qsv, 0);
2054 for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
2055 rte_hash_lookup(g_handle, &g_rand_keys[0]);
2057 /* Update quiescent state */
2058 rte_rcu_qsbr_quiescent(g_qsv, 0);
2059 } while (!writer_done);
2061 rte_rcu_qsbr_thread_offline(g_qsv, 0);
2062 (void)rte_rcu_qsbr_thread_unregister(g_qsv, 0);
2068 * rte_hash_rcu_qsbr_add sync mode functional test.
2069 * 1 Reader and 1 writer. They cannot be in the same thread in this test.
2070 * - Create hash which supports maximum 8 (9 if ext bkt is enabled) entries
2071 * - Add RCU QSBR variable to hash
2072 * - Register a reader thread. Reader keeps looking up a specific key.
2073 * - Writer keeps adding and deleting a specific key.
2076 test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt)
2078 uint32_t total_entries = (ext_bkt == 0) ? 8 : 9;
2080 uint8_t hash_extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF;
2083 hash_extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
2085 struct rte_hash_parameters params_pseudo_hash = {
2086 .name = "test_hash_rcu_qsbr_sync_mode",
2087 .entries = total_entries,
2088 .key_len = sizeof(struct flow_key), /* 13 */
2089 .hash_func = pseudo_hash,
2090 .hash_func_init_val = 0,
2092 .extra_flag = hash_extra_flag,
2094 int pos[total_entries];
2095 int expected_pos[total_entries];
2099 struct rte_hash_rcu_config rcu_cfg = {0};
2104 for (i = 0; i < total_entries; i++) {
2105 g_rand_keys[i].port_dst = i;
2106 g_rand_keys[i].port_src = i+1;
2110 printf("\n# Running RCU QSBR sync mode functional test with"
2113 printf("\n# Running RCU QSBR sync mode functional test\n");
2115 g_handle = rte_hash_create(¶ms_pseudo_hash);
2116 RETURN_IF_ERROR_RCU_QSBR(g_handle == NULL, "Hash creation failed");
2118 /* Create RCU QSBR variable */
2119 sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
2120 g_qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
2121 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
2122 RETURN_IF_ERROR_RCU_QSBR(g_qsv == NULL,
2123 "RCU QSBR variable creation failed");
2125 status = rte_rcu_qsbr_init(g_qsv, RTE_MAX_LCORE);
2126 RETURN_IF_ERROR_RCU_QSBR(status != 0,
2127 "RCU QSBR variable initialization failed");
2130 rcu_cfg.mode = RTE_HASH_QSBR_MODE_SYNC;
2131 /* Attach RCU QSBR to hash table */
2132 status = rte_hash_rcu_qsbr_add(g_handle, &rcu_cfg);
2133 RETURN_IF_ERROR_RCU_QSBR(status != 0,
2134 "Attach RCU QSBR to hash table failed");
2136 /* Launch reader thread */
2137 rte_eal_remote_launch(test_hash_rcu_qsbr_reader, NULL,
2138 rte_get_next_lcore(-1, 1, 0));
2141 for (i = 0; i < total_entries; i++) {
2142 pos[i] = rte_hash_add_key(g_handle, &g_rand_keys[i]);
2143 print_key_info("Add", &g_rand_keys[i], pos[i]);
2144 RETURN_IF_ERROR_RCU_QSBR(pos[i] < 0,
2145 "failed to add key (pos[%u]=%d)", i, pos[i]);
2146 expected_pos[i] = pos[i];
2151 for (i = 0; i < WRITER_ITERATIONS; i++) {
2152 expected_pos[0] = pos[0];
2153 pos[0] = rte_hash_del_key(g_handle, &g_rand_keys[0]);
2154 print_key_info("Del", &g_rand_keys[0], status);
2155 RETURN_IF_ERROR_RCU_QSBR(pos[0] != expected_pos[0],
2156 "failed to del correct key (pos[%u]=%d)"
2159 pos[0] = rte_hash_add_key(g_handle, &g_rand_keys[0]);
2160 print_key_info("Add", &g_rand_keys[0], pos[0]);
2161 RETURN_IF_ERROR_RCU_QSBR(pos[0] < 0,
2162 "failed to add key (pos[%u]=%d)", 0,
2167 /* Wait until reader exited. */
2168 rte_eal_mp_wait_lcore();
2170 rte_hash_free(g_handle);
2178 * Do all unit and performance tests.
2183 if (test_add_delete() < 0)
2185 if (test_hash_add_delete_jhash2() < 0)
2187 if (test_hash_add_delete_2_jhash2() < 0)
2189 if (test_hash_add_delete_jhash_1word() < 0)
2191 if (test_hash_add_delete_jhash_2word() < 0)
2193 if (test_hash_add_delete_jhash_3word() < 0)
2195 if (test_hash_get_key_with_position() < 0)
2197 if (test_hash_find_existing() < 0)
2199 if (test_add_update_delete() < 0)
2201 if (test_add_update_delete_free() < 0)
2203 if (test_add_delete_free_lf() < 0)
2205 if (test_five_keys() < 0)
2207 if (test_full_bucket() < 0)
2209 if (test_extendable_bucket() < 0)
2212 if (test_fbk_hash_find_existing() < 0)
2214 if (fbk_hash_unit_test() < 0)
2216 if (test_hash_creation_with_bad_parameters() < 0)
2218 if (test_hash_creation_with_good_parameters() < 0)
2221 /* ext table disabled */
2222 if (test_average_table_utilization(0) < 0)
2224 if (test_hash_iteration(0) < 0)
2227 /* ext table enabled */
2228 if (test_average_table_utilization(1) < 0)
2230 if (test_hash_iteration(1) < 0)
2233 run_hash_func_tests();
2235 if (test_crc32_hash_alg_equiv() < 0)
2238 if (test_hash_rcu_qsbr_add() < 0)
2241 if (test_hash_rcu_qsbr_dq_mode(0) < 0)
2244 if (test_hash_rcu_qsbr_dq_mode(1) < 0)
2247 if (test_hash_rcu_qsbr_sync_mode(0) < 0)
2250 if (test_hash_rcu_qsbr_sync_mode(1) < 0)
2256 REGISTER_TEST_COMMAND(hash_autotest, test_hash);