[dpdk-dev] [PATCH v5 10/10] test/hash: verify rte_jhash_1word/2words/3words

Pablo de Lara pablo.de.lara.guarch at intel.com
Fri May 22 12:16:11 CEST 2015


Added new test that verifies that rte_jhash_1words,
rte_jhash_2words and rte_jhash_3words return the same
values as rte_jhash.

Note that this patch has been added after the update
of the jhash function because these 3 functions did not
return the same values as rte_jhash before

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch at intel.com>
---
 app/test/test_hash_functions.c |   48 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c
index 04b2862..7c830b2 100644
--- a/app/test/test_hash_functions.c
+++ b/app/test/test_hash_functions.c
@@ -241,6 +241,51 @@ verify_jhash_32bits(void)
 }
 
 /*
+ * Verify that rte_jhash and rte_jhash_1word, rte_jhash_2words
+ * and rte_jhash_3words return the same
+ */
+static int
+verify_jhash_words(void)
+{
+	unsigned i;
+	uint32_t key[3];
+	uint32_t hash, hash_words;
+
+	for (i = 0; i < 3; i++)
+		key[i] = rand();
+
+	/* Test rte_jhash_1word */
+	hash = rte_jhash(key, 4, 0);
+	hash_words = rte_jhash_1word(key[0], 0);
+	if (hash != hash_words) {
+		printf("rte_jhash returns different value (0x%x)"
+		       "than rte_jhash_1word (0x%x)\n",
+		       hash, hash_words);
+		return -1;
+	}
+	/* Test rte_jhash_2words */
+	hash = rte_jhash(key, 8, 0);
+	hash_words = rte_jhash_2words(key[0], key[1], 0);
+	if (hash != hash_words) {
+		printf("rte_jhash returns different value (0x%x)"
+		       "than rte_jhash_2words (0x%x)\n",
+		       hash, hash_words);
+		return -1;
+	}
+	/* Test rte_jhash_3words */
+	hash = rte_jhash(key, 12, 0);
+	hash_words = rte_jhash_3words(key[0], key[1], key[2], 0);
+	if (hash != hash_words) {
+		printf("rte_jhash returns different value (0x%x)"
+		       "than rte_jhash_3words (0x%x)\n",
+		       hash, hash_words);
+		return -1;
+	}
+
+	return 0;
+}
+
+/*
  * Run all functional tests for hash functions
  */
 static int
@@ -252,6 +297,9 @@ run_hash_func_tests(void)
 	if (verify_jhash_32bits() != 0)
 		return -1;
 
+	if (verify_jhash_words() != 0)
+		return -1;
+
 	return 0;
 
 }
-- 
1.7.4.1



More information about the dev mailing list