2 * Wine Conformance Test EXE
4 * Copyright 2003, 2004 Jakob Eriksson (for Solid Form Sweden AB)
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Ferenc Wagner
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.
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.
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This program is dedicated to Anna Lindh,
23 * Swedish Minister of Foreign Affairs.
24 * Anna was murdered September 11, 2003.
29 #include "wine/port.h"
57 static struct wine_test
*wine_tests
;
58 static struct rev_info
*rev_infos
= NULL
;
59 static const char whitespace
[] = " \t\r\n";
61 static int running_under_wine ()
63 HMODULE module
= GetModuleHandleA("ntdll.dll");
65 if (!module
) return 0;
66 return (GetProcAddress(module
, "wine_server_call") != NULL
);
69 static int running_on_visible_desktop ()
77 desktop
= GetDesktopWindow();
79 hrgn
= CreateRectRgn(0, 0, 0, 0);
80 GetRandomRgn(hdc
, hrgn
, SYSRGN
);
82 visible
= GetRgnBox(hrgn
, &rc
) != NULLREGION
;
85 ReleaseDC(desktop
, hdc
);
95 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
96 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
98 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
99 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
100 report (R_FATAL
, "Can't get OS version.");
103 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
104 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
105 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
106 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
107 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
108 ver
.dwPlatformId
, ver
.szCSDVersion
);
112 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
113 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
114 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
115 ver
.wProductType
, ver
.wReserved
);
118 static inline int is_dot_dir(const char* x
)
120 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
123 void remove_dir (const char *dir
)
128 size_t dirlen
= strlen (dir
);
130 /* Make sure the directory exists before going further */
131 memcpy (path
, dir
, dirlen
);
132 strcpy (path
+ dirlen
++, "\\*");
133 hFind
= FindFirstFile (path
, &wfd
);
134 if (hFind
== INVALID_HANDLE_VALUE
) return;
137 char *lp
= wfd
.cFileName
;
139 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
140 if (is_dot_dir (lp
)) continue;
141 strcpy (path
+ dirlen
, lp
);
142 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
144 else if (!DeleteFile (path
))
145 report (R_WARNING
, "Can't delete file %s: error %d",
146 path
, GetLastError ());
147 } while (FindNextFile (hFind
, &wfd
));
149 if (!RemoveDirectory (dir
))
150 report (R_WARNING
, "Can't remove directory %s: error %d",
151 dir
, GetLastError ());
154 const char* get_test_source_file(const char* test
, const char* subtest
)
156 static const char* special_dirs
[][2] = {
157 { "gdi32", "gdi"}, { "kernel32", "kernel" },
158 { "msacm32", "msacm" },
159 { "user32", "user" }, { "winspool.drv", "winspool" },
160 { "ws2_32", "winsock" }, { 0, 0 }
162 static char buffer
[MAX_PATH
];
165 for (i
= 0; special_dirs
[i
][0]; i
++) {
166 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
167 test
= special_dirs
[i
][1];
172 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
176 const char* get_file_rev(const char* file
)
178 const struct rev_info
* rev
;
180 for(rev
= rev_infos
; rev
->file
; rev
++) {
181 if (strcmp(rev
->file
, file
) == 0) return rev
->rev
;
187 void extract_rev_infos ()
189 char revinfo
[256], *p
;
190 int size
= 0, i
, len
;
191 HMODULE module
= GetModuleHandle (NULL
);
193 for (i
= 0; TRUE
; i
++) {
196 rev_infos
= xrealloc (rev_infos
, size
* sizeof (*rev_infos
));
198 memset(rev_infos
+ i
, 0, sizeof(rev_infos
[i
]));
200 len
= LoadStringA (module
, REV_INFO
+i
, revinfo
, sizeof(revinfo
));
201 if (len
== 0) break; /* end of revision info */
202 if (len
>= sizeof(revinfo
) - 1)
203 report (R_FATAL
, "Revision info too long.");
204 if(!(p
= strrchr(revinfo
, ':')))
205 report (R_FATAL
, "Revision info malformed (i=%d)", i
);
207 rev_infos
[i
].file
= strdup(revinfo
);
208 rev_infos
[i
].rev
= strdup(p
+ 1);
212 void* extract_rcdata (int id
, int type
, DWORD
* size
)
218 if (!(rsrc
= FindResource (NULL
, (LPTSTR
)id
, MAKEINTRESOURCE(type
))) ||
219 !(*size
= SizeofResource (0, rsrc
)) ||
220 !(hdl
= LoadResource (0, rsrc
)) ||
221 !(addr
= LockResource (hdl
)))
226 /* Fills in the name and exename fields */
228 extract_test (struct wine_test
*test
, const char *dir
, int id
)
233 int strlen
, bufflen
= 128;
236 code
= extract_rcdata (id
, TESTRES
, &size
);
237 if (!code
) report (R_FATAL
, "Can't find test resource %d: %d",
238 id
, GetLastError ());
239 test
->name
= xmalloc (bufflen
);
240 while ((strlen
= LoadStringA (NULL
, id
, test
->name
, bufflen
))
243 test
->name
= xrealloc (test
->name
, bufflen
);
245 if (!strlen
) report (R_FATAL
, "Can't read name of test %d.", id
);
246 test
->exename
= strmake (NULL
, "%s/%s", dir
, test
->name
);
247 exepos
= strstr (test
->name
, "_test.exe");
248 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
250 test
->name
= xrealloc (test
->name
, exepos
- test
->name
+ 1);
251 report (R_STEP
, "Extracting: %s", test
->name
);
253 if (!(fout
= fopen (test
->exename
, "wb")) ||
254 (fwrite (code
, size
, 1, fout
) != 1) ||
255 fclose (fout
)) report (R_FATAL
, "Failed to write file %s.",
259 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
262 Return the exit status, -2 if can't create process or the return
263 value of WaitForSingleObject.
266 run_ex (char *cmd
, const char *out
, DWORD ms
)
269 PROCESS_INFORMATION pi
;
270 int fd
, oldstdout
= -1;
273 GetStartupInfo (&si
);
274 si
.wShowWindow
= SW_HIDE
;
275 si
.dwFlags
= STARTF_USESHOWWINDOW
;
278 fd
= open (out
, O_WRONLY
| O_CREAT
, 0666);
280 report (R_FATAL
, "Can't open '%s': %d", out
, errno
);
283 report (R_FATAL
, "Can't save stdout: %d", errno
);
284 if (-1 == dup2 (fd
, 1))
285 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
289 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, 0,
290 NULL
, NULL
, &si
, &pi
)) {
293 CloseHandle (pi
.hThread
);
294 wait
= WaitForSingleObject (pi
.hProcess
, ms
);
295 if (wait
== WAIT_OBJECT_0
) {
296 GetExitCodeProcess (pi
.hProcess
, &status
);
300 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
,
304 report (R_ERROR
, "Process '%s' timed out.", cmd
);
307 report (R_ERROR
, "Wait returned %d", wait
);
310 if (!TerminateProcess (pi
.hProcess
, 257))
311 report (R_ERROR
, "TerminateProcess failed: %d",
313 wait
= WaitForSingleObject (pi
.hProcess
, 5000);
317 "Wait for termination of '%s' failed: %d",
318 cmd
, GetLastError ());
323 report (R_ERROR
, "Can't kill process '%s'", cmd
);
326 report (R_ERROR
, "Waiting for termination: %d",
330 CloseHandle (pi
.hProcess
);
335 if (-1 == dup2 (oldstdout
, 1))
336 report (R_FATAL
, "Can't recover stdout: %d", errno
);
343 get_subtests (const char *tempdir
, struct wine_test
*test
, int id
)
348 char buffer
[8192], *index
;
349 static const char header
[] = "Valid test names:";
352 test
->subtest_count
= 0;
354 subname
= tempnam (0, "sub");
355 if (!subname
) report (R_FATAL
, "Can't name subtests file.");
357 extract_test (test
, tempdir
, id
);
358 run_ex (test
->exename
, subname
, 5000);
360 subfile
= fopen (subname
, "r");
362 report (R_ERROR
, "Can't open subtests output of %s: %d",
366 total
= fread (buffer
, 1, sizeof buffer
, subfile
);
368 if (sizeof buffer
== total
) {
369 report (R_ERROR
, "Subtest list of %s too big.",
370 test
->name
, sizeof buffer
);
375 index
= strstr (buffer
, header
);
377 report (R_ERROR
, "Can't parse subtests output of %s",
381 index
+= sizeof header
;
384 test
->subtests
= xmalloc (allocated
* sizeof(char*));
385 index
= strtok (index
, whitespace
);
387 if (test
->subtest_count
== allocated
) {
389 test
->subtests
= xrealloc (test
->subtests
,
390 allocated
* sizeof(char*));
392 test
->subtests
[test
->subtest_count
++] = strdup (index
);
393 index
= strtok (NULL
, whitespace
);
395 test
->subtests
= xrealloc (test
->subtests
,
396 test
->subtest_count
* sizeof(char*));
399 if (remove (subname
))
400 report (R_WARNING
, "Can't delete file '%s': %d",
406 run_test (struct wine_test
* test
, const char* subtest
)
409 const char* file
= get_test_source_file(test
->name
, subtest
);
410 const char* rev
= get_file_rev(file
);
411 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
413 xprintf ("%s:%s start %s %s\n", test
->name
, subtest
, file
, rev
);
414 status
= run_ex (cmd
, NULL
, 120000);
416 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
420 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
421 LPTSTR lpszName
, LONG_PTR lParam
)
428 run_tests (char *logname
, const char *tag
)
430 int nr_of_files
= 0, nr_of_tests
= 0, i
;
433 char *strres
, *eol
, *nextline
;
436 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
439 logname
= tempnam (0, "res");
440 if (!logname
) report (R_FATAL
, "Can't name logfile.");
442 report (R_OUT
, logname
);
444 logfile
= open (logname
, O_WRONLY
| O_CREAT
| O_EXCL
| O_APPEND
,
448 report (R_FATAL
, "File %s already exists.", logname
);
449 else report (R_FATAL
, "Could not open logfile: %d", errno
);
451 if (-1 == dup2 (logfile
, 1))
452 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
455 tempdir
= tempnam (0, "wct");
457 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
458 report (R_DIR
, tempdir
);
459 if (!CreateDirectory (tempdir
, NULL
))
460 report (R_FATAL
, "Could not create directory: %s", tempdir
);
462 xprintf ("Version 3\n");
463 strres
= extract_rcdata (WINE_BUILD
, STRINGRES
, &strsize
);
464 xprintf ("Tests from build ");
465 if (strres
) xprintf ("%.*s", strsize
, strres
);
466 else xprintf ("-\n");
467 strres
= extract_rcdata (TESTS_URL
, STRINGRES
, &strsize
);
468 xprintf ("Archive: ");
469 if (strres
) xprintf ("%.*s", strsize
, strres
);
470 else xprintf ("-\n");
471 xprintf ("Tag: %s\n", tag
?tag
:"");
472 xprintf ("Build info:\n");
473 strres
= extract_rcdata (BUILD_INFO
, STRINGRES
, &strsize
);
475 eol
= memchr (strres
, '\n', strsize
);
478 eol
= strres
+ strsize
;
480 strsize
-= eol
- strres
+ 1;
481 nextline
= strsize
?eol
+1:NULL
;
482 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
484 xprintf (" %.*s\n", eol
-strres
, strres
);
487 xprintf ("Operating system version:\n");
489 xprintf ("Test output:\n" );
491 report (R_STATUS
, "Counting tests");
492 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
493 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
494 report (R_FATAL
, "Can't enumerate test files: %d",
496 wine_tests
= xmalloc (nr_of_files
* sizeof wine_tests
[0]);
498 report (R_STATUS
, "Extracting tests");
499 report (R_PROGRESS
, 0, nr_of_files
);
500 for (i
= 0; i
< nr_of_files
; i
++) {
501 get_subtests (tempdir
, wine_tests
+i
, i
);
502 nr_of_tests
+= wine_tests
[i
].subtest_count
;
504 report (R_DELTA
, 0, "Extracting: Done");
506 report (R_STATUS
, "Running tests");
507 report (R_PROGRESS
, 1, nr_of_tests
);
508 for (i
= 0; i
< nr_of_files
; i
++) {
509 struct wine_test
*test
= wine_tests
+ i
;
512 for (j
= 0; j
< test
->subtest_count
; j
++) {
513 report (R_STEP
, "Running: %s:%s", test
->name
,
515 run_test (test
, test
->subtests
[j
]);
518 report (R_DELTA
, 0, "Running: Done");
520 report (R_STATUS
, "Cleaning up");
522 remove_dir (tempdir
);
533 Usage: winetest [OPTION]...\n\n\
534 -c console mode, no GUI\n\
535 -e preserve the environment\n\
536 -h print this message and exit\n\
537 -q quiet mode, no output at all\n\
538 -o FILE put report into FILE, do not submit\n\
539 -s FILE submit FILE, do not run tests\n\
540 -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
543 int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrevInst
,
544 LPSTR cmdLine
, int cmdShow
)
546 char *logname
= NULL
;
547 const char *cp
, *submit
= NULL
, *tag
= NULL
;
550 if (!running_on_visible_desktop ()) {
551 report (R_ERROR
, "Tests must be run on a visible desktop");
555 /* initialize the revision information first */
558 cmdLine
= strtok (cmdLine
, whitespace
);
560 if (cmdLine
[0] != '-' || cmdLine
[2]) {
561 report (R_ERROR
, "Not a single letter option: %s", cmdLine
);
565 switch (cmdLine
[1]) {
579 submit
= strtok (NULL
, whitespace
);
581 report (R_WARNING
, "ignoring tag for submission");
585 logname
= strtok (NULL
, whitespace
);
588 tag
= strtok (NULL
, whitespace
);
589 cp
= badtagchar (tag
);
591 report (R_ERROR
, "invalid char in tag: %c", *cp
);
597 report (R_ERROR
, "invalid option: -%c", cmdLine
[1]);
601 cmdLine
= strtok (NULL
, whitespace
);
604 if (reset_env
&& (putenv ("WINETEST_PLATFORM=windows") ||
605 putenv ("WINETEST_DEBUG=1") ||
606 putenv ("WINETEST_INTERACTIVE=0") ||
607 putenv ("WINETEST_REPORT_SUCCESS=0")))
608 report (R_FATAL
, "Could not reset environment: %d", errno
);
610 report (R_STATUS
, "Starting up");
612 logname
= run_tests (NULL
, tag
);
613 if (report (R_ASK
, MB_YESNO
, "Do you want to submit the "
614 "test results?") == IDYES
)
615 if (!send_file (logname
) && remove (logname
))
616 report (R_WARNING
, "Can't remove logfile: %d.", errno
);
618 } else run_tests (logname
, tag
);
619 report (R_STATUS
, "Finished");