VTC·续1

filewrite#

Write strings to file

filewrite [-a] /somefile “Hello” “ “ “Worldn”

The -a flag opens the file in append mode.

haproxy#

Define and interact with haproxy instances.

To define a haproxy server, you’ll use this syntax:

haproxy hNAME -conf-OK CONFIG
haproxy hNAME -conf-BAD ERROR CONFIG
haproxy hNAME [-D] [-W] [-arg STRING] [-conf[+vcl] STRING]

The first haproxy hNAME invocation will start the haproxy master process in the background, waiting for the -start switch to actually start the child.

Arguments:

hNAME Identify the HAProxy server with a string, it must starts with ‘h’. -conf-OK CONFIG

Run haproxy in ‘-c’ mode to check config is OK stdout/stderr should contain ‘Configuration file is valid’ The exit code should be 0. -conf-BAD ERROR CONFIG

Run haproxy in ‘-c’ mode to check config is BAD. “ERROR” should be part of the diagnostics on stdout/stderr. The exit code should be 1. -D Run HAproxy in daemon mode. If not given ‘-d’ mode used. -W Enable HAproxy in Worker mode. -S Enable HAproxy Master CLI in Worker mode -arg STRING Pass an argument to haproxy, for example “-h simple_list”. -cli STRING Specify the spec to be run by the command line interface (CLI). -mcli STRING Specify the spec to be run by the command line interface (CLI) of the Master process. -conf STRING Specify the configuration to be loaded by this HAProxy instance. -conf+backend STRING

Specify the configuration to be loaded by this HAProxy instance, all server instances will be automatically appended -start Start this HAProxy instance. -wait Stop this HAProxy instance. -expectexit NUMBER Expect haproxy to exit(3) with this value

haproxy CLI Specification#

expect OP STRING Regex match the CLI reception buffer with STRING if OP is ~ or, on the contrary, if OP is !~ check that there is no regex match.

send STRING Push STRING on the CLI connection. STRING will be terminated by an end of line character (n).

include#

Executes a vtc fragment:

include FILE [...]

Open a file and execute it as a VTC fragment. This command is available everywhere commands are given.

logexpect#

Reads the VSL and looks for records matching a given specification. It will process records trying to match the first pattern, and when done, will continue processing, trying to match the following pattern. If a pattern isn’t matched, the test will fail.

logexpect threads are declared this way:

logexpect lNAME -v <id> [-g <grouping>] [-d 0|1] [-q query] \
        [vsl arguments] {
                expect <skip> <vxid> <tag> <regex>
                expect <skip> <vxid> <tag> <regex>
                fail add <vxid> <tag> <regex>
                fail clear
                abort
                ...
        } [-start|-wait|-run]

And once declared, you can start them, or wait on them:

logexpect lNAME <-start|-wait>

With:

lNAME Name the logexpect thread, it must start with ‘l’. -v id Specify the varnish instance to use (most of the time, id=v1). -g <session|request|vxid|raw Decide how records are grouped, see -g in man varnishlog for more information. -d <0|1> Start processing log records at the head of the log instead of the tail. -q query Filter records using a query expression, see man vsl-query for more information. Multiple -q options are not supported. -m Also emit log records for misses (only for debugging) -err Invert the meaning of success. Usually called once to expect the logexpect to fail -start Start the logexpect thread in the background. -wait Wait for the logexpect thread to finish -run Equivalent to “-start -wait”.

VSL arguments (similar to the varnishlog options):

-C Use caseless regex -i Include tags -I <[taglist:]regex> Include by regex -T Transaction end timeout

expect specification:

skip: [uint||?] Max number of record to skip vxid: [uint||=] vxid to match tag: [tagname|*|=] Tag to match against regex: regular expression to match against (optional)

For skip, vxid and tag, ‘*’ matches anything, ‘=’ expects the value of the previous matched record. The ‘?’ marker is equivalent to zero, expecting a match on the next record. The difference is that ‘?’ can be used when the order of individual consecutive logs is not deterministic. In other words, lines from a block of alternatives marked by ‘?’ can be matched in any order, but all need to match eventually.

fail specification:

add: Add to the fail list

Arguments are equivalent to expect, except for skip missing

clear: Clear the fail list

Any number of fail specifications can be active during execution of a logexpect. All active fail specifications are matched against every log line and, if any match, the logexpect fails immediately.

For a logexpect to end successfully, there must be no specs on the fail list, so logexpects should always end with

expect fail clear

abort specification:

abort(3) varnishtest, intended to help debugging of the VSL client library itself.

loop#

loop NUMBER STRING Process STRING as a specification, NUMBER times.

This works inside all specification strings

process#

Run a process with stdin+stdout on a pseudo-terminal and stderr on a pipe.

Output from the pseudo-terminal is copied verbatim to ${pNAME_out}, and the -log/-dump/-hexdump flags will also put it in the vtc-log.

The pseudo-terminal is not in ECHO mode, but if the programs run set it to ECHO mode (“stty sane”) any input sent to the process will also appear in this stream because of the ECHO.

Output from the stderr-pipe is copied verbatim to ${pNAME_err}, and is always included in the vtc_log.

process pNAME SPEC [-allow-core] [-expect-exit N] [-expect-signal N] [-dump] [-hexdump] [-log] [-run] [-close] [-kill SIGNAL] [-start] [-stop] [-wait] [-write STRING] [-writeln STRING] [-writehex HEXSTRING] [-need-bytes [+]NUMBER] [-screen-dump] [-winsz LINES COLUMNS] [-ansi-response] [-expect-cursor LINE COLUMN] [-expect-text LINE COLUMN TEXT] [-match-text LINE COLUMN REGEXP]

pNAME Name of the process. It must start with ‘p’. SPEC The command(s) to run in this process. -hexdump Log output with vtc_hexdump(). Must be before -start/-run. -dump Log output with vtc_dump(). Must be before -start/-run. -log Log output with VLU/vtc_log(). Must be before -start/-run. -start Start the process. -expect-exit N Expect exit status N -expect-signal N Expect signal in exit status N -allow-core Core dump in exit status is OK -wait Wait for the process to finish. -run Shorthand for -start -wait.
In most cases, if you just want to start a process and wait for it to finish, you can use the shell command instead. The following commands are equivalent:

shell "do --something" <br/> process p1 "do --something" -run

However, you may use the process variant to conveniently collect the standard input and output without dealing with shell redirections yourself. The shell command can also expect an expression from either output, consider using it if you only need to match one. -key KEYSYM Send emulated key-press. KEYSYM can be one of (NPAGE, PPAGE, HOME, END) -kill SIGNAL Send a signal to the process. The argument can be either the string “TERM”, “INT”, or “KILL” for SIGTERM, SIGINT or SIGKILL signals, respectively, or a hyphen (-) followed by the signal number.
If you need to use other signal names, you can use the kill(1) command directly:

shell "kill -USR1 ${pNAME_pid}"

Note that SIGHUP usage is discouraged in test cases. -stop Shorthand for -kill TERM. -close Alias for “-kill HUP” -winsz LINES COLUMNS Change the terminal window size to LIN lines and COL columns. -write STRING Write a string to the process’ stdin. -writeln STRING Same as -write followed by a newline (\n). -writehex HEXSTRING Same as -write but interpreted as hexadecimal bytes. -need-bytes [+]NUMBER Wait until at least NUMBER bytes have been received in total. If ‘+’ is prefixed, NUMBER new bytes must be received. -ansi-response Respond to terminal respond-back sequences -expect-cursor LINE COLUMN Expect cursors location -expect-text LINE COLUMNS TEXT Wait for TEXT to appear at LIN,COL on the virtual screen. Lines and columns are numbered 1…N LIN==0 means “on any line” COL==0 means “anywhere on the line” -match-text LINE COLUMN REGEXP Wait for the PAT regular expression to match the text at LIN,COL on the virtual screen. Lines and columns are numbered 1…N LIN==0 means “on any line” COL==0 means “anywhere on the line” -screen-dump Dump the virtual screen into vtc_log

setenv#

Set or change an environment variable:

setenv FOO "bar baz"

The above will set the environment variable $FOO to the value provided. There is also an -ifunset argument which will only set the value if the environment variable does not already exist:

setenv -ifunset FOO quux

shell#

NOTE: This command is available everywhere commands are given.

Pass the string given as argument to a shell. If you have multiple commands to run, you can use curly brackets to describe a multi-lines script, eg:

shell {
        echo begin
        cat /etc/fstab
        echo end
}

By default a zero exit code is expected, otherwise the vtc will fail.

Notice that the commandstring is prefixed with “exec 2>&1;” to combine stderr and stdout back to the test process.

Optional arguments:

-err Expect non-zero exit code. -exit N Expect exit code N instead of zero. -expect STRING Expect string to be found in stdout+err. -match REGEXP Expect regexp to match the stdout+err output.

stream#

(note: this section is at the top-level for easier navigation, but it’s part of the client/server specification)

Streams map roughly to a request in HTTP/2, a request is sent on stream N, the response too, then the stream is discarded. The main exception is the first stream, 0, that serves as coordinator.

Stream syntax follow the client/server one:

stream ID [SPEC] [ACTION]

