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

Function test_add_delete

dpdk/app/test/test_hash.c:276–347  ·  view source on GitHub ↗

* Basic sequence of operations for a single key: * - add * - lookup (hit) * - delete * - lookup (miss) * * Repeat the test case when 'free on delete' is disabled. * - add * - lookup (hit) * - delete * - lookup (miss) * - free */

Source from the content-addressed store, hash-verified

274 * - free
275 */
276static int test_add_delete(void)
277{
278 struct rte_hash *handle;
279 /* test with standard add/lookup/delete functions */
280 int pos0, expectedPos0;
281
282 ut_params.name = "test1";
283 handle = rte_hash_create(&ut_params);
284 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
285
286 pos0 = rte_hash_add_key(handle, &keys[0]);
287 print_key_info("Add", &keys[0], pos0);
288 RETURN_IF_ERROR(pos0 < 0, "failed to add key (pos0=%d)", pos0);
289 expectedPos0 = pos0;
290
291 pos0 = rte_hash_lookup(handle, &keys[0]);
292 print_key_info("Lkp", &keys[0], pos0);
293 RETURN_IF_ERROR(pos0 != expectedPos0,
294 "failed to find key (pos0=%d)", pos0);
295
296 pos0 = rte_hash_del_key(handle, &keys[0]);
297 print_key_info("Del", &keys[0], pos0);
298 RETURN_IF_ERROR(pos0 != expectedPos0,
299 "failed to delete key (pos0=%d)", pos0);
300
301 pos0 = rte_hash_lookup(handle, &keys[0]);
302 print_key_info("Lkp", &keys[0], pos0);
303 RETURN_IF_ERROR(pos0 != -ENOENT,
304 "fail: found key after deleting! (pos0=%d)", pos0);
305
306 rte_hash_free(handle);
307
308 /* repeat test with precomputed hash functions */
309 hash_sig_t hash_value;
310 int pos1, expectedPos1, delPos1;
311
312 ut_params.extra_flag = RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL;
313 handle = rte_hash_create(&ut_params);
314 RETURN_IF_ERROR(handle == NULL, "hash creation failed");
315 ut_params.extra_flag = 0;
316
317 hash_value = rte_hash_hash(handle, &keys[0]);
318 pos1 = rte_hash_add_key_with_hash(handle, &keys[0], hash_value);
319 print_key_info("Add", &keys[0], pos1);
320 RETURN_IF_ERROR(pos1 < 0, "failed to add key (pos1=%d)", pos1);
321 expectedPos1 = pos1;
322
323 pos1 = rte_hash_lookup_with_hash(handle, &keys[0], hash_value);
324 print_key_info("Lkp", &keys[0], pos1);
325 RETURN_IF_ERROR(pos1 != expectedPos1,
326 "failed to find key (pos1=%d)", pos1);
327
328 pos1 = rte_hash_del_key_with_hash(handle, &keys[0], hash_value);
329 print_key_info("Del", &keys[0], pos1);
330 RETURN_IF_ERROR(pos1 != expectedPos1,
331 "failed to delete key (pos1=%d)", pos1);
332 delPos1 = pos1;
333

Callers 1

test_hashFunction · 0.70

Calls 11

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
rte_hash_hashFunction · 0.85
print_key_infoFunction · 0.70

Tested by

no test coverage detected