[4.1] bb867d8 A `cmd` feature for custom shell-based checks

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 29 13:03:09 CEST 2016


commit bb867d8c9d10656d96037e3283556bd789d2115e
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Aug 18 17:51:11 2016 +0200

    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

diff --git a/bin/varnishtest/tests/a00014.vtc b/bin/varnishtest/tests/a00014.vtc
new file mode 100644
index 0000000..860c1ca
--- /dev/null
+++ b/bin/varnishtest/tests/a00014.vtc
@@ -0,0 +1,6 @@
+varnishtest "Custom feature verification"
+
+feature cmd true
+feature cmd false
+
+this is an invalid varnishtest command
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 7c1ee4d..870f46c 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -569,7 +569,7 @@ cmd_random(CMD_ARGS)
 static void
 cmd_feature(CMD_ARGS)
 {
-	int i;
+	int i, r;
 
 	(void)priv;
 	(void)cmd;
@@ -613,6 +613,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;



More information about the varnish-commit mailing list