MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_hash_iteration

Function test_hash_iteration

dpdk/app/test/test_hash.c:1526–1597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1524
1525#define NUM_ENTRIES 256
1526static int test_hash_iteration(uint32_t ext_table)
1527{
1528 struct rte_hash *handle;
1529 unsigned i;
1530 uint8_t keys[NUM_ENTRIES][MAX_KEYSIZE];
1531 const void *next_key;
1532 void *next_data;
1533 void *data[NUM_ENTRIES];
1534 unsigned added_keys;
1535 uint32_t iter = 0;
1536 int ret = 0;
1537
1538 ut_params.entries = NUM_ENTRIES;
1539 ut_params.name = "test_hash_iteration";
1540 ut_params.hash_func = rte_jhash;
1541 ut_params.key_len = 16;
1542 if (ext_table)
1543 ut_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1544 else
1545 ut_params.extra_flag &= ~RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
1546
1547 handle = rte_hash_create(&ut_params);
1548 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
1549
1550 /* Add random entries until key cannot be added */
1551 for (added_keys = 0; added_keys < NUM_ENTRIES; added_keys++) {
1552 data[added_keys] = (void *) ((uintptr_t) rte_rand());
1553 for (i = 0; i < ut_params.key_len; i++)
1554 keys[added_keys][i] = rte_rand() % 255;
1555 ret = rte_hash_add_key_data(handle, keys[added_keys], data[added_keys]);
1556 if (ret < 0) {
1557 if (ext_table) {
1558 printf("Insertion failed for ext table\n");
1559 goto err;
1560 }
1561 break;
1562 }
1563 }
1564
1565 /* Iterate through the hash table */
1566 while (rte_hash_iterate(handle, &next_key, &next_data, &iter) >= 0) {
1567 /* Search for the key in the list of keys added */
1568 for (i = 0; i < NUM_ENTRIES; i++) {
1569 if (memcmp(next_key, keys[i], ut_params.key_len) == 0) {
1570 if (next_data != data[i]) {
1571 printf("Data found in the hash table is"
1572 "not the data added with the key\n");
1573 goto err;
1574 }
1575 added_keys--;
1576 break;
1577 }
1578 }
1579 if (i == NUM_ENTRIES) {
1580 printf("Key found in the hash table was not added\n");
1581 goto err;
1582 }
1583 }

Callers 1

test_hashFunction · 0.85

Calls 6

rte_hash_createFunction · 0.85
rte_randFunction · 0.85
rte_hash_add_key_dataFunction · 0.85
rte_hash_iterateFunction · 0.85
rte_hash_freeFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected