[master] 6356fb4 Add the binheap test to make check

Poul-Henning Kamp phk at FreeBSD.org
Sat Nov 18 17:36:09 UTC 2017


commit 6356fb41d12d249a96ce39cfce4492756d21dae4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Nov 18 17:34:42 2017 +0000

    Add the binheap test to make check

diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am
index bbef1a2..7570fa0 100644
--- a/lib/libvarnish/Makefile.am
+++ b/lib/libvarnish/Makefile.am
@@ -40,10 +40,13 @@ libvarnish_a_SOURCES = \
 	vtcp.c \
 	vtim.c
 
-TESTS = vnum_c_test
+TESTS = vnum_c_test binheap
 
 noinst_PROGRAMS = ${TESTS}
 
+binheap_SOURCES = binary_heap.c
+binheap_CFLAGS = -DTEST_DRIVER
+
 vnum_c_test_SOURCES = vnum.c vas.c
 vnum_c_test_CFLAGS = -DNUM_C_TEST -include config.h
 vnum_c_test_LDADD = ${LIBM}
diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/binary_heap.c
index 94de6f8..196ac6e 100644
--- a/lib/libvarnish/binary_heap.c
+++ b/lib/libvarnish/binary_heap.c
@@ -40,8 +40,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "binary_heap.h"
 #include "vas.h"
+#include "binary_heap.h"
 
 /* Parameters --------------------------------------------------------*/
 
@@ -458,6 +458,7 @@ binheap_reorder(const struct binheap *bh, unsigned idx)
 #include <stdio.h>
 #include <strings.h>
 
+#include "vdef.h"
 #include "miniobj.h"
 
 /* Test driver -------------------------------------------------------*/
@@ -481,37 +482,34 @@ struct foo {
 	unsigned	n;
 };
 
-#if 1
-#define M 31011091	/* Number of operations */
-#define N 17313102	/* Number of items */
-#else
-#define M 3401		/* Number of operations */
-#define N 1131		/* Number of items */
-#endif
+#define M 153557	/* Number of operations */
+#define N 43117		/* Number of items */
 #define R -1		/* Random modulus */
 
 struct foo *ff[N];
 
-static int
+static int __match_proto__(binheap_cmp_t)
 cmp(void *priv, const void *a, const void *b)
 {
 	const struct foo *fa, *fb;
 
+	(void)priv;
 	CAST_OBJ_NOTNULL(fa, a, FOO_MAGIC);
 	CAST_OBJ_NOTNULL(fb, b, FOO_MAGIC);
 	return (fa->key < fb->key);
 }
 
-void
+static void __match_proto__(binheap_update_t)
 update(void *priv, void *a, unsigned u)
 {
 	struct foo *fa;
 
+	(void)priv;
 	CAST_OBJ_NOTNULL(fa, a, FOO_MAGIC);
 	fa->idx = u;
 }
 
-void
+static void
 chk2(struct binheap *bh)
 {
 	unsigned u, v;
@@ -529,9 +527,11 @@ int
 main(int argc, char **argv)
 {
 	struct binheap *bh;
-	unsigned u, v, lr, n;
+	unsigned j, u, v, lr, n;
 	struct foo *fp;
 
+	(void)argc;
+	(void)argv;
 	if (0) {
 		srandomdev();
 		u = random();
@@ -545,7 +545,7 @@ main(int argc, char **argv)
 		child(bh, n + 1, &u, &v);
 	}
 
-	while (1) {
+	for(j = 0; j < 2; j++) {
 		/* First insert our N elements */
 		for (u = 0; u < N; u++) {
 			lr = random() % R;


More information about the varnish-commit mailing list