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

Function test_adjust_tuple

dpdk/app/test/test_thash.c:729–805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

727}
728
729static int
730test_adjust_tuple(void)
731{
732 struct rte_thash_ctx *ctx;
733 struct rte_thash_subtuple_helper *h;
734 const int key_len = 40;
735 const uint8_t *new_key;
736 uint8_t tuple[TUPLE_SZ];
737 uint32_t tmp_tuple[TUPLE_SZ / sizeof(uint32_t)];
738 uint32_t tuple_copy[TUPLE_SZ / sizeof(uint32_t)];
739 uint32_t hash;
740 int reta_sz = CHAR_BIT;
741 int ret;
742 unsigned int i, desired_value = rte_rand() & HASH_MSK(reta_sz);
743
744 memset(tuple, 0xab, TUPLE_SZ);
745
746 ctx = rte_thash_init_ctx("test", key_len, reta_sz, NULL, 0);
747 RTE_TEST_ASSERT(ctx != NULL, "can not create thash ctx\n");
748
749 /*
750 * set offset to be in the middle of a byte
751 * set size of the subtuple to be 2 * rets_sz
752 * to have the room for random bits
753 */
754 ret = rte_thash_add_helper(ctx, "test", reta_sz * 2,
755 (5 * CHAR_BIT) + 4);
756 RTE_TEST_ASSERT(ret == 0, "can not add helper, ret %d\n", ret);
757
758 new_key = rte_thash_get_key(ctx);
759
760 h = rte_thash_get_helper(ctx, "test");
761 RTE_TEST_ASSERT(h != NULL, "can not find helper\n");
762
763 ret = rte_thash_adjust_tuple(ctx, h, tuple, TUPLE_SZ, desired_value,
764 1, NULL, NULL);
765 RTE_TEST_ASSERT(ret == 0, "can not adjust tuple, ret %d\n", ret);
766
767 for (i = 0; i < (TUPLE_SZ / 4); i++)
768 tmp_tuple[i] =
769 rte_be_to_cpu_32(*(uint32_t *)&tuple[i * 4]);
770
771 hash = rte_softrss(tmp_tuple, TUPLE_SZ / 4, new_key);
772 RTE_TEST_ASSERT((hash & HASH_MSK(reta_sz)) ==
773 desired_value, "bad desired value\n");
774
775
776 /* Pass previously calculated tuple to callback function */
777 memcpy(tuple_copy, tuple, TUPLE_SZ);
778
779 memset(tuple, 0xab, TUPLE_SZ);
780 ret = rte_thash_adjust_tuple(ctx, h, tuple, TUPLE_SZ, desired_value,
781 1, cmp_tuple_eq, tuple_copy);
782 RTE_TEST_ASSERT(ret == -EEXIST,
783 "adjust tuple didn't indicate collision\n");
784
785 /*
786 * Make the function to generate random bits into subtuple

Callers

nothing calls this directly

Calls 10

rte_randFunction · 0.85
memsetFunction · 0.85
rte_thash_init_ctxFunction · 0.85
rte_thash_add_helperFunction · 0.85
rte_thash_get_keyFunction · 0.85
rte_thash_get_helperFunction · 0.85
rte_thash_adjust_tupleFunction · 0.85
rte_softrssFunction · 0.85
rte_thash_free_ctxFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected