VTC

Vinyl Cache Test Case Syntax

Manual section:

7

OVERVIEW

This document describes the syntax used by Vinyl Cache Test Cases files (.vtc). A vtc file describe a scenario with different scripted HTTP-talking entities, and generally one or more Vinyl Cache instances to test.

PARSING

A vtc file will be read word after word, with very little tokenization, meaning a syntax error won’t be detected until the test actually reach the relevant action in the test.

A parsing error will most of the time result in an assert being triggered. If this happens, please refer yourself to the related source file and line number. However, this guide should help you avoid the most common mistakes.

Words and strings

The parser splits words by detecting whitespace characters and a string is a word, or a series of words on the same line enclosed by double-quotes (”…”), or, for multi-line strings, enclosed in curly brackets ({…}).

Comments

The leading whitespaces of lines are ignored. Empty lines (or ones consisting only of whitespaces) are ignored too, as are the lines starting with “#” that are comments.

Lines and commands

Test files take at most one command per line, with the first word of the line being the command and the following ones being its arguments. To continue over to a new line without breaking the argument string, you can escape the newline character (\n) with a backslash (\).

MACROS

When a string is processed, macro expansion is performed. Macros are in the form ${<name>[,<args>...]}, they have a name followed by an optional comma- or space-separated list of arguments. Leading and trailing spaces are ignored.

The macros ${foo,bar,baz} and ${ foo bar baz } are equivalent. If an argument contains a space or a comma, arguments can be quoted. For example the macro ${foo,"bar,baz"} gives one argument bar,baz to the macro called foo.

Unless documented otherwise, all macros are simple macros that don’t take arguments.

Built-in macros

${bad_backend}

A socket address that will reliably never accept connections.

${bad_ip}

An unlikely IPv4 address.

${date}

The current date and time formatted for HTTP.

${listen_addr}

The default listen address various components use, by default a random port on localhost.

${localhost}

The first IP address that resolves to “localhost”.

${pwd}

The working directory from which vinyltest was executed.

${string,<action>[,<args>...]}

The string macro is the entry point for text generation, it takes a specialized action with each its own set of arguments.

${string,repeat,<uint>,<str>}

Repeat uint times the string str.

${testdir}

The directory containing the VTC script of the ongoing test case execution.

${tmpdir}

The dedicated working directory for the ongoing test case execution, which happens to also be the current working directory. Useful when an absolute path to the working directory is needed.

${topbuild}

Only present when the -i option is used, to work on Vinyl Cache itself instead of a regular installation.

SYNTAX

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 vinyl instance to use (most of the time, id=v1).

-g <session|request|vxid|raw

Decide how records are grouped, see -g in man vinyllog 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 vinyllog options):

-C

Use caseless regex

-i <taglist>

Include tags

-I <[taglist:]regex>

Include by regex

-T <seconds>

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 <skip> <vxid> <tag> <termination-condition> fail clear

abort specification:

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

vinyl

Define and interact with vinyl instances.

To define a vinyld, you’ll use this syntax:

vinyl vNAME [-arg STRING] [-vcl STRING] [-vcl+backend STRING]
        [-errvcl STRING STRING] [-jail STRING] [-proto PROXY]

The first vinyl vNAME invocation will start the vinyld master process in the background, waiting for the -start switch to actually start the child.

Types used in the description below:

PATTERN

is a ‘glob’ style pattern (ie: fnmatch(3)) as used in shell filename expansion.

Arguments:

vNAME

Identify the vinyld server with a string, it must starts with ‘v’.

-arg STRING

Pass an argument to vinyld, for example “-h simple_list”.

If the ${vinyld_args_prepend} or ${vinyld_args_append} macros are defined, they are expanded and inserted before / appended to the vinyld command line as constructed by vinyltest, before the command line itself is expanded. This enables tweaks to the vinyld command line without editing test cases. This macros can be defined using the -D option for vinyltest.

-vcl STRING

Specify the VCL to load on this vinyld instance. You’ll probably want to use multi-lines strings for this ({…}).

