int exec_file(const char *fn, const char *script, const char *tmpdir, char *logbuf, unsigned loglen) { unsigned old_err; FILE *f; struct extmacro *m; signal(SIGPIPE, SIG_IGN); vtc_loginit(logbuf, loglen); vltop = vtc_logopen("top"); AN(vltop); init_macro(); init_sema(); /* Apply extmacro definitions */ VTAILQ_FOREACH(m, &extmacro_list, list) macro_def(vltop, NULL, m->name, "%s", m->val); /* * We need an IP number which will not repond, ever, and that is a * lot harder than it sounds. This IP# is from RFC5737 and a * C-class broadcast at that. * If tests involving ${bad_ip} fails and you run linux, you should * check your /proc/sys/net/ipv4/ip_nonlocal_bind setting. */ macro_def(vltop, NULL, "bad_ip", "192.0.2.255"); /* Move into our tmpdir */ AZ(chdir(tmpdir)); macro_def(vltop, NULL, "tmpdir", "%s", tmpdir); /* Drop file to tell what was going on here */ f = fopen("INFO", "w"); AN(f); fprintf(f, "Test case: %s\n", fn); AZ(fclose(f)); vtc_stop = 0; vtc_log(vltop, 1, "TEST %s starting", fn); vtc_thread = pthread_self(); parse_string(script, cmds, NULL, vltop); old_err = vtc_error; vtc_stop = 1; vtc_log(vltop, 1, "RESETTING after %s", fn); reset_cmds(cmds); vtc_error = old_err; if (vtc_error) vtc_log(vltop, 1, "TEST %s FAILED", fn); else vtc_log(vltop, 1, "TEST %s completed", fn); return (vtc_error); }
static struct varnish * varnish_new(const char *name) { struct varnish *v; struct vsb *vsb; char buf[1024]; AN(name); ALLOC_OBJ(v, VARNISH_MAGIC); AN(v); REPLACE(v->name, name); v->vl = vtc_logopen(name); AN(v->vl); bprintf(buf, "${tmpdir}/%s", name); vsb = macro_expand(v->vl, buf); AN(vsb); v->workdir = strdup(VSB_data(vsb)); AN(v->workdir); VSB_delete(vsb); bprintf(buf, "rm -rf %s ; mkdir -p %s ; echo ' %ld' > %s/_S", v->workdir, v->workdir, random(), v->workdir); AZ(system(buf)); if (*v->name != 'v') vtc_log(v->vl, 0, "Varnish name must start with 'v'"); v->args = VSB_new_auto(); v->storage = VSB_new_auto(); VSB_printf(v->storage, "-sfile,%s,10M", v->workdir); AZ(VSB_finish(v->storage)); v->cli_fd = -1; VTAILQ_INSERT_TAIL(&varnishes, v, list); return (v); }
int exec_file(const char *fn, const char *script, const char *tmpdir, char *logbuf, unsigned loglen) { unsigned old_err; char *cwd, *p; FILE *f; struct extmacro *m; signal(SIGPIPE, SIG_IGN); vtc_loginit(logbuf, loglen); vltop = vtc_logopen("top"); AN(vltop); init_macro(); init_sema(); /* Apply extmacro definitions */ VTAILQ_FOREACH(m, &extmacro_list, list) macro_def(vltop, NULL, m->name, m->val); /* Other macro definitions */ cwd = getcwd(NULL, PATH_MAX); macro_def(vltop, NULL, "pwd", cwd); macro_def(vltop, NULL, "topbuild", "%s/%s", cwd, TOP_BUILDDIR); macro_def(vltop, NULL, "bad_ip", "10.255.255.255"); /* Move into our tmpdir */ AZ(chdir(tmpdir)); macro_def(vltop, NULL, "tmpdir", tmpdir); /* Drop file to tell what was going on here */ f = fopen("INFO", "w"); AN(f); fprintf(f, "Test case: %s\n", fn); AZ(fclose(f)); vtc_stop = 0; vtc_desc = NULL; vtc_log(vltop, 1, "TEST %s starting", fn); p = strdup(script); AN(p); vtc_thread = pthread_self(); parse_string(p, cmds, NULL, vltop); old_err = vtc_error; vtc_stop = 1; vtc_log(vltop, 1, "RESETTING after %s", fn); reset_cmds(cmds); vtc_error = old_err; if (vtc_error) vtc_log(vltop, 1, "TEST %s FAILED", fn); else vtc_log(vltop, 1, "TEST %s completed", fn); free(vtc_desc); return (vtc_error); }