]> git.droids-corp.org - dpdk.git/commitdiff
app/test: fix crash for fbk hashes with a lot of entries
authorBruce Richardson <bruce.richardson@intel.com>
Fri, 17 Oct 2014 13:18:12 +0000 (14:18 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 20 Oct 2014 21:50:35 +0000 (23:50 +0200)
The four-byte-key (fbk) autotest was allocating the keys to be used for
the test on the stack. When the number of entries in the table was
increased significantly, for example, to test larger hashes by increase the
value of ENTRIES, this array of keys was greater than that
allowed on the stack, and so caused problems, i.e. crashes and core dumps.

The solution is to have the keys dynamically allocated on the heap using
malloc. Now if ENTRIES is increased and we run out of memory we get an
error message instead of a crash.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
app/test/test_hash_perf.c

index 7bb701609e8b92f3ce6e8f2527c5daecb5d2301d..be34957c1583cb7b02d098a24243857ffd4c99c2 100644 (file)
@@ -397,6 +397,7 @@ struct tbl_perf_test_params tbl_perf_params[] =
        if (cond) {                                                     \
                printf("ERROR line %d: " str "\n", __LINE__, ##__VA_ARGS__); \
                if (handle) rte_fbk_hash_free(handle);                  \
+               if (keys) rte_free(keys);                               \
                return -1;                                              \
        }                                                               \
 } while(0)
@@ -697,8 +698,8 @@ fbk_hash_perf_test(void)
                .entries_per_bucket = 4,
                .socket_id = rte_socket_id(),
        };
-       struct rte_fbk_hash_table *handle;
-       uint32_t keys[ENTRIES] = {0};
+       struct rte_fbk_hash_table *handle = NULL;
+       uint32_t *keys = NULL;
        unsigned indexes[TEST_SIZE];
        uint64_t lookup_time = 0;
        unsigned added = 0;
@@ -708,6 +709,10 @@ fbk_hash_perf_test(void)
        handle = rte_fbk_hash_create(&params);
        RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation failed");
 
+       keys = rte_zmalloc(NULL, ENTRIES * sizeof(*keys), 0);
+       RETURN_IF_ERROR_FBK(keys == NULL,
+               "fbk hash: memory allocation for key store failed");
+
        /* Generate random keys and values. */
        for (i = 0; i < ENTRIES; i++) {
                uint32_t key = (uint32_t)rte_rand();