return status;
}
#else
-# define _WIN32_LEAN_AND_MEAN
-# define popen _popen
-# define pclose _pclose
-# include <windows.h>
-# include <io.h>
-# include <fcntl.h>
/*
* Bidirectional piping implementation for windows using CreatePipe and DuplicateHandle +
* other hacks.
*/
-
typedef struct {
int __dummy;
/* TODO: implement */
(void)files;
return;
}
-
-# ifdef __MINGW32__
- /* mingw32 has dirent.h */
-# include <dirent.h>
-# elif defined (_WIN32)
- /*
- * visual studio lacks dirent.h it's a posix thing
- * so we emulate it with the WinAPI.
- */
-
- struct dirent {
- long d_ino;
- unsigned short d_reclen;
- unsigned short d_namlen;
- char d_name[FILENAME_MAX];
- };
-
- typedef struct {
- struct _finddata_t dd_dta;
- struct dirent dd_dir;
- long dd_handle;
- int dd_stat;
- char dd_name[1];
- } DIR;
-
- DIR *opendir(const char *name) {
- DIR *dir = (DIR*)mem_a(sizeof(DIR) + strlen(name));
- if (!dir)
- return NULL;
-
- strcpy(dir->dd_name, name);
- return dir;
- }
-
- int closedir(DIR *dir) {
- FindClose((HANDLE)dir->dd_handle);
- mem_d ((void*)dir);
- return 0;
- }
-
- struct dirent *readdir(DIR *dir) {
- WIN32_FIND_DATA info;
- struct dirent *data;
- int rets;
-
- if (!dir->dd_handle) {
- char *dirname;
- if (*dir->dd_name) {
- size_t n = strlen(dir->dd_name);
- if ((dirname = (char*)mem_a(n + 5) /* 4 + 1 */)) {
- strcpy(dirname, dir->dd_name);
- strcpy(dirname + n, "\\*.*"); /* 4 + 1 */
- }
- } else {
- if (!(dirname = util_strdup("\\*.*")))
- return NULL;
- }
-
- dir->dd_handle = (long)FindFirstFile(dirname, &info);
- mem_d(dirname);
- rets = !(!dir->dd_handle);
- } else if (dir->dd_handle != -11) {
- rets = FindNextFile ((HANDLE)dir->dd_handle, &info);
- } else {
- rets = 0;
- }
-
- if (!rets)
- return NULL;
-
- if ((data = (struct dirent*)mem_a(sizeof(struct dirent)))) {
- strncpy(data->d_name, info.cFileName, FILENAME_MAX - 1);
- data->d_name[FILENAME_MAX - 1] = '\0'; /* terminate */
- data->d_namlen = strlen(data->d_name);
- }
- return data;
- }
-
- /*
- * Visual studio also lacks S_ISDIR for sys/stat.h, so we emulate this as well
- * which is not hard at all.
- */
-# undef S_ISDIR /* undef just incase */
-# define S_ISDIR(X) ((X)&_S_IFDIR)
-# endif
-#endif
+#endif /*! _WIN32 */
#define TASK_COMPILE 0
#define TASK_EXECUTE 1
-
/*
* Task template system:
* templates are rules for a specific test, used to create a "task" that
return false;
/* top down parsing */
- while (file_getline(&back, &size, fp) != EOF) {
+ while (fs_file_getline(&back, &size, fp) != EOF) {
/* skip whitespace */
data = back;
if (*data && (*data == ' ' || *data == '\t'))
FILE *tempfile = NULL;
task_template_t *tmpl = NULL;
- memset (fullfile, 0, sizeof(fullfile));
snprintf(fullfile, sizeof(fullfile), "%s/%s", dir, file);
- tempfile = file_open(fullfile, "r");
+ tempfile = fs_file_open(fullfile, "r");
tmpl = (task_template_t*)mem_a(sizeof(task_template_t));
task_template_nullify(tmpl);
}
success:
- file_close(tempfile);
+ fs_file_close(tempfile);
return tmpl;
failure:
* so the check to see if it's not null here is required.
*/
if (tempfile)
- file_close(tempfile);
+ fs_file_close(tempfile);
mem_d (tmpl);
return NULL;
dir = opendir(curdir);
while ((files = readdir(dir))) {
- memset (buffer, 0,sizeof(buffer));
snprintf(buffer, sizeof(buffer), "%s/%s", curdir, files->d_name);
if (stat(buffer, &directory) == -1) {
* which will be refered to with a handle in the task for
* reading the data from the pipe.
*/
- memset (buf,0,sizeof(buf));
if (qcflags) {
if (tmpl->testflags && !strcmp(tmpl->testflags, "-no-defs")) {
snprintf(buf, sizeof(buf), "%s %s/%s %s %s -o %s",
* Open up some file desciptors for logging the stdout/stderr
* to our own.
*/
- memset (buf,0,sizeof(buf));
snprintf(buf, sizeof(buf), "%s.stdout", tmpl->tempfilename);
task.stdoutlogfile = util_strdup(buf);
- if (!(task.stdoutlog = file_open(buf, "w"))) {
+ if (!(task.stdoutlog = fs_file_open(buf, "w"))) {
con_err("error opening %s for stdout\n", buf);
continue;
}
- memset (buf,0,sizeof(buf));
snprintf(buf, sizeof(buf), "%s.stderr", tmpl->tempfilename);
task.stderrlogfile = util_strdup(buf);
- if (!(task.stderrlog = file_open(buf, "w"))) {
+ if (!(task.stderrlog = fs_file_open(buf, "w"))) {
con_err("error opening %s for stderr\n", buf);
continue;
}
dir = opendir(curdir);
while ((files = readdir(dir))) {
- memset(buffer, 0, sizeof(buffer));
if (strstr(files->d_name, "TMP") ||
strstr(files->d_name, ".stdout") ||
strstr(files->d_name, ".stderr"))
* annoying to have to do all this cleanup work.
*/
if (task_tasks[i].runhandles) task_pclose(task_tasks[i].runhandles);
- if (task_tasks[i].stdoutlog) file_close (task_tasks[i].stdoutlog);
- if (task_tasks[i].stderrlog) file_close (task_tasks[i].stderrlog);
+ if (task_tasks[i].stdoutlog) fs_file_close (task_tasks[i].stdoutlog);
+ if (task_tasks[i].stderrlog) fs_file_close (task_tasks[i].stderrlog);
/*
* Only remove the log files if the test actually compiled otherwise
char *data = NULL;
size_t size = 0;
size_t compare = 0;
- while (file_getline(&data, &size, execute) != EOF) {
+ while (fs_file_getline(&data, &size, execute) != EOF) {
if (!strcmp(data, "No main function found\n")) {
con_err("test failure: `%s` (No main function found) [%s]\n",
tmpl->description,
* execution this takes more work since a task needs to be generated
* from thin air and executed INLINE.
*/
+#include <math.h>
void task_schedualize(size_t *pad) {
+ char space[2][64];
bool execute = false;
char *data = NULL;
char **match = NULL;
size_t size = 0;
- size_t i;
- size_t j;
+ size_t i = 0;
+ size_t j = 0;
- util_debug("TEST", "found %d tasks, preparing to execute\n", vec_size(task_tasks));
+ snprintf(space[0], sizeof(space[0]), "%d", (int)vec_size(task_tasks));
+
+ for (; i < vec_size(task_tasks); i++) {
+ memset(space[1], 0, sizeof(space[1]));
+ snprintf(space[1], sizeof(space[1]), "%d", (int)(i + 1));
+
+ con_out("test #%u %*s", i + 1, strlen(space[0]) - strlen(space[1]), "");
- for (i = 0; i < vec_size(task_tasks); i++) {
util_debug("TEST", "executing task: %d: %s\n", i, task_tasks[i].tmpl->description);
/*
* Generate a task from thin air if it requires execution in
* Read data from stdout first and pipe that stuff into a log file
* then we do the same for stderr.
*/
- while (file_getline(&data, &size, task_tasks[i].runhandles[1]) != EOF) {
- file_puts(task_tasks[i].stdoutlog, data);
+ while (fs_file_getline(&data, &size, task_tasks[i].runhandles[1]) != EOF) {
+ fs_file_puts(task_tasks[i].stdoutlog, data);
if (strstr(data, "failed to open file")) {
task_tasks[i].compiled = false;
execute = false;
}
- fflush(task_tasks[i].stdoutlog);
+ fs_file_flush(task_tasks[i].stdoutlog);
}
- while (file_getline(&data, &size, task_tasks[i].runhandles[2]) != EOF) {
+ while (fs_file_getline(&data, &size, task_tasks[i].runhandles[2]) != EOF) {
/*
* If a string contains an error we just dissalow execution
* of it in the vm.
task_tasks[i].compiled = false;
}
- file_puts(task_tasks[i].stderrlog, data);
- fflush(task_tasks[i].stdoutlog);
+ fs_file_puts (task_tasks[i].stderrlog, data);
+ fs_file_flush(task_tasks[i].stdoutlog);
}
if (!task_tasks[i].compiled && strcmp(task_tasks[i].tmpl->proceduretype, "-fail")) {
- con_err("test failure: `%s` (failed to compile) see %s.stdout and %s.stderr [%s]\n",
+ con_err("failure: `%s` (failed to compile) see %s.stdout and %s.stderr [%s]\n",
task_tasks[i].tmpl->description,
task_tasks[i].tmpl->tempfilename,
task_tasks[i].tmpl->tempfilename,
}
if (!execute) {
- con_out("test succeeded: `%s` %*s\n",
+ con_out("succeeded: `%s` %*s\n",
task_tasks[i].tmpl->description,
(pad[0] + pad[1] - strlen(task_tasks[i].tmpl->description)) +
(strlen(task_tasks[i].tmpl->rulesfile) - pad[1]),
if (!task_execute(task_tasks[i].tmpl, &match)) {
size_t d = 0;
- con_err("test failure: `%s` (invalid results from execution) [%s]\n",
+ con_err("failure: `%s` (invalid results from execution) [%s]\n",
task_tasks[i].tmpl->description,
task_tasks[i].tmpl->rulesfile
);
mem_d(match[j]);
vec_free(match);
- con_out("test succeeded: `%s` %*s\n",
+ con_out("succeeded: `%s` %*s\n",
task_tasks[i].tmpl->description,
(pad[0] + pad[1] - strlen(task_tasks[i].tmpl->description)) +
(strlen(task_tasks[i].tmpl->rulesfile) - pad[1]),