hash: remove deprecated function and macros
[dpdk.git] / app / test / test_hash.c
index 448586c..4f2509d 100644 (file)
@@ -66,6 +66,7 @@
 static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc};
 static uint32_t hashtest_initvals[] = {0};
 static uint32_t hashtest_key_lens[] = {0, 2, 4, 5, 6, 7, 8, 10, 11, 15, 16, 21, 31, 32, 33, 63, 64};
+#define MAX_KEYSIZE 64
 /******************************************************************************/
 #define LOCAL_FBK_HASH_ENTRIES_MAX (1 << 15)
 
@@ -238,7 +239,7 @@ test_crc32_hash_alg_equiv(void)
 static void run_hash_func_test(rte_hash_function f, uint32_t init_val,
                uint32_t key_len)
 {
-       static uint8_t key[RTE_HASH_KEY_LENGTH_MAX];
+       static uint8_t key[MAX_KEYSIZE];
        unsigned i;
 
 
@@ -1100,7 +1101,7 @@ test_hash_creation_with_good_parameters(void)
 static int test_average_table_utilization(void)
 {
        struct rte_hash *handle;
-       uint8_t simple_key[RTE_HASH_KEY_LENGTH_MAX];
+       uint8_t simple_key[MAX_KEYSIZE];
        unsigned i, j;
        unsigned added_keys, average_keys_added = 0;
        int ret;
@@ -1149,6 +1150,70 @@ static int test_average_table_utilization(void)
        return 0;
 }
 
+#define NUM_ENTRIES 1024
+static int test_hash_iteration(void)
+{
+       struct rte_hash *handle;
+       unsigned i;
+       uint8_t keys[NUM_ENTRIES][MAX_KEYSIZE];
+       const void *next_key;
+       void *next_data;
+       void *data[NUM_ENTRIES];
+       unsigned added_keys;
+       uint32_t iter = 0;
+       int ret = 0;
+
+       ut_params.entries = NUM_ENTRIES;
+       ut_params.name = "test_hash_iteration";
+       ut_params.hash_func = rte_jhash;
+       ut_params.key_len = 16;
+       handle = rte_hash_create(&ut_params);
+       RETURN_IF_ERROR(handle == NULL, "hash creation failed");
+
+       /* Add random entries until key cannot be added */
+       for (added_keys = 0; added_keys < NUM_ENTRIES; added_keys++) {
+               data[added_keys] = (void *) ((uintptr_t) rte_rand());
+               for (i = 0; i < ut_params.key_len; i++)
+                       keys[added_keys][i] = rte_rand() % 255;
+               ret = rte_hash_add_key_data(handle, keys[added_keys], data[added_keys]);
+               if (ret < 0)
+                       break;
+       }
+
+       /* Iterate through the hash table */
+       while (rte_hash_iterate(handle, &next_key, &next_data, &iter) >= 0) {
+               /* Search for the key in the list of keys added */
+               for (i = 0; i < NUM_ENTRIES; i++) {
+                       if (memcmp(next_key, keys[i], ut_params.key_len) == 0) {
+                               if (next_data != data[i]) {
+                                       printf("Data found in the hash table is"
+                                              "not the data added with the key\n");
+                                       goto err;
+                               }
+                               added_keys--;
+                               break;
+                       }
+               }
+               if (i == NUM_ENTRIES) {
+                       printf("Key found in the hash table was not added\n");
+                       goto err;
+               }
+       }
+
+       /* Check if all keys have been iterated */
+       if (added_keys != 0) {
+               printf("There were still %u keys to iterate\n", added_keys);
+               goto err;
+       }
+
+       rte_hash_free(handle);
+       return 0;
+
+err:
+       rte_hash_free(handle);
+       return -1;
+}
+
 static uint8_t key[16] = {0x00, 0x01, 0x02, 0x03,
                        0x04, 0x05, 0x06, 0x07,
                        0x08, 0x09, 0x0a, 0x0b,
@@ -1408,6 +1473,8 @@ test_hash(void)
                return -1;
        if (test_average_table_utilization() < 0)
                return -1;
+       if (test_hash_iteration() < 0)
+               return -1;
 
        run_hash_func_tests();