summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>2015-01-21 09:37:21 -0200
committerLucas De Marchi <lucas.demarchi@intel.com>2015-01-21 10:17:27 -0200
commit22f602c3c5c7275a0554d84c6d19b485f4ca6054 (patch)
tree4702d1efab1653d740ebe1a9f7f7272dab3f27eb
parent9c2d39c73532e22c8df37382e24765d69450f78b (diff)
downloadkmod-22f602c3c5c7275a0554d84c6d19b485f4ca6054.tar.gz
testsuite: add test for growing then shrinking a hash
-rw-r--r--testsuite/test-hash.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/testsuite/test-hash.c b/testsuite/test-hash.c
index c1aa1eb..1bea04e 100644
--- a/testsuite/test-hash.c
+++ b/testsuite/test-hash.c
@@ -246,4 +246,37 @@ static int test_hash_add_unique(const struct test *t)
DEFINE_TEST(test_hash_add_unique,
.description = "test hash_add_unique with different key orders")
+
+static int test_hash_massive_add_del(const struct test *t)
+{
+ char buf[1024 * 8];
+ char *k;
+ struct hash *h;
+ unsigned int i, N = 1024;
+
+ h = hash_new(8, NULL);
+
+ k = &buf[0];
+ for (i = 0; i < N; i++) {
+ snprintf(k, 8, "k%d", i);
+ hash_add(h, k, k);
+ k += 8;
+ }
+
+ assert_return(hash_get_count(h) == N, EXIT_FAILURE);
+
+ k = &buf[0];
+ for (i = 0; i < N; i++) {
+ hash_del(h, k);
+ k += 8;
+ }
+
+ assert_return(hash_get_count(h) == 0, EXIT_FAILURE);
+
+ hash_free(h);
+ return 0;
+}
+DEFINE_TEST(test_hash_massive_add_del,
+ .description = "test multiple adds followed by multiple dels")
+
TESTSUITE_MAIN();