/*
- * 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.
* hindex.h. */
#include <config.h>
+#undef NDEBUG
#include "hindex.h"
+#include <assert.h>
#include <string.h>
#include "hash.h"
+#include "ovstest.h"
+#include "random.h"
#include "util.h"
-#undef NDEBUG
-#include <assert.h>
-
/* Sample hindex element. */
struct element {
int value;
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;
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");
}
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)
mod4_hash,
mod3_hash,
mod2_hash,
+ multipart_hash,
};
size_t i;
}
}
-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);