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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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"
59 static struct wine_test
*wine_tests
;
60 static int nr_of_files
, nr_of_tests
;
61 static struct rev_info
*rev_infos
= NULL
;
62 static const char whitespace
[] = " \t\r\n";
63 static const char testexe
[] = "_test.exe";
65 static char * get_file_version(char * file_name
)
67 static char version
[32];
71 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
73 char * data
= xmalloc(size
);
75 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
76 static char backslash
[] = "\\";
77 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
79 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
80 sprintf(version
, "%d.%d.%d.%d",
81 pFixedVersionInfo
->dwFileVersionMS
>> 16,
82 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
83 pFixedVersionInfo
->dwFileVersionLS
>> 16,
84 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
86 sprintf(version
, "version not available");
88 sprintf(version
, "unknown");
91 sprintf(version
, "failed");
93 sprintf(version
, "version not available");
98 static int running_under_wine (void)
100 HMODULE module
= GetModuleHandleA("ntdll.dll");
102 if (!module
) return 0;
103 return (GetProcAddress(module
, "wine_server_call") != NULL
);
106 static int running_on_visible_desktop (void)
109 HMODULE huser32
= GetModuleHandle("user32.dll");
110 FARPROC pGetProcessWindowStation
= GetProcAddress(huser32
, "GetProcessWindowStation");
111 FARPROC pGetUserObjectInformationA
= GetProcAddress(huser32
, "GetUserObjectInformationA");
113 desktop
= GetDesktopWindow();
114 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
115 return IsWindowVisible(desktop
);
117 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
121 USEROBJECTFLAGS uoflags
;
123 wstation
= (HWINSTA
)pGetProcessWindowStation();
124 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
125 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
127 return IsWindowVisible(desktop
);
130 static void print_version (void)
135 const char *(*wine_get_build_id
)(void);
137 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEX
);
138 if (!(ext
= GetVersionEx ((OSVERSIONINFO
*) &ver
)))
140 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
141 if (!GetVersionEx ((OSVERSIONINFO
*) &ver
))
142 report (R_FATAL
, "Can't get OS version.");
145 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
146 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
147 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
148 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
149 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
150 ver
.dwPlatformId
, ver
.szCSDVersion
);
152 wine_get_build_id
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
153 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
155 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
157 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
161 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
162 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
163 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
164 ver
.wProductType
, ver
.wReserved
);
167 static inline int is_dot_dir(const char* x
)
169 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
172 static void remove_dir (const char *dir
)
177 size_t dirlen
= strlen (dir
);
179 /* Make sure the directory exists before going further */
180 memcpy (path
, dir
, dirlen
);
181 strcpy (path
+ dirlen
++, "\\*");
182 hFind
= FindFirstFile (path
, &wfd
);
183 if (hFind
== INVALID_HANDLE_VALUE
) return;
186 char *lp
= wfd
.cFileName
;
188 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
189 if (is_dot_dir (lp
)) continue;
190 strcpy (path
+ dirlen
, lp
);
191 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
193 else if (!DeleteFile (path
))
194 report (R_WARNING
, "Can't delete file %s: error %d",
195 path
, GetLastError ());
196 } while (FindNextFile (hFind
, &wfd
));
198 if (!RemoveDirectory (dir
))
199 report (R_WARNING
, "Can't remove directory %s: error %d",
200 dir
, GetLastError ());
203 static const char* get_test_source_file(const char* test
, const char* subtest
)
205 static const char* special_dirs
[][2] = {
208 static char buffer
[MAX_PATH
];
211 for (i
= 0; special_dirs
[i
][0]; i
++) {
212 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
213 test
= special_dirs
[i
][1];
218 snprintf(buffer
, sizeof(buffer
), "dlls/%s/tests/%s.c", test
, subtest
);
222 static const char* get_file_rev(const char* file
)
224 const struct rev_info
* rev
;
226 for(rev
= rev_infos
; rev
->file
; rev
++) {
227 if (strcmp(rev
->file
, file
) == 0) return rev
->rev
;
233 static void extract_rev_infos (void)
235 char revinfo
[256], *p
;
238 HMODULE module
= GetModuleHandle (NULL
);
240 for (i
= 0; TRUE
; i
++) {
243 rev_infos
= xrealloc (rev_infos
, size
* sizeof (*rev_infos
));
245 memset(rev_infos
+ i
, 0, sizeof(rev_infos
[i
]));
247 len
= LoadStringA (module
, REV_INFO
+i
, revinfo
, sizeof(revinfo
));
248 if (len
== 0) break; /* end of revision info */
249 if (len
>= sizeof(revinfo
) - 1)
250 report (R_FATAL
, "Revision info too long.");
251 if(!(p
= strrchr(revinfo
, ':')))
252 report (R_FATAL
, "Revision info malformed (i=%d)", i
);
254 rev_infos
[i
].file
= strdup(revinfo
);
255 rev_infos
[i
].rev
= strdup(p
+ 1);
259 static void* extract_rcdata (LPTSTR name
, int type
, DWORD
* size
)
265 if (!(rsrc
= FindResource (NULL
, name
, MAKEINTRESOURCE(type
))) ||
266 !(*size
= SizeofResource (0, rsrc
)) ||
267 !(hdl
= LoadResource (0, rsrc
)) ||
268 !(addr
= LockResource (hdl
)))
273 /* Fills in the name and exename fields */
275 extract_test (struct wine_test
*test
, const char *dir
, LPTSTR res_name
)
283 code
= extract_rcdata (res_name
, TESTRES
, &size
);
284 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
285 res_name
, GetLastError ());
286 test
->name
= xstrdup( res_name
);
287 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
288 exepos
= strstr (test
->name
, testexe
);
289 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
291 test
->name
= xrealloc (test
->name
, exepos
- test
->name
+ 1);
292 report (R_STEP
, "Extracting: %s", test
->name
);
294 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
295 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
296 if (hfile
== INVALID_HANDLE_VALUE
)
297 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
299 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
300 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
305 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
308 Return the exit status, -2 if can't create process or the return
309 value of WaitForSingleObject.
312 run_ex (char *cmd
, const char *out
, const char *tempdir
, DWORD ms
)
315 PROCESS_INFORMATION pi
;
316 int fd
, oldstdout
= -1;
319 GetStartupInfo (&si
);
323 fd
= open (out
, O_WRONLY
| O_CREAT
, 0666);
325 report (R_FATAL
, "Can't open '%s': %d", out
, errno
);
328 report (R_FATAL
, "Can't save stdout: %d", errno
);
329 if (-1 == dup2 (fd
, 1))
330 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
334 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
335 NULL
, tempdir
, &si
, &pi
)) {
338 CloseHandle (pi
.hThread
);
339 wait
= WaitForSingleObject (pi
.hProcess
, ms
);
340 if (wait
== WAIT_OBJECT_0
) {
341 GetExitCodeProcess (pi
.hProcess
, &status
);
345 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
,
349 report (R_ERROR
, "Process '%s' timed out.", cmd
);
352 report (R_ERROR
, "Wait returned %d", wait
);
355 if (!TerminateProcess (pi
.hProcess
, 257))
356 report (R_ERROR
, "TerminateProcess failed: %d",
358 wait
= WaitForSingleObject (pi
.hProcess
, 5000);
362 "Wait for termination of '%s' failed: %d",
363 cmd
, GetLastError ());
368 report (R_ERROR
, "Can't kill process '%s'", cmd
);
371 report (R_ERROR
, "Waiting for termination: %d",
375 CloseHandle (pi
.hProcess
);
380 if (-1 == dup2 (oldstdout
, 1))
381 report (R_FATAL
, "Can't recover stdout: %d", errno
);
388 get_subtests (const char *tempdir
, struct wine_test
*test
, LPTSTR res_name
)
393 char buffer
[8192], *index
;
394 static const char header
[] = "Valid test names:";
397 test
->subtest_count
= 0;
399 subname
= tempnam (0, "sub");
400 if (!subname
) report (R_FATAL
, "Can't name subtests file.");
402 extract_test (test
, tempdir
, res_name
);
403 cmd
= strmake (NULL
, "%s --list", test
->exename
);
404 run_ex (cmd
, subname
, tempdir
, 5000);
407 subfile
= fopen (subname
, "r");
409 report (R_ERROR
, "Can't open subtests output of %s: %d",
413 total
= fread (buffer
, 1, sizeof buffer
, subfile
);
415 if (sizeof buffer
== total
) {
416 report (R_ERROR
, "Subtest list of %s too big.",
417 test
->name
, sizeof buffer
);
422 index
= strstr (buffer
, header
);
424 report (R_ERROR
, "Can't parse subtests output of %s",
428 index
+= sizeof header
;
431 test
->subtests
= xmalloc (allocated
* sizeof(char*));
432 index
= strtok (index
, whitespace
);
434 if (test
->subtest_count
== allocated
) {
436 test
->subtests
= xrealloc (test
->subtests
,
437 allocated
* sizeof(char*));
439 test
->subtests
[test
->subtest_count
++] = strdup (index
);
440 index
= strtok (NULL
, whitespace
);
442 test
->subtests
= xrealloc (test
->subtests
,
443 test
->subtest_count
* sizeof(char*));
446 if (remove (subname
))
447 report (R_WARNING
, "Can't delete file '%s': %d",
453 run_test (struct wine_test
* test
, const char* subtest
, const char *tempdir
)
456 const char* file
= get_test_source_file(test
->name
, subtest
);
457 const char* rev
= get_file_rev(file
);
458 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
460 xprintf ("%s:%s start %s %s\n", test
->name
, subtest
, file
, rev
);
461 status
= run_ex (cmd
, NULL
, tempdir
, 120000);
463 xprintf ("%s:%s done (%d)\n", test
->name
, subtest
, status
);
467 EnumTestFileProc (HMODULE hModule
, LPCTSTR lpszType
,
468 LPTSTR lpszName
, LONG_PTR lParam
)
475 extract_test_proc (HMODULE hModule
, LPCTSTR lpszType
,
476 LPTSTR lpszName
, LONG_PTR lParam
)
478 const char *tempdir
= (const char *)lParam
;
479 char dllname
[MAX_PATH
];
482 /* Check if the main dll is present on this system */
483 CharLowerA(lpszName
);
484 strcpy(dllname
, lpszName
);
485 *strstr(dllname
, testexe
) = 0;
487 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
489 xprintf (" %s=dll is missing\n", dllname
);
494 xprintf (" %s=%s\n", dllname
, get_file_version(dllname
));
496 get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
);
497 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
503 run_tests (char *logname
)
506 char *tempdir
, *shorttempdir
;
508 char *strres
, *eol
, *nextline
;
512 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
515 logname
= tempnam (0, "res");
516 if (!logname
) report (R_FATAL
, "Can't name logfile.");
518 report (R_OUT
, logname
);
520 logfile
= open (logname
, O_WRONLY
| O_CREAT
| O_EXCL
| O_APPEND
,
524 report (R_FATAL
, "File %s already exists.", logname
);
525 else report (R_FATAL
, "Could not open logfile: %d", errno
);
527 if (-1 == dup2 (logfile
, 1))
528 report (R_FATAL
, "Can't redirect stdout: %d", errno
);
531 tempdir
= tempnam (0, "wct");
533 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
534 shorttempdir
= strdup (tempdir
);
535 if (shorttempdir
) { /* try stable path for ZoneAlarm */
536 strstr (shorttempdir
, "wct")[3] = 0;
537 if (CreateDirectoryA (shorttempdir
, NULL
)) {
539 tempdir
= shorttempdir
;
540 } else free (shorttempdir
);
542 if (tempdir
!= shorttempdir
&& !CreateDirectoryA (tempdir
, NULL
))
543 report (R_FATAL
, "Could not create directory: %s", tempdir
);
544 report (R_DIR
, tempdir
);
546 xprintf ("Version 4\n");
547 strres
= extract_rcdata (MAKEINTRESOURCE(WINE_BUILD
), STRINGRES
, &strsize
);
548 xprintf ("Tests from build ");
549 if (LoadStringA( 0, IDS_BUILD_ID
, build
, sizeof(build
) )) xprintf( "%s\n", build
);
550 else if (strres
) xprintf ("%.*s", strsize
, strres
);
551 else xprintf ("-\n");
552 strres
= extract_rcdata (MAKEINTRESOURCE(TESTS_URL
), STRINGRES
, &strsize
);
553 xprintf ("Archive: ");
554 if (strres
) xprintf ("%.*s", strsize
, strres
);
555 else xprintf ("-\n");
556 xprintf ("Tag: %s\n", tag
);
557 xprintf ("Build info:\n");
558 strres
= extract_rcdata (MAKEINTRESOURCE(BUILD_INFO
), STRINGRES
, &strsize
);
560 eol
= memchr (strres
, '\n', strsize
);
563 eol
= strres
+ strsize
;
565 strsize
-= eol
- strres
+ 1;
566 nextline
= strsize
?eol
+1:NULL
;
567 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
569 xprintf (" %.*s\n", eol
-strres
, strres
);
572 xprintf ("Operating system version:\n");
574 xprintf ("Dll info:\n" );
576 report (R_STATUS
, "Counting tests");
577 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
578 EnumTestFileProc
, (LPARAM
)&nr_of_files
))
579 report (R_FATAL
, "Can't enumerate test files: %d",
581 wine_tests
= xmalloc (nr_of_files
* sizeof wine_tests
[0]);
583 report (R_STATUS
, "Extracting tests");
584 report (R_PROGRESS
, 0, nr_of_files
);
587 if (!EnumResourceNames (NULL
, MAKEINTRESOURCE(TESTRES
),
588 extract_test_proc
, (LPARAM
)tempdir
))
589 report (R_FATAL
, "Can't enumerate test files: %d",
592 xprintf ("Test output:\n" );
594 report (R_DELTA
, 0, "Extracting: Done");
596 report (R_STATUS
, "Running tests");
597 report (R_PROGRESS
, 1, nr_of_tests
);
598 for (i
= 0; i
< nr_of_files
; i
++) {
599 struct wine_test
*test
= wine_tests
+ i
;
602 for (j
= 0; j
< test
->subtest_count
; j
++) {
603 report (R_STEP
, "Running: %s:%s", test
->name
,
605 run_test (test
, test
->subtests
[j
], tempdir
);
608 report (R_DELTA
, 0, "Running: Done");
610 report (R_STATUS
, "Cleaning up");
612 remove_dir (tempdir
);
623 "Usage: winetest [OPTION]...\n\n"
624 " -c console mode, no GUI\n"
625 " -e preserve the environment\n"
626 " -h print this message and exit\n"
627 " -p shutdown when the tests are done\n"
628 " -q quiet mode, no output at all\n"
629 " -o FILE put report into FILE, do not submit\n"
630 " -s FILE submit FILE, do not run tests\n"
631 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
634 int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrevInst
,
635 LPSTR cmdLine
, int cmdShow
)
637 char *logname
= NULL
;
638 const char *cp
, *submit
= NULL
;
643 /* initialize the revision information first */
646 cmdLine
= strtok (cmdLine
, whitespace
);
648 if (cmdLine
[0] != '-' || cmdLine
[2]) {
649 report (R_ERROR
, "Not a single letter option: %s", cmdLine
);
653 switch (cmdLine
[1]) {
673 submit
= strtok (NULL
, whitespace
);
675 report (R_WARNING
, "ignoring tag for submission");
679 logname
= strtok (NULL
, whitespace
);
682 tag
= strtok (NULL
, whitespace
);
683 if (strlen (tag
) > MAXTAGLEN
)
684 report (R_FATAL
, "tag is too long (maximum %d characters)",
686 cp
= findbadtagchar (tag
);
688 report (R_ERROR
, "invalid char in tag: %c", *cp
);
694 report (R_ERROR
, "invalid option: -%c", cmdLine
[1]);
698 cmdLine
= strtok (NULL
, whitespace
);
701 static CHAR platform_windows
[] = "WINETEST_PLATFORM=windows",
702 platform_wine
[] = "WINETEST_PLATFORM=wine",
703 debug_yes
[] = "WINETEST_DEBUG=1",
704 interactive_no
[] = "WINETEST_INTERACTIVE=0",
705 report_success_no
[] = "WINETEST_REPORT_SUCCESS=0";
708 report (R_STATUS
, "Starting up");
710 if (!running_on_visible_desktop ())
711 report (R_FATAL
, "Tests must be run on a visible desktop");
713 platform
= running_under_wine () ? platform_wine
: platform_windows
;
715 if (reset_env
&& (putenv (platform
) ||
716 putenv (debug_yes
) ||
717 putenv (interactive_no
) ||
718 putenv (report_success_no
)))
719 report (R_FATAL
, "Could not reset environment: %d", errno
);
723 report (R_FATAL
, "Please specify a tag (-t option) if "
724 "running noninteractive!");
725 if (guiAskTag () == IDABORT
) exit (1);
730 logname
= run_tests (NULL
);
731 if (report (R_ASK
, MB_YESNO
, "Do you want to submit the "
732 "test results?") == IDYES
)
733 if (!send_file (logname
) && remove (logname
))
734 report (R_WARNING
, "Can't remove logfile: %d.", errno
);
736 } else run_tests (logname
);
737 report (R_STATUS
, "Finished");
742 TOKEN_PRIVILEGES npr
;
744 /* enable the shutdown privilege for the current process */
745 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
747 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME
, &npr
.Privileges
[0].Luid
);
748 npr
.PrivilegeCount
= 1;
749 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
750 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
753 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);