From: Dale Weiler Date: Sat, 17 Nov 2012 08:10:31 +0000 (+0000) Subject: Test system works, and added some working tests! X-Git-Tag: 0.1.9~416 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=56987b41eb205c26e0785d6727aa0c5b188983a2;p=xonotic%2Fgmqcc.git Test system works, and added some working tests! --- diff --git a/test.c b/test.c index ad87183..744a669 100644 --- a/test.c +++ b/test.c @@ -118,6 +118,7 @@ typedef struct { char *comparematch; char *proceduretype; char *sourcefile; + char *tempfilename; } task_template_t; /* @@ -289,6 +290,7 @@ void task_template_nullify(task_template_t *template) { template->executeflags = NULL; template->comparematch = NULL; template->sourcefile = NULL; + template->tempfilename = NULL; } task_template_t *task_template_compile(const char *file, const char *dir) { @@ -448,6 +450,12 @@ bool task_propogate(const char *curdir) { success = false; continue; } + /* + * Generate a temportary file name for the output binary + * so we don't trample over an existing one. + */ + template->tempfilename = tempnam(curdir, "TMPDAT"); + /* * Generate the command required to open a pipe to a process @@ -456,11 +464,12 @@ bool task_propogate(const char *curdir) { */ char buf[4096]; /* one page should be enough */ memset (buf,0,sizeof(buf)); - snprintf(buf, sizeof(buf), "%s %s/%s %s", + snprintf(buf, sizeof(buf), "%s %s/%s %s -o %s", task_bins[TASK_COMPILE], curdir, template->sourcefile, - template->compileflags + template->compileflags, + template->tempfilename ); /* @@ -479,14 +488,54 @@ bool task_propogate(const char *curdir) { vec_push(task_tasks, task); } } + + closedir(dir); return success; } -void task_destroy() { +/* + * Removes all temporary 'progs.dat' files created during compilation + * of all tests' + */ +void task_cleanup(const char *curdir) { + DIR *dir; + struct dirent *files; + struct stat directory; + char buffer[4096]; + + dir = opendir(curdir); + + while ((files = readdir(dir))) { + memset(buffer, 0, sizeof(buffer)); + stat(files->d_name, &directory); + + if (strstr(files->d_name, "TMP")) { + snprintf(buffer, sizeof(buffer), "%s/%s", curdir, files->d_name); + if (remove(buffer)) + con_err("error removing temporary file: %s\n", buffer); + else + con_out("removed temporary file: %s\n", buffer); + } + } + + closedir(dir); +} + +void task_destroy(const char *curdir) { + /* + * Free all the data in the task list and finally the list itself + * then proceed to cleanup anything else outside the program like + * temporary files. + */ size_t i; for (i = 0; i < vec_size(task_tasks); i++) task_template_destroy(&task_tasks[i].template); vec_free(task_tasks); + + /* + * Cleanup outside stuff like temporary files. + */ + task_cleanup(curdir); } /* @@ -505,15 +554,15 @@ bool task_execute(task_template_t *template) { * actually specified. */ if (!strcmp(template->executeflags, "$null")) { - snprintf(buffer, sizeof(buffer), "%s %s %s", + snprintf(buffer, sizeof(buffer), "%s %s", task_bins[TASK_EXECUTE], - template->executeflags, - "progs.dat" + template->tempfilename ); } else { - snprintf(buffer, sizeof(buffer), "%s %s", + snprintf(buffer, sizeof(buffer), "%s %s %s", task_bins[TASK_EXECUTE], - "progs.dat" + template->executeflags, + template->tempfilename ); } @@ -545,6 +594,13 @@ bool task_execute(task_template_t *template) { 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'; + /* null list */ if (!strcmp(template->comparematch, "$null")) success = true; @@ -566,7 +622,7 @@ bool task_execute(task_template_t *template) { * execution this takes more work since a task needs to be generated * from thin air and executed INLINE. */ -void task_schedualize() { +void task_schedualize(const char *curdir) { bool execute = false; char *back = NULL; char *data = NULL; @@ -626,12 +682,6 @@ void task_schedualize() { (task_tasks[i].template->successmessage) ? task_tasks[i].template->successmessage : "unknown" ); - - /* - * We need to unlink the progs.dat file that is sitting around - * collecting dust. - */ - unlink("progs.dat"); } if (back) mem_d(back); @@ -641,7 +691,7 @@ int main(int argc, char **argv) { con_init(); if (!task_propogate("tests")) { con_err("error: failed to propogate tasks\n"); - task_destroy(); + task_destroy("tests"); return -1; } /* @@ -651,9 +701,9 @@ int main(int argc, char **argv) { * it's designed to prevent lock contention, and possible syncronization * issues. */ - task_schedualize(); + task_schedualize("tests"); + task_destroy("tests"); - task_destroy(); util_meminfo(); return 0; } diff --git a/tests/builtin.tmpl b/tests/builtin.tmpl index 7f34174..d81cad9 100644 --- a/tests/builtin.tmpl +++ b/tests/builtin.tmpl @@ -3,6 +3,7 @@ I: builtin.qc D: test builtin functions T: -execute C: -std=gmqcc -E: builtins failed +E: $null +F: builtins failed S: builtins worked M: hello world