Commit d1799613 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

A `cmd` feature for custom shell-based checks

In addition to harcoded features in varnishtest, this opens a window for
out-of-tree uses of the test framework to skip test cases if an external
component (a database system, OS-specific capabilities, an environment
variable, a library, etc) is missing.

This feature takes an extra argument, a command-line that must exit with
a zero status. Complex feature testing can nicely be wrapped in scripts
at the user's discretion:

    feature cmd "my --command=line"

If the test is skipped, it is logged as:

    **   top   0.0 === feature cmd "my --command=line"
    *    top   0.0 SKIPPING test, missing feature: my --command=line

If the command-line is missing, it is logged as:

    **   top   0.0 === feature cmd
    ---- top   0.0 Missing the command line
parent 2567e6f1
varnishtest "Custom feature verification"
feature cmd true
feature cmd false
this is an invalid varnishtest command
......@@ -604,12 +604,14 @@ cmd_random(CMD_ARGS)
* The vcache user is present
* group_varnish
* The varnish group is present
* cmd <command-line>
* A command line that should execute with a zero exit status
*/
static void
cmd_feature(CMD_ARGS)
{
int i;
int i, r;
(void)priv;
(void)cmd;
......@@ -653,6 +655,15 @@ cmd_feature(CMD_ARGS)
getgrnam("varnish") != NULL)
continue;
if (!strcmp(av[i], "cmd")) {
i++;
if (av[i] == NULL)
vtc_log(vl, 0, "Missing the command-line");
r = system(av[i]);
if (WEXITSTATUS(r) == 0)
continue;
}
vtc_log(vl, 1, "SKIPPING test, missing feature: %s", av[i]);
vtc_stop = 1;
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment