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
2f5ac240
Commit
2f5ac240
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
d9c3cdda
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
16 deletions
+56
-16
u00003.vtc
bin/varnishtest/tests/u00003.vtc
+5
-1
u00006.vtc
bin/varnishtest/tests/u00006.vtc
+8
-4
vtc.c
bin/varnishtest/vtc.c
+43
-11
No files found.
bin/varnishtest/tests/u00003.vtc
View file @
2f5ac240
...
...
@@ -9,6 +9,10 @@ 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" \
...
...
@@ -71,5 +75,5 @@ 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 -
expect "0 miss
" \
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
View file @
2f5ac240
...
...
@@ -42,7 +42,8 @@ shell -err -expect {-X: Syntax error in "**"} \
process p1 -wait
shell {grep -q "0 CLI" ${tmpdir}/vlog}
shell -expect "0 CLI" "varnishlog -n ${v1_name} -d -g raw"
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
...
...
@@ -63,7 +64,10 @@ delay 1
shell "kill `cat ${tmpdir}/vlog.pid`"
shell -expect "/foo" {
varnishlog -r ${tmpdir}/vlog.bin~ -i ReqURL -q "RespStatus == 200"
shell -match {^\*[ ]+<< Request\s+>>[ ]+1001[ ]+
-[ ]+1001 ReqURL[ ]+c /foo
$} {
varnishlog -v -r ${tmpdir}/vlog.bin~ -i ReqURL -q "RespStatus == 200"
}
shell -expect "/bar" "varnishlog -r ${tmpdir}/vlog.bin -x ReqURL"
shell -match "-[ ]+BereqURL[ ]+/bar" \
"varnishlog -r ${tmpdir}/vlog.bin -x ReqURL"
bin/varnishtest/vtc.c
View file @
2f5ac240
...
...
@@ -430,8 +430,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
...
...
@@ -452,8 +453,11 @@ cmd_varnishtest(CMD_ARGS)
* \-exit N
* Expect exit code N instead of zero.
*
* \-expect string
* Expect str to be found in stdout+err.
* \-expect STRING
* Expect string to be found in stdout+err.
*
* \-match REGEXP
* Expect regexp to match the stdout+err output.
*/
/* SECTION: client-server.spec.shell shell
*
...
...
@@ -461,17 +465,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_fatal
(
vl
,
"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
);
...
...
@@ -503,6 +516,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_fatal
(
vl
,
"shell_match failed: (
\"
%s
\"
)"
,
re
);
else
vtc_log
(
vl
,
4
,
"shell_match succeeded"
);
VRE_free
(
&
vre
);
}
VSB_destroy
(
&
vsb
);
}
...
...
@@ -511,11 +532,13 @@ cmd_shell_engine(struct vtclog *vl, int ok,
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
;
...
...
@@ -526,14 +549,23 @@ cmd_shell(CMD_ARGS)
n
+=
1
;
ok
=
atoi
(
av
[
n
]);
}
else
if
(
!
strcmp
(
av
[
n
],
"-expect"
))
{
if
(
re
!=
NULL
)
vtc_fatal
(
vl
,
"Cannot use -expect with -match"
);
n
+=
1
;
expect
=
av
[
n
];
}
else
if
(
!
strcmp
(
av
[
n
],
"-match"
))
{
if
(
expect
!=
NULL
)
vtc_fatal
(
vl
,
"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
);
}
/* SECTION: err_shell err_shell
...
...
@@ -560,7 +592,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
);
}
/* SECTION: delay delay
...
...
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