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

Function test_full_bucket

dpdk/app/test/test_hash.c:794–892  ·  view source on GitHub ↗

* Add keys to the same bucket until bucket full. * - add 5 keys to the same bucket (hash created with 4 keys per bucket): * first 4 successful, 5th successful, pushing existing item in bucket * - lookup the 5 keys: 5 hits * - add the 5 keys again: 5 OK * - lookup the 5 keys: 5 hits (updated data) * - delete the 5 keys: 5 OK * - lookup the 5 keys: 5 misses */

Source from the content-addressed store, hash-verified

792 * - lookup the 5 keys: 5 misses
793 */
794static int test_full_bucket(void)
795{
796 struct rte_hash_parameters params_pseudo_hash = {
797 .name = "test4",
798 .entries = 64,
799 .key_len = sizeof(struct flow_key),
800 .hash_func = pseudo_hash,
801 .hash_func_init_val = 0,
802 .socket_id = 0,
803 };
804 struct rte_hash *handle;
805 int pos[5];
806 int expected_pos[5];
807 unsigned i;
808
809 handle = rte_hash_create(&params_pseudo_hash);
810 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
811
812 /* Fill bucket */
813 for (i = 0; i < 4; i++) {
814 pos[i] = rte_hash_add_key(handle, &keys[i]);
815 print_key_info("Add", &keys[i], pos[i]);
816 RETURN_IF_ERROR(pos[i] < 0,
817 "failed to add key (pos[%u]=%d)", i, pos[i]);
818 expected_pos[i] = pos[i];
819 }
820 /*
821 * This should work and will push one of the items
822 * in the bucket because it is full
823 */
824 pos[4] = rte_hash_add_key(handle, &keys[4]);
825 print_key_info("Add", &keys[4], pos[4]);
826 RETURN_IF_ERROR(pos[4] < 0,
827 "failed to add key (pos[4]=%d)", pos[4]);
828 expected_pos[4] = pos[4];
829
830 /* Lookup */
831 for (i = 0; i < 5; i++) {
832 pos[i] = rte_hash_lookup(handle, &keys[i]);
833 print_key_info("Lkp", &keys[i], pos[i]);
834 RETURN_IF_ERROR(pos[i] != expected_pos[i],
835 "failed to find key (pos[%u]=%d)", i, pos[i]);
836 }
837
838 /* Add - update */
839 for (i = 0; i < 5; i++) {
840 pos[i] = rte_hash_add_key(handle, &keys[i]);
841 print_key_info("Add", &keys[i], pos[i]);
842 RETURN_IF_ERROR(pos[i] != expected_pos[i],
843 "failed to add key (pos[%u]=%d)", i, pos[i]);
844 }
845
846 /* Lookup */
847 for (i = 0; i < 5; i++) {
848 pos[i] = rte_hash_lookup(handle, &keys[i]);
849 print_key_info("Lkp", &keys[i], pos[i]);
850 RETURN_IF_ERROR(pos[i] != expected_pos[i],
851 "failed to find key (pos[%u]=%d)", i, pos[i]);

Callers 1

test_hashFunction · 0.85

Calls 6

rte_hash_createFunction · 0.85
rte_hash_add_keyFunction · 0.85
rte_hash_lookupFunction · 0.85
rte_hash_del_keyFunction · 0.85
rte_hash_freeFunction · 0.85
print_key_infoFunction · 0.70

Tested by

no test coverage detected