Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Wine Conformance Test EXE |
| 3 | * |
| 4 | * Copyright 2003 Jakob Eriksson (for Solid Form Sweden AB) |
| 5 | * Copyright 2003 Dimitrie O. Paun |
| 6 | * Copyright 2003 Ferenc Wagner |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 21 | * |
| 22 | * This program is dedicated to Anna Lindh, |
| 23 | * Swedish Minister of Foreign Affairs. |
| 24 | * Anna was murdered September 11, 2003. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "wine/port.h" |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <errno.h> |
| 34 | #ifdef HAVE_UNISTD_H |
| 35 | # include <unistd.h> |
| 36 | #endif |
| 37 | #include <windows.h> |
| 38 | |
| 39 | #include "winetest.h" |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 40 | #include "resource.h" |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 41 | |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 42 | struct wine_test |
| 43 | { |
| 44 | char *name; |
| 45 | int resource; |
| 46 | int subtest_count; |
| 47 | char **subtests; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 48 | char *exename; |
| 49 | }; |
| 50 | |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 51 | struct rev_info |
| 52 | { |
| 53 | const char* file; |
| 54 | const char* rev; |
| 55 | }; |
| 56 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 57 | static struct wine_test *wine_tests; |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 58 | static struct rev_info *rev_infos = NULL; |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 59 | static const char whitespace[] = " \t\r\n"; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 60 | |
Jakob Eriksson | 82c191f | 2004-04-23 00:06:57 +0000 | [diff] [blame] | 61 | static int running_under_wine () |
| 62 | { |
| 63 | HMODULE module = GetModuleHandleA("ntdll.dll"); |
| 64 | |
| 65 | if (!module) return 0; |
Alexandre Julliard | 9db147e | 2004-04-23 02:46:18 +0000 | [diff] [blame] | 66 | return (GetProcAddress(module, "wine_server_call") != NULL); |
Jakob Eriksson | 82c191f | 2004-04-23 00:06:57 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 69 | void print_version () |
| 70 | { |
| 71 | OSVERSIONINFOEX ver; |
| 72 | BOOL ext; |
| 73 | |
| 74 | ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
| 75 | if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver))) |
| 76 | { |
| 77 | ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
| 78 | if (!GetVersionEx ((OSVERSIONINFO *) &ver)) |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 79 | report (R_FATAL, "Can't get OS version."); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Ferenc Wagner | 21b8503 | 2004-04-23 02:52:21 +0000 | [diff] [blame] | 82 | xprintf (" bRunningUnderWine=%d\n", running_under_wine ()); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 83 | xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n" |
| 84 | " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n", |
| 85 | ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, |
| 86 | ver.dwPlatformId, ver.szCSDVersion); |
| 87 | |
| 88 | if (!ext) return; |
| 89 | |
| 90 | xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n" |
| 91 | " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n", |
| 92 | ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask, |
| 93 | ver.wProductType, ver.wReserved); |
| 94 | } |
| 95 | |
| 96 | static inline int is_dot_dir(const char* x) |
| 97 | { |
| 98 | return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0)))); |
| 99 | } |
| 100 | |
| 101 | void remove_dir (const char *dir) |
| 102 | { |
| 103 | HANDLE hFind; |
| 104 | WIN32_FIND_DATA wfd; |
| 105 | char path[MAX_PATH]; |
| 106 | size_t dirlen = strlen (dir); |
| 107 | |
| 108 | /* Make sure the directory exists before going further */ |
| 109 | memcpy (path, dir, dirlen); |
| 110 | strcpy (path + dirlen++, "\\*"); |
| 111 | hFind = FindFirstFile (path, &wfd); |
| 112 | if (hFind == INVALID_HANDLE_VALUE) return; |
| 113 | |
| 114 | do { |
| 115 | char *lp = wfd.cFileName; |
| 116 | |
| 117 | if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */ |
| 118 | if (is_dot_dir (lp)) continue; |
| 119 | strcpy (path + dirlen, lp); |
| 120 | if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) |
| 121 | remove_dir(path); |
| 122 | else if (!DeleteFile (path)) |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 123 | report (R_WARNING, "Can't delete file %s: error %d", |
| 124 | path, GetLastError ()); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 125 | } while (FindNextFile (hFind, &wfd)); |
| 126 | FindClose (hFind); |
| 127 | if (!RemoveDirectory (dir)) |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 128 | report (R_WARNING, "Can't remove directory %s: error %d", |
| 129 | dir, GetLastError ()); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 132 | const char* get_test_source_file(const char* test, const char* subtest) |
| 133 | { |
| 134 | static const char* special_dirs[][2] = { |
| 135 | { "gdi32", "gdi"}, { "kernel32", "kernel" }, |
Ferenc Wagner | 70cd740 | 2004-05-05 19:00:34 +0000 | [diff] [blame] | 136 | { "msacm32", "msacm" }, |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 137 | { "user32", "user" }, { "winspool.drv", "winspool" }, |
| 138 | { "ws2_32", "winsock" }, { 0, 0 } |
| 139 | }; |
| 140 | static char buffer[MAX_PATH]; |
| 141 | int i; |
| 142 | |
| 143 | for (i = 0; special_dirs[i][0]; i++) { |
| 144 | if (strcmp(test, special_dirs[i][0]) == 0) { |
| 145 | test = special_dirs[i][1]; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest); |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 151 | return buffer; |
| 152 | } |
| 153 | |
| 154 | const char* get_file_rev(const char* file) |
| 155 | { |
| 156 | const struct rev_info* rev; |
| 157 | |
| 158 | for(rev = rev_infos; rev->file; rev++) { |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 159 | if (strcmp(rev->file, file) == 0) return rev->rev; |
| 160 | } |
| 161 | |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 162 | return "-"; |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void extract_rev_infos () |
| 166 | { |
| 167 | char revinfo[256], *p; |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 168 | int size = 0, i, len; |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 169 | HMODULE module = GetModuleHandle (NULL); |
| 170 | |
| 171 | for (i = 0; TRUE; i++) { |
| 172 | if (i >= size) { |
| 173 | size += 100; |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 174 | rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos)); |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 175 | } |
| 176 | memset(rev_infos + i, 0, sizeof(rev_infos[i])); |
| 177 | |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 178 | len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo)); |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 179 | if (len == 0) break; /* end of revision info */ |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 180 | if (len >= sizeof(revinfo) - 1) |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 181 | report (R_FATAL, "Revision info too long."); |
| 182 | if(!(p = strrchr(revinfo, ':'))) |
| 183 | report (R_FATAL, "Revision info malformed (i=%d)", i); |
| 184 | *p = 0; |
| 185 | rev_infos[i].file = strdup(revinfo); |
| 186 | rev_infos[i].rev = strdup(p + 1); |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 187 | } |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 190 | void* extract_rcdata (int id, int type, DWORD* size) |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 191 | { |
| 192 | HRSRC rsrc; |
| 193 | HGLOBAL hdl; |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 194 | LPVOID addr; |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 195 | |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 196 | if (!(rsrc = FindResource (NULL, (LPTSTR)id, MAKEINTRESOURCE(type))) || |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 197 | !(*size = SizeofResource (0, rsrc)) || |
| 198 | !(hdl = LoadResource (0, rsrc)) || |
| 199 | !(addr = LockResource (hdl))) |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 200 | return NULL; |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 201 | return addr; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 204 | /* Fills in the name and exename fields */ |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 205 | void |
| 206 | extract_test (struct wine_test *test, const char *dir, int id) |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 207 | { |
| 208 | BYTE* code; |
| 209 | DWORD size; |
| 210 | FILE* fout; |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 211 | int strlen, bufflen = 128; |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 212 | char *exepos; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 213 | |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 214 | code = extract_rcdata (id, TESTRES, &size); |
| 215 | if (!code) report (R_FATAL, "Can't find test resource %d: %d", |
| 216 | id, GetLastError ()); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 217 | test->name = xmalloc (bufflen); |
| 218 | while ((strlen = LoadStringA (NULL, id, test->name, bufflen)) |
| 219 | == bufflen - 1) { |
| 220 | bufflen *= 2; |
| 221 | test->name = xrealloc (test->name, bufflen); |
| 222 | } |
| 223 | if (!strlen) report (R_FATAL, "Can't read name of test %d.", id); |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 224 | test->exename = strmake (NULL, "%s/%s", dir, test->name); |
Ferenc Wagner | 8387770 | 2004-03-19 01:54:10 +0000 | [diff] [blame] | 225 | exepos = strstr (test->name, "_test.exe"); |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 226 | if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name); |
| 227 | *exepos = 0; |
| 228 | test->name = xrealloc (test->name, exepos - test->name + 1); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 229 | report (R_STEP, "Extracting: %s", test->name); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 230 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 231 | if (!(fout = fopen (test->exename, "wb")) || |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 232 | (fwrite (code, size, 1, fout) != 1) || |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 233 | fclose (fout)) report (R_FATAL, "Failed to write file %s.", |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 234 | test->exename); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 237 | /* Run a command for MS milliseconds. If OUT != NULL, also redirect |
| 238 | stdout to there. |
| 239 | |
| 240 | Return the exit status, -2 if can't create process or the return |
| 241 | value of WaitForSingleObject. |
| 242 | */ |
| 243 | int |
| 244 | run_ex (char *cmd, const char *out, DWORD ms) |
| 245 | { |
| 246 | STARTUPINFO si; |
| 247 | PROCESS_INFORMATION pi; |
| 248 | int fd, oldstdout = -1; |
| 249 | DWORD wait, status; |
| 250 | |
| 251 | GetStartupInfo (&si); |
| 252 | si.wShowWindow = SW_HIDE; |
| 253 | si.dwFlags = STARTF_USESHOWWINDOW; |
| 254 | |
| 255 | if (out) { |
| 256 | fd = open (out, O_WRONLY | O_CREAT, 0666); |
| 257 | if (-1 == fd) |
| 258 | report (R_FATAL, "Can't open '%s': %d", out, errno); |
| 259 | oldstdout = dup (1); |
| 260 | if (-1 == oldstdout) |
| 261 | report (R_FATAL, "Can't save stdout: %d", errno); |
| 262 | if (-1 == dup2 (fd, 1)) |
| 263 | report (R_FATAL, "Can't redirect stdout: %d", errno); |
| 264 | close (fd); |
| 265 | } |
| 266 | |
| 267 | if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0, |
| 268 | NULL, NULL, &si, &pi)) { |
| 269 | status = -2; |
| 270 | } else { |
| 271 | CloseHandle (pi.hThread); |
| 272 | wait = WaitForSingleObject (pi.hProcess, ms); |
| 273 | if (wait == WAIT_OBJECT_0) { |
| 274 | GetExitCodeProcess (pi.hProcess, &status); |
| 275 | } else { |
| 276 | switch (wait) { |
| 277 | case WAIT_FAILED: |
| 278 | report (R_ERROR, "Wait for '%s' failed: %d", cmd, |
| 279 | GetLastError ()); |
| 280 | break; |
| 281 | case WAIT_TIMEOUT: |
| 282 | report (R_ERROR, "Process '%s' timed out.", cmd); |
| 283 | break; |
| 284 | default: |
| 285 | report (R_ERROR, "Wait returned %d", wait); |
| 286 | } |
| 287 | status = wait; |
| 288 | if (!TerminateProcess (pi.hProcess, 257)) |
| 289 | report (R_ERROR, "TerminateProcess failed: %d", |
| 290 | GetLastError ()); |
| 291 | wait = WaitForSingleObject (pi.hProcess, 5000); |
| 292 | switch (wait) { |
| 293 | case WAIT_FAILED: |
| 294 | report (R_ERROR, |
| 295 | "Wait for termination of '%s' failed: %d", |
| 296 | cmd, GetLastError ()); |
| 297 | break; |
| 298 | case WAIT_OBJECT_0: |
| 299 | break; |
| 300 | case WAIT_TIMEOUT: |
| 301 | report (R_ERROR, "Can't kill process '%s'", cmd); |
| 302 | break; |
| 303 | default: |
| 304 | report (R_ERROR, "Waiting for termination: %d", |
| 305 | wait); |
| 306 | } |
| 307 | } |
| 308 | CloseHandle (pi.hProcess); |
| 309 | } |
| 310 | |
| 311 | if (out) { |
| 312 | close (1); |
| 313 | if (-1 == dup2 (oldstdout, 1)) |
| 314 | report (R_FATAL, "Can't recover stdout: %d", errno); |
| 315 | close (oldstdout); |
| 316 | } |
| 317 | return status; |
| 318 | } |
| 319 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 320 | void |
| 321 | get_subtests (const char *tempdir, struct wine_test *test, int id) |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 322 | { |
| 323 | char *subname; |
| 324 | FILE *subfile; |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 325 | size_t total; |
| 326 | char buffer[8192], *index; |
Francois Gouget | cfc3943 | 2004-05-04 04:13:05 +0000 | [diff] [blame] | 327 | static const char header[] = "Valid test names:"; |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 328 | int allocated; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 329 | |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 330 | test->subtest_count = 0; |
| 331 | |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 332 | subname = tempnam (0, "sub"); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 333 | if (!subname) report (R_FATAL, "Can't name subtests file."); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 334 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 335 | extract_test (test, tempdir, id); |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 336 | run_ex (test->exename, subname, 5000); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 337 | |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 338 | subfile = fopen (subname, "r"); |
| 339 | if (!subfile) { |
| 340 | report (R_ERROR, "Can't open subtests output of %s: %d", |
| 341 | test->name, errno); |
| 342 | goto quit; |
| 343 | } |
| 344 | total = fread (buffer, 1, sizeof buffer, subfile); |
| 345 | fclose (subfile); |
| 346 | if (sizeof buffer == total) { |
| 347 | report (R_ERROR, "Subtest list of %s too big.", |
| 348 | test->name, sizeof buffer); |
| 349 | goto quit; |
| 350 | } |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 351 | buffer[total] = 0; |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 352 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 353 | index = strstr (buffer, header); |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 354 | if (!index) { |
| 355 | report (R_ERROR, "Can't parse subtests output of %s", |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 356 | test->name); |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 357 | goto quit; |
| 358 | } |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 359 | index += sizeof header; |
| 360 | |
| 361 | allocated = 10; |
| 362 | test->subtests = xmalloc (allocated * sizeof(char*)); |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 363 | index = strtok (index, whitespace); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 364 | while (index) { |
| 365 | if (test->subtest_count == allocated) { |
| 366 | allocated *= 2; |
| 367 | test->subtests = xrealloc (test->subtests, |
| 368 | allocated * sizeof(char*)); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 369 | } |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 370 | test->subtests[test->subtest_count++] = strdup (index); |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 371 | index = strtok (NULL, whitespace); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 372 | } |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 373 | test->subtests = xrealloc (test->subtests, |
| 374 | test->subtest_count * sizeof(char*)); |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 375 | |
| 376 | quit: |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 377 | if (remove (subname)) |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 378 | report (R_WARNING, "Can't delete file '%s': %d", |
| 379 | subname, errno); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 380 | free (subname); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 383 | void |
| 384 | run_test (struct wine_test* test, const char* subtest) |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 385 | { |
| 386 | int status; |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 387 | const char* file = get_test_source_file(test->name, subtest); |
| 388 | const char* rev = get_file_rev(file); |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 389 | char *cmd = strmake (NULL, "%s %s", test->exename, subtest); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 390 | |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 391 | xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev); |
Ferenc Wagner | 90baafe | 2004-04-20 04:00:07 +0000 | [diff] [blame] | 392 | status = run_ex (cmd, NULL, 120000); |
| 393 | free (cmd); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 394 | xprintf ("%s:%s done (%d)\n", test->name, subtest, status); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 397 | BOOL CALLBACK |
| 398 | EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType, |
| 399 | LPTSTR lpszName, LONG_PTR lParam) |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 400 | { |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 401 | (*(int*)lParam)++; |
| 402 | return TRUE; |
| 403 | } |
| 404 | |
Ferenc Wagner | 8c4a4df | 2004-02-20 19:56:29 +0000 | [diff] [blame] | 405 | char * |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 406 | run_tests (char *logname, const char *tag) |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 407 | { |
| 408 | int nr_of_files = 0, nr_of_tests = 0, i; |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 409 | char *tempdir; |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 410 | int logfile; |
| 411 | char *strres, *eol, *nextline; |
| 412 | DWORD strsize; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 413 | |
Ferenc Wagner | f8dba77 | 2004-07-06 21:03:22 +0000 | [diff] [blame] | 414 | SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 415 | |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 416 | if (!logname) { |
| 417 | logname = tempnam (0, "res"); |
| 418 | if (!logname) report (R_FATAL, "Can't name logfile."); |
| 419 | } |
| 420 | report (R_OUT, logname); |
| 421 | |
| 422 | logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND, |
| 423 | 0666); |
| 424 | if (-1 == logfile) { |
| 425 | if (EEXIST == errno) |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 426 | report (R_FATAL, "File %s already exists.", logname); |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 427 | else report (R_FATAL, "Could not open logfile: %d", errno); |
| 428 | } |
| 429 | if (-1 == dup2 (logfile, 1)) |
| 430 | report (R_FATAL, "Can't redirect stdout: %d", errno); |
| 431 | close (logfile); |
| 432 | |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 433 | tempdir = tempnam (0, "wct"); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 434 | if (!tempdir) |
| 435 | report (R_FATAL, "Can't name temporary dir (check %%TEMP%%)."); |
| 436 | report (R_DIR, tempdir); |
| 437 | if (!CreateDirectory (tempdir, NULL)) |
| 438 | report (R_FATAL, "Could not create directory: %s", tempdir); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 439 | |
Ferenc Wagner | 1fb75dc | 2004-04-22 23:43:54 +0000 | [diff] [blame] | 440 | xprintf ("Version 3\n"); |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 441 | strres = extract_rcdata (WINE_BUILD, STRINGRES, &strsize); |
| 442 | xprintf ("Tests from build "); |
| 443 | if (strres) xprintf ("%.*s", strsize, strres); |
| 444 | else xprintf ("-\n"); |
| 445 | strres = extract_rcdata (TESTS_URL, STRINGRES, &strsize); |
| 446 | xprintf ("Archive: "); |
| 447 | if (strres) xprintf ("%.*s", strsize, strres); |
| 448 | else xprintf ("-\n"); |
Ferenc Wagner | 8387770 | 2004-03-19 01:54:10 +0000 | [diff] [blame] | 449 | xprintf ("Tag: %s\n", tag?tag:""); |
Ferenc Wagner | 21b8503 | 2004-04-23 02:52:21 +0000 | [diff] [blame] | 450 | xprintf ("Build info:\n"); |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 451 | strres = extract_rcdata (BUILD_INFO, STRINGRES, &strsize); |
| 452 | while (strres) { |
| 453 | eol = memchr (strres, '\n', strsize); |
| 454 | if (!eol) { |
| 455 | nextline = NULL; |
| 456 | eol = strres + strsize; |
| 457 | } else { |
| 458 | strsize -= eol - strres + 1; |
| 459 | nextline = strsize?eol+1:NULL; |
| 460 | if (eol > strres && *(eol-1) == '\r') eol--; |
| 461 | } |
| 462 | xprintf (" %.*s\n", eol-strres, strres); |
| 463 | strres = nextline; |
| 464 | } |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 465 | xprintf ("Operating system version:\n"); |
| 466 | print_version (); |
| 467 | xprintf ("Test output:\n" ); |
| 468 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 469 | report (R_STATUS, "Counting tests"); |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 470 | if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES), |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 471 | EnumTestFileProc, (LPARAM)&nr_of_files)) |
| 472 | report (R_FATAL, "Can't enumerate test files: %d", |
| 473 | GetLastError ()); |
| 474 | wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 475 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 476 | report (R_STATUS, "Extracting tests"); |
Ferenc Wagner | feaad96 | 2004-02-21 04:01:56 +0000 | [diff] [blame] | 477 | report (R_PROGRESS, 0, nr_of_files); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 478 | for (i = 0; i < nr_of_files; i++) { |
Ferenc Wagner | 24624f6 | 2004-06-15 22:45:15 +0000 | [diff] [blame] | 479 | get_subtests (tempdir, wine_tests+i, i); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 480 | nr_of_tests += wine_tests[i].subtest_count; |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 481 | } |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 482 | report (R_DELTA, 0, "Extracting: Done"); |
| 483 | |
| 484 | report (R_STATUS, "Running tests"); |
Ferenc Wagner | feaad96 | 2004-02-21 04:01:56 +0000 | [diff] [blame] | 485 | report (R_PROGRESS, 1, nr_of_tests); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 486 | for (i = 0; i < nr_of_files; i++) { |
| 487 | struct wine_test *test = wine_tests + i; |
| 488 | int j; |
| 489 | |
| 490 | for (j = 0; j < test->subtest_count; j++) { |
Ferenc Wagner | 8387770 | 2004-03-19 01:54:10 +0000 | [diff] [blame] | 491 | report (R_STEP, "Running: %s:%s", test->name, |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 492 | test->subtests[j]); |
| 493 | run_test (test, test->subtests[j]); |
| 494 | } |
| 495 | } |
| 496 | report (R_DELTA, 0, "Running: Done"); |
| 497 | |
| 498 | report (R_STATUS, "Cleaning up"); |
| 499 | close (1); |
| 500 | remove_dir (tempdir); |
| 501 | free (tempdir); |
| 502 | free (wine_tests); |
| 503 | |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 504 | return logname; |
| 505 | } |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 506 | |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 507 | void |
| 508 | usage () |
| 509 | { |
| 510 | fprintf (stderr, "\ |
| 511 | Usage: winetest [OPTION]...\n\n\ |
| 512 | -c console mode, no GUI\n\ |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 513 | -e preserve the environment\n\ |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 514 | -h print this message and exit\n\ |
| 515 | -q quiet mode, no output at all\n\ |
| 516 | -o FILE put report into FILE, do not submit\n\ |
| 517 | -s FILE submit FILE, do not run tests\n\ |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 518 | -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"); |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 519 | } |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 520 | |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 521 | int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, |
| 522 | LPSTR cmdLine, int cmdShow) |
| 523 | { |
Ferenc Wagner | 8c4a4df | 2004-02-20 19:56:29 +0000 | [diff] [blame] | 524 | char *logname = NULL; |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 525 | const char *cp, *submit = NULL, *tag = NULL; |
| 526 | int reset_env = 1; |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 527 | |
Dimitrie O. Paun | cbe0e49 | 2004-03-20 19:21:39 +0000 | [diff] [blame] | 528 | /* initialize the revision information first */ |
| 529 | extract_rev_infos(); |
| 530 | |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 531 | cmdLine = strtok (cmdLine, whitespace); |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 532 | while (cmdLine) { |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 533 | if (cmdLine[0] != '-' || cmdLine[2]) { |
| 534 | report (R_ERROR, "Not a single letter option: %s", cmdLine); |
| 535 | usage (); |
| 536 | exit (2); |
| 537 | } |
| 538 | switch (cmdLine[1]) { |
| 539 | case 'c': |
| 540 | report (R_TEXTMODE); |
| 541 | break; |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 542 | case 'e': |
| 543 | reset_env = 0; |
| 544 | break; |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 545 | case 'h': |
| 546 | usage (); |
| 547 | exit (0); |
| 548 | case 'q': |
| 549 | report (R_QUIET); |
| 550 | break; |
| 551 | case 's': |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 552 | submit = strtok (NULL, whitespace); |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 553 | if (tag) |
| 554 | report (R_WARNING, "ignoring tag for submission"); |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 555 | send_file (submit); |
| 556 | break; |
| 557 | case 'o': |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 558 | logname = strtok (NULL, whitespace); |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 559 | break; |
| 560 | case 't': |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 561 | tag = strtok (NULL, whitespace); |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 562 | cp = badtagchar (tag); |
| 563 | if (cp) { |
| 564 | report (R_ERROR, "invalid char in tag: %c", *cp); |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 565 | usage (); |
| 566 | exit (2); |
| 567 | } |
Ferenc Wagner | a122499 | 2004-03-24 23:40:06 +0000 | [diff] [blame] | 568 | break; |
| 569 | default: |
| 570 | report (R_ERROR, "invalid option: -%c", cmdLine[1]); |
| 571 | usage (); |
| 572 | exit (2); |
| 573 | } |
Ferenc Wagner | cb10a70 | 2004-09-07 19:33:52 +0000 | [diff] [blame] | 574 | cmdLine = strtok (NULL, whitespace); |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 575 | } |
Ferenc Wagner | 2d0d484 | 2004-07-22 23:42:03 +0000 | [diff] [blame] | 576 | if (!submit) { |
| 577 | if (reset_env && (putenv ("WINETEST_PLATFORM=windows") || |
| 578 | putenv ("WINETEST_DEBUG=1") || |
| 579 | putenv ("WINETEST_INTERACTIVE=0") || |
| 580 | putenv ("WINETEST_REPORT_SUCCESS=0"))) |
| 581 | report (R_FATAL, "Could not reset environment: %d", errno); |
| 582 | |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 583 | report (R_STATUS, "Starting up"); |
Ferenc Wagner | fbf77db | 2004-10-04 19:32:20 +0000 | [diff] [blame] | 584 | if (!logname) { |
| 585 | logname = run_tests (NULL, tag); |
| 586 | if (report (R_ASK, MB_YESNO, "Do you want to submit the " |
| 587 | "test results?") == IDYES) |
| 588 | if (!send_file (logname) && remove (logname)) |
| 589 | report (R_WARNING, "Can't remove logfile: %d.", errno); |
| 590 | free (logname); |
| 591 | } else run_tests (logname, tag); |
Ferenc Wagner | efc6725 | 2004-02-19 04:12:42 +0000 | [diff] [blame] | 592 | report (R_STATUS, "Finished"); |
| 593 | } |
Ferenc Wagner | 354f662 | 2004-01-15 01:48:05 +0000 | [diff] [blame] | 594 | exit (0); |
Alexandre Julliard | 9f71bd9 | 2003-12-04 02:01:39 +0000 | [diff] [blame] | 595 | } |