Another test case.
authorRobert Haas <rhaas@postgresql.org>
Fri, 27 Jul 2012 18:28:04 +0000 (18:28 +0000)
committerRobert Haas <rhaas@postgresql.org>
Fri, 27 Jul 2012 18:28:04 +0000 (18:28 +0000)
contrib/hashtest/hashtest--1.0.sql
contrib/hashtest/hashtest.c

index b35a520af6373b0b770a6ab66e3557dd02ec806b..5d37927618b1823f27f8b67a244019e025fa5a0e 100644 (file)
@@ -21,6 +21,11 @@ RETURNS void
 AS 'MODULE_PATHNAME', 'chash_concurrent_test'
 LANGUAGE C;
 
+CREATE FUNCTION chash_collision_test()
+RETURNS void
+AS 'MODULE_PATHNAME', 'chash_collision_test'
+LANGUAGE C;
+
 CREATE FUNCTION dynahash_insert_test()
 RETURNS void
 AS 'MODULE_PATHNAME', 'dynahash_insert_test'
index 90d525da1dea6c078b6e83e2a6e5ea77e5ce8aef..16ac27a194cbc0d5d4967f0ff39bd6bf9876e30f 100644 (file)
@@ -18,6 +18,7 @@ Datum         chash_insert_test(PG_FUNCTION_ARGS);
 Datum          chash_search_test(PG_FUNCTION_ARGS);
 Datum          chash_delete_test(PG_FUNCTION_ARGS);
 Datum          chash_concurrent_test(PG_FUNCTION_ARGS);
+Datum          chash_collision_test(PG_FUNCTION_ARGS);
 Datum          dynahash_insert_test(PG_FUNCTION_ARGS);
 Datum          dynahash_search_test(PG_FUNCTION_ARGS);
 Datum          dynahash_delete_test(PG_FUNCTION_ARGS);
@@ -26,6 +27,8 @@ static void hashtest_shmem_startup(void);
 PG_FUNCTION_INFO_V1(chash_insert_test);
 PG_FUNCTION_INFO_V1(chash_search_test);
 PG_FUNCTION_INFO_V1(chash_delete_test);
+PG_FUNCTION_INFO_V1(chash_concurrent_test);
+PG_FUNCTION_INFO_V1(chash_collision_test);
 PG_FUNCTION_INFO_V1(dynahash_insert_test);
 PG_FUNCTION_INFO_V1(dynahash_search_test);
 PG_FUNCTION_INFO_V1(dynahash_delete_test);
@@ -225,6 +228,49 @@ chash_concurrent_test(PG_FUNCTION_ARGS)
        PG_RETURN_VOID();
 }
 
+Datum
+chash_collision_test(PG_FUNCTION_ARGS)
+{
+       uint32  i;
+       hentry  e;
+
+       /* Don't stack-allocate this. */
+       static bool mine[10000];
+
+       memset(mine, 0, 10000 * sizeof(bool));
+
+       for (i = 0; i < 10000; ++i)
+       {
+               bool ok;
+
+               e.key = i;
+               e.val = MyProcPid;
+               ok = CHashInsert(chash, &e);
+               if (ok)
+                       mine[i] = true;
+       }
+
+       for (i = 0; i < 10000; ++i)
+       {
+               bool ok;
+
+               if (!mine[i])
+                       continue;
+               e.key = i;
+               ok = CHashSearch(chash, &e);
+               if (!ok)
+                       elog(LOG, "search %u: not found", i);
+               if (e.val != MyProcPid)
+                       elog(LOG, "search %u: expected %u found %u",
+                                i, (unsigned) MyProcPid, e.val);
+               ok = CHashDelete(chash, &e);
+               if (!ok)
+                       elog(LOG, "delete %u: not found", i);
+       }
+
+       PG_RETURN_VOID();
+}
+
 static bool
 dynahash_insert(uint32 key, uint32 val)
 {