[master] 2937cac1d vtc: add process pNAME -match-text LIN COL PAT
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon May 30 12:17:04 UTC 2022
commit 2937cac1dac6926c165ff8ec5182f98cb7c6d8d8
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date: Fri Feb 4 13:19:23 2022 +0100
vtc: add process pNAME -match-text LIN COL PAT
Signed-off-by: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc
new file mode 100644
index 000000000..79c5aec7b
--- /dev/null
+++ b/bin/varnishtest/tests/a00009.vtc
@@ -0,0 +1,34 @@
+varnishtest "VTC process: match text"
+
+process p1 {
+ echo 0123
+ echo 4567
+ echo 89AB
+ echo CDEF
+} -run -screen-dump
+
+# y == 0, x == 0
+process p1 -match-text 0 0 "0123"
+process p1 -match-text 0 0 "0.*3"
+process p1 -match-text 0 0 "0123\(.|\n)*^CDEF"
+process p1 -match-text 0 0 "0123\(.|\n)*^89AB\(.|\n)*F$"
+
+# y != 0, x == 0
+process p1 -match-text 1 0 "4567"
+process p1 -match-text 2 0 "4567"
+process p1 -match-text 2 0 "4567\(.|\n)*^9"
+process p1 -match-text 3 0 "89AB"
+process p1 -match-text 4 0 "C.*F"
+
+# y == 0, x != 0
+process p1 -match-text 0 1 "4567"
+process p1 -match-text 0 2 "567"
+process p1 -match-text 0 2 "123\(.|\n)*^5"
+process p1 -match-text 0 2 "567\(.|\n)*^9"
+
+# y != 0, x != 0
+process p1 -match-text 1 1 "4567\(.|\n)*^89"
+process p1 -match-text 2 2 "567\(.|\n)*^9"
+process p1 -match-text 3 4 "B\(.|\n)*^F"
+process p1 -match-text 4 3 "EF"
+
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index 4f6356b34..6a148a5bb 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -50,6 +50,7 @@
#include "vtc.h"
+#include "vre.h"
#include "vev.h"
#include "vlu.h"
#include "vsb.h"
@@ -354,6 +355,64 @@ term_expect_cursor(const struct process *pp, const char *lin, const char *col)
pos->tp_col + 1, y);
}
+static void
+term_match_text(struct process *pp,
+ const char *lin, const char *col, const char *re)
+{
+ int i, x, y, l, err, erroff;
+ struct vsb *vsb, re_vsb[1];
+ size_t len;
+ vre_t *vre;
+ char errbuf[VRE_ERROR_LEN];
+
+ vsb = VSB_new_auto();
+ AN(vsb);
+
+ y = strtoul(lin, NULL, 0);
+ if (y < 0 || y > pp->nlin)
+ vtc_fatal(pp->vl, "YYY %d nlin %d", y, pp->nlin);
+ x = strtoul(col, NULL, 0);
+ for(l = 0; l < 10 && x > pp->ncol; l++) // wait for screen change
+ usleep(100000);
+ if (x < 0 || x > pp->ncol)
+ vtc_fatal(pp->vl, "XXX %d ncol %d", x, pp->ncol);
+
+ if (x)
+ x--;
+
+ if (y)
+ y--;
+
+ vre = VRE_compile(re, 0, &err, &erroff, 1);
+ if (vre == NULL) {
+ AN(VSB_init(re_vsb, errbuf, sizeof errbuf));
+ AZ(VRE_error(re_vsb, err));
+ AZ(VSB_finish(re_vsb));
+ VSB_fini(re_vsb);
+ vtc_fatal(pp->vl, "invalid regexp \"%s\" at %d (%s)",
+ re, erroff, errbuf);
+ }
+
+ AZ(pthread_mutex_lock(&pp->mtx));
+
+ len = (pp->nlin - y) * (pp->ncol - x);
+ for (i = y; i < pp->nlin; i++) {
+ VSB_bcat(vsb, &pp->vram[i][x], pp->ncol - x);
+ VSB_putc(vsb, '\n');
+ }
+
+ AZ(VSB_finish(vsb));
+
+ if (VRE_match(vre, VSB_data(vsb), len, 0, NULL) < 1)
+ vtc_fatal(pp->vl, "match failed: (\"%s\")", re);
+ else
+ vtc_log(pp->vl, 4, "match succeeded");
+
+ AZ(pthread_mutex_unlock(&pp->mtx));
+ VSB_destroy(&vsb);
+ VRE_free(&vre);
+}
+
/**********************************************************************
* Allocate and initialize a process
*/
@@ -932,6 +991,12 @@ process_close(struct process *p)
* LIN==0 means "on any line"
* COL==0 means "anywhere on the line"
*
+ * \-match-text LIN COL PAT
+ * 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"
+ *
* \-close
* Alias for "-kill HUP"
*
@@ -1067,6 +1132,14 @@ cmd_process(CMD_ARGS)
av += 2;
continue;
}
+ if (!strcmp(*av, "-match-text")) {
+ AN(av[1]);
+ AN(av[2]);
+ AN(av[3]);
+ term_match_text(p, av[1], av[2], av[3]);
+ av += 3;
+ continue;
+ }
if (!strcmp(*av, "-screen_dump") ||
!strcmp(*av, "-screen-dump")) {
term_screen_dump(p);
More information about the varnish-commit
mailing list