stefan pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=e6c8bf7fbf0590fe947c66826ce27cf942cb1115

commit e6c8bf7fbf0590fe947c66826ce27cf942cb1115
Author: Mike Blumenkrantz <zm...@osg.samsung.com>
Date:   Fri Mar 30 14:27:51 2018 -0400

    tests: rework eina hash fuzzing tests
    
    these are supposed to be for testing the finding of values not in the
    hash, not basic hash operations
    
    fix T6839
    
    Reviewed-by: Stefan Schmidt <ste...@osg.samsung.com>
---
 src/tests/eina/eina_test_hash.c | 117 +++++++++++++---------------------------
 1 file changed, 38 insertions(+), 79 deletions(-)

diff --git a/src/tests/eina/eina_test_hash.c b/src/tests/eina/eina_test_hash.c
index 149b1094fc..4c57fd3a62 100644
--- a/src/tests/eina/eina_test_hash.c
+++ b/src/tests/eina/eina_test_hash.c
@@ -268,119 +268,78 @@ EFL_END_TEST
 EFL_START_TEST(eina_test_hash_int32_fuzze)
 {
    Eina_Hash *hash;
-   Eina_List *added = NULL;
-   unsigned int *r;
+   unsigned int *r, *array;
    unsigned int i;
-   unsigned int j;
    unsigned int seed;
+   unsigned int num_loops = 10000;
 
    seed = time(NULL);
    srand(seed);
 
-   hash = eina_hash_int32_new(free);
+   hash = eina_hash_int32_new(NULL);
+
+   array = malloc(sizeof(int) * num_loops);
+   for (i = 0; i < num_loops; ++i)
+     {
+        r = array + i;
+        *r = rand() % 10000;
+        ck_assert_int_ne(eina_hash_direct_add(hash, r, r), 0);
+     }
 
-   for (i = 0; i < 10000; ++i)
+   for (i = 0; i < num_loops / 2; ++i)
      {
-        r = malloc(sizeof (unsigned int));
-        *r = rand();
-        eina_hash_direct_add(hash, r, r);
+        unsigned int tr = rand() + 10000;
+        r = eina_hash_find(hash, &tr);
+        ck_assert_ptr_null(r);
      }
 
-   for (j = 0; j < 100; ++j)
+   for (i = 0; i < num_loops / 2; ++i)
      {
-        for (i = 0; i < 1000; ++i)
-          {
-             do
-               {
-                  unsigned int tr;
-
-                  tr = rand();
-                  r = eina_hash_find(hash, &tr);
-                  if (r)
-                    {
-                       r = NULL;
-                       continue;
-                    }
-
-                  r = malloc(sizeof (unsigned int));
-                  *r = tr;
-                  eina_hash_direct_add(hash, r, r);
-                  added = eina_list_append(added, r);
-               }
-             while (r == NULL);
-          }
-
-        EINA_LIST_FREE(added, r)
-          {
-             unsigned int *s;
-
-             s = eina_hash_find(hash, r);
-             fail_if(s != r);
-             eina_hash_del(hash, r, r);
-          }
+        unsigned int tr = (rand() % 10000) - (10000 * 2);
+        r = eina_hash_find(hash, &tr);
+        ck_assert_ptr_null(r);
      }
 
    eina_hash_free(hash);
+   free(array);
 }
 EFL_END_TEST
 
 EFL_START_TEST(eina_test_hash_string_fuzze)
 {
    Eina_Hash *hash;
-   Eina_List *added = NULL;
-   char *r;
    unsigned int i;
-   unsigned int j;
    unsigned int seed;
+   char *array;
+   unsigned int num_loops = 100;
 
    seed = time(NULL);
    srand(seed);
 
-   hash = eina_hash_string_superfast_new(free);
+   hash = eina_hash_string_superfast_new(NULL);
 
-   for (i = 0; i < 10000; ++i)
-     {
-        char convert[128];
+   array = malloc(num_loops * 10);
+   ck_assert_ptr_nonnull(array);
 
-        eina_convert_itoa(rand(), convert);
-        r = strdup(convert);
-        eina_hash_direct_add(hash, r, r);
+   for (i = 0; i < num_loops; ++i)
+     {
+        char *tmp = array + (i * 10);
+        eina_convert_itoa(i, tmp);
+        fail_if(eina_hash_direct_add(hash, tmp, tmp) != EINA_TRUE);
      }
 
-   for (j = 0; j < 50; ++j)
+   for (i = 0; i < num_loops; ++i)
      {
-        for (i = 0; i < 1000; ++i)
-          {
-             do
-               {
-                  char convert[128];
-
-                  eina_convert_itoa(rand(), convert);
-                  r = eina_hash_find(hash, convert);
-                  if (r)
-                    {
-                       r = NULL;
-                       continue;
-                    }
-
-                  r = strdup(convert);
-                  eina_hash_direct_add(hash, r, r);
-                  added = eina_list_append(added, r);
-               }
-             while (r == NULL);
-          }
-
-        EINA_LIST_FREE(added, r)
-          {
-             char *s;
-
-             s = eina_hash_find(hash, r);
-             fail_if(s != r);
-             eina_hash_del(hash, r, r);
-          }
+        char convert[128];
+        char *r;
+
+        eina_convert_itoa(rand() + num_loops, convert);
+        r = eina_hash_find(hash, convert);
+        ck_assert_ptr_null(r);
      }
 
    eina_hash_free(hash);
+   free(array);
 }
 EFL_END_TEST
 

-- 


Reply via email to