]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
TESTS: slightly reorganize the code in the tests/ directory
authorWilly Tarreau <w@1wt.eu>
Fri, 2 Apr 2021 08:33:38 +0000 (10:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Apr 2021 08:51:12 +0000 (10:51 +0200)
The code that is there to run some unit tests on some internal features
was moved to tests/unit. Ideally it should be buildable from the main
makefile though this is not yet the case.

The code that is kept for experimentation purposes (hashes, syscall
optimization etc) as well as some captures of the results was moved
to tests/exp.

A few totally obsolete files which couldn't build anymore and were
not relevant to current versions were removed.

19 files changed:
tests/0000-debug-stats.diff [deleted file]
tests/exp/blocksig.c [moved from tests/blocksig.c with 100% similarity]
tests/exp/filltab25.c [moved from tests/filltab25.c with 100% similarity]
tests/exp/hash_results.txt [moved from tests/hash_results.txt with 100% similarity]
tests/exp/hashing-results.txt [moved from tests/hashing-results.txt with 100% similarity]
tests/exp/io_limits.txt [moved from tests/io_limits.txt with 100% similarity]
tests/exp/ip-hash.c [moved from tests/ip-hash.c with 100% similarity]
tests/exp/test_hashes.c [moved from tests/test_hashes.c with 100% similarity]
tests/exp/testinet.c [moved from tests/testinet.c with 95% similarity]
tests/exp/uri_hash.c [moved from tests/uri_hash.c with 100% similarity]
tests/reset.c [deleted file]
tests/sockstat.txt [deleted file]
tests/test.c [deleted file]
tests/test_pools.c [deleted file]
tests/unit/ist.c [moved from tests/ist.c with 99% similarity]
tests/unit/test-arg.c [moved from tests/test-arg.c with 86% similarity]
tests/unit/test-inherited-fd.py [moved from tests/test-inherited-fd.py with 100% similarity]
tests/unit/test-list.c [moved from tests/test-list.c with 96% similarity]
tests/unit/test-sockpair.py [moved from tests/test-sockpair.py with 100% similarity]

diff --git a/tests/0000-debug-stats.diff b/tests/0000-debug-stats.diff
deleted file mode 100644 (file)
index 223df2c..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-From: Krzysztof Oledzki <ole@ans.pl>
-Date: Sun, 20 Apr 2008 22:19:09 +0200 (CEST)
-Subject: Re: [PATCH]  Flush buffers also where there are exactly 0 bytes left
-
-I'm also attaching a debug patch that helps to trigger this bug.
-
-Without the fix:
-# echo -ne "GET /haproxy?stats;csv;norefresh HTTP/1.0\r\n\r\n"|nc 127.0.0.1=
- 801|wc -c
-16384
-
-With the fix:
-# echo -ne "GET /haproxy?stats;csv;norefresh HTTP/1.0\r\n\r\n"|nc 127.0.0.1=
- 801|wc -c
-33089
-
-Best regards,
-
-diff --git a/src/dumpstats.c b/src/dumpstats.c
-index ddadddd..28bbfce 100644
---- a/src/dumpstats.c
-+++ b/src/dumpstats.c
-@@ -593,6 +593,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
-       msg.len = 0;
-       msg.str = trash;
-+      int i;
-       switch (s->data_ctx.stats.px_st) {
-       case DATA_ST_PX_INIT:
-@@ -667,6 +668,13 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
-               /* print the frontend */
-               if ((px->cap & PR_CAP_FE) &&
-                   (!(s->data_ctx.stats.flags & STAT_BOUND) || (s->data_ctx.stats.type & (1 << STATS_TYPE_FE)))) {
-+
-+                      if (1) {
-+                              for (i=0; i<16096; i++)
-+                                      chunk_printf(&msg, trashlen, "*");
-+
-+                              chunk_printf(&msg, trashlen, "\n");
-+#if 0
-                       if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
-                               chunk_printf(&msg, trashlen,
-                                    /* name, queue */
-@@ -694,6 +702,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri)
-                                    px->failed_req,
-                                    px->state == PR_STRUN ? "OPEN" :
-                                    px->state == PR_STIDLE ? "FULL" : "STOP");
-+#endif
-                       } else {
-                               chunk_printf(&msg, trashlen,
-                                    /* pxid, name, queue cur, queue max, */
-
-
similarity index 100%
rename from tests/blocksig.c
rename to tests/exp/blocksig.c
similarity index 100%
rename from tests/filltab25.c
rename to tests/exp/filltab25.c
similarity index 100%
rename from tests/io_limits.txt
rename to tests/exp/io_limits.txt
similarity index 100%
rename from tests/ip-hash.c
rename to tests/exp/ip-hash.c
similarity index 100%
rename from tests/test_hashes.c
rename to tests/exp/test_hashes.c
similarity index 95%
rename from tests/testinet.c
rename to tests/exp/testinet.c
index 2140115dc028b590d84787fc6d420b0ecdf7744e..0eb87e9dc3cdc8ddd6cca051cb56aad4b9146e29 100644 (file)
@@ -20,8 +20,9 @@
 #include <syslog.h>
 
 
-main() {
+int main() {
     printf("sizeof sockaddr=%d\n", sizeof(struct sockaddr));
     printf("sizeof sockaddr_in=%d\n", sizeof(struct sockaddr_in));
     printf("sizeof sockaddr_in6=%d\n", sizeof(struct sockaddr_in6));
+    return 0;
 }
similarity index 100%
rename from tests/uri_hash.c
rename to tests/exp/uri_hash.c
diff --git a/tests/reset.c b/tests/reset.c
deleted file mode 100644 (file)
index ec09b94..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <fcntl.h>
-
-int main(int argc, char **argv) {
-       char *addr;
-       int port;
-       int sock;
-       struct sockaddr_in saddr;
-       const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
-
-       if (argc < 4) {
-               fprintf(stderr,
-                       "usage : %s <addr> <port> <string>\n"
-                       "        This will connect to TCP port <addr>:<port> and send string <string>\n"
-                       "        then immediately reset.\n",
-                       argv[0]);
-               exit(1);
-       }
-
-       addr = argv[1];
-       port = atoi(argv[2]);
-
-       sock = socket(AF_INET, SOCK_STREAM, 0);
-       bzero(&saddr, sizeof(saddr));
-       saddr.sin_addr.s_addr = inet_addr(addr);
-       saddr.sin_port = htons(port);
-       saddr.sin_family = AF_INET;
-
-       if (connect(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
-               perror("connect");
-               exit(1);
-       }
-
-       send(sock, argv[3], strlen(argv[3]), MSG_DONTWAIT | MSG_NOSIGNAL);
-       setsockopt(sock, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
-       close(sock);
-       exit(0);
-}
diff --git a/tests/sockstat.txt b/tests/sockstat.txt
deleted file mode 100644 (file)
index 3962ae9..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-willy@pcw:haproxy-1.1.17-pre3$ cat /proc/net/sockstat 
-sockets: used 117
-TCP: inuse 82 orphan 15 tw 561836 alloc 88 mem 75
-UDP: inuse 13
-RAW: inuse 0
-FRAG: inuse 0 memory 0
-
diff --git a/tests/test.c b/tests/test.c
deleted file mode 100644 (file)
index 4595712..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-main() {
-  write(1, "HTTP", 4);
-  write(1, "/1.0", 4);
-  write(1, " 200", 4);
-  write(1, " OK\r\n", 5);
-  write(1, "TOTO: 1\r\n", 9);
-  write(1, "Hdr2: 2\r\n", 9);
-  write(1, "Hdr3:", 5);
-  write(1, " 2\r\n", 4);
-  write(1, "\r\n\r\n", 4);
-  write(1, "DATA\r\n", 6);
-}
-
diff --git a/tests/test_pools.c b/tests/test_pools.c
deleted file mode 100644 (file)
index c8558db..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Contribution from Aleksandar Lazic <al-haproxy@none.at>
- *
- * Build with :
- *   gcc -O2 -o test_pools test_pools.c
- * or with dlmalloc too :
- *   gcc -O2 -o test_pools -D USE_DLMALLOC test_pools.c -DUSE_DL_PREFIX dlmalloc.c
- */
-
-#include <sys/time.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdio.h>
-
-static struct timeval timeval_current(void)
-{
-       struct timeval tv;
-       gettimeofday(&tv, NULL);
-       return tv;
-}
-
-static double timeval_elapsed(struct timeval *tv)
-{
-       struct timeval tv2 = timeval_current();
-       return (tv2.tv_sec - tv->tv_sec) + 
-              (tv2.tv_usec - tv->tv_usec)*1.0e-6;
-}
-
-#define torture_assert(test, expr, str) if (!(expr)) { \
-       printf("failure: %s [\n%s: Expression %s failed: %s\n]\n", \
-               test, __location__, #expr, str); \
-       return false; \
-}
-
-#define torture_assert_str_equal(test, arg1, arg2, desc) \
-       if (strcmp(arg1, arg2)) { \
-               printf("failure: %s [\n%s: Expected %s, got %s: %s\n]\n", \
-                  test, __location__, arg1, arg2, desc); \
-               return false; \
-       }
-
-/* added pools from haproxy */
-#include <stdlib.h>
-
-/*
- * Returns a pointer to an area of <__len> bytes taken from the pool <pool> or
- * dynamically allocated. In the first case, <__pool> is updated to point to
- * the next element in the list.
- */
-#define pool_alloc_from(__pool, __len)                      \
-({                                                          \
-        void *__p;                                          \
-        if ((__p = (__pool)) == NULL)                       \
-                __p = malloc(((__len) >= sizeof (void *)) ? \
-                      (__len) : sizeof(void *));            \
-        else {                                              \
-                __pool = *(void **)(__pool);                \
-        }                                                   \
-        __p;                                                \
-})
-
-/*
- * Puts a memory area back to the corresponding pool.
- * Items are chained directly through a pointer that
- * is written in the beginning of the memory area, so
- * there's no need for any carrier cell. This implies
- * that each memory area is at least as big as one
- * pointer.
- */
-#define pool_free_to(__pool, __ptr)             \
-({                                              \
-        *(void **)(__ptr) = (void *)(__pool);   \
-        __pool = (void *)(__ptr);               \
-})
-
-/*
- * Returns a pointer to type <type> taken from the
- * pool <pool_type> or dynamically allocated. In the
- * first case, <pool_type> is updated to point to the
- * next element in the list.
- */
-#define pool_alloc(type)                                \
-({                                                      \
-        void *__p;                                      \
-        if ((__p = pool_##type) == NULL)                \
-                __p = malloc(sizeof_##type);            \
-        else {                                          \
-                pool_##type = *(void **)pool_##type;   \
-        }                                               \
-        __p;                                            \
-})
-
-/*
- * Puts a memory area back to the corresponding pool.
- * Items are chained directly through a pointer that
- * is written in the beginning of the memory area, so
- * there's no need for any carrier cell. This implies
- * that each memory area is at least as big as one
- * pointer.
- */
-#define pool_free(type, ptr)                            \
-({                                                      \
-        *(void **)ptr = (void *)pool_##type;            \
-        pool_##type = (void *)ptr;                      \
-})
-
-/*
- * This function destroys a pull by freeing it completely.
- * This should be called only under extreme circumstances.
- */
-static inline void pool_destroy(void **pool)
-{
-       void *temp, *next;
-       next = pool;
-       while (next) {
-               temp = next;
-               next = *(void **)temp;
-               free(temp);
-       }
-}
-
-#define sizeof_talloc   1000
-
-/*
-  measure the speed of hapx versus malloc
-*/
-static bool test_speed1(void)
-{
-        void **pool_talloc = NULL;
-       void *ctx = pool_alloc(talloc);
-       unsigned count;
-       const int loop = 1000;
-       int i;
-       struct timeval tv;
-
-       printf("test: speed [\nhaproxy-pool VS MALLOC SPEED 2\n]\n");
-
-       tv = timeval_current();
-       count = 0;
-       do {
-               void *p1, *p2, *p3;
-               for (i=0;i<loop;i++) {
-                       p1 = pool_alloc_from(pool_talloc, 10 + loop % 100);
-                       p2 = pool_alloc_from(pool_talloc, strlen("foo bar") + 1);
-                       strcpy(p2, "foo bar");
-                       p3 = pool_alloc_from(pool_talloc, 300);
-                       pool_free_to(pool_talloc,p1);
-                       pool_free_to(pool_talloc,p3);
-                       pool_free_to(pool_talloc,p2);
-               }
-               count += 3 * loop;
-       } while (timeval_elapsed(&tv) < 5.0);
-
-       fprintf(stderr, "haproxy : %10.0f ops/sec\n", count/timeval_elapsed(&tv));
-
-        pool_destroy(pool_talloc);
-
-       tv = timeval_current();
-       count = 0;
-       do {
-               void *p1, *p2, *p3;
-               for (i=0;i<loop;i++) {
-                       p1 = malloc(10 + loop % 100);
-                       p2 = malloc(strlen("foo bar") + 1);
-                       strcpy(p2, "foo bar");
-                       p3 = malloc(300);
-                       free(p1);
-                       free(p2);
-                       free(p3);
-               }
-               count += 3 * loop;
-       } while (timeval_elapsed(&tv) < 5.0);
-       fprintf(stderr, "malloc  : %10.0f ops/sec\n", count/timeval_elapsed(&tv));
-
-#ifdef USE_DLMALLOC
-       tv = timeval_current();
-       count = 0;
-       do {
-               void *p1, *p2, *p3;
-               for (i=0;i<loop;i++) {
-                       p1 = dlmalloc(10 + loop % 100);
-                       p2 = dlmalloc(strlen("foo bar") + 1);
-                       strcpy(p2, "foo bar");
-                       p3 = dlmalloc(300);
-                       dlfree(p1);
-                       dlfree(p2);
-                       dlfree(p3);
-               }
-               count += 3 * loop;
-       } while (timeval_elapsed(&tv) < 5.0);
-       fprintf(stderr, "dlmalloc: %10.0f ops/sec\n", count/timeval_elapsed(&tv));
-#endif
-
-       printf("success: speed1\n");
-
-       return true;
-}
-
-int main(void)
-{
-       bool ret = test_speed1();
-       if (!ret)
-               return -1;
-       return 0;
-}
similarity index 99%
rename from tests/ist.c
rename to tests/unit/ist.c
index ee319636601d53de1b09a38126c204302941dc96..43b34387af59f1f98d2ec487cba55803b9e2ac8f 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "common/ist.h"
+#include <import/ist.h>
 
 
 // pre-extracted from ist.h using the following expression :
similarity index 86%
rename from tests/test-arg.c
rename to tests/unit/test-arg.c
index 222f2b234eea218060734f177f7c58354a718fee..1871f8c8da7bf0227e28119c25e9c6b55af9f7c5 100644 (file)
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "proto/arg.h"
+#include <haproxy/arg.h>
 
 int main(int argc, char **argv)
 {
@@ -23,7 +23,7 @@ int main(int argc, char **argv)
 
        printf("Using mask=0x%08x\n", mask);
        nbargs = make_arg_list(argv[1], strlen(argv[1]), mask,
-                              &argp, &err_msg, &err_ptr, &err_arg);
+                              &argp, &err_msg, &err_ptr, &err_arg, NULL);
 
        printf("nbargs=%d\n", nbargs);
        if (nbargs < 0) {
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
 
                for (arg = 0; arg < nbargs; arg++)
                        printf("arg %d: type=%d, int=0x%08x\n",
-                              arg, argp[arg].type, *(int*)&argp[arg].data.uint);
+                              arg, argp[arg].type, *(int*)&argp[arg].data.sint);
        }
        return 0;
 }
similarity index 96%
rename from tests/test-list.c
rename to tests/unit/test-list.c
index e2e07f9777b7e3f1ab0bb2956493b60ae13ac87a..a76c82a271e0bdd634c583e7373b407a5da29569 100644 (file)
@@ -6,7 +6,7 @@
 
 /* Stress test the mt_lists.
  * Compile from the haproxy directory with :
- * cc -Iinclude tests/test-list.c -lpthread -O2 -o test-list
+ * cc -I../../include test-list.c -pthread -O2 -o test-list
  * The only argument it takes is the number of threads to be used.
  * ./test-list 4
  */