[Mesa-dev] [PATCH 1/7] util/tests: Expand collision test for hash table

Thomas Helland thomashelland90 at gmail.com
Tue Feb 21 20:53:31 UTC 2017


Add a test to exercise a worst case collision scenario
that may cause us to not be able to find an empty
slot in the table even though it is not full.
This hits the bug in my last revision of the series
converting the hash table to quadratic probing.

V2: Feedback from Emil Velikov
    -Don't include code in the assert
---
 src/util/tests/hash_table/collision.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/util/tests/hash_table/collision.c b/src/util/tests/hash_table/collision.c
index 69a4c29eca..51a537757b 100644
--- a/src/util/tests/hash_table/collision.c
+++ b/src/util/tests/hash_table/collision.c
@@ -91,5 +91,19 @@ main(int argc, char **argv)
 
    _mesa_hash_table_destroy(ht, NULL);
 
+   /* Try inserting multiple items with the same hash
+    * This exercises a worst case scenario where we might fail to find
+    * an empty slot in the table, even though there is free space
+    */
+   ht = _mesa_hash_table_create(NULL, NULL, _mesa_key_string_equal);
+   for (i = 0; i < 100; i++) {
+      char *key = malloc(10);
+      sprintf(key, "spam%d", i);
+      entry2 = _mesa_hash_table_insert_pre_hashed(ht, bad_hash, key, NULL);
+      assert(entry2 != NULL);
+   }
+
+   _mesa_hash_table_destroy(ht, NULL);
+
    return 0;
 }
-- 
2.11.1



More information about the mesa-dev mailing list