| 847 | } |
| 848 | |
| 849 | static int |
| 850 | test_adjust_tuple_mb(uint32_t reta_sz, uint32_t bofs) |
| 851 | { |
| 852 | struct rte_thash_ctx *ctx; |
| 853 | struct rte_thash_subtuple_helper *h; |
| 854 | const int key_len = 40; |
| 855 | const uint8_t *new_key; |
| 856 | uint8_t orig_tuple[TUPLE_SZ]; |
| 857 | uint8_t tuple_1[TUPLE_SZ]; |
| 858 | uint8_t tuple_2[TUPLE_SZ]; |
| 859 | uint32_t orig_hash; |
| 860 | int rc, ret; |
| 861 | uint32_t adj_bits; |
| 862 | unsigned int random = rte_rand(); |
| 863 | unsigned int desired_value = random & HASH_MSK(reta_sz); |
| 864 | |
| 865 | const uint32_t h_offset = offsetof(union rte_thash_tuple, v4.dport) * CHAR_BIT; |
| 866 | const uint32_t h_size = sizeof(uint16_t) * CHAR_BIT - bofs; |
| 867 | |
| 868 | printf("===%s(reta_sz=%u,bofs=%u)===\n", __func__, reta_sz, bofs); |
| 869 | |
| 870 | memset(orig_tuple, 0xab, sizeof(orig_tuple)); |
| 871 | |
| 872 | ctx = rte_thash_init_ctx("test", key_len, reta_sz, NULL, 0); |
| 873 | RTE_TEST_ASSERT(ctx != NULL, "can not create thash ctx\n"); |
| 874 | |
| 875 | ret = rte_thash_add_helper(ctx, "test", h_size, h_offset); |
| 876 | RTE_TEST_ASSERT(ret == 0, "can not add helper, ret %d\n", ret); |
| 877 | |
| 878 | new_key = rte_thash_get_key(ctx); |
| 879 | |
| 880 | h = rte_thash_get_helper(ctx, "test"); |
| 881 | |
| 882 | orig_hash = calc_tuple_hash(orig_tuple, new_key); |
| 883 | |
| 884 | adj_bits = rte_thash_get_complement(h, orig_hash, desired_value); |
| 885 | |
| 886 | /* use method #1, update tuple manually */ |
| 887 | memcpy(tuple_1, orig_tuple, sizeof(tuple_1)); |
| 888 | { |
| 889 | uint16_t nv, ov, *p; |
| 890 | |
| 891 | p = (uint16_t *)(tuple_1 + h_offset / CHAR_BIT); |
| 892 | ov = p[0]; |
| 893 | nv = ov ^ rte_cpu_to_be_16(adj_bits << bofs); |
| 894 | printf("%s#%d: ov=%#hx, nv=%#hx, adj=%#x;\n", |
| 895 | __func__, __LINE__, ov, nv, adj_bits); |
| 896 | p[0] = nv; |
| 897 | } |
| 898 | |
| 899 | rc = check_adj_tuple(tuple_1, new_key, desired_value, orig_hash, |
| 900 | adj_bits, reta_sz, "method #1"); |
| 901 | if (h_offset % CHAR_BIT == 0) |
| 902 | ret |= rc; |
| 903 | |
| 904 | /* use method #2, use library function to adjust tuple */ |
| 905 | memcpy(tuple_2, orig_tuple, sizeof(tuple_2)); |
| 906 |
no test coverage detected