[Openvpn-devel,M] Change in openvpn[master]: Remove dead list test code

Message ID 36a59041b20ad2903c425b5510e0e273bffe33c9-HTML@gerrit.openvpn.net
State Superseded
Headers show
Series [Openvpn-devel,M] Change in openvpn[master]: Remove dead list test code | expand

Commit Message

selvanair (Code Review) Nov. 20, 2023, 11:11 a.m. UTC
Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/446?usp=email

to review the following change.


Change subject: Remove dead list test code
......................................................................

Remove dead list test code

Change-Id: I7511bc43cd6a0bcb89476f27d5822ab4a78d0d21
---
M src/openvpn/init.c
M src/openvpn/list.c
M src/openvpn/list.h
3 files changed, 0 insertions(+), 191 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/46/446/1

Patch

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 8c707a4..5618c69 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -865,11 +865,6 @@ 
     return false;
 #endif
 
-#ifdef LIST_TEST
-    list_test();
-    return false;
-#endif
-
 #ifdef IFCONFIG_POOL_TEST
     ifconfig_pool_test(0x0A010004, 0x0A0100FF);
     return false;
diff --git a/src/openvpn/list.c b/src/openvpn/list.c
index 480f39d..dc4b1df 100644
--- a/src/openvpn/list.c
+++ b/src/openvpn/list.c
@@ -326,185 +326,6 @@ 
 }
 
 
-#ifdef LIST_TEST
-
-/*
- * Test the hash code by implementing a simple
- * word frequency algorithm.
- */
-
-struct word
-{
-    const char *word;
-    int n;
-};
-
-static uint32_t
-word_hash_function(const void *key, uint32_t iv)
-{
-    const char *str = (const char *) key;
-    const int len = strlen(str);
-    return hash_func((const uint8_t *)str, len, iv);
-}
-
-static bool
-word_compare_function(const void *key1, const void *key2)
-{
-    return strcmp((const char *)key1, (const char *)key2) == 0;
-}
-
-static void
-print_nhash(struct hash *hash)
-{
-    struct hash_iterator hi;
-    struct hash_element *he;
-    int count = 0;
-
-    hash_iterator_init(hash, &hi, true);
-
-    while ((he = hash_iterator_next(&hi)))
-    {
-        printf("%d ", (int) he->value);
-        ++count;
-    }
-    printf("\n");
-
-    hash_iterator_free(&hi);
-    ASSERT(count == hash_n_elements(hash));
-}
-
-static void
-rmhash(struct hash *hash, const char *word)
-{
-    hash_remove(hash, word);
-}
-
-void
-list_test(void)
-{
-    openvpn_thread_init();
-
-    {
-        struct gc_arena gc = gc_new();
-        struct hash *hash = hash_init(10000, get_random(), word_hash_function, word_compare_function);
-        struct hash *nhash = hash_init(256, get_random(), word_hash_function, word_compare_function);
-
-        printf("hash_init n_buckets=%d mask=0x%08x\n", hash->n_buckets, hash->mask);
-
-        /* parse words from stdin */
-        while (true)
-        {
-            char buf[256];
-            char wordbuf[256];
-            int wbi;
-            int bi;
-            char c;
-
-            if (!fgets(buf, sizeof(buf), stdin))
-            {
-                break;
-            }
-
-            bi = wbi = 0;
-            do
-            {
-                c = buf[bi++];
-                if (isalnum(c) || c == '_')
-                {
-                    ASSERT(wbi < (int) sizeof(wordbuf));
-                    wordbuf[wbi++] = c;
-                }
-                else
-                {
-                    if (wbi)
-                    {
-                        struct word *w;
-                        ASSERT(wbi < (int) sizeof(wordbuf));
-                        wordbuf[wbi++] = '\0';
-
-                        /* word is parsed from stdin */
-
-                        /* does it already exist in table? */
-                        w = (struct word *) hash_lookup(hash, wordbuf);
-
-                        if (w)
-                        {
-                            /* yes, increment count */
-                            ++w->n;
-                        }
-                        else
-                        {
-                            /* no, make a new object */
-                            ALLOC_OBJ_GC(w, struct word, &gc);
-                            w->word = string_alloc(wordbuf, &gc);
-                            w->n = 1;
-                            ASSERT(hash_add(hash, w->word, w, false));
-                            ASSERT(hash_add(nhash, w->word, (void *) ((random() & 0x0F) + 1), false));
-                        }
-                    }
-                    wbi = 0;
-                }
-            } while (c);
-        }
-
-#if 1
-        /* remove some words from the table */
-        {
-            rmhash(hash, "true");
-            rmhash(hash, "false");
-        }
-#endif
-
-        /* output contents of hash table */
-        {
-            int base;
-            int inc = 0;
-            int count = 0;
-
-            for (base = 0; base < hash_n_buckets(hash); base += inc)
-            {
-                struct hash_iterator hi;
-                struct hash_element *he;
-                inc = (get_random() % 3) + 1;
-                hash_iterator_init_range(hash, &hi, true, base, base + inc);
-
-                while ((he = hash_iterator_next(&hi)))
-                {
-                    struct word *w = (struct word *) he->value;
-                    printf("%6d '%s'\n", w->n, w->word);
-                    ++count;
-                }
-
-                hash_iterator_free(&hi);
-            }
-            ASSERT(count == hash_n_elements(hash));
-        }
-
-#if 1
-        /* test hash_remove_by_value function */
-        {
-            int i;
-            for (i = 1; i <= 16; ++i)
-            {
-                printf("[%d] ***********************************\n", i);
-                print_nhash(nhash);
-                hash_remove_by_value(nhash, (void *) i, true);
-            }
-            printf("FINAL **************************\n");
-            print_nhash(nhash);
-        }
-#endif
-
-        hash_free(hash);
-        hash_free(nhash);
-        gc_free(&gc);
-    }
-
-    openvpn_thread_cleanup();
-}
-
-#endif /* ifdef LIST_TEST */
-
 /*
  * --------------------------------------------------------------------
  * hash() -- hash a variable-length key into a 32-bit value
diff --git a/src/openvpn/list.h b/src/openvpn/list.h
index 94d14f2..18afc54 100644
--- a/src/openvpn/list.h
+++ b/src/openvpn/list.h
@@ -33,8 +33,6 @@ 
  * client instances over various key spaces.
  */
 
-/* define this to enable special list test mode */
-/*#define LIST_TEST*/
 
 #include "basic.h"
 #include "buffer.h"
@@ -114,11 +112,6 @@ 
 
 uint32_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval);
 
-#ifdef LIST_TEST
-void list_test(void);
-
-#endif
-
 static inline uint32_t
 hash_value(const struct hash *hash, const void *key)
 {