From: "plaisthos (Code Review)" Date: Mon, 20 Nov 2023 11:11:19 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <36a59041b20ad2903c425b5510e0e273bffe33c9-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="13/rpfhLk0A="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Remove dead list test code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --13/rpfhLk0A= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=3Demail 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 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 =3D (const char *) key; - const int len =3D 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) =3D=3D 0; -} - -static void -print_nhash(struct hash *hash) -{ - struct hash_iterator hi; - struct hash_element *he; - int count =3D 0; - - hash_iterator_init(hash, &hi, true); - - while ((he =3D hash_iterator_next(&hi))) - { - printf("%d ", (int) he->value); - ++count; - } - printf("\n"); - - hash_iterator_free(&hi); - ASSERT(count =3D=3D 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 =3D gc_new(); - struct hash *hash =3D hash_init(10000, get_random(), word_hash_fun= ction, word_compare_function); - struct hash *nhash =3D hash_init(256, get_random(), word_hash_func= tion, word_compare_function); - - printf("hash_init n_buckets=3D%d mask=3D0x%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 =3D wbi =3D 0; - do - { - c =3D buf[bi++]; - if (isalnum(c) || c =3D=3D '_') - { - ASSERT(wbi < (int) sizeof(wordbuf)); - wordbuf[wbi++] =3D c; - } - else - { - if (wbi) - { - struct word *w; - ASSERT(wbi < (int) sizeof(wordbuf)); - wordbuf[wbi++] =3D '\0'; - - /* word is parsed from stdin */ - - /* does it already exist in table? */ - w =3D (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 =3D string_alloc(wordbuf, &gc); - w->n =3D 1; - ASSERT(hash_add(hash, w->word, w, false)); - ASSERT(hash_add(nhash, w->word, (void *) ((ran= dom() & 0x0F) + 1), false)); - } - } - wbi =3D 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 =3D 0; - int count =3D 0; - - for (base =3D 0; base < hash_n_buckets(hash); base +=3D inc) - { - struct hash_iterator hi; - struct hash_element *he; - inc =3D (get_random() % 3) + 1; - hash_iterator_init_range(hash, &hi, true, base, base + inc= ); - - while ((he =3D hash_iterator_next(&hi))) - { - struct word *w =3D (struct word *) he->value; - printf("%6d '%s'\n", w->n, w->word); - ++count; - } - - hash_iterator_free(&hi); - } - ASSERT(count =3D=3D hash_n_elements(hash)); - } - -#if 1 - /* test hash_remove_by_value function */ - { - int i; - for (i =3D 1; i <=3D 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) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/446?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I7511bc43cd6a0bcb89476f27d5822ab4a78d0d21 Gerrit-Change-Number: 446 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --13/rpfhLk0A= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

Vi= ew Change

Remove dead list test code

Change-Id: I7511bc43cd6a0bc= b89476f27d5822ab4a78d0d21
---
M src/openvpn/init.c
M src/openvpn/l= ist.c
M src/openvpn/list.h
3 files changed, 0 insertions(+), 191 dele= tions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/cha=
nges/46/446/1
diff --git a/src/openvpn/init.c b/src/openvpn/init.c<=
/span>
index 8c707a4..5618c69 100644
--- a/src/ope= nvpn/init.c
+++ b/src/openvpn/init.c
@@ -86= 5,11 +865,6 @@
return false;
#endif

-#ifde= f LIST_TEST
- list_t= est();
- return fals= e;
-#endif
-

#ifdef IFCONFIG_= POOL_TEST
ifconfig_pool_test(0x0A010004, 0x0A0100FF);<= /span>
return false;
diff --git a/src/openvpn= /list.c b/src/openvpn/list.c
index 480f39d..dc4b1df 100644<= /span>
--- a/src/openvpn/list.c
+++ b/src/openvpn/= list.c
@@ -326,185 +326,6 @@
}
<= span>


-
-/*
- * Test the hash code by implementing a si= mple
- * 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 =3D (const char *) key;
= - const int len =3D strlen(str= );
- return hash_fun= c((const uint8_t *)str, len, iv);
-}
-<= br>-static bool
-word_compare_function(const void *key1,= const void *key2)
-{
- return strcmp((cons= t char *)key1, (const char *)key2) =3D=3D 0;
-}
-static void=
-print_nhash(struct hash *has= h)
-{
- struct hash_iterator hi;
= - struct hash_element *he;
- int count =3D 0;
-
- hash_iterator_init(hash, &hi, true);
-
- while ((he =3D hash_iterator_next(&= hi)))
- {
= - printf("%d ", = (int) he->value);
- = ++count;
- }<= /span>
- printf("\n&qu= ot;);
-
- hash_iterator_free(&hi);
- ASSERT(count =3D=3D ha= sh_n_elements(hash));
-= }
-
-static void
-rmhash(struct hash *hash, const char *word)<= br>-{
- hash_remove(hash, word);
-}
-
-void
-list_test(void)-{
- openvpn_thread_init();
-
- {
- = struct gc_arena gc =3D gc_new();
- struct hash *hash =3D hash_init(10000, get_random(), wor= d_hash_function, word_compare_function);
- struct hash *nhash =3D hash_init(256, get_random= (), word_hash_function, word_compare_function);
-
- printf("hash_init n_buckets=3D%d mask=3D0x%08x\n", h= ash->n_buckets, hash->mask);
-
- = /* parse words from stdin */
- while (true)
- {
- = char buf[256];
- = char wordbuf[256];
- int wbi;
- int bi;
- char c;
- if (!f= gets(buf, sizeof(buf), stdin))
- {
= - break;
- }
-

- bi =3D wbi =3D = 0;
- do
- {
- c =3D buf[bi++];
- if (isa= lnum(c) || c =3D=3D '_')
- {
- ASSERT(wbi < (int) sizeof(wordbuf));- wordbuf[wb= i++] =3D c;
- = }
- = else
- = {
- = if (wbi)
- = {
- = struct word *w;
- ASSERT(wbi < (int) sizeof(wordbuf));
- wor= dbuf[wbi++] =3D '\0';
-
- = /* word is parsed from stdin */
-
-= /* does it already exist in table? */
- w =3D (stru= ct word *) hash_lookup(hash, wordbuf);

-
- = if (w)
- {
- /* yes, increment count */
<= span style=3D"color: hsl(0, 100%, 40%);">- ++w-&= gt;n;

- = }
- = else
- = {
- = /* no, make a new object */
- ALLOC_OBJ_GC(w= , struct word, &gc);
- = w->n =3D 1;
- ASSERT(hash_add(hash, w->word, w, false));=
- = ASSERT(hash_add(nhash, w->word, (void *) ((random() & 0x0F) += 1), false));
- = }
- = }
- = wbi =3D 0;
- }
= - } while (c);
- }
-<= br>-#if 1
- /* remove some words from the table= */
- {- rmhash(hash, "= ;true");
- = rmhash(hash, "false");
- }
-
<= span style=3D"color: hsl(0, 100%, 40%);">- /* output contents of has= h table */

- {
- int base;
- int inc =3D= 0;
- int co= unt =3D 0;
-
= - for (base =3D 0; bas= e < hash_n_buckets(hash); base +=3D inc)
- {
- struct hash_iterator hi;
- struct hash_element *he;
- inc =3D= (get_random() % 3) + 1;
-
- while ((he =3D has= h_iterator_next(&hi)))

- {
= - struct word *w =3D (struct word *) he->value;
- printf(= "%6d '%s'\n", w->n, w->word);
- ++count;
- }

-
- hash_iterator_free(&hi);
- }
- ASSERT(count =3D=3D hash_n_element= s(hash));
- }
-
-#if 1
- /* test hash_remove_by_value function */
= - {
- int i;
- for (i =3D 1; i <=3D 16; ++i)
- {- printf("[%= d] ***********************************\n", i);
- print_nhash(nhash);<= br>- hash_remove_b= y_value(nhash, (void *) i, true);
- }
- printf("FINAL **************************\n");
- print_nhash(n= hash);
- }
-#endif
-
- hash_free(hash);
- hash_free(nhash);
- gc_free(&gc);
- }
-
- openvpn_th= read_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.hindex 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 &q= uot;buffer.h"
@@ -114,11 +112,6 @@

uint32_t hash_func(const uint8_t *k, uint32_t length, uint3= 2_t initval);

-#ifdef LIST_TEST
-void list_test(void);
-
-#endif-
static inline= uint32_t
hash_value(const struct hash *hash, const void *= key)
{

To view, visit = change 44= 6. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7511bc43cd6a0bcb89476f27d58= 22ab4a78d0d21
Gerrit-Change-Number: 446
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--13/rpfhLk0A=--