ID is the HTTP/2 stream number, while SPEC describes what will be done in that stream. If ID has the value next, the actual stream number is computed based on the last one.

Note that, when parsing a stream action, if the entity isn’t operating in HTTP/2 mode, these spec is ran before:

txpri/rxpri # client/server
stream 0 {
    txsettings
    rxsettings
    txsettings -ack
    rxsettings
    expect settings.ack == true
} -run

And HTTP/2 mode is then activated before parsing the specification.

Actions#

-start Run the specification in a thread, giving back control immediately. -wait Wait for the started thread to finish running the spec. -run equivalent to calling -start then -wait.

Specification#

The specification of a stream follows the exact same rules as one for a client or a server.

txreq, txresp, txcont, txpush#

These four commands are about sending headers. txreq and txresp will send HEADER frames; txcont will send CONTINUATION frames; txpush PUSH frames. The only difference between txreq and txresp are the default headers set by each of them.

-noadd Do not add default headers. Useful to avoid duplicates when sending default headers using -hdr, -idxHdr and -litIdxHdr. -status INT (txresp) Set the :status pseudo-header. -url STRING (txreq, txpush) Set the :path pseudo-header. -method STRING (txreq, txpush) Set the :method pseudo-header. -req STRING (txreq, txpush) Alias for -method. -scheme STRING (txreq, txpush) Set the :scheme pseudo-header. -hdr STRING1 STRING2 Insert a header, STRING1 being the name, and STRING2 the value. -idxHdr INT Insert an indexed header, using INT as index. -litIdxHdr inc|not|never INT huf|plain STRING Insert an literal, indexed header. The first argument specify if the header should be added to the table, shouldn’t, or mustn’t be compressed if/when retransmitted.
INT is the index of the header name to use.
The third argument informs about the Huffman encoding: yes (huf) or no (plain).
The last term is the literal value of the header. -litHdr inc|not|never huf|plain STRING1 huf|plain STRING2 Insert a literal header, with the same first argument as -litIdxHdr.
The second and third terms tell what the name of the header is and if it should be Huffman-encoded, while the last two do the same regarding the value. -body STRING (txreq, txresp) Specify a body, effectively putting STRING into a DATA frame after the HEADER frame is sent. -bodyfrom FILE (txreq, txresp) Same as -body but content is read from FILE. -bodylen INT (txreq, txresp) Do the same thing as -body but generate a string of INT length for you. -gzipbody STRING (txreq, txresp) Gzip STRING and send it as body. -gziplen NUMBER (txreq, txresp) Combine -bodylen and -gzipbody: generate a string of length NUMBER, gzip it and send as body. -nostrend (txreq, txresp) Don’t set the END_STREAM flag automatically, making the peer expect a body after the headers. -nohdrend Don’t set the END_HEADERS flag automatically, making the peer expect more HEADER frames. -dep INT (txreq, txresp) Tell the peer that this content depends on the stream with the INT id. -ex (txreq, txresp) Make the dependency exclusive (-dep is still needed). -weight (txreq, txresp) Set the weight for the dependency. -promised INT (txpush) The id of the promised stream. -pad STRING / -padlen INT (txreq, txresp, txpush) Add string as padding to the frame, either the one you provided with -pad, or one that is generated for you, of length INT is -padlen case.

txdata#

By default, data frames are empty. The receiving end will know the whole body has been delivered thanks to the END_STREAM flag set in the last DATA frame, and txdata automatically set it.

-data STRING Data to be embedded into the frame. -datalen INT Generate and INT-bytes long string to be sent in the frame. -pad STRING / -padlen INT Add string as padding to the frame, either the one you provided with -pad, or one that is generated for you, of length INT is -padlen case. -nostrend Don’t set the END_STREAM flag, allowing to send more data on this stream.

rxreq, rxresp#

These are two convenience functions to receive headers and body of an incoming request or response. The only difference is that rxreq can only be by a server, and rxresp by a client.

rxhdrs#

rxhdrs will expect one HEADER frame, then, depending on the arguments, zero or more CONTINUATION frame.

-all Keep waiting for CONTINUATION frames until END_HEADERS flag is seen. -some INT Retrieve INT - 1 CONTINUATION frames after the HEADER frame.

rxpush#

This works like rxhdrs, expecting a PUSH frame and then zero or more CONTINUATION frames.

-all Keep waiting for CONTINUATION frames until END_HEADERS flag is seen. -some INT Retrieve INT - 1 CONTINUATION frames after the PUSH frame.

rxdata#

Receiving data is done using the rxdata keywords and will retrieve one DATA frame, if you wish to receive more, you can use these two convenience arguments: