+
+ rte_hash_free(handle);
+
+ return 0;
+}
+
+#define ITERATIONS 3
+/*
+ * Test to see the average table utilization (entries added/max entries)
+ * before hitting a random entry that cannot be added
+ */
+static int test_average_table_utilization(void)
+{
+ struct rte_hash *handle;
+ uint8_t simple_key[MAX_KEYSIZE];
+ unsigned i, j;
+ unsigned added_keys, average_keys_added = 0;
+ int ret;
+
+ printf("\n# Running test to determine average utilization"
+ "\n before adding elements begins to fail\n");
+ printf("Measuring performance, please wait");
+ fflush(stdout);
+ ut_params.entries = 1 << 16;
+ ut_params.name = "test_average_utilization";
+ ut_params.hash_func = rte_jhash;
+ handle = rte_hash_create(&ut_params);
+ RETURN_IF_ERROR(handle == NULL, "hash creation failed");
+
+ for (j = 0; j < ITERATIONS; j++) {
+ ret = 0;
+ /* Add random entries until key cannot be added */
+ for (added_keys = 0; ret >= 0; added_keys++) {
+ for (i = 0; i < ut_params.key_len; i++)
+ simple_key[i] = rte_rand() % 255;
+ ret = rte_hash_add_key(handle, simple_key);
+ }
+ if (ret != -ENOSPC) {
+ printf("Unexpected error when adding keys\n");
+ rte_hash_free(handle);
+ return -1;
+ }
+
+ average_keys_added += added_keys;
+
+ /* Reset the table */
+ rte_hash_reset(handle);
+
+ /* Print a dot to show progress on operations */
+ printf(".");
+ fflush(stdout);