X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_hash_functions.c;h=9652b04d45fffc9ff28286807d00d0680920db0f;hb=dd0eedb1cfcf0cb7423d859177c5bc6f931eaf8a;hp=fcc9d0573ab55a8048061ef36366e5cfed20db10;hpb=6298d2c55ae8e621f3c3f202ef4e18d1ab9f798a;p=dpdk.git diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c index fcc9d0573a..9652b04d45 100644 --- a/app/test/test_hash_functions.c +++ b/app/test/test_hash_functions.c @@ -54,26 +54,30 @@ * e.g.: key size = 4, key = 0x03020100 * key size = 8, key = 0x0706050403020100 */ -static uint32_t hash_values_jhash[2][10] = {{ - 0x821cc2db, 0xa491f494, 0xace4cd87, 0x9e867842, - 0xd32442d6, 0x5fbafeab, 0x9cac434c, 0xecad9b0d, - 0x2dcf235e, 0xaab655d0 +static uint32_t hash_values_jhash[2][12] = {{ + 0x8ba9414b, 0xdf0d39c9, + 0xe4cf1d42, 0xd4ccb93c, 0x5e84eafc, 0x21362cfe, + 0x2f4775ab, 0x9ff036cc, 0xeca51474, 0xbc9d6816, + 0x12926a31, 0x1c9fa888 }, { - 0xc1111b14, 0x9a95039e, 0x84f208a0, 0xfa28f3fb, - 0xfa13f7d3, 0xc7aed470, 0x74caa938, 0xa9288066, - 0xd0140735, 0xbf00519d + 0x5c62c303, 0x1b8cf784, + 0x8270ac65, 0x05fa6668, 0x762df861, 0xda088f2f, + 0x59614cd4, 0x7a94f690, 0xdc1e4993, 0x30825494, + 0x91d0e462, 0x768087fc } }; -static uint32_t hash_values_crc[2][10] = {{ +static uint32_t hash_values_crc[2][12] = {{ + 0x00000000, 0xf26b8303, 0x91545164, 0x06040eb1, 0x9bb99201, 0xcc4c4fe4, - 0x14a90993, 0xf8a5dd8c, 0xc62beb31, 0x32bf340e, - 0x72f9d22b, 0x4a11475e + 0x14a90993, 0xf8a5dd8c, 0xcaa1ad0b, 0x7ac1e03e, + 0x43f44466, 0x4a11475e }, { + 0xbdfd3980, 0x70204542, 0x98cd4c70, 0xd52c702f, 0x41fc0e1c, 0x3905f65c, - 0x94bff47f, 0x1bab102d, 0xd2911ed7, 0xe8faa813, - 0x6bea184b, 0x53028d3e + 0x94bff47f, 0x1bab102d, 0xf4a2c645, 0xbf441539, + 0x789c104f, 0x53028d3e } }; @@ -85,10 +89,11 @@ 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[] = { + 1, 2, /* Unusual key sizes */ 4, 8, 16, 32, 48, 64, /* standard key sizes */ 9, /* IPv4 SRC + DST + protocol, unpadded */ 13, /* IPv4 5-tuple, unpadded */ @@ -119,7 +124,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; @@ -204,7 +209,7 @@ verify_precalculated_hash_func_tests(void) } /* - * Verify that rte_jhash and rte_jhash2 return the same + * Verify that rte_jhash and rte_jhash_32b return the same */ static int verify_jhash_32bits(void) @@ -223,12 +228,12 @@ 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_jhash2((const uint32_t *)key, + hash32 = rte_jhash_32b((const unaligned_uint32_t *)key, hashtest_key_lens[i] >> 2, hashtest_initvals[j]); if (hash != hash32) { printf("rte_jhash returns different value (0x%x)" - "than rte_jhash2 (0x%x)\n", + "than rte_jhash_32b (0x%x)\n", hash, hash32); return -1; } @@ -239,6 +244,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 +301,9 @@ run_hash_func_tests(void) if (verify_jhash_32bits() != 0) return -1; + if (verify_jhash_words() != 0) + return -1; + return 0; } @@ -266,8 +319,4 @@ test_hash_functions(void) return 0; } -static struct test_command hash_functions_cmd = { - .command = "hash_functions_autotest", - .callback = test_hash_functions, -}; -REGISTER_TEST_COMMAND(hash_functions_cmd); +REGISTER_TEST_COMMAND(hash_functions_autotest, test_hash_functions);