summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2012-01-09 14:18:12 -0500
committerSimo Sorce <simo@redhat.com>2012-01-09 15:00:39 -0500
commit8df169fdffb564ec932fede4216a123a71f1cc9a (patch)
tree7fd24957835a48d78c734c6bb870b4fcea9bf828
parent5a70b84cb66fb8c7a3fce0e3f2e4b61e0b2ea9d4 (diff)
downloadsssd-8df169fdffb564ec932fede4216a123a71f1cc9a.tar.gz
sssd-8df169fdffb564ec932fede4216a123a71f1cc9a.tar.bz2
sssd-8df169fdffb564ec932fede4216a123a71f1cc9a.zip
Add a random + identity test for murmurhash3
This test always generate a random string so each time the test is run we will test the hash function with a new value. It also hashes the same string twice and compares the result so that we have a chance of catching if uninitialized variables are getting mixed into the value calculation and end up generating different results for the same input.
-rw-r--r--src/tests/util-tests.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tests/util-tests.c b/src/tests/util-tests.c
index 557be10e..3dc6ae66 100644
--- a/src/tests/util-tests.c
+++ b/src/tests/util-tests.c
@@ -417,6 +417,34 @@ START_TEST(test_murmurhash3_check)
}
END_TEST
+START_TEST(test_murmurhash3_random)
+{
+ char test[16];
+ uint32_t result1;
+ uint32_t result2;
+ unsigned int init_seed;
+ unsigned int seed;
+ size_t len;
+ int i;
+
+ /* generate a random string so each time we test with different values */
+ init_seed = time(0);
+ seed = init_seed;
+ /* use also random length (min len = 1) */
+ len = 1 + rand_r(&seed) % 14;
+ for (i = 0; i < len; i++) {
+ test[i] = 1 + rand_r(&seed) % 254;
+ }
+ test[len] = '\0'; /* null terminate */
+
+ fprintf(stdout, "test_murmurhash3_random seed: %d\n", init_seed);
+
+ result1 = murmurhash3(test, len + 1, init_seed);
+ result2 = murmurhash3(test, len + 1, init_seed);
+ fail_if(result1 != result2);
+}
+END_TEST
+
Suite *util_suite(void)
{
Suite *s = suite_create("util");
@@ -440,6 +468,7 @@ Suite *util_suite(void)
TCase *tc_mh3 = tcase_create("murmurhash3");
tcase_add_test (tc_mh3, test_murmurhash3_check);
+ tcase_add_test (tc_mh3, test_murmurhash3_random);
tcase_set_timeout(tc_mh3, 60);
suite_add_tcase (s, tc_util);