]> err.no Git - varnish/commitdiff
Make it possible to check stats counter values for a varnish instance
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 10 Jul 2008 08:00:33 +0000 (08:00 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 10 Jul 2008 08:00:33 +0000 (08:00 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2912 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/vtc_varnish.c

index 1fbec6e55c8af1a1ddd5042ffbdc1df3489b329d..60d3c99a6fbf2c8fffba931b722b45c267cf33b0 100644 (file)
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <signal.h>
 #include <pthread.h>
+#include <inttypes.h>
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -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);
        }