Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit d405442

Browse files
committed
Add support for externally built vtest with vtc_varnish as a shared object
Ref #4398
1 parent bb1259f commit d405442

5 files changed

Lines changed: 213 additions & 15 deletions

File tree

bin/varnishtest/Makefile.am

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,34 @@ TESTS = @VTC_TESTS@
44

55
include $(top_srcdir)/vtc.am
66

7-
DISTCLEANFILES = _.ok
8-
97
AM_CPPFLAGS = \
108
-I$(top_srcdir)/include \
119
-I$(top_builddir)/include \
1210
-I$(top_builddir) \
1311
-I$(top_srcdir)/lib/libvgz \
1412
-I$(srcdir)/vtest2/lib
1513

14+
EXTRA_DIST = \
15+
$(top_srcdir)/bin/varnishtest/tests/*.vtc \
16+
$(top_srcdir)/bin/varnishtest/tests/common.pem \
17+
$(top_srcdir)/bin/varnishtest/tests/README
18+
19+
################################################################################
20+
## BEGIN HAVE_VTEST_SUBMODULE
21+
##
22+
## not indendet on purpose
23+
if HAVE_VTEST_SUBMODULE
24+
25+
EXTRA_DIST += \
26+
$(srcdir)/vtest2/src/../tests/*.vtc \
27+
vtest2/src/gensequences \
28+
vtest2/src/sequences \
29+
vtest2/src/teken.3 \
30+
vtest2/src/huffman_gen.py \
31+
vtest2/src/tbl/vhp_huffman.h
32+
33+
DISTCLEANFILES = _.ok
34+
1635
bin_PROGRAMS = varnishtest
1736

1837
# for -i invocation / a00000.vtc
@@ -80,16 +99,6 @@ varnishtest_CFLAGS = \
8099
-DVTEST_WITH_VTC_VSM \
81100
-DTOP_BUILDDIR='"${top_builddir}"'
82101

83-
EXTRA_DIST = $(srcdir)/vtest2/src/../tests/*.vtc \
84-
$(top_srcdir)/bin/varnishtest/tests/*.vtc \
85-
$(top_srcdir)/bin/varnishtest/tests/common.pem \
86-
$(top_srcdir)/bin/varnishtest/tests/README \
87-
vtest2/src/gensequences \
88-
vtest2/src/sequences \
89-
vtest2/src/teken.3 \
90-
vtest2/src/huffman_gen.py \
91-
vtest2/src/tbl/vhp_huffman.h
92-
93102
teken.c: teken_state.h
94103

95104
teken_state.h: $(srcdir)/vtest2/src/sequences $(srcdir)/vtest2/src/gensequences
@@ -110,3 +119,54 @@ BUILT_SOURCES = \
110119
CLEANFILES = \
111120
$(BUILT_SOURCES) \
112121
vtest
122+
123+
##
124+
## END HAVE_VTEST_SUBMODULE
125+
################################################################################
126+
else
127+
################################################################################
128+
## BEGIN vtc_varnish ext
129+
130+
lib_LTLIBRARIES = libvtc_varnish.la libdummy.la
131+
132+
# XXX TODO
133+
# - for actual move, the sources need to be relocated from VTest2 back to here
134+
# - for actual move, remove -DVTEST_WITH_...
135+
# - solve WITH_PERSISTENT_STORAGE
136+
libvtc_varnish_la_SOURCES = \
137+
vtest2/src/vtc_varnish.c \
138+
vtest2/src/vtc_vsm.c \
139+
vtest2/src/vtc_logexp.c \
140+
vtc_ext_varnish.c
141+
142+
libvtc_varnish_la_CFLAGS = \
143+
@VTEST_CFLAGS@ \
144+
-DVTEST_WITH_VTC_LOGEXPECT \
145+
-DVTEST_WITH_VTC_VARNISH \
146+
-DVTEST_WITH_VTC_VSM
147+
148+
libvtc_varnish_la_LIBADD = \
149+
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
150+
$(top_builddir)/lib/libvarnish/libvarnish.la \
151+
$(top_builddir)/lib/libvgz/libvgz.la \
152+
${PTHREAD_LIBS} ${NET_LIBS} ${LIBM}
153+
154+
libdummy_la_SOURCES = libdummy.c
155+
156+
bin_PROGRAMS = varnishtest
157+
158+
varnishtest_SOURCES = varnishtest.c
159+
# to get the libtool wrapper
160+
varnishtest_LDADD = libdummy.la
161+
162+
# for the out-of-tree vtest mode, the vtest wrapper from in-tree mode must not
163+
# exist, or else we get an infinit exec loop
164+
clean-vtest:
165+
rm -f vtest
166+
167+
all-local: clean-vtest
168+
169+
## END vtc_varnish ext
170+
################################################################################
171+
endif
172+

bin/varnishtest/libdummy.c

Whitespace-only changes.

bin/varnishtest/varnishtest.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*-
2+
* Copyright 2025 UPLEX - Nils Goroll Systemoptimierung
3+
* All rights reserved.
4+
*
5+
* Author: Nils Goroll <nils.goroll@uplex.de>
6+
*
7+
* SPDX-License-Identifier: BSD-2-Clause
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
* 1. Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28+
* SUCH DAMAGE.
29+
*
30+
* Wrapper to call vtest with additional extensions
31+
*
32+
* The problem solved by this code can easily also be solved with a two-liner
33+
* shell script, except that we would need to implement all the mechanics to
34+
* locate libvtc_varnish.so while it is still uninstalled. But for this simple
35+
* program, libtool handles it all.
36+
*/
37+
38+
#include <errno.h>
39+
#include <stdlib.h>
40+
#include <stdio.h>
41+
#include <string.h>
42+
#include <unistd.h>
43+
44+
#include "vdef.h"
45+
46+
const char *addargs[]= {
47+
"vtest", "-E", "libvtc_varnish.so"
48+
};
49+
50+
int
51+
main(int argc, char **argv)
52+
{
53+
size_t n = vcountof(addargs);
54+
char **narg = calloc(argc + n, sizeof *narg);
55+
int r;
56+
57+
if (narg == NULL)
58+
return (ENOMEM);
59+
memcpy(&narg[0], &addargs[0], n * sizeof *narg);
60+
memcpy(&narg[n], &argv[1], (argc - 1) * sizeof *narg);
61+
r = execvp(narg[0], narg);
62+
fprintf(stderr, "execvp(%s): %d (%s)\n", narg[0], errno,
63+
strerror(errno));
64+
return (r);
65+
}

