#include <sys/stat.h>
#include <dirent.h>
-bool opts_memchk = true;
+bool opts_memchk = false;
bool opts_debug = false;
char *task_bins[] = {
"./gmqcc",
return status;
}
+#else
+
#endif
#define TASK_COMPILE 0
* this will result in the task failing.
*/
typedef struct {
- char *description;
- char *failuremessage;
- char *successmessage;
- char *compileflags;
- char *executeflags;
- char *comparematch;
- char *proceduretype;
- char *sourcefile;
- char *tempfilename;
+ char *description;
+ char *failuremessage;
+ char *successmessage;
+ char *compileflags;
+ char *executeflags;
+ char *proceduretype;
+ char *sourcefile;
+ char *tempfilename;
+ char **comparematch;
} task_template_t;
/*
case 'T': destval = &template->proceduretype; break;
case 'C': destval = &template->compileflags; break;
case 'E': destval = &template->executeflags; break;
- case 'M': destval = &template->comparematch; break;
case 'I': destval = &template->sourcefile; break;
default:
con_printmsg(LVL_ERROR, __FILE__, __LINE__, "internal error",
case 'T':
case 'C':
case 'E':
- case 'M':
case 'I':
if (data[1] != ':') {
con_printmsg(LVL_ERROR, file, line, "template parse error",
}
break;
+ /*
+ * Match requires it's own system since we allow multiple M's
+ * for multi-line matching.
+ */
+ case 'M':
+ {
+ char *value = &data[3];
+ if (data[1] != ':') {
+ con_printmsg(LVL_ERROR, file, line, "template parse error",
+ "expected `:` after `%c`",
+ *data
+ );
+ goto failure;
+ }
+
+ if (value && *value && (*value == ' ' || *value == '\t'))
+ value++;
+
+ /*
+ * Value will contain a newline character at the end, we need to strip
+ * this otherwise kaboom, seriously, kaboom :P
+ */
+ *strrchr(value, '\n')='\0';
+
+ vec_push(template->comparematch, util_strdup(value));
+
+ break;
+ }
+
default:
con_printmsg(LVL_ERROR, file, line, "template parse error",
"invalid tag `%c`", *data
if ((*template)->proceduretype) mem_d((*template)->proceduretype);
if ((*template)->compileflags) mem_d((*template)->compileflags);
if ((*template)->executeflags) mem_d((*template)->executeflags);
- if ((*template)->comparematch) mem_d((*template)->comparematch);
if ((*template)->sourcefile) mem_d((*template)->sourcefile);
+ /*
+ * Delete all allocated string for task template then destroy the
+ * main vector.
+ */
+ {
+ size_t i = 0;
+ for (; i < vec_size((*template)->comparematch); i++)
+ mem_d((*template)->comparematch[i]);
+
+ vec_free((*template)->comparematch);
+ }
+
/*
* Nullify all the template members otherwise NULL comparision
* checks will fail if template pointer is reused.
* We made it here, which concludes the file/directory is not
* actually a directory, so it must be a file :)
*/
- if (strstr(files->d_name, ".tmpl")) {
- con_out("compiling task template: %s/%s\n", curdir, files->d_name);
+ if (strstr(files->d_name, ".tmpl") == &files->d_name[strlen(files->d_name) - (sizeof(".tmpl") - 1)]) {
+ util_debug("TEST", "compiling task template: %s/%s\n", curdir, files->d_name);
task_template_t *template = task_template_compile(files->d_name, curdir);
if (!template) {
con_err("error compiling task template: %s\n", files->d_name);
continue;
}
- con_out("executing test: `%s` [%s]\n", template->description, buf);
+ util_debug("TEST", "executing test: `%s` [%s]\n", template->description, buf);
/*
* Open up some file desciptors for logging the stdout/stderr
* to our own.
*/
memset (buf,0,sizeof(buf));
- snprintf(buf, sizeof(buf), "%s/%s.stdout", curdir, template->sourcefile);
+ snprintf(buf, sizeof(buf), "%s.stdout", template->tempfilename);
task.stdoutlogfile = util_strdup(buf);
- task.stdoutlog = fopen(buf, "w");
+ 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/%s.stderr", curdir, template->sourcefile);
+ snprintf(buf, sizeof(buf), "%s.stderr", template->tempfilename);
task.stderrlogfile = util_strdup(buf);
- task.stderrlog = fopen(buf, "w");
+ if (!(task.stderrlog = fopen(buf, "w"))) {
+ con_err("error opening %s for stderr\n", buf);
+ continue;
+ }
vec_push(task_tasks, task);
}
if (remove(buffer))
con_err("error removing temporary file: %s\n", buffer);
else
- con_out("removed temporary file: %s\n", buffer);
+ util_debug("TEST", "removed temporary file: %s\n", buffer);
}
}
if (remove(buffer))
con_err("error removing temporary file: %s\n", buffer);
else
- con_out("removed temporary file: %s\n", buffer);
+ util_debug("TEST", "removed temporary file: %s\n", buffer);
}
}
if (remove(task_tasks[i].stdoutlogfile))
con_err("error removing stdout log file: %s\n", task_tasks[i].stdoutlogfile);
else
- con_out("removed stdout log file: %s\n", task_tasks[i].stdoutlogfile);
+ util_debug("TEST", "removed stdout log file: %s\n", task_tasks[i].stdoutlogfile);
if (remove(task_tasks[i].stderrlogfile))
con_err("error removing stderr log file: %s\n", task_tasks[i].stderrlogfile);
else
- con_out("removed stderr log file: %s\n", task_tasks[i].stderrlogfile);
+ util_debug("TEST", "removed stderr log file: %s\n", task_tasks[i].stderrlogfile);
}
/* free util_strdup data for log files */
);
}
- con_out("executing qcvm: `%s` [%s]\n",
+ util_debug("TEST", "executing qcvm: `%s` [%s]\n",
template->description,
buffer
);
* and handle accordingly.
*/
{
- char *data = NULL;
- size_t size = 0;
- while (util_getline(&data, &size, execute) != EOF) {}
-
- if (!strcmp(data, "No main function found\n")) {
- con_err("test failure: `%s` [%s] (No main function found)\n",
- template->description,
- (template->failuremessage) ?
- template->failuremessage : "unknown"
- );
- pclose(execute);
- return false;
+ char *data = NULL;
+ size_t size = 0;
+ size_t compare = 0;
+ while (util_getline(&data, &size, execute) != EOF) {
+ if (!strcmp(data, "No main function found\n")) {
+ con_err("test failure: `%s` [%s] (No main function found)\n",
+ template->description,
+ (template->failuremessage) ?
+ template->failuremessage : "unknown"
+ );
+ pclose(execute);
+ return false;
+ }
+
+ /*
+ * Trim newlines from data since they will just break our
+ * ability to properly validate matches.
+ */
+ if (strrchr(data, '\n'))
+ *strrchr(data, '\n') = '\0';
+
+
+ /*
+ * We only care about the last line from the output for now
+ * implementing multi-line match is TODO.
+ */
+ success = !!!(strcmp(data, template->comparematch[compare++]));
}
-
- /*
- * Trim newlines from data since they will just break our
- * ability to properly validate matches.
- */
- if (strrchr(data, '\n'))
- *strrchr(data, '\n') = '\0';
-
- /* null list */
- if (!strcmp(template->comparematch, "$null"))
- success = true;
-
- /*
- * We only care about the last line from the output for now
- * implementing multi-line match is TODO.
- */
- if (!strcmp(data, template->comparematch))
- success = true;
}
pclose(execute);
return success;
* in the virtual machine.
*/
if (!task_execute(task_tasks[i].template)) {
- con_err("test failure: `%s` [%s]\n",
+ con_err("test failure: `%s` [%s] see %s.stdout and %s.stderr\n",
task_tasks[i].template->description,
(task_tasks[i].template->failuremessage) ?
- task_tasks[i].template->failuremessage : "unknown"
+ task_tasks[i].template->failuremessage : "unknown",
+ task_tasks[i].template->tempfilename,
+ task_tasks[i].template->tempfilename
);
continue;
}
return true;
}
+/*
+ * Fancy GCC-like LONG parsing allows things like --opt=param with
+ * assignment operator. This is used for redirecting stdout/stderr
+ * console to specific files of your choice.
+ */
+static bool parsecmd(const char *optname, int *argc_, char ***argv_, char **out, int ds, bool split) {
+ int argc = *argc_;
+ char **argv = *argv_;
+
+ size_t len = strlen(optname);
+
+ if (strncmp(argv[0]+ds, optname, len))
+ return false;
+
+ /* it's --optname, check how the parameter is supplied */
+ if (argv[0][ds+len] == '=') {
+ *out = argv[0]+ds+len+1;
+ return true;
+ }
+
+ if (!split || argc < ds) /* no parameter was provided, or only single-arg form accepted */
+ return false;
+
+ /* using --opt param */
+ *out = argv[1];
+ --*argc_;
+ ++*argv_;
+ return true;
+}
+
int main(int argc, char **argv) {
+ char *redirout = (char*)stdout;
+ char *redirerr = (char*)stderr;
con_init();
+
+ /*
+ * Command line option parsing commences now We only need to support
+ * a few things in the test suite.
+ */
+ while (argc > 1) {
+ ++argv;
+ --argc;
+
+ if (argv[0][0] == '-') {
+ if (parsecmd("redirout", &argc, &argv, &redirout, 1, false))
+ continue;
+ if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false))
+ continue;
+
+ con_change(redirout, redirerr);
+
+ if (!strcmp(argv[0]+1, "debug")) {
+ opts_debug = true;
+ continue;
+ }
+ if (!strcmp(argv[0]+1, "memchk")) {
+ opts_memchk = true;
+ continue;
+ }
+ if (!strcmp(argv[0]+1, "nocolor")) {
+ con_color(0);
+ continue;
+ }
+
+ con_err("invalid argument %s\n", argv[0]+1);
+ return -1;
+ }
+ }
+ con_change(redirout, redirerr);
test_perform("tests");
util_meminfo();
return 0;