X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_hash.c;h=d522cb7f8cbf6ec8cd6f0cace32d118c6c63676c;hb=7dc92d17298d8fd05a912606f02a094566ec0b3f;hp=bd4d0cb7226f368e221ccb252ea4d3fa2f96c51f;hpb=9c7d8eed1a45da868b4bedd542b9961da460006e;p=dpdk.git diff --git a/app/test/test_hash.c b/app/test/test_hash.c index bd4d0cb722..d522cb7f8c 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -74,13 +74,17 @@ static uint32_t hashtest_key_lens[] = {0, 2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21, } \ } while (0) -/* 5-tuple key type */ +/* + * 5-tuple key type. + * Should be packed to avoid holes with potentially + * undefined content in the middle. + */ struct flow_key { uint32_t ip_src; uint32_t ip_dst; uint16_t port_src; uint16_t port_dst; - uint8_t proto; + uint32_t proto; } __rte_packed; /* @@ -147,7 +151,7 @@ static struct flow_key keys[5] = { { /* Parameters used for hash table in unit test functions. Name set later. */ static struct rte_hash_parameters ut_params = { .entries = 64, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = rte_jhash, .hash_func_init_val = 0, .socket_id = 0, @@ -792,7 +796,7 @@ static int test_full_bucket(void) struct rte_hash_parameters params_pseudo_hash = { .name = "test4", .entries = 64, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -895,7 +899,7 @@ static int test_extendable_bucket(void) struct rte_hash_parameters params_pseudo_hash = { .name = "test5", .entries = 64, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -1606,6 +1610,17 @@ static struct rte_hash_parameters hash_params_ex = { .socket_id = 0, }; +/* + * Wrapper function around rte_jhash_32b. + * It is required because rte_jhash_32b() accepts the length + * as size of 4-byte units. + */ +static inline uint32_t +test_jhash_32b(const void *k, uint32_t length, uint32_t initval) +{ + return rte_jhash_32b(k, length >> 2, initval); +} + /* * add/delete key with jhash2 */ @@ -1618,7 +1633,7 @@ test_hash_add_delete_jhash2(void) hash_params_ex.name = "hash_test_jhash2"; hash_params_ex.key_len = 4; - hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b; + hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b; handle = rte_hash_create(&hash_params_ex); if (handle == NULL) { @@ -1639,8 +1654,7 @@ test_hash_add_delete_jhash2(void) ret = 0; fail_jhash2: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1657,7 +1671,7 @@ test_hash_add_delete_2_jhash2(void) hash_params_ex.name = "hash_test_2_jhash2"; hash_params_ex.key_len = 8; - hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b; + hash_params_ex.hash_func = (rte_hash_function)test_jhash_32b; handle = rte_hash_create(&hash_params_ex); if (handle == NULL) @@ -1674,8 +1688,7 @@ test_hash_add_delete_2_jhash2(void) ret = 0; fail_2_jhash2: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1739,8 +1752,7 @@ test_hash_add_delete_jhash_1word(void) ret = 0; fail_jhash_1word: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1774,8 +1786,7 @@ test_hash_add_delete_jhash_2word(void) ret = 0; fail_jhash_2word: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1809,8 +1820,7 @@ test_hash_add_delete_jhash_3word(void) ret = 0; fail_jhash_3word: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1915,7 +1925,7 @@ test_hash_rcu_qsbr_dq_mode(uint8_t ext_bkt) struct rte_hash_parameters params_pseudo_hash = { .name = "test_hash_rcu_qsbr_dq_mode", .entries = total_entries, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -2085,7 +2095,7 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) struct rte_hash_parameters params_pseudo_hash = { .name = "test_hash_rcu_qsbr_sync_mode", .entries = total_entries, - .key_len = sizeof(struct flow_key), /* 13 */ + .key_len = sizeof(struct flow_key), .hash_func = pseudo_hash, .hash_func_init_val = 0, .socket_id = 0, @@ -2180,6 +2190,8 @@ test_hash_rcu_qsbr_sync_mode(uint8_t ext_bkt) static int test_hash(void) { + RTE_BUILD_BUG_ON(sizeof(struct flow_key) % sizeof(uint32_t) != 0); + if (test_add_delete() < 0) return -1; if (test_hash_add_delete_jhash2() < 0)