test/mbuf: fix forged mbuf in clone test
[dpdk.git] / app / test / test_hash_readwrite_lf.c
index 7943e3d..1f2fba4 100644 (file)
@@ -139,6 +139,52 @@ get_enabled_cores_list(void)
        return 0;
 }
 
+static int
+init_params(int rwc_lf, int use_jhash, int htm, int ext_bkt)
+{
+       struct rte_hash *handle;
+
+       struct rte_hash_parameters hash_params = {
+               .entries = TOTAL_ENTRY,
+               .key_len = sizeof(uint32_t),
+               .hash_func_init_val = 0,
+               .socket_id = rte_socket_id(),
+       };
+
+       if (use_jhash)
+               hash_params.hash_func = rte_jhash;
+       else
+               hash_params.hash_func = rte_hash_crc;
+
+       if (rwc_lf)
+               hash_params.extra_flag =
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF |
+                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+       else if (htm)
+               hash_params.extra_flag =
+                       RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT |
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
+                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+       else
+               hash_params.extra_flag =
+                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
+                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
+
+       if (ext_bkt)
+               hash_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
+
+       hash_params.name = "tests";
+
+       handle = rte_hash_create(&hash_params);
+       if (handle == NULL) {
+               printf("hash creation failed");
+               return -1;
+       }
+
+       tbl_rwc_test_param.h = handle;
+       return 0;
+}
+
 static inline int
 check_bucket(uint32_t bkt_idx, uint32_t key)
 {
@@ -213,6 +259,9 @@ generate_keys(void)
        uint32_t count_keys_extbkt = 0;
        uint32_t i;
 
+       if (init_params(0, 0, 0, 0) != 0)
+               return -1;
+
        /*
         * keys will consist of a) keys whose addition to the hash table
         * will result in shifting of the existing keys to their alternate
@@ -486,6 +535,7 @@ generate_keys(void)
               tbl_rwc_test_param.count_keys_ks_extbkt);
 
        rte_free(found);
+       rte_free(scanned_bkts);
        rte_hash_free(tbl_rwc_test_param.h);
        return 0;
 
@@ -496,58 +546,14 @@ err:
        rte_free(keys_absent);
        rte_free(found);
        rte_free(tbl_rwc_test_param.keys_shift_path);
+       rte_free(keys_non_shift_path);
        rte_free(keys_ext_bkt);
        rte_free(keys_ks_extbkt);
        rte_free(scanned_bkts);
+       rte_hash_free(tbl_rwc_test_param.h);
        return -1;
 }
 
-static int
-init_params(int rwc_lf, int use_jhash, int htm, int ext_bkt)
-{
-       struct rte_hash *handle;
-
-       struct rte_hash_parameters hash_params = {
-               .entries = TOTAL_ENTRY,
-               .key_len = sizeof(uint32_t),
-               .hash_func_init_val = 0,
-               .socket_id = rte_socket_id(),
-       };
-
-       if (use_jhash)
-               hash_params.hash_func = rte_jhash;
-       else
-               hash_params.hash_func = rte_hash_crc;
-
-       if (rwc_lf)
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
-       else if (htm)
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT |
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
-       else
-               hash_params.extra_flag =
-                       RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY |
-                       RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD;
-
-       if (ext_bkt)
-               hash_params.extra_flag |= RTE_HASH_EXTRA_FLAGS_EXT_TABLE;
-
-       hash_params.name = "tests";
-
-       handle = rte_hash_create(&hash_params);
-       if (handle == NULL) {
-               printf("hash creation failed");
-               return -1;
-       }
-
-       tbl_rwc_test_param.h = handle;
-       return 0;
-}
-
 static int
 test_rwc_reader(__attribute__((unused)) void *arg)
 {
@@ -559,16 +565,9 @@ test_rwc_reader(__attribute__((unused)) void *arg)
        uint32_t read_cnt;
        uint32_t *keys;
        uint32_t extra_keys;
-       int32_t *pos;
+       int32_t pos[BULK_LOOKUP_SIZE];
        void *temp_a[BULK_LOOKUP_SIZE];
 
-       /* Used to identify keys not inserted in the hash table */
-       pos = rte_malloc(NULL, sizeof(uint32_t) * BULK_LOOKUP_SIZE, 0);
-       if (pos == NULL) {
-               printf("RTE_MALLOC failed\n");
-               return -1;
-       }
-
        if (read_type & READ_FAIL) {
                keys = tbl_rwc_test_param.keys_absent;
                read_cnt = tbl_rwc_test_param.count_keys_absent;
@@ -1252,7 +1251,6 @@ test_hash_readwrite_lf_main(void)
         */
        int rwc_lf = 0;
        int htm;
-       int use_jhash = 0;
        int ext_bkt = 0;
 
        if (rte_lcore_count() < 2) {
@@ -1270,8 +1268,6 @@ test_hash_readwrite_lf_main(void)
        else
                htm = 0;
 
-       if (init_params(rwc_lf, use_jhash, htm, ext_bkt) != 0)
-               return -1;
        if (generate_keys() != 0)
                return -1;
        if (get_enabled_cores_list() != 0)
@@ -1429,7 +1425,9 @@ results:
        rte_free(tbl_rwc_test_param.keys_ks);
        rte_free(tbl_rwc_test_param.keys_absent);
        rte_free(tbl_rwc_test_param.keys_shift_path);
-       rte_free(scanned_bkts);
+       rte_free(tbl_rwc_test_param.keys_non_shift_path);
+       rte_free(tbl_rwc_test_param.keys_ext_bkt);
+       rte_free(tbl_rwc_test_param.keys_ks_extbkt);
        return 0;
 }