bin/varnishtest/vtc_ext_varnish.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*-
2+
* Copyright 2025 UPLEX - Nils Goroll Systemoptimierung
3+
* All rights reserved.
4+
*
5+
* Author: Nils Goroll <nils.goroll@uplex.de>
6+
*
7+
* SPDX-License-Identifier: BSD-2-Clause
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
* 1. Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28+
* SUCH DAMAGE.
29+
*/
30+
31+
#include "config.h"
32+
33+
#include "vtc.h"
34+
35+
#define CMDS \
36+
CMD_TOP(logexpect) \
37+
CMD_TOP(varnish) \
38+
CMD_TOP(vsm)
39+
40+
#define CMD_TOP(x) cmd_f cmd_##x;
41+
CMDS
42+
43+
#undef CMD_TOP
44+
#define CMD_TOP(x) {#x, cmd_##x},
45+
46+
static struct cmds varnish_cmds[3] = {
47+
CMDS
48+
};
49+
50+
static __attribute__((constructor)) void
51+
register_varnish_top_cmds(void)
52+
{
53+
register_top_cmds(varnish_cmds, vcountof(varnish_cmds));
54+
}
55+

configure.ac

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ Copyright 2010-2025 UPLEX - Nils Goroll Systemoptimierung])
55
AC_REVISION([$Id$])
66
AC_INIT([Varnish], [trunk], [varnish-dev@varnish-cache.org])
77
AC_CONFIG_SRCDIR(include/miniobj.h)
8-
if ! test -f "${srcdir}/bin/varnishtest/vtest2/src/vtc_main.c" ; then
9-
AC_MSG_ERROR([vtest2 seems to be missing, use "git clone --recursive" or "git submodule update --init"])
10-
fi
118
AC_CONFIG_HEADERS([config.h])
129
AC_CONFIG_MACRO_DIR([m4])
1310
AC_CONFIG_AUX_DIR([build-aux])
@@ -50,6 +47,27 @@ CC="$PTHREAD_CC"
5047

5148
AC_PROG_INSTALL
5249

50+
AM_CONDITIONAL([HAVE_VTEST_SUBMODULE],
51+
[test -f "${srcdir}/bin/varnishtest/vtest2/src/vtc_main.c"])
52+
AM_COND_IF([HAVE_VTEST_SUBMODULE], [], [
53+
AC_ARG_VAR([VTEST], [The vtest program from VTest2])
54+
AM_MISSING_PROG([VTEST], [vtest])
55+
AC_CHECK_PROGS([VTEST], [vtest])
56+
if test "x$VTEST" = "xno"; then
57+
AC_MSG_ERROR([requires vtest. Either clone the submodule, or set VTEST, or add it to PATH])
58+
fi
59+
60+
AC_ARG_VAR([VTEST_CFLAGS], [compiler flags to find vtc.h])
61+
if test "$ac_cv_env_VTEST_CFLAGS_set" = "set"; then
62+
VTEST_CFLAGS="$ac_cv_env_VTEST_CFLAGS_value"
63+
else
64+
PKG_CHECK_MODULES([VTEST], [vtest], [], [
65+
AC_MSG_ERROR([requires vtest includes. Either clone the submodule, or set VTEST_CFLAGS, or add the pkg-config .pc file])
66+
])
67+
fi
68+
AC_SUBST([VTEST_CFLAGS])
69+
])
70+
5371
AC_ARG_WITH([rst2man],
5472
AS_HELP_STRING([--with-rst2man=PATH], [Location of rst2man (auto)]),
5573
[RST2MAN="$withval"],

0 commit comments

Comments
 (0)