From 4906e5f067b67d25a1f378d7ec86347a78992c0f Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 26 Jun 2008 08:53:51 +0000 Subject: [PATCH] Add -chunked primitive for easier message composition. Go over varnishtest with FlexeLint git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2816 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishtest/flint.lnt | 109 ++++++++++-------- varnish-cache/bin/varnishtest/flint.sh | 3 +- .../bin/varnishtest/tests/b00007.vtc | 4 +- varnish-cache/bin/varnishtest/vtc.c | 12 +- varnish-cache/bin/varnishtest/vtc.h | 2 +- varnish-cache/bin/varnishtest/vtc_client.c | 9 +- varnish-cache/bin/varnishtest/vtc_http.c | 100 ++++++++++------ varnish-cache/bin/varnishtest/vtc_log.c | 2 + varnish-cache/bin/varnishtest/vtc_server.c | 9 +- varnish-cache/bin/varnishtest/vtc_varnish.c | 14 +-- 10 files changed, 148 insertions(+), 116 deletions(-) diff --git a/varnish-cache/bin/varnishtest/flint.lnt b/varnish-cache/bin/varnishtest/flint.lnt index cbc66ac7..babc1f30 100644 --- a/varnish-cache/bin/varnishtest/flint.lnt +++ b/varnish-cache/bin/varnishtest/flint.lnt @@ -7,38 +7,44 @@ // 796 and 797 (out-of-bounds errors). -elib(123) // size is both a variable and a macro with args -emacro(736, isnan) // isnanf +-efile(766, ../../config.h) --sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) +// -header(../../config.h) --sem(vsb_new, @p == malloc(1)) --sem(vsb_delete, custodial(1)) +// Fix strchr() semtics, it can only return NULL if arg2 != 0 +-sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) +// +// -sem(vsb_new, @p == malloc(1)) +// -sem(vsb_delete, custodial(1)) -sem(lbv_assert, r_no) -sem(lbv_xxxassert, r_no) - --ffc // No automatic custody - +// -sem(WS_Init, custodial(2)) +// -sem(http_Setup, custodial(2)) +// +// -ffc // No automatic custody +// -e763 // Redundant declaration for symbol '...' previously declared --e726 // Extraneous comma ignored --e728 // Symbol ... not explicitly initialized +// -e726 // Extraneous comma ignored +// -e728 // Symbol ... not explicitly initialized -e716 // while(1) ... --e785 // Too few initializers for aggregate --e786 // String concatenation within initializer - --emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types) --emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types) --emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) --emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small) +// -e785 // Too few initializers for aggregate +// -e786 // String concatenation within initializer +// +// -emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types) +// -emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types) +// -emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) +// -emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small) -emacro(506, VTAILQ_FOREACH_SAFE) // constant value boolean - +// -esym(534, sprintf) // Ignoring return value of function --esym(534, asprintf) // Ignoring return value of function +// -esym(534, asprintf) // Ignoring return value of function -esym(534, printf) // Ignoring return value of function -esym(534, fprintf) // Ignoring return value of function -esym(534, memset) // Ignoring return value of function --esym(534, memcpy) // Ignoring return value of function --esym(534, memmove) // Ignoring return value of function --esym(534, strcpy) // Ignoring return value of function +// -esym(534, memcpy) // Ignoring return value of function +// -esym(534, memmove) // Ignoring return value of function +// -esym(534, strcpy) // Ignoring return value of function -esym(534, vsb_printf) // Ignoring return value of function -esym(534, vsb_cat) // Ignoring return value of function -esym(534, vsb_bcat) // Ignoring return value of function @@ -46,33 +52,44 @@ -esym(534, strcat) // Ignoring return value of function -esym(534, strcpy) // Ignoring return value of function -esym(534, strlcpy) // Ignoring return value of function - --emacro(506, isnan) // constant value boolean --emacro(747, isnan) // significant coersion --emacro(506, assert) // constant value boolean --emacro(827, assert) // loop not reachable --emacro(774, assert) // booelan always true - -// cache.h --emacro(506, INCOMPL) // Constant value Boolean - -// Review all below this line /////////////////////////////////////////////// - +// +// -emacro(506, isnan) // constant value boolean +// -emacro(747, isnan) // significant coersion +// -emacro(506, assert) // constant value boolean +// -emacro(827, assert) // loop not reachable +// -emacro(774, assert) // booelan always true +// -emacro(774, HTTPH) // always false +// +// // cache.h +// -emacro(506, INCOMPL) // Constant value Boolean +// +// // cache_center.c +// -efunc(525, CNT_Session) // Negative indentation from line +// -efunc(525, http_FilterFields) // Negative indentation from line +// -efunc(539, http_FilterFields) // Positive indentation from line +// +// // cache_vcl.c +// -efunc(525, vcl_handlingname) // Negative indentation from line +// -esym(528, vcl_handlingname) // Not referenced +// -e641 // Converting enum 'cli_status_e' to int +// +// // Review all below this line /////////////////////////////////////////////// +// -e732 // Loss of sign (arg. no. 2) (int to unsigned -e737 // [45] Loss of sign in promotion from int to unsigned -e713 // Loss of precision (assignment) (unsigned long long to long long) -e574 // Signed-unsigned mix with relational --e712 // Loss of precision (assignment) (long long to --e747 // Significant prototype coercion (arg. no. 2) long - -/* - --e767 // Macro redef (system queue.h vs ours ) - --e506 // Constant value boolean --e818 // Pointer parameter '...' could be declared as pointing to const --e774 // Boolean within 'if' always evaluates to False --e534 // Ignoring return value of function --e557 // unrecog format - -*/ +// -e712 // Loss of precision (assignment) (long long to +// -e747 // Significant prototype coercion (arg. no. 2) long +// +// /* +// +// -e767 // Macro redef (system queue.h vs ours ) +// +// -e506 // Constant value boolean +// -e818 // Pointer parameter '...' could be declared as pointing to const +// -e774 // Boolean within 'if' always evaluates to False +// -e534 // Ignoring return value of function +// -e557 // unrecog format +// +// */ diff --git a/varnish-cache/bin/varnishtest/flint.sh b/varnish-cache/bin/varnishtest/flint.sh index bc54f11d..c4c1a6ab 100755 --- a/varnish-cache/bin/varnishtest/flint.sh +++ b/varnish-cache/bin/varnishtest/flint.sh @@ -6,11 +6,10 @@ flexelint \ -I. \ -I../../include \ -I../.. \ - -DVARNISH_STATE_DIR=\"foo\" \ flint.lnt \ *.c > $T 2>&1 -for t in Error Warning Info +for t in Error Warning Info Note do sed -n "/$t [0-9][0-9][0-9]:/s/.*\($t [0-9][0-9][0-9]\).*/\1/p" $T done | awk ' diff --git a/varnish-cache/bin/varnishtest/tests/b00007.vtc b/varnish-cache/bin/varnishtest/tests/b00007.vtc index 5cc58d08..c0c00add 100644 --- a/varnish-cache/bin/varnishtest/tests/b00007.vtc +++ b/varnish-cache/bin/varnishtest/tests/b00007.vtc @@ -19,8 +19,8 @@ server s1 { send "Transfer-encoding: chunked\r\n" send "\r\n" send "00000004\r\n1234\r\n" - send "00000004\r\n1234\r\n" - send "00000000\r\n" + chunked "1234" + chunked "" } server s1 -start diff --git a/varnish-cache/bin/varnishtest/vtc.c b/varnish-cache/bin/varnishtest/vtc.c index ef47e31e..d22becd0 100644 --- a/varnish-cache/bin/varnishtest/vtc.c +++ b/varnish-cache/bin/varnishtest/vtc.c @@ -61,11 +61,11 @@ read_file(const char *fn) err(1, "Cannot open %s", fn); buf = malloc(sz); assert(buf != NULL); - s = read(fd, buf, sz); + s = read(fd, buf, sz - 1); if (s <= 0) err(1, "Cannot read %s", fn); - assert(s < sz); /* XXX: increase MAX_FILESIZE */ AZ(close (fd)); + assert(s < sz); /* XXX: increase MAX_FILESIZE */ buf[s] = '\0'; buf = realloc(buf, s + 1); assert(buf != NULL); @@ -141,7 +141,7 @@ parse_string(char *buf, const struct cmds *cmd, void *priv) p++; } else if (*p == '{') { /* Braces */ nest_brace = 0; - token_s[tn] = p; + token_s[tn] = p + 1; for (; *p != '\0'; p++) { if (*p == '{') nest_brace++; @@ -151,7 +151,7 @@ parse_string(char *buf, const struct cmds *cmd, void *priv) } } assert(*p == '}'); - token_e[tn++] = ++p; + token_e[tn++] = p++; } else { /* other tokens */ token_s[tn] = p; for (; *p != '\0' && !isspace(*p); p++) @@ -228,7 +228,7 @@ cmd_shell(CMD_ARGS) AN(av[1]); AZ(av[2]); vtc_dump(vl, 4, "shell", av[1]); - system(av[1]); + (void)system(av[1]); /* XXX: assert ? */ } /********************************************************************** @@ -303,7 +303,7 @@ exec_file(const char *fn) */ int -main(int argc, char **argv) +main(int argc, char * const *argv) { int ch; diff --git a/varnish-cache/bin/varnishtest/vtc.h b/varnish-cache/bin/varnishtest/vtc.h index 0c0751fa..22332637 100644 --- a/varnish-cache/bin/varnishtest/vtc.h +++ b/varnish-cache/bin/varnishtest/vtc.h @@ -30,7 +30,7 @@ struct vsb; struct vtclog; struct cmds; -#define CMD_ARGS char **av, void *priv, const struct cmds *cmd +#define CMD_ARGS char * const *av, void *priv, const struct cmds *cmd typedef void cmd_f(CMD_ARGS); struct cmds { diff --git a/varnish-cache/bin/varnishtest/vtc_client.c b/varnish-cache/bin/varnishtest/vtc_client.c index 7349be61..b36774ce 100644 --- a/varnish-cache/bin/varnishtest/vtc_client.c +++ b/varnish-cache/bin/varnishtest/vtc_client.c @@ -208,11 +208,10 @@ cmd_client(CMD_ARGS) client_run(c); continue; } - if (**av == '{') { - c->spec = *av; - continue; + if (**av == '-') { + vtc_log(c->vl, 0, "Unknown client argument: %s", *av); + exit (1); } - vtc_log(c->vl, 0, "Unknown client argument: %s", *av); - exit (1); + c->spec = *av; } } diff --git a/varnish-cache/bin/varnishtest/vtc_http.c b/varnish-cache/bin/varnishtest/vtc_http.c index ab7272b9..7d02a0fe 100644 --- a/varnish-cache/bin/varnishtest/vtc_http.c +++ b/varnish-cache/bin/varnishtest/vtc_http.c @@ -51,6 +51,8 @@ struct http { int timeout; struct vtclog *vl; + struct vsb *vsb; + int nrxbuf; char *rxbuf; @@ -58,12 +60,31 @@ struct http { char *resp[MAX_HDR]; }; +/* XXX: we may want to vary this */ +static const char *nl = "\r\n"; + +/********************************************************************** + * Finish and write the vsb to the fd + */ + +static void +http_write(const struct http *hp, int lvl, const char *pfx) +{ + int l; + + vsb_finish(hp->vsb); + AZ(vsb_overflowed(hp->vsb)); + vtc_dump(hp->vl, lvl, pfx, vsb_data(hp->vsb)); + l = write(hp->fd, vsb_data(hp->vsb), vsb_len(hp->vsb)); + assert(l == vsb_len(hp->vsb)); +} + /********************************************************************** * find header */ static char * -http_find_header(char **hh, const char *hdr) +http_find_header(char * const *hh, const char *hdr) { int n, l; char *r; @@ -235,7 +256,7 @@ http_splitheader(struct http *hp, int req) */ static void -http_swallow_body(struct http *hp, char **hh) +http_swallow_body(const struct http *hp, char * const *hh) { char *p, b[BUFSIZ + 1]; int l, i; @@ -334,14 +355,11 @@ static void cmd_http_txresp(CMD_ARGS) { struct http *hp; - struct vsb *vsb; const char *proto = "HTTP/1.1"; const char *status = "200"; const char *msg = "Ok"; const char *body = NULL; int dohdr = 0; - const char *nl = "\r\n"; - int l; (void)cmd; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); @@ -349,7 +367,7 @@ cmd_http_txresp(CMD_ARGS) assert(!strcmp(av[0], "txresp")); av++; - vsb = vsb_newauto(); + vsb_clear(hp->vsb); for(; *av != NULL; av++) { if (!strcmp(*av, "-proto")) { @@ -377,11 +395,11 @@ cmd_http_txresp(CMD_ARGS) } if (!strcmp(*av, "-hdr")) { if (dohdr == 0) { - vsb_printf(vsb, "%s %s %s%s", + vsb_printf(hp->vsb, "%s %s %s%s", proto, status, msg, nl); dohdr = 1; } - vsb_printf(vsb, "%s%s", av[1], nl); + vsb_printf(hp->vsb, "%s%s", av[1], nl); av++; continue; } @@ -389,21 +407,16 @@ cmd_http_txresp(CMD_ARGS) exit (1); } if (dohdr == 0) { - vsb_printf(vsb, "%s %s %s%s", + vsb_printf(hp->vsb, "%s %s %s%s", proto, status, msg, nl); dohdr = 1; } - vsb_cat(vsb, nl); + vsb_cat(hp->vsb, nl); if (body != NULL) { - vsb_cat(vsb, body); - vsb_cat(vsb, nl); + vsb_cat(hp->vsb, body); + vsb_cat(hp->vsb, nl); } - vsb_finish(vsb); - AZ(vsb_overflowed(vsb)); - vtc_dump(hp->vl, 4, NULL, vsb_data(vsb)); - l = write(hp->fd, vsb_data(vsb), vsb_len(vsb)); - assert(l == vsb_len(vsb)); - vsb_delete(vsb); + http_write(hp, 4, "txresp"); } /********************************************************************** @@ -439,14 +452,11 @@ static void cmd_http_txreq(CMD_ARGS) { struct http *hp; - struct vsb *vsb; const char *req = "GET"; const char *url = "/"; const char *proto = "HTTP/1.1"; const char *body = NULL; int dohdr = 0; - const char *nl = "\r\n"; - int l; (void)cmd; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); @@ -454,7 +464,7 @@ cmd_http_txreq(CMD_ARGS) assert(!strcmp(av[0], "txreq")); av++; - vsb = vsb_newauto(); + vsb_clear(hp->vsb); for(; *av != NULL; av++) { if (!strcmp(*av, "-url")) { @@ -477,11 +487,11 @@ cmd_http_txreq(CMD_ARGS) } if (!strcmp(*av, "-hdr")) { if (dohdr == 0) { - vsb_printf(vsb, "%s %s %s%s", + vsb_printf(hp->vsb, "%s %s %s%s", req, url, proto, nl); dohdr = 1; } - vsb_printf(vsb, "%s%s", av[1], nl); + vsb_printf(hp->vsb, "%s%s", av[1], nl); av++; continue; } @@ -494,21 +504,16 @@ cmd_http_txreq(CMD_ARGS) exit (1); } if (dohdr == 0) { - vsb_printf(vsb, "%s %s %s%s", + vsb_printf(hp->vsb, "%s %s %s%s", req, url, proto, nl); dohdr = 1; } - vsb_cat(vsb, nl); + vsb_cat(hp->vsb, nl); if (body != NULL) { - vsb_cat(vsb, body); - vsb_cat(vsb, nl); + vsb_cat(hp->vsb, body); + vsb_cat(hp->vsb, nl); } - vsb_finish(vsb); - AZ(vsb_overflowed(vsb)); - vtc_dump(hp->vl, 4, NULL, vsb_data(vsb)); - l = write(hp->fd, vsb_data(vsb), vsb_len(vsb)); - assert(l == vsb_len(vsb)); - vsb_delete(vsb); + http_write(hp, 4, "txreq"); } /********************************************************************** @@ -531,6 +536,24 @@ cmd_http_send(CMD_ARGS) } +/********************************************************************** + * Send a string as chunked encoding + */ + +static void +cmd_http_chunked(CMD_ARGS) +{ + struct http *hp; + + (void)cmd; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AN(av[1]); + AZ(av[2]); + vsb_clear(hp->vsb); + vsb_printf(hp->vsb, "%x%s%s%s", strlen(av[1]), nl, av[1], nl); + http_write(hp, 4, "chunked"); +} + /********************************************************************** * Execute HTTP specifications @@ -543,6 +566,7 @@ static struct cmds http_cmds[] = { { "rxresp", cmd_http_rxresp }, { "expect", cmd_http_expect }, { "send", cmd_http_send }, + { "chunked", cmd_http_chunked }, { "delay", cmd_delay }, { NULL, NULL } }; @@ -560,14 +584,14 @@ http_process(struct vtclog *vl, const char *spec, int sock, int client) hp->client = client; hp->timeout = 1000; hp->nrxbuf = 8192; + hp->vsb = vsb_newauto(); + AN(hp->vsb); - s = strdup(spec + 1); + s = strdup(spec); q = strchr(s, '\0'); assert(q > s); - q--; - assert(*q == '}'); - *q = '\0'; AN(s); parse_string(s, http_cmds, hp); + vsb_delete(hp->vsb); free(hp); } diff --git a/varnish-cache/bin/varnishtest/vtc_log.c b/varnish-cache/bin/varnishtest/vtc_log.c index 44b85be0..c352d3ac 100644 --- a/varnish-cache/bin/varnishtest/vtc_log.c +++ b/varnish-cache/bin/varnishtest/vtc_log.c @@ -73,6 +73,7 @@ static const char *lead[] = { #define NLEAD (sizeof(lead)/sizeof(lead[0])) +//lint -e{818} void vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...) { @@ -98,6 +99,7 @@ vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...) * Dump a string */ +//lint -e{818} void vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str) { diff --git a/varnish-cache/bin/varnishtest/vtc_server.c b/varnish-cache/bin/varnishtest/vtc_server.c index 71ed0534..02373ce5 100644 --- a/varnish-cache/bin/varnishtest/vtc_server.c +++ b/varnish-cache/bin/varnishtest/vtc_server.c @@ -252,11 +252,10 @@ cmd_server(CMD_ARGS) server_wait(s); continue; } - if (**av == '{') { - s->spec = *av; - continue; + if (**av == '-') { + vtc_log(s->vl, 0, "Unknown server argument: %s", *av); + exit (1); } - vtc_log(s->vl, 0, "Unknown server argument: %s", *av); - exit (1); + s->spec = *av; } } diff --git a/varnish-cache/bin/varnishtest/vtc_varnish.c b/varnish-cache/bin/varnishtest/vtc_varnish.c index 2d3cff44..8afc7840 100644 --- a/varnish-cache/bin/varnishtest/vtc_varnish.c +++ b/varnish-cache/bin/varnishtest/vtc_varnish.c @@ -29,19 +29,17 @@ #include -#include #include #include #include #include -#include #include +#include #include #include #include - #include "vqueue.h" #include "miniobj.h" #include "libvarnish.h" @@ -91,7 +89,7 @@ varnish_ask_cli(const struct varnish *v, const char *cmd, char **repl) assert(i == strlen(cmd)); i = write(v->cli_fd, "\n", 1); assert(i == 1); - i = cli_readres(v->cli_fd, &retval, &r, 1000); + i = cli_readres(v->cli_fd, &retval, &r, 1.0); assert(i == 0); vtc_dump(v->vl, 4, "CLI RX", r); vtc_log(v->vl, 3, "CLI STATUS %u", retval); @@ -358,10 +356,9 @@ varnish_vcl(struct varnish *v, const char *vcl) */ static void -varnish_vclbackend(struct varnish *v, char *vcl) +varnish_vclbackend(struct varnish *v, const char *vcl) { struct vsb *vsb, *vsb2; - char *p; enum cli_status_e u; if (v->cli_fd < 0) @@ -381,11 +378,6 @@ varnish_vclbackend(struct varnish *v, char *vcl) varnish_cli_encode(vsb, vsb_data(vsb2)); - if (*vcl == '{') { - p = strchr(++vcl, '\0'); - if (p > vcl && p[-1] == '}') - p[-1] = '\0'; - } varnish_cli_encode(vsb, vcl); vsb_printf(vsb, "\"", *vcl); -- 2.39.5