X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-hmap.c;h=dd79dc95f06fcbce7ad8d7dd18355a00b01fd2c3;hb=6d7d2ace1494936d11b8cabcec26c7e4d0fdda68;hp=684a5bae2458c69a62d3e468b1cdf6587f4ff242;hpb=064af42167bf4fc9aaea2702d80ce08074b889c0;p=sliver-openvswitch.git diff --git a/tests/test-hmap.c b/tests/test-hmap.c index 684a5bae2..dd79dc95f 100644 --- a/tests/test-hmap.c +++ b/tests/test-hmap.c @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2013 Nicira, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* A non-exhaustive test for some of the functions and macros declared in * hmap.h. */ @@ -5,6 +21,7 @@ #include "hmap.h" #include #include "hash.h" +#include "random.h" #include "util.h" #undef NDEBUG @@ -40,7 +57,7 @@ check_hmap(struct hmap *hmap, const int values[], size_t n, hmap_values = xmalloc(sizeof *sort_values * n); i = 0; - HMAP_FOR_EACH (e, struct element, node, hmap) { + HMAP_FOR_EACH (e, node, hmap) { assert(i < n); hmap_values[i++] = e->value; } @@ -61,8 +78,7 @@ check_hmap(struct hmap *hmap, const int values[], size_t n, for (i = 0; i < n; i++) { size_t count = 0; - HMAP_FOR_EACH_WITH_HASH (e, struct element, node, - hash(values[i]), hmap) { + HMAP_FOR_EACH_WITH_HASH (e, node, hash(values[i]), hmap) { count += e->value == values[i]; } assert(count == 1); @@ -93,7 +109,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; @@ -108,8 +124,8 @@ print_hmap(const char *name, struct hmap *hmap) struct element *e; printf("%s:", name); - HMAP_FOR_EACH (e, struct element, node, hmap) { - printf(" %d(%zu)", e->value, e->node.hash & hmap->mask); + HMAP_FOR_EACH (e, node, hmap) { + printf(" %d(%"PRIuSIZE")", e->value, e->node.hash & hmap->mask); } printf("\n"); } @@ -141,7 +157,7 @@ good_hash(int value) } static size_t -constant_hash(int value UNUSED) +constant_hash(int value OVS_UNUSED) { return 123; } @@ -226,7 +242,7 @@ test_hmap_for_each_safe(hash_func *hash) i = 0; n_remaining = n; - HMAP_FOR_EACH_SAFE (e, next, struct element, node, &hmap) { + HMAP_FOR_EACH_SAFE (e, next, node, &hmap) { assert(i < n); if (pattern & (1ul << e->value)) { size_t j;