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"
58 static struct wine_test
*wine_tests
;
59 static struct rev_info
*rev_infos
= NULL
;
60 static const char whitespace
[] = " \t\r\n";
62 static int running_under_wine ()
64 HMODULE module
= GetModuleHandleA("ntdll.dll");
66 if (!module
) return 0;
67 return (GetProcAddress(module
, "wine_server_call") != NULL
);
70 static int running_on_visible_desktop ()
72 FARPROC pGetProcessWindowStation
= GetProcAddress(GetModuleHandle("user32.dll"), "GetProcessWindowStation");
74 if (pGetProcessWindowStation
)
78 USEROBJECTFLAGS uoflags
;
79 FARPROC pGetUserObjectInformationA
= GetProcAddress(GetModuleHandle("user32.dll"), "GetUserObjectInformationA");
81 wstation
= (HWINSTA
)pGetProcessWindowStation();
82 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
83 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
86 return IsWindowVisible(GetDesktopWindow());
94 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
95 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
97 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
98 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
99 report (R_FATAL
, "Can't get OS version.");
102 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
103 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
104 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
105 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
106 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
107 ver
.dwPlatformId
, ver
.szCSDVersion
);
111 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
112 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
113 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
114 ver
.wProductType
, ver
.wReserved
);
117 static inline int is_dot_dir(const char* x
)
119 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
122 void remove_dir (const char *dir
)
127 size_t dirlen
= strlen (dir
);
129 /* Make sure the directory exists before going further */
130 memcpy (path
, dir
, dirlen
);
131 strcpy (path
+ dirlen
++, "\\*");
132 hFind
= FindFirstFile (path
, &wfd
);
133 if (hFind
== INVALID_HANDLE_VALUE
) return;
136 char *lp
= wfd
.cFileName
;
138 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
139 if (is_dot_dir (lp
)) continue;
140 strcpy (path
+ dirlen
, lp
);
141 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
143 else if (!DeleteFile (path
))
144 report (R_WARNING
, "Can't delete file %s: error %d",
145 path
, GetLastError ());
146 } while (FindNextFile (hFind
, &wfd
));
148 if (!RemoveDirectory (dir
))
149 report (R_WARNING
, "Can't remove directory %s: error %d",
150 dir
, GetLastError ());
153 const char* get_test_source_file(const char* test
, const char* subtest
)
155 static const char* special_dirs
[][2] = {
156 { "gdi32", "gdi"}, { "kernel32", "kernel" },
157 { "msacm32", "msacm" },
158 { "user32", "user" }, { "winspool.drv", "winspool" },
159 { "ws2_32", "winsock" }, { 0, 0 }
161 static char buffer
[MAX_PATH
];
164 for (i
= 0; special_dirs
[i
][0]; i
++) {
165 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
166 test
= special_dirs
[i
][1];
171 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
175 const char* get_file_rev(const char* file
)
177 const struct rev_info
* rev
;
179 for(rev
= rev_infos
; rev
->file
; rev
++) {
180 if (strcmp(rev
->file
, file
) == 0) return rev
->rev
;
186 void extract_rev_infos ()
188 char revinfo
[256], *p
;
189 int size
= 0, i
, len
;
190 HMODULE module
= GetModuleHandle (NULL
);
192 for (i
= 0; TRUE
; i
++) {
195 rev_infos
= xrealloc (rev_infos
, size
* sizeof (*rev_infos
));
197 memset(rev_infos
+ i
, 0, sizeof(rev_infos
[i
]));
199 len
= LoadStringA (module
, REV_INFO
+i
, revinfo
, sizeof(revinfo
));
200 if (len
== 0) break; /* end of revision info */
201 if (len
>= sizeof(revinfo
) - 1)
202 report (R_FATAL
, "Revision info too long.");
203 if(!(p
= strrchr(revinfo
, ':')))
204 report (R_FATAL
, "Revision info malformed (i=%d)", i
);
206 rev_infos
[i
].file
= strdup(revinfo
);
207 rev_infos
[i
].rev
= strdup(p
+ 1);
211 void* extract_rcdata (int id
, int type
, DWORD
* size
)
217 if (!(rsrc
= FindResource (NULL
, (LPTSTR
)id
, MAKEINTRESOURCE(type
))) ||
218 !(*size
= SizeofResource (0, rsrc
)) ||
219 !(hdl
= LoadResource (0, rsrc
)) ||
220 !(addr
= LockResource (hdl
)))
225 /* Fills in the name and exename fields */
227 extract_test (struct wine_test
*test
, const char *dir
, int id
)
232 int strlen
, bufflen
= 128;
235 code
= extract_rcdata (id
, TESTRES
, &size
);
236 if (!code
) report (R_FATAL
, "Can't find test resource %d: %d",
237 id
, GetLastError ());
238 test
->name
= xmalloc (bufflen
);
239 while ((strlen
= LoadStringA (NULL
, id
, test
->name
, bufflen
))
242 test
->name
= xrealloc (test
->name
, bufflen
);
244 if (!strlen
) report (R_FATAL
, "Can't read name of test %d.", id
);
245 test
->exename
= strmake (NULL
, "%s/%s", dir
, test
->name
);
246 exepos
= strstr (test
->name
, "_test.exe");
247 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
249 test
->name
= xrealloc (test
->name
, exepos
- test
->name
+ 1);
250 report (R_STEP
, "Extracting: %s", test
->name
);
252 if (!(fout
= fopen (test
->exename
, "wb")) ||
253 (fwrite (code
, size
, 1, fout
) != 1) ||
254 fclose (fout
)) report (R_FATAL
, "Failed to write file %s.",
258 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
261 Return the exit status, -2 if can't create process or the return
262 value of WaitForSingleObject.
265 run_ex (char *cmd
, const char *out
, DWORD ms
)
268 PROCESS_INFORMATION pi
;
269 int fd
, oldstdout
= -1;
272 GetStartupInfo (&si
);
273 si
.wShowWindow
= SW_HIDE
;
274 si
.dwFlags
= STARTF_USESHOWWINDOW
;
277 fd
= open (out
, O_WRONLY
| O_CREAT
, 0666);
279 report (R_FATAL
, "Can't open '%s': %d", out
, errno
);
282 report (R_FATAL
, "Can't save stdout: %d", errno
);
283 if (-1 == dup2 (fd
, 1))
284 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
288 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, 0,
289 NULL
, NULL
, &si
, &pi
)) {
292 CloseHandle (pi
.hThread
);
293 wait
= WaitForSingleObject (pi
.hProcess
, ms
);
294 if (wait
== WAIT_OBJECT_0
) {
295 GetExitCodeProcess (pi
.hProcess
, &status
);
299 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
,
303 report (R_ERROR
, "Process '%s' timed out.", cmd
);
306 report (R_ERROR
, "Wait returned %d", wait
);
309 if (!TerminateProcess (pi
.hProcess
, 257))
310 report (R_ERROR
, "TerminateProcess failed: %d",
312 wait
= WaitForSingleObject (pi
.hProcess
, 5000);
316 "Wait for termination of '%s' failed: %d",
317 cmd
, GetLastError ());
322 report (R_ERROR
, "Can't kill process '%s'", cmd
);
325 report (R_ERROR
, "Waiting for termination: %d",
329 CloseHandle (pi
.hProcess
);
334 if (-1 == dup2 (oldstdout
, 1))
335 report (R_FATAL
, "Can't recover stdout: %d", errno
);
342 get_subtests (const char *tempdir
, struct wine_test
*test
, int id
)
347 char buffer
[8192], *index
;
348 static const char header
[] = "Valid test names:";
351 test
->subtest_count
= 0;
353 subname
= tempnam (0, "sub");
354 if (!subname
) report (R_FATAL
, "Can't name subtests file.");
356 extract_test (test
, tempdir
, id
);
357 run_ex (test
->exename
, subname
, 5000);
359 subfile
= fopen (subname
, "r");
361 report (R_ERROR
, "Can't open subtests output of %s: %d",
365 total
= fread (buffer
, 1, sizeof buffer
, subfile
);
367 if (sizeof buffer
== total
) {
368 report (R_ERROR
, "Subtest list of %s too big.",
369 test
->name
, sizeof buffer
);
374 index
= strstr (buffer
, header
);
376 report (R_ERROR
, "Can't parse subtests output of %s",
380 index
+= sizeof header
;
383 test
->subtests
= xmalloc (allocated
* sizeof(char*));
384 index
= strtok (index
, whitespace
);
386 if (test
->subtest_count
== allocated
) {
388 test
->subtests
= xrealloc (test
->subtests
,
389 allocated
* sizeof(char*));
391 test
->subtests
[test
->subtest_count
++] = strdup (index
);
392 index
= strtok (NULL
, whitespace
);
394 test
->subtests
= xrealloc (test
->subtests
,
395 test
->subtest_count
* sizeof(char*));
398 if (remove (subname
))
399 report (R_WARNING
, "Can't delete file '%s': %d",
405 run_test (struct wine_test
* test
, const char* subtest
)
408 const char* file
= get_test_source_file(test
->name
, subtest
);
409 const char* rev
= get_file_rev(file
);
410 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
412 xprintf ("%s:%s start %s %s\n", test
->name
, subtest
, file
, rev
);
413 status
= run_ex (cmd
, NULL
, 120000);
415 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
419 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
420 LPTSTR lpszName
, LONG_PTR lParam
)
427 run_tests (char *logname
, const char *tag
)
429 int nr_of_files
= 0, nr_of_tests
= 0, i
;
432 char *strres
, *eol
, *nextline
;
435 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
438 logname
= tempnam (0, "res");
439 if (!logname
) report (R_FATAL
, "Can't name logfile.");
441 report (R_OUT
, logname
);
443 logfile
= open (logname
, O_WRONLY
| O_CREAT
| O_EXCL
| O_APPEND
,
447 report (R_FATAL
, "File %s already exists.", logname
);
448 else report (R_FATAL
, "Could not open logfile: %d", errno
);
450 if (-1 == dup2 (logfile
, 1))
451 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
454 tempdir
= tempnam (0, "wct");
456 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
457 report (R_DIR
, tempdir
);
458 if (!CreateDirectory (tempdir
, NULL
))
459 report (R_FATAL
, "Could not create directory: %s", tempdir
);
461 xprintf ("Version 3\n");
462 strres
= extract_rcdata (WINE_BUILD
, STRINGRES
, &strsize
);
463 xprintf ("Tests from build ");
464 if (strres
) xprintf ("%.*s", strsize
, strres
);
465 else xprintf ("-\n");
466 strres
= extract_rcdata (TESTS_URL
, STRINGRES
, &strsize
);
467 xprintf ("Archive: ");
468 if (strres
) xprintf ("%.*s", strsize
, strres
);
469 else xprintf ("-\n");
470 xprintf ("Tag: %s\n", tag
?tag
:"");
471 xprintf ("Build info:\n");
472 strres
= extract_rcdata (BUILD_INFO
, STRINGRES
, &strsize
);
474 eol
= memchr (strres
, '\n', strsize
);
477 eol
= strres
+ strsize
;
479 strsize
-= eol
- strres
+ 1;
480 nextline
= strsize
?eol
+1:NULL
;
481 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
483 xprintf (" %.*s\n", eol
-strres
, strres
);
486 xprintf ("Operating system version:\n");
488 xprintf ("Test output:\n" );
490 report (R_STATUS
, "Counting tests");
491 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
492 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
493 report (R_FATAL
, "Can't enumerate test files: %d",
495 wine_tests
= xmalloc (nr_of_files
* sizeof wine_tests
[0]);
497 report (R_STATUS
, "Extracting tests");
498 report (R_PROGRESS
, 0, nr_of_files
);
499 for (i
= 0; i
< nr_of_files
; i
++) {
500 get_subtests (tempdir
, wine_tests
+i
, i
);
501 nr_of_tests
+= wine_tests
[i
].subtest_count
;
503 report (R_DELTA
, 0, "Extracting: Done");
505 report (R_STATUS
, "Running tests");
506 report (R_PROGRESS
, 1, nr_of_tests
);
507 for (i
= 0; i
< nr_of_files
; i
++) {
508 struct wine_test
*test
= wine_tests
+ i
;
511 for (j
= 0; j
< test
->subtest_count
; j
++) {
512 report (R_STEP
, "Running: %s:%s", test
->name
,
514 run_test (test
, test
->subtests
[j
]);
517 report (R_DELTA
, 0, "Running: Done");
519 report (R_STATUS
, "Cleaning up");
521 remove_dir (tempdir
);
532 Usage: winetest [OPTION]...\n\n\
533 -c console mode, no GUI\n\
534 -e preserve the environment\n\
535 -h print this message and exit\n\
536 -q quiet mode, no output at all\n\
537 -o FILE put report into FILE, do not submit\n\
538 -s FILE submit FILE, do not run tests\n\
539 -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
542 int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrevInst
,
543 LPSTR cmdLine
, int cmdShow
)
545 char *logname
= NULL
;
546 const char *cp
, *submit
= NULL
, *tag
= NULL
;
549 if (!running_on_visible_desktop ()) {
550 report (R_ERROR
, "Tests must be run on a visible desktop");
554 /* initialize the revision information first */
557 cmdLine
= strtok (cmdLine
, whitespace
);
559 if (cmdLine
[0] != '-' || cmdLine
[2]) {
560 report (R_ERROR
, "Not a single letter option: %s", cmdLine
);
564 switch (cmdLine
[1]) {
578 submit
= strtok (NULL
, whitespace
);
580 report (R_WARNING
, "ignoring tag for submission");
584 logname
= strtok (NULL
, whitespace
);
587 tag
= strtok (NULL
, whitespace
);
588 cp
= badtagchar (tag
);
590 report (R_ERROR
, "invalid char in tag: %c", *cp
);
596 report (R_ERROR
, "invalid option: -%c", cmdLine
[1]);
600 cmdLine
= strtok (NULL
, whitespace
);
603 if (reset_env
&& (putenv ("WINETEST_PLATFORM=windows") ||
604 putenv ("WINETEST_DEBUG=1") ||
605 putenv ("WINETEST_INTERACTIVE=0") ||
606 putenv ("WINETEST_REPORT_SUCCESS=0")))
607 report (R_FATAL
, "Could not reset environment: %d", errno
);
609 report (R_STATUS
, "Starting up");
611 logname
= run_tests (NULL
, tag
);
612 if (report (R_ASK
, MB_YESNO
, "Do you want to submit the "
613 "test results?") == IDYES
)
614 if (!send_file (logname
) && remove (logname
))
615 report (R_WARNING
, "Can't remove logfile: %d.", errno
);
617 } else run_tests (logname
, tag
);
618 report (R_STATUS
, "Finished");