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

Function test_five_keys

dpdk/app/test/test_hash.c:704–782  ·  view source on GitHub ↗

* Sequence of operations for 5 keys * - add keys * - lookup keys: hit * - add keys (update) * - lookup keys: hit (updated data) * - delete keys : hit * - lookup keys: miss */

Source from the content-addressed store, hash-verified

702 * - lookup keys: miss
703 */
704static int test_five_keys(void)
705{
706 struct rte_hash *handle;
707 const void *key_array[5] = {0};
708 int pos[5];
709 int expected_pos[5];
710 unsigned i;
711 int ret;
712
713 ut_params.name = "test3";
714 handle = rte_hash_create(&ut_params);
715 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
716
717 /* Add */
718 for (i = 0; i < 5; i++) {
719 pos[i] = rte_hash_add_key(handle, &keys[i]);
720 print_key_info("Add", &keys[i], pos[i]);
721 RETURN_IF_ERROR(pos[i] < 0,
722 "failed to add key (pos[%u]=%d)", i, pos[i]);
723 expected_pos[i] = pos[i];
724 }
725
726 /* Lookup */
727 for(i = 0; i < 5; i++)
728 key_array[i] = &keys[i];
729
730 ret = rte_hash_lookup_bulk(handle, &key_array[0], 5, (int32_t *)pos);
731 if(ret == 0)
732 for(i = 0; i < 5; i++) {
733 print_key_info("Lkp", key_array[i], pos[i]);
734 RETURN_IF_ERROR(pos[i] != expected_pos[i],
735 "failed to find key (pos[%u]=%d)", i, pos[i]);
736 }
737
738 /* Add - update */
739 for (i = 0; i < 5; i++) {
740 pos[i] = rte_hash_add_key(handle, &keys[i]);
741 print_key_info("Add", &keys[i], pos[i]);
742 RETURN_IF_ERROR(pos[i] != expected_pos[i],
743 "failed to add key (pos[%u]=%d)", i, pos[i]);
744 }
745
746 /* Lookup */
747 for (i = 0; i < 5; i++) {
748 pos[i] = rte_hash_lookup(handle, &keys[i]);
749 print_key_info("Lkp", &keys[i], pos[i]);
750 RETURN_IF_ERROR(pos[i] != expected_pos[i],
751 "failed to find key (pos[%u]=%d)", i, pos[i]);
752 }
753
754 /* Delete */
755 for (i = 0; i < 5; i++) {
756 pos[i] = rte_hash_del_key(handle, &keys[i]);
757 print_key_info("Del", &keys[i], pos[i]);
758 RETURN_IF_ERROR(pos[i] != expected_pos[i],
759 "failed to delete key (pos[%u]=%d)", i, pos[i]);
760 }
761

Callers 1

test_hashFunction · 0.70

Calls 7

rte_hash_createFunction · 0.85
rte_hash_add_keyFunction · 0.85
rte_hash_lookup_bulkFunction · 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