- memset (buf,0,sizeof(buf));
- snprintf(buf, sizeof(buf), "%s.stdout", template->tempfilename);
- task.stdoutlogfile = util_strdup(buf);
- if (!(task.stdoutlog = fopen(buf, "w"))) {
- con_err("error opening %s for stdout\n", buf);
- continue;
- }
-
- memset (buf,0,sizeof(buf));
- snprintf(buf, sizeof(buf), "%s.stderr", template->tempfilename);
- task.stderrlogfile = util_strdup(buf);
- if (!(task.stderrlog = fopen(buf, "w"))) {
- con_err("error opening %s for stderr\n", buf);
- continue;
+ if (strcmp(files->d_name + strlen(files->d_name) - 5, ".tmpl") == 0) {
+ task_template_t *tmpl = task_template_compile(files->d_name, directories[i], pad);
+ char buf[4096]; /* one page should be enough */
+ char *qcflags = NULL;
+ task_t task;
+
+ util_debug("TEST", "compiling task template: %s/%s\n", directories[i], files->d_name);
+ found ++;
+ if (!tmpl) {
+ con_err("error compiling task template: %s\n", files->d_name);
+ success = false;
+ continue;
+ }
+ /*
+ * Generate a temportary file name for the output binary
+ * so we don't trample over an existing one.
+ */
+ tmpl->tempfilename = NULL;
+ util_asprintf(&tmpl->tempfilename, "%s/TMPDAT.%s", directories[i], files->d_name);
+
+ /*
+ * Additional QCFLAGS enviroment variable may be used
+ * to test compile flags for all tests. This needs to be
+ * BEFORE other flags (so that the .tmpl can override them)
+ */
+ #ifdef _MSC_VER
+ {
+ char buffer[4096];
+ size_t size;
+ getenv_s(&size, buffer, sizeof(buffer), "QCFLAGS");
+ qcflags = buffer;
+ }
+ #else
+ qcflags = getenv("QCFLAGS");
+ #endif
+
+ /*
+ * Generate the command required to open a pipe to a process
+ * which will be refered to with a handle in the task for
+ * reading the data from the pipe.
+ */
+ if (strcmp(tmpl->proceduretype, "-pp")) {
+ if (qcflags) {
+ if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s %s -o %s",
+ task_bins[TASK_COMPILE],
+ directories[i],
+ tmpl->sourcefile,
+ qcflags,
+ tmpl->compileflags,
+ tmpl->tempfilename
+ );
+ } else {
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s %s -o %s",
+ task_bins[TASK_COMPILE],
+ curdir,
+ defs,
+ directories[i],
+ tmpl->sourcefile,
+ qcflags,
+ tmpl->compileflags,
+ tmpl->tempfilename
+ );
+ }
+ } else {
+ if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s -o %s",
+ task_bins[TASK_COMPILE],
+ directories[i],
+ tmpl->sourcefile,
+ tmpl->compileflags,
+ tmpl->tempfilename
+ );
+ } else {
+ util_snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s -o %s",
+ task_bins[TASK_COMPILE],
+ curdir,
+ defs,
+ directories[i],
+ tmpl->sourcefile,
+ tmpl->compileflags,
+ tmpl->tempfilename
+ );
+ }
+ }
+ } else {
+ /* Preprocessing (qcflags mean shit all here we don't allow them) */
+ if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
+ util_snprintf(buf, sizeof(buf), "%s -E %s/%s -o %s",
+ task_bins[TASK_COMPILE],
+ directories[i],
+ tmpl->sourcefile,
+ tmpl->tempfilename
+ );
+ } else {
+ util_snprintf(buf, sizeof(buf), "%s -E %s/%s %s/%s -o %s",
+ task_bins[TASK_COMPILE],
+ curdir,
+ defs,
+ directories[i],
+ tmpl->sourcefile,
+ tmpl->tempfilename
+ );
+ }
+ }
+
+ /*
+ * The task template was compiled, now lets create a task from
+ * the template data which has now been propagated.
+ */
+ task.tmpl = tmpl;
+ if (!(task.runhandles = task_popen(buf, "r"))) {
+ con_err("error opening pipe to process for test: %s\n", tmpl->description);
+ success = false;
+ continue;
+ }
+
+ util_debug("TEST", "executing test: `%s` [%s]\n", tmpl->description, buf);
+
+ /*
+ * Open up some file desciptors for logging the stdout/stderr
+ * to our own.
+ */
+ util_snprintf(buf, sizeof(buf), "%s.stdout", tmpl->tempfilename);
+ task.stdoutlogfile = util_strdup(buf);
+ if (!(task.stdoutlog = fs_file_open(buf, "w"))) {
+ con_err("error opening %s for stdout\n", buf);
+ continue;
+ }
+
+ util_snprintf(buf, sizeof(buf), "%s.stderr", tmpl->tempfilename);
+ task.stderrlogfile = util_strdup(buf);
+ if (!(task.stderrlog = fs_file_open(buf, "w"))) {
+ con_err("error opening %s for stderr\n", buf);
+ continue;
+ }
+
+ vec_push(task_tasks, task);