X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_hash_functions.c;h=3ad6d80d6ec91d03708018d9a77c606b2a63131c;hb=b28c67c3ba8a665d3e8a2a3c3244cb4e151da7e3;hp=8af8601d2fe281634731260490600d4c3f4baf01;hpb=7530c9eea7d99ef3c026a69b8e5d82bcce7e7813;p=dpdk.git diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c index 8af8601d2f..3ad6d80d6e 100644 --- a/app/test/test_hash_functions.c +++ b/app/test/test_hash_functions.c @@ -85,7 +85,7 @@ static uint32_t hash_values_crc[2][10] = {{ * from the array entries is tested. */ #define HASHTEST_ITERATIONS 1000000 - +#define MAX_KEYSIZE 64 static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc}; static uint32_t hashtest_initvals[] = {0, 0xdeadbeef}; static uint32_t hashtest_key_lens[] = { @@ -119,7 +119,7 @@ static void run_hash_func_perf_test(uint32_t key_len, uint32_t init_val, rte_hash_function f) { - static uint8_t key[HASHTEST_ITERATIONS][RTE_HASH_KEY_LENGTH_MAX]; + static uint8_t key[HASHTEST_ITERATIONS][MAX_KEYSIZE]; uint64_t ticks, start, end; unsigned i, j; @@ -223,7 +223,7 @@ verify_jhash_32bits(void) hash = rte_jhash(key, hashtest_key_lens[i], hashtest_initvals[j]); /* Divide key length by 4 in rte_jhash for 32 bits */ - hash32 = rte_jhash_32b((const uint32_t *)key, + hash32 = rte_jhash_32b((const unaligned_uint32_t *)key, hashtest_key_lens[i] >> 2, hashtest_initvals[j]); if (hash != hash32) { @@ -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; }