-vcl+backend STRING

Do the exact same thing as -vcl, but adds the definition block of known backends (ie. already defined).

-errvcl STRING1 STRING2

Load STRING2 as VCL, expecting it to fail, and vinyld to send an error string matching STRING1

-jail STRING

Look at man vinyld (-j) for more information.

-proto PROXY

Have vinyld use the proxy protocol. Note that PROXY here is the actual string.

You can decide to start the vinyld instance and/or wait for several events:

vinyl vNAME [-start] [-wait] [-wait-running] [-wait-stopped]
-start

Start the child process.

Once successfully started, the following macros are available for the default listen address: ${vNAME_addr}, ${vNAME_port} and ${vNAME_sock}. Additional macros are available, including the listen address name for each address vNAME listens to, like for example: ${vNAME_a0_addr}.

-stop

Stop the child process.

-syntax

Set the VCL syntax level for this command (default: 4.1)

-wait

Wait for that instance to terminate.

-wait-running

Wait for the vinyld child process to be started.

-wait-stopped

Wait for the vinyld child process to stop.

-cleanup

Once vinyld is stopped, clean everything after it. This is only used in very few tests and you should never need it.

-expectexit NUMBER

Expect vinyld to exit(3) with this value

Once vinyld is started, you can talk to it (as you would through vinyladm) with these additional switches:

vinyl vNAME [-cli STRING] [-cliok STRING] [-clierr STRING]
              [-clijson STRING]
-cli STRING|-cliok STRING|-clierr STATUS STRING|-cliexpect [!] REGEXP STRING

All four of these will send STRING to the CLI, the only difference is what they expect the result to be. -cli doesn’t expect anything, -cliok expects 200, -clierr expects STATUS, and -cliexpect expects the REGEXP to match the returned response. -cliexpect ! … negates the match

-clijson STRING

Send STRING to the CLI, expect success (CLIS_OK/200) and check that the response is parsable JSON.

It is also possible to interact with its shared memory (as you would through tools like vinylstat) with additional switches:

-expect !PATTERN|PATTERN OP NUMBER|PATTERN OP PATTERN

Look into the VSM and make sure the first VSC counter identified by PATTERN has a correct value. OP can be ==, >, >=, <, <=. For example:

vinyl v1 -expect SM?.s1.g_space > 1000000
vinyl v1 -expect cache_hit >= cache_hit_grace

In the ! form the test fails if a counter matches PATTERN.

The MAIN. namespace can be omitted from PATTERN.

The test takes up to 5 seconds before timing out.

-vsc PATTERN

Dump VSC counters matching PATTERN.

-vsl_catchup

Wait until the logging thread has idled to make sure that all the generated log is flushed

Environment variables:

VTEST_VINYL_VCL_PREPEND can be used to inject VCL code into all VCL created by the vinyl command before VCL provided by the caller using the -vcl or -vcl+backend argument. That is, VTEST_VINYL_VCL_PREPEND is injected after the implicit “vcl x.y;” statement and backend definitions generated by the vinyl command.

vsm

Interact with the shared memory of a vinyl instance.

To define a VSM consumer, use this syntax:

vsm mNAME [-n STRING]

Arguments:

mNAME

Identify the VSM consumer, it must starts with ‘m’.

-n STRING

Choose the working directory of the vinyl instance. By default a VSM consumer connects to ${v1_name}.

-attach

Attach to a new vinyl instance. Implicitly detach from the current vinyl instance if applicable.

-detach

Detach from the current vinyl instance.

-expect-status STRING

Check that the status of VSM matches the list of status flags from STRING. The expected status is represented as a comma-separated list of flags. The list of flags in STRING is not sensitive to the order of flags.

The available flags are:

  • mgt-running

  • mgt-changed

  • mgt-restarted

  • wrk-running

  • wrk-changed

  • wrk-restarted

Expecting a status automatically attaches to the vinyl instance if that was not already the case.

HISTORY

This document has been written by Guillaume Quintard.

SEE ALSO