[master] c132ce2 Introduce more process macros for convenience
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Jan 20 13:28:05 CET 2017
commit c132ce2477436a5b694b2435994646da49738d3f
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Fri Jan 20 12:49:12 2017 +0100
Introduce more process macros for convenience
While at it, kill the `workdir` field that is neither used nor exposed,
and wrongfully based on the misleading ${pwd}. The overall documentation
also got a refresh, not just the new macros.
diff --git a/bin/varnishtest/tests/u00000.vtc b/bin/varnishtest/tests/u00000.vtc
index 8684c25..3ed2eaf 100644
--- a/bin/varnishtest/tests/u00000.vtc
+++ b/bin/varnishtest/tests/u00000.vtc
@@ -24,11 +24,11 @@ process p2 -wait
process p3 -wait
# check stdout
-shell "grep -q foo ${tmpdir}/p1/stdout"
-shell "grep -q bar ${tmpdir}/p2/stdout"
-shell "grep -q baz ${tmpdir}/p3/stdout"
+shell "grep -q foo ${p1_out}"
+shell "grep -q bar ${p2_out}"
+shell "grep -q baz ${p3_out}"
# check stderr
-shell "test -f ${tmpdir}/p1/stderr -a ! -s ${tmpdir}/p1/stderr"
-shell "test -f ${tmpdir}/p2/stderr -a ! -s ${tmpdir}/p2/stderr"
-shell "test -f ${tmpdir}/p3/stderr -a ! -s ${tmpdir}/p3/stderr"
+shell "test -f ${p1_err} -a ! -s ${p1_err}"
+shell "test -f ${p2_err} -a ! -s ${p2_err}"
+shell "test -f ${p3_err} -a ! -s ${p3_err}"
diff --git a/bin/varnishtest/tests/u00005.vtc b/bin/varnishtest/tests/u00005.vtc
index 031b79c..d80f197 100644
--- a/bin/varnishtest/tests/u00005.vtc
+++ b/bin/varnishtest/tests/u00005.vtc
@@ -15,18 +15,18 @@ delay 1
process p1 {varnishstat -1 -n ${v1_name} -f ^LCK.vbe.destroy \
-f LCK.vbe.* -f LCK.mempool.* | tr '[1-9]' '0'} -run
-shell "grep -q vbe ${tmpdir}/p1/stdout"
-shell "grep -q mempool ${tmpdir}/p1/stdout"
-shell -err "grep -q LCK.vbe.destroy ${tmpdir}/p1/stdout"
+shell "grep -q vbe ${p1_out}"
+shell "grep -q mempool ${p1_out}"
+shell -err "grep -q LCK.vbe.destroy ${p1_out}"
process p2 {varnishstat -1 -n ${v1_name} -f ^*vbe.destroy \
-f *vbe* -f *mempool* | tr '[1-9]' '0'} -run
-shell "grep -q vbe ${tmpdir}/p2/stdout"
-shell "grep -q mempool ${tmpdir}/p2/stdout"
-shell -err "grep -q LCK.vbe.destroy ${tmpdir}/p2/stdout"
+shell "grep -q vbe ${p2_out}"
+shell "grep -q mempool ${p2_out}"
+shell -err "grep -q LCK.vbe.destroy ${p2_out}"
-shell "cmp -s ${tmpdir}/p1/stdout ${tmpdir}/p2/stdout"
+shell "cmp -s ${p1_out} ${p2_out}"
shell -expect "cache_hit" \
"varnishstat -1 -n ${v1_name} -f MAIN.cache_hit"
diff --git a/bin/varnishtest/tests/u00006.vtc b/bin/varnishtest/tests/u00006.vtc
index 60092e9..5721a2b 100644
--- a/bin/varnishtest/tests/u00006.vtc
+++ b/bin/varnishtest/tests/u00006.vtc
@@ -39,8 +39,8 @@ shell -err -expect {-x: Syntax error in "**"} \
shell -err -expect {-X: Syntax error in "**"} \
{varnishlog -X "**:bar"}
process p1 -wait
-shell {grep -q "0 CLI" ${tmpdir}/p1/stdout}
+shell {grep -q "0 CLI" ${p1_out}}
process p2 -wait
-shell {grep -q "0 CLI" ${tmpdir}/p2/output}
+shell {grep -q "0 CLI" ${p2_dir}/output}
process p3 -wait
-shell -expect "0 CLI" {varnishlog -g raw -r ${tmpdir}/p3/output.bin}
+shell -expect "0 CLI" {varnishlog -g raw -r ${p3_dir}/output.bin}
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index e0d2744..831ad0b 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -439,20 +439,21 @@ cmd_varnishtest(CMD_ARGS)
* echo end
* }
*
- * By default a zero exit code is expected.
+ * By default a zero exit code is expected, otherwise the vtc will fail.
*
* Notice that the commandstring is prefixed with "exec 2>&1;" to join
* stderr and stdout back to the varnishtest process.
*
* Optional arguments:
*
- * -err - expect non-zero exit code
+ * \-err
+ * Expect non-zero exit code.
*
- * -exit N - expect exit code N
+ * \-exit N
+ * Expect exit code N instead of zero.
*
- * -expect string - expect str to be found in stdout+err
- *
- * The vtc will fail if the return code of the shell is not 0.
+ * \-expect string
+ * Expect str to be found in stdout+err.
*/
/* SECTION: client-server.spec.shell shell
*
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index f8209ff..6cac10f 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -53,8 +53,7 @@ struct process {
VTAILQ_ENTRY(process) list;
char *spec;
- char *workdir;
- char *outdir;
+ char *dir;
char *out;
char *err;
int fd_to;
@@ -101,13 +100,12 @@ process_new(const char *name)
p->vl = vtc_logopen(name);
AN(p->vl);
- PROCESS_EXPAND(workdir, "%s", "${pwd}");
- PROCESS_EXPAND(outdir, "${tmpdir}/%s", name);
+ PROCESS_EXPAND(dir, "${tmpdir}/%s", name);
PROCESS_EXPAND(out, "${tmpdir}/%s/stdout", name);
PROCESS_EXPAND(err, "${tmpdir}/%s/stderr", name);
bprintf(buf, "rm -rf %s ; mkdir -p %s ; touch %s %s",
- p->outdir, p->outdir, p->out, p->err);
+ p->dir, p->dir, p->out, p->err);
AZ(system(buf));
p->fd_to = -1;
@@ -134,20 +132,30 @@ process_delete(struct process *p)
AZ(pthread_mutex_destroy(&p->mtx));
vtc_logclose(p->vl);
free(p->name);
- free(p->workdir);
- free(p->outdir);
+ free(p->dir);
free(p->out);
free(p->err);
/*
- * We do not delete the outdir, it may contain useful stdout
- * and stderr files.
+ * We do not delete the directory, it may contain useful stdout
+ * and stderr files. They will be deleted on account of belonging
+ * to the test's tmpdir.
*/
/* XXX: MEMLEAK (?) */
FREE_OBJ(p);
}
+static void
+process_undef(struct process *p)
+{
+ CHECK_OBJ_NOTNULL(p, PROCESS_MAGIC);
+
+ macro_undef(p->vl, p->name, "dir");
+ macro_undef(p->vl, p->name, "out");
+ macro_undef(p->vl, p->name, "err");
+}
+
/**********************************************************************
* Start the process thread
*/
@@ -184,6 +192,7 @@ process_thread(void *priv)
if (p->fd_to >= 0)
closefd(&p->fd_to);
+ /* NB: We keep the other macros around */
macro_undef(p->vl, p->name, "pid");
p->pid = -1;
@@ -251,6 +260,9 @@ process_start(struct process *p)
}
vtc_log(p->vl, 3, "PID: %ld", (long)p->pid);
macro_def(p->vl, p->name, "pid", "%ld", (long)p->pid);
+ macro_def(p->vl, p->name, "dir", "%s", p->dir);
+ macro_def(p->vl, p->name, "out", "%s", p->out);
+ macro_def(p->vl, p->name, "err", "%s", p->err);
closefd(&fds[0]);
p->fd_to = fds[1];
if (p->log) {
@@ -372,9 +384,9 @@ process_close(struct process *p)
/* SECTION: process process
*
* Run a process in the background with stdout and stderr redirected to
- * ${tmpdir}/pNAME/stdout and ${tmpdir}/pNAME/stderr, respectively::
+ * ${pNAME_out} and ${pNAME_err}, both located in ${pNAME_dir}::
*
- * process pNAME SPEC [-start] [-log] [-wait] [-run] [-kill STRING] \
+ * process pNAME SPEC [-log] [-start] [-wait] [-run] [-kill STRING] \
* [-stop] [-write STRING] [-writeln STRING] [-close]
*
* pNAME
@@ -383,24 +395,45 @@ process_close(struct process *p)
* SPEC
* The command(s) to run in this process.
*
- * \-start
- * Start the process.
- *
* \-log
* Log stdout/stderr with vtc_dump() (must be before -start/-run)
*
+ * \-start
+ * Start the process.
+ *
* \-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 varnishtest ``shell`` command instead.
+ * The following commands are equivalent::
+ *
+ * shell "do --something"
+ *
+ * process p1 "do --something" -run
+ *
+ * However, you may use the 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.
+ *
* \-kill STRING
* 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 signals, 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.
*
@@ -432,6 +465,7 @@ cmd_process(CMD_ARGS)
if (p->hasthread)
process_wait(p);
VTAILQ_REMOVE(&processes, p, list);
+ process_undef(p);
process_delete(p);
}
return;
More information about the varnish-commit
mailing list