app/test: verify more jhash functions
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Wed, 10 Jun 2015 15:25:27 +0000 (16:25 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 16 Jun 2015 10:19:20 +0000 (12:19 +0200)
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@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
app/test/test_hash_functions.c

index 8af8601..df7c909 100644 (file)
@@ -239,6 +239,51 @@ verify_jhash_32bits(void)
        return 0;
 }
 
+/*
+ * 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
  */
@@ -251,6 +296,9 @@ run_hash_func_tests(void)
        if (verify_jhash_32bits() != 0)
                return -1;
 
+       if (verify_jhash_words() != 0)
+               return -1;
+
        return 0;
 
 }