From: phk Date: Tue, 17 Jun 2008 07:10:14 +0000 (+0000) Subject: Add a delay command, it takes second.fraction and uses usleep() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b57132c11f38f16988aa6307e562721b05cf3a3;p=varnish Add a delay command, it takes second.fraction and uses usleep() below 100s and sleep() over. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2712 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishtest/vtc.c b/varnish-cache/bin/varnishtest/vtc.c index 113ca179..249f9752 100644 --- a/varnish-cache/bin/varnishtest/vtc.c +++ b/varnish-cache/bin/varnishtest/vtc.c @@ -249,7 +249,29 @@ cmd_test(char **av, void *priv) /********************************************************************** - * Execute a file + * Dump command arguments + */ + +void +cmd_delay(char **av, void *priv) +{ + double f; + + (void)priv; + if (av == NULL) + return; + AN(av[1]); + AZ(av[2]); + f = strtod(av[1], NULL); + if (f > 100.) { + sleep((int)f); + } else { + usleep((int)(f * 1e6)); + } +} + +/********************************************************************** + * Dump command arguments */ void @@ -263,11 +285,16 @@ cmd_dump(char **av, void *priv) printf("\t<%s>\n", *av++); } +/********************************************************************** + * Execute a file + */ + static struct cmds cmds[] = { { "server", cmd_server }, { "client", cmd_client }, { "stats", cmd_stats }, { "varnish", cmd_varnish }, + { "delay", cmd_delay }, { "test", cmd_test }, { NULL, NULL } }; @@ -294,6 +321,7 @@ main(int argc, char **argv) int ch; setbuf(stdout, NULL); + setbuf(stderr, NULL); while ((ch = getopt(argc, argv, "")) != -1) { switch (ch) { case '?': diff --git a/varnish-cache/bin/varnishtest/vtc.h b/varnish-cache/bin/varnishtest/vtc.h index 23d38316..b227b7df 100644 --- a/varnish-cache/bin/varnishtest/vtc.h +++ b/varnish-cache/bin/varnishtest/vtc.h @@ -36,6 +36,8 @@ struct cmds { void parse_string(char *buf, const struct cmds *cmd, void *priv); void cmd_dump(char **av, void *priv); +void cmd_delay(char **av, void *priv); + void cmd_server(char **av, void *priv); void cmd_client(char **av, void *priv); void cmd_vcl(char **av, void *priv);