From 3479d1c16687ea39e31fa259abb7597fcfd825db Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 10 Jul 2008 08:00:33 +0000 Subject: [PATCH] Make it possible to check stats counter values for a varnish instance git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2912 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishtest/vtc_varnish.c | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/varnish-cache/bin/varnishtest/vtc_varnish.c b/varnish-cache/bin/varnishtest/vtc_varnish.c index 1fbec6e5..60d3c99a 100644 --- a/varnish-cache/bin/varnishtest/vtc_varnish.c +++ b/varnish-cache/bin/varnishtest/vtc_varnish.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -392,6 +393,47 @@ varnish_vclbackend(struct varnish *v, const char *vcl) vsb_delete(vsb2); } +/********************************************************************** + * Check statistics + */ + +static void +varnish_expect(struct varnish *v, char * const *av) { + uint64_t val, ref; + int good; + char *p; + +#define MAC_STAT(n, t, f, d) \ + if (!strcmp(av[0], #n)) { \ + val = v->stats->n; \ + } else +#include "stat_field.h" +#undef MAC_STAT + { + vtc_log(v->vl, 0, "stats field %s unknown", av[0]); + } + + ref = strtoumax(av[2], &p, 0); + if (ref == UINTMAX_MAX || *p) + vtc_log(v->vl, 0, "Syntax error in number (%s)", av[2]); + good = 0; + if (!strcmp(av[1], "==")) { if (val == ref) good = 1; } + else if (!strcmp(av[1], "!=")) { if (val != ref) good = 1; } + else if (!strcmp(av[1], ">")) { if (val > ref) good = 1; } + else if (!strcmp(av[1], "<")) { if (val < ref) good = 1; } + else if (!strcmp(av[1], ">=")) { if (val >= ref) good = 1; } + else if (!strcmp(av[1], "<=")) { if (val <= ref) good = 1; } + else { + vtc_log(v->vl, 0, "comparison %s unknown", av[1]); + } + if (good) + vtc_log(v->vl, 2, "as expected: %s (%ju) %s %s", + av[0], val, av[1], av[2]); + else + vtc_log(v->vl, 0, "Not true: %s (%ju) %s %s (%ju)", + av[0], val, av[1], av[2], ref); +} + /********************************************************************** * Varnish server cmd dispatch */ @@ -478,6 +520,12 @@ cmd_varnish(CMD_ARGS) varnish_wait(v); continue; } + if (!strcmp(*av, "-expect")) { + av++; + varnish_expect(v, av); + av += 2; + continue; + } vtc_log(v->vl, 0, "Unknown varnish argument: %s", *av); exit (1); } -- 2.39.5