Exemple #1
0
void
vtc_expect(struct vtclog *vl,
    const char *olhs, const char *lhs,
    const char *cmp,
    const char *orhs, const char *rhs)
{
	vre_t *vre;
	const char *error;
	int erroroffset;
	int i, j, retval = -1;
	double fl, fr;

	j = lhs == NULL || rhs == NULL;
	if (lhs == NULL)
		lhs = "<undef>";
	if (rhs == NULL)
		rhs = "<undef>";

	if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
		vre = VRE_compile(rhs, 0, &error, &erroroffset);
		if (vre == NULL)
			vtc_fatal(vl, "REGEXP error: %s (@%d) (%s)",
			    error, erroroffset, rhs);
		i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0);
		retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
		VRE_free(&vre);
	} else if (!strcmp(cmp, "==")) {
		retval = strcmp(lhs, rhs) == 0;
	} else if (!strcmp(cmp, "!=")) {
		retval = strcmp(lhs, rhs) != 0;
	} else if (j) {
		// fail inequality comparisons if either side is undef'ed
		retval = 0;
	} else {
		fl = VNUM(lhs);
		fr = VNUM(rhs);
		if (!strcmp(cmp, "<"))
			retval = isless(fl, fr);
		else if (!strcmp(cmp, ">"))
			retval = isgreater(fl, fr);
		else if (!strcmp(cmp, "<="))
			retval = islessequal(fl, fr);
		else if (!strcmp(cmp, ">="))
			retval = isgreaterequal(fl, fr);
	}

	if (retval == -1)
		vtc_fatal(vl,
		    "EXPECT %s (%s) %s %s (%s) test not implemented",
		    olhs, lhs, cmp, orhs, rhs);
	else if (retval == 0)
		vtc_fatal(vl, "EXPECT %s (%s) %s \"%s\" failed",
		    olhs, lhs, cmp, rhs);
	else
		vtc_log(vl, 4, "EXPECT %s (%s) %s \"%s\" match",
		    olhs, lhs, cmp, rhs);
}
Exemple #2
0
struct vsb *
vtc_hex_to_bin(struct vtclog *vl, const char *arg)
{
	struct vsb *vsb;
	unsigned sh = 4;
	unsigned c, b = 0;

	vsb = VSB_new_auto();
	AN(vsb);
	for (; *arg != '\0'; arg++) {
		if (vct_issp(*arg) || *arg == '\n')
			continue;
		c = (uint8_t)*arg;
		if (c >= '0' && c <= '9')
			b |= (c - 48U) << sh;
		else if (c >= 'A' && c <= 'F')
			b |= (c - 55U) << sh;
		else if (c >= 'a' && c <= 'f')
			b |= (c - 87U) << sh;
		else
			vtc_fatal(vl,"Illegal hex string");
		sh = 4 - sh;
		if (sh == 4) {
			VSB_putc(vsb, b);
			b = 0;
		}
	}
	if (sh != 4)
		VSB_putc(vsb, b);
	AZ(VSB_finish(vsb));
	return (vsb);
}
Exemple #3
0
void
vtc_wait4(struct vtclog *vl, long pid,
    int expect_status, int expect_signal, int allow_core)
{
	int status, r;
	struct rusage ru;

	r = wait4(pid, &status, 0, &ru);
	if (r < 0)
		vtc_fatal(vl, "wait4 failed on pid %ld: %s",
		    pid, strerror(errno));
	assert(r == pid);
	vtc_log(vl, 2, "WAIT4 pid=%ld status=0x%04x (user %.6f sys %.6f)",
	    pid, status,
	    ru.ru_utime.tv_sec + 1e-6 * ru.ru_utime.tv_usec,
	    ru.ru_stime.tv_sec + 1e-6 * ru.ru_stime.tv_usec
	);

	if (WIFEXITED(status) && expect_signal <= 0 &&
	    WEXITSTATUS(status) == expect_status)
		return;

	if (expect_signal < 0)
		expect_signal = -expect_signal;

	if (WIFSIGNALED(status) && WCOREDUMP(status) <= allow_core &&
	    WTERMSIG(status) == expect_signal)
		return;
	vtc_log(vl, 1, "Expected exit: 0x%x signal: %d core: %d",
	    expect_status, expect_signal, allow_core);
	vtc_fatal(vl, "Bad exit status: 0x%04x exit 0x%x signal %d core %d",
	    status,
	    WEXITSTATUS(status),
	    WIFSIGNALED(status) ? WTERMSIG(status) : 0,
	    WCOREDUMP(status));
}
Exemple #4
0
vtc_log_VAS_Fail(const char *func, const char *file, int line,
    const char *cond, enum vas_e why)
{
	struct vtclog *vl;

	(void)why;
	vl = pthread_getspecific(log_key);
	if (vl == NULL || vl->act) {
		fprintf(stderr,
		    "Assert error in %s(), %s line %d:\n"
		    "  Condition(%s) not true.\n",
		    func, file, line, cond);
	} else
		vtc_fatal(vl, "Assert error in %s(), %s line %d:"
		    "  Condition(%s) not true.\n", func, file, line, cond);
	abort();
}