Commit 2937cac1 authored by Asad Sajjad Ahmed's avatar Asad Sajjad Ahmed Committed by Dridi Boukelmoune

vtc: add process pNAME -match-text LIN COL PAT

Signed-off-by: 's avatarDridi Boukelmoune <dridi.boukelmoune@gmail.com>
parent d8a627ec
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"
......@@ -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);
......
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