-
Notifications
You must be signed in to change notification settings - Fork 5
/
ext_test.c
151 lines (124 loc) · 3.13 KB
/
ext_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "mrbig.h"
//#define DEBUGGING "jajamensan"
#ifdef DEBUGGING
char cfgdir[256];
int dirsep = '\\';
void mrlog(char *p)
{
printf("mrlog: %s\n", p);
}
#endif
static void pickup_file(char *fn)
{
char full_fn[256], machname[256], testname[256];
char *b, *s, *p;
FILE *fp;
size_t n;
if (debug) mrlog("pickup_file(%s)", fn);
if (get_option("no_ext", 0)) {
/* no mrsend with clear status because we don't
know the names of the tests
*/
return;
}
snprintf(full_fn, sizeof(full_fn), "%s%c%s", pickupdir, dirsep, fn);
p = strchr(fn, '.');
if (p) {
*p++ = 0;
strncpy(machname, fn, sizeof(machname));
strncpy(testname, p, sizeof(testname));
} else {
strncpy(machname, mrmachine, sizeof(machname));
strncpy(testname, fn, sizeof(machname));
}
machname[sizeof(machname)-1] = 0;
testname[sizeof(testname)-1] = 0;
if (debug) {
mrlog("pickup_file(%s)", fn);
mrlog("Full path '%s'", full_fn);
mrlog("machname = '%s'", machname);
mrlog("testname = '%s'", testname);
}
fp = big_fopen("pickup_file", full_fn, "r");
if (!fp) {
mrlog("Can't pick up file");
goto Exit;
}
b = big_malloc("pickup_file", report_size);
s = big_malloc("pickup_file", report_size);
n = fread(b, 1, report_size-1, fp);
big_fclose("pickup_file", fp);
remove(full_fn);
b[n] = 0;
no_return(b);
p = strchr(b, '\n');
if (p == NULL) {
mrlog("No color in pickup file");
goto Exit;
}
*p++ = 0;
snprintf(s, report_size, "%s\n\n%s\n", now, p);
mrsend(machname, testname, b, s);
Exit:
big_free("pickup_file", b);
big_free("pickup_file", s);
}
static void pickup(void)
{
char pattern[1024];
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
pattern[0] = '\0';
snprcat(pattern, sizeof pattern, "%s%c*", pickupdir, dirsep);
if (debug) {
mrlog("pickup()");
mrlog("picking up from '%s'", pattern);
}
hFind = FindFirstFile(pattern, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
mrlog("Invalid pickup directory");
return;
}
do {
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
pickup_file(FindFileData.cFileName);
} while (FindNextFile(hFind, &FindFileData));
FindClose(hFind);
}
void ext_tests(void)
{
char cfgfile[1024], cmd[1024], *p;
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD n;
int i;
if (debug > 1) mrlog("ext_tests()");
cfgfile[0] = '\0';
snprcat(cfgfile, sizeof cfgfile, "%s%c%s", cfgdir, dirsep, "ext.cfg");
read_cfg("ext", cfgfile);
for (i = 0; get_cfg("ext", cmd, sizeof cmd, i); i++) {
p = strchr(cmd, '\n');
if (p) *p = '\0';
if (cmd[0] == '#' || cmd[0] == '\0') continue;
if (debug) mrlog("Ext test: %s", cmd);
ZeroMemory(&si, sizeof si);
ZeroMemory(&pi, sizeof pi);
if (CreateProcess(NULL, cmd, NULL, NULL, FALSE,
CREATE_NO_WINDOW|DETACHED_PROCESS,
NULL, NULL, &si, &pi)) {
/* Wait no more than two minutes */
n = WaitForSingleObject(pi.hProcess, 120*1000);
if (debug) mrlog("WaitForSingleObject returns %d", n);
if (n == WAIT_TIMEOUT) {
TerminateProcess(pi.hProcess, EXIT_FAILURE);
mrlog("Terminating process");
mrlog(cmd);
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
} else {
mrlog("CreateProcess failed");
}
}
pickup();
}