Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
0dffccfe
Commit
0dffccfe
authored
Jan 21, 2017
by
Federico G. Schwindt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add regexp matching support to the shell command
Change some tests to use the new parameter and more coverage.
parent
b0916736
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
191 additions
and
9 deletions
+191
-9
u00003.vtc
bin/varnishtest/tests/u00003.vtc
+79
-0
u00006.vtc
bin/varnishtest/tests/u00006.vtc
+73
-0
vtc.c
bin/varnishtest/vtc.c
+39
-9
No files found.
bin/varnishtest/tests/u00003.vtc
0 → 100644
View file @
0dffccfe
varnishtest "varnishncsa coverage"
server s1 -repeat 2 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {} -start
shell "varnishncsa -n ${v1_name} -D -P ${tmpdir}/ncsa.pid -w ${tmpdir}/ncsa.log"
shell -expect "Usage: varnishncsa <options>" \
"varnishncsa -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishncsa -V"
shell -err -expect "Missing -w option" \
{varnishncsa -D}
shell -err -expect "Unknown format specifier at: %{foo}A" \
{varnishncsa -F "%{foo}A"}
shell -err -expect "Unknown format specifier at: %A" \
{varnishncsa -F "%A"}
shell -err -expect "Unknown formatting extension: foo" \
{varnishncsa -F "%{foo}x"}
shell -err -expect "Usage: varnishncsa <options>" \
{varnishncsa extra}
shell -err -expect "Missing tag in VSL:" \
{varnishncsa -F "%{VSL:}x"}
shell -err -expect "Unknown log tag: nonexistent" \
{varnishncsa -F "%{VSL:nonexistent}x"}
shell -err -expect "Tag not unique: Req" \
{varnishncsa -F "%{VSL:Req}x"}
shell -err -expect "Unknown log tag: Begin[" \
{varnishncsa -F "%{VSL:Begin[}x"}
shell -err -expect "Syntax error: VSL:Begin]" \
{varnishncsa -F "%{VSL:Begin]}x"}
shell -err -expect "Unknown log tag: Begin[a" \
{varnishncsa -F "%{VSL:Begin[a}x"}
shell -err -expect "Syntax error: VSL:Begin[a]" \
{varnishncsa -F "%{VSL:Begin[a]}x"}
shell -err -expect "Syntax error. Field specifier must be positive: Begin[0]" \
{varnishncsa -F "%{VSL:Begin[0]}x"}
shell -err -expect "Field specifier 999999999999 for the tag VSL:Begin[999999999999] is probably too high" \
{varnishncsa -F "%{VSL:Begin[999999999999]}x"}
shell -err -expect "Can't open format file (No such file or directory)" \
{varnishncsa -f /nonexistent/file}
shell -err -expect "Empty format file" \
{varnishncsa -f /dev/null}
# In Linux and SunOS, getline(3) fails when the stream refers to a
# directory but happily works in FreeBSD.
#shell -err -expect "Can't read format from file (Is a directory)" \
# {varnishncsa -f ${tmpdir}}
delay 1
client c1 {
txreq -url /foo
rxresp
} -run
delay 1
shell "mv ${tmpdir}/ncsa.log ${tmpdir}/ncsa.old.log >/dev/null 2>&1"
shell "kill -HUP `cat ${tmpdir}/ncsa.pid`"
client c1 {
txreq -url /bar
rxresp
} -run
delay 1
shell "kill `cat ${tmpdir}/ncsa.pid`"
shell "grep -q /foo ${tmpdir}/ncsa.old.log"
shell "grep -q /bar ${tmpdir}/ncsa.log"
shell {echo "%{VSL:Begin}x %{Varnish:vxid}x %D %T %{Varnish:handling}x %{%Z}t" >${tmpdir}/format}
shell -match "req 1000 rxreq 1001 [0-9]{5} 0 miss [A-Z]{3,}" \
{varnishncsa -n ${v1_name} -d -f ${tmpdir}/format}
bin/varnishtest/tests/u00006.vtc
0 → 100644
View file @
0dffccfe
varnishtest "varnishlog coverage"
server s1 -repeat 2 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {} -start
process p1 {
exec varnishlog -n ${v1_name} -g raw -k 3 -w ${tmpdir}/vlog -A
} -start
shell {
exec varnishlog -n ${v1_name} -D -P ${tmpdir}/vlog.pid \
-w ${tmpdir}/vlog.bin
}
shell -expect "Usage: varnishlog <options>" \
"varnishlog -h"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
"varnishlog -V"
shell -err -expect "Usage: varnishlog <options>" \
"varnishlog extra"
shell -err -expect "Missing -w option" \
"varnishlog -D"
shell -err -expect "-L: Range error" \
"varnishlog -L 0"
shell -err -expect {-i: "foo" matches zero tags} \
"varnishlog -i foo"
shell -err -expect {-i: "Resp" is ambiguous} \
"varnishlog -i Resp"
shell -err -expect {-I: "foo" matches zero tags} \
"varnishlog -I foo:bar"
shell -err -expect {-I: "Resp" is ambiguous} \
"varnishlog -I Resp:bar"
shell -err -expect {-I: Regex error at position 4 (missing ))} \
{varnishlog -I "(foo"}
shell -err -expect {-x: Syntax error in "**"} \
{varnishlog -x "**"}
shell -err -expect {-X: Syntax error in "**"} \
{varnishlog -X "**:bar"}
process p1 -wait
shell {grep -q "0 CLI" ${tmpdir}/vlog}
shell -match "0 CLI[ ]+- Wr 200 [0-9]+ PONG" \
{varnishlog -n ${v1_name} -d -g raw -X "Wr 200 [0-9]+ [^P]"}
client c1 {
txreq -url /foo
rxresp
} -run
delay 1
shell "mv ${tmpdir}/vlog.bin ${tmpdir}/vlog.bin~ >/dev/null 2>&1"
shell "kill -HUP `cat ${tmpdir}/vlog.pid`"
client c1 {
txreq -url /bar
rxresp
} -run
delay 1
shell "kill `cat ${tmpdir}/vlog.pid`"
shell -match {^\*[ ]+<< Request\s+>>[ ]+1001[ ]+
-[ ]+1001 ReqURL[ ]+c /foo
$} {
varnishlog -v -r ${tmpdir}/vlog.bin~ -i ReqURL -q "RespStatus == 200"
}
shell -match "-[ ]+BereqURL[ ]+/bar" \
"varnishlog -r ${tmpdir}/vlog.bin -x ReqURL"
bin/varnishtest/vtc.c
View file @
0dffccfe
...
...
@@ -427,8 +427,9 @@ cmd_varnishtest(CMD_ARGS)
/* SECTION: shell shell
*
* Pass the string given as argument to a shell. If you have multiple commands
* to run, you can use curly barces to describe a multi-lines script, eg::
* Pass the string given as argument to a shell. If you have multiple
* commands to run, you can use curly barces to describe a multi-lines
* script, eg::
*
* shell {
* echo begin
...
...
@@ -449,6 +450,7 @@ cmd_varnishtest(CMD_ARGS)
*
* -expect string - expect str to be found in stdout+err
*
* -match regexp - expect regexp to match the stdout+err output
* The vtc will fail if the return code of the shell is not 0.
*/
/* SECTION: client-server.spec.shell shell
...
...
@@ -457,17 +459,26 @@ cmd_varnishtest(CMD_ARGS)
*/
static
void
cmd_shell_engine
(
struct
vtclog
*
vl
,
int
ok
,
const
char
*
cmd
,
const
char
*
expect
)
cmd_shell_engine
(
struct
vtclog
*
vl
,
int
ok
,
const
char
*
cmd
,
const
char
*
expect
,
const
char
*
re
)
{
struct
vsb
*
vsb
;
FILE
*
fp
;
vre_t
*
vre
=
NULL
;
const
char
*
errptr
;
int
r
,
c
;
int
err
;
AN
(
vl
);
AN
(
cmd
);
vsb
=
VSB_new_auto
();
AN
(
vsb
);
if
(
re
!=
NULL
)
{
vre
=
VRE_compile
(
re
,
0
,
&
errptr
,
&
err
);
if
(
vre
==
NULL
)
vtc_log
(
vl
,
0
,
"shell_match invalid regexp (
\"
%s
\"
)"
,
re
);
}
VSB_printf
(
vsb
,
"exec 2>&1 ; %s"
,
cmd
);
AZ
(
VSB_finish
(
vsb
));
vtc_dump
(
vl
,
4
,
"shell_cmd"
,
VSB_data
(
vsb
),
-
1
);
...
...
@@ -499,6 +510,14 @@ cmd_shell_engine(struct vtclog *vl, int ok,
"shell_expect not found: (
\"
%s
\"
)"
,
expect
);
else
vtc_log
(
vl
,
4
,
"shell_expect found"
);
}
else
if
(
vre
!=
NULL
)
{
if
(
VRE_exec
(
vre
,
VSB_data
(
vsb
),
VSB_len
(
vsb
),
0
,
0
,
NULL
,
0
,
NULL
)
<
1
)
vtc_log
(
vl
,
0
,
"shell_match failed: (
\"
%s
\"
)"
,
re
);
else
vtc_log
(
vl
,
4
,
"shell_match succeeded"
);
VRE_free
(
&
vre
);
}
VSB_destroy
(
&
vsb
);
}
...
...
@@ -507,11 +526,13 @@ cmd_shell_engine(struct vtclog *vl, int ok,
static
void
cmd_shell
(
CMD_ARGS
)
{
(
void
)
priv
;
(
void
)
cmd
;
const
char
*
expect
=
NULL
;
const
char
*
re
=
NULL
;
int
n
;
int
ok
=
0
;
const
char
*
expect
=
NULL
;
(
void
)
priv
;
(
void
)
cmd
;
if
(
av
==
NULL
)
return
;
...
...
@@ -522,14 +543,23 @@ cmd_shell(CMD_ARGS)
n
+=
1
;
ok
=
atoi
(
av
[
n
]);
}
else
if
(
!
strcmp
(
av
[
n
],
"-expect"
))
{
if
(
re
!=
NULL
)
vtc_log
(
vl
,
0
,
"Cannot use -expect with -match"
);
n
+=
1
;
expect
=
av
[
n
];
}
else
if
(
!
strcmp
(
av
[
n
],
"-match"
))
{
if
(
expect
!=
NULL
)
vtc_log
(
vl
,
0
,
"Cannot use -match with -expect"
);
n
+=
1
;
re
=
av
[
n
];
}
else
{
break
;
}
}
AN
(
av
[
n
]);
cmd_shell_engine
(
vl
,
ok
,
av
[
n
],
expect
);
cmd_shell_engine
(
vl
,
ok
,
av
[
n
],
expect
,
re
);
}
/**********************************************************************
...
...
@@ -549,7 +579,7 @@ cmd_err_shell(CMD_ARGS)
AZ
(
av
[
3
]);
vtc_log
(
vl
,
1
,
"NOTICE: err_shell is deprecated, use 'shell -err -expect'"
);
cmd_shell_engine
(
vl
,
-
1
,
av
[
2
],
av
[
1
]);
cmd_shell_engine
(
vl
,
-
1
,
av
[
2
],
av
[
1
]
,
NULL
);
}
/**********************************************************************
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment