X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-hindex.c;h=4c4fdf2a6b2caf38d69a37527ed8af242dda1908;hb=cfc50ae514f805dcd9c14589f21158185424daf6;hp=b5fe9f014598c55eafc9195c7be35d81fad2d62e;hpb=822b7f52108e1936f68fe2f726d0796df1b19903;p=sliver-openvswitch.git diff --git a/tests/test-hindex.c b/tests/test-hindex.c index b5fe9f014..4c4fdf2a6 100644 --- a/tests/test-hindex.c +++ b/tests/test-hindex.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2013 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,9 @@ #include "hindex.h" #include #include "hash.h" +#include "random.h" #include "util.h" +#include "ovstest.h" #undef NDEBUG #include @@ -108,7 +110,7 @@ static void shuffle(int *p, size_t n) { for (; n > 1; n--, p++) { - int *q = &p[rand() % n]; + int *q = &p[random_range(n)]; int tmp = *p; *p = *q; *q = tmp; @@ -136,7 +138,7 @@ print_hindex(const char *name, struct hindex *hindex) printf("%s:", name); HINDEX_FOR_EACH (e, node, hindex) { - printf(" %d(%zu)", e->value, e->node.hash & hindex->mask); + printf(" %d(%"PRIuSIZE")", e->value, e->node.hash & hindex->mask); } printf("\n"); } @@ -177,6 +179,12 @@ mod2_hash(int value) return value % 2; } +static size_t +multipart_hash(int value) +{ + return (mod4_hash(value) << 16) | (constant_hash(value) & 0xFFFF); +} + /* Tests basic hindex insertion and deletion. */ static void test_hindex_insert_delete(hash_func *hash) @@ -297,6 +305,7 @@ run_test(void (*function)(hash_func *)) mod4_hash, mod3_hash, mod2_hash, + multipart_hash, }; size_t i; @@ -307,13 +316,13 @@ run_test(void (*function)(hash_func *)) } } -int -main(void) +static void +test_hindex_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { run_test(test_hindex_insert_delete); run_test(test_hindex_for_each_safe); run_test(test_hindex_reserve_shrink); printf("\n"); - return 0; } +OVSTEST_REGISTER("test-hindex", test_hindex_main);