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)
282 code = extract_rcdata (res_name, TESTRES, &size);
283 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
284 res_name, GetLastError ());
285 test->name = xstrdup( res_name );
286 test->exename = strmake (NULL, "%s/%s", dir, test->name);
287 exepos = strstr (test->name, testexe);
288 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
290 test->name = xrealloc (test->name, exepos - test->name + 1);
291 report (R_STEP, "Extracting: %s", test->name);
293 if (!(fout = fopen (test->exename, "wb")) ||
294 (fwrite (code, size, 1, fout) != 1) ||
295 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
299 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
302 Return the exit status, -2 if can't create process or the return
303 value of WaitForSingleObject.
306 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
309 PROCESS_INFORMATION pi;
310 int fd, oldstdout = -1;
313 GetStartupInfo (&si);
317 fd = open (out, O_WRONLY | O_CREAT, 0666);
319 report (R_FATAL, "Can't open '%s': %d", out, errno);
322 report (R_FATAL, "Can't save stdout: %d", errno);
323 if (-1 == dup2 (fd, 1))
324 report (R_FATAL, "Can't redirect stdout: %d", errno);
328 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP,
329 NULL, tempdir, &si, &pi)) {
332 CloseHandle (pi.hThread);
333 wait = WaitForSingleObject (pi.hProcess, ms);
334 if (wait == WAIT_OBJECT_0) {
335 GetExitCodeProcess (pi.hProcess, &status);
339 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
343 report (R_ERROR, "Process '%s' timed out.", cmd);
346 report (R_ERROR, "Wait returned %d", wait);
349 if (!TerminateProcess (pi.hProcess, 257))
350 report (R_ERROR, "TerminateProcess failed: %d",
352 wait = WaitForSingleObject (pi.hProcess, 5000);
356 "Wait for termination of '%s' failed: %d",
357 cmd, GetLastError ());
362 report (R_ERROR, "Can't kill process '%s'", cmd);
365 report (R_ERROR, "Waiting for termination: %d",
369 CloseHandle (pi.hProcess);
374 if (-1 == dup2 (oldstdout, 1))
375 report (R_FATAL, "Can't recover stdout: %d", errno);
382 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
387 char buffer[8192], *index;
388 static const char header[] = "Valid test names:";
391 test->subtest_count = 0;
393 subname = tempnam (0, "sub");
394 if (!subname) report (R_FATAL, "Can't name subtests file.");
396 extract_test (test, tempdir, res_name);
397 cmd = strmake (NULL, "%s --list", test->exename);
398 run_ex (cmd, subname, tempdir, 5000);
401 subfile = fopen (subname, "r");
403 report (R_ERROR, "Can't open subtests output of %s: %d",
407 total = fread (buffer, 1, sizeof buffer, subfile);
409 if (sizeof buffer == total) {
410 report (R_ERROR, "Subtest list of %s too big.",
411 test->name, sizeof buffer);
416 index = strstr (buffer, header);
418 report (R_ERROR, "Can't parse subtests output of %s",
422 index += sizeof header;
425 test->subtests = xmalloc (allocated * sizeof(char*));
426 index = strtok (index, whitespace);
428 if (test->subtest_count == allocated) {
430 test->subtests = xrealloc (test->subtests,
431 allocated * sizeof(char*));
433 test->subtests[test->subtest_count++] = strdup (index);
434 index = strtok (NULL, whitespace);
436 test->subtests = xrealloc (test->subtests,
437 test->subtest_count * sizeof(char*));
440 if (remove (subname))
441 report (R_WARNING, "Can't delete file '%s': %d",
447 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
450 const char* file = get_test_source_file(test->name, subtest);
451 const char* rev = get_file_rev(file);
452 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
454 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
455 status = run_ex (cmd, NULL, tempdir, 120000);
457 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
461 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
462 LPTSTR lpszName, LONG_PTR lParam)
469 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
470 LPTSTR lpszName, LONG_PTR lParam)
472 const char *tempdir = (const char *)lParam;
473 char dllname[MAX_PATH];
476 /* Check if the main dll is present on this system */
477 CharLowerA(lpszName);
478 strcpy(dllname, lpszName);
479 *strstr(dllname, testexe) = 0;
481 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
483 xprintf (" %s=dll is missing\n", dllname);
488 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
490 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
491 nr_of_tests += wine_tests[nr_of_files].subtest_count;
497 run_tests (char *logname)
500 char *tempdir, *shorttempdir;
502 char *strres, *eol, *nextline;
506 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
509 logname = tempnam (0, "res");
510 if (!logname) report (R_FATAL, "Can't name logfile.");
512 report (R_OUT, logname);
514 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
518 report (R_FATAL, "File %s already exists.", logname);
519 else report (R_FATAL, "Could not open logfile: %d", errno);
521 if (-1 == dup2 (logfile, 1))
522 report (R_FATAL, "Can't redirect stdout: %d", errno);
525 tempdir = tempnam (0, "wct");
527 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
528 shorttempdir = strdup (tempdir);
529 if (shorttempdir) { /* try stable path for ZoneAlarm */
530 strstr (shorttempdir, "wct")[3] = 0;
531 if (CreateDirectoryA (shorttempdir, NULL)) {
533 tempdir = shorttempdir;
534 } else free (shorttempdir);
536 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
537 report (R_FATAL, "Could not create directory: %s", tempdir);
538 report (R_DIR, tempdir);
540 xprintf ("Version 4\n");
541 strres = extract_rcdata (MAKEINTRESOURCE(WINE_BUILD), STRINGRES, &strsize);
542 xprintf ("Tests from build ");
543 if (LoadStringA( 0, IDS_BUILD_ID, build, sizeof(build) )) xprintf( "%s\n", build );
544 else if (strres) xprintf ("%.*s", strsize, strres);
545 else xprintf ("-\n");
546 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
547 xprintf ("Archive: ");
548 if (strres) xprintf ("%.*s", strsize, strres);
549 else xprintf ("-\n");
550 xprintf ("Tag: %s\n", tag);
551 xprintf ("Build info:\n");
552 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
554 eol = memchr (strres, '\n', strsize);
557 eol = strres + strsize;
559 strsize -= eol - strres + 1;
560 nextline = strsize?eol+1:NULL;
561 if (eol > strres && *(eol-1) == '\r') eol--;
563 xprintf (" %.*s\n", eol-strres, strres);
566 xprintf ("Operating system version:\n");
568 xprintf ("Dll info:\n" );
570 report (R_STATUS, "Counting tests");
571 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
572 EnumTestFileProc, (LPARAM)&nr_of_files))
573 report (R_FATAL, "Can't enumerate test files: %d",
575 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
577 report (R_STATUS, "Extracting tests");
578 report (R_PROGRESS, 0, nr_of_files);
581 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
582 extract_test_proc, (LPARAM)tempdir))
583 report (R_FATAL, "Can't enumerate test files: %d",
586 xprintf ("Test output:\n" );
588 report (R_DELTA, 0, "Extracting: Done");
590 report (R_STATUS, "Running tests");
591 report (R_PROGRESS, 1, nr_of_tests);
592 for (i = 0; i < nr_of_files; i++) {
593 struct wine_test *test = wine_tests + i;
596 for (j = 0; j < test->subtest_count; j++) {
597 report (R_STEP, "Running: %s:%s", test->name,
599 run_test (test, test->subtests[j], tempdir);
602 report (R_DELTA, 0, "Running: Done");
604 report (R_STATUS, "Cleaning up");
606 remove_dir (tempdir);
617 "Usage: winetest [OPTION]...\n\n"
618 " -c console mode, no GUI\n"
619 " -e preserve the environment\n"
620 " -h print this message and exit\n"
621 " -p shutdown when the tests are done\n"
622 " -q quiet mode, no output at all\n"
623 " -o FILE put report into FILE, do not submit\n"
624 " -s FILE submit FILE, do not run tests\n"
625 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
628 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
629 LPSTR cmdLine, int cmdShow)
631 char *logname = NULL;
632 const char *cp, *submit = NULL;
637 /* initialize the revision information first */
640 cmdLine = strtok (cmdLine, whitespace);
642 if (cmdLine[0] != '-' || cmdLine[2]) {
643 report (R_ERROR, "Not a single letter option: %s", cmdLine);
647 switch (cmdLine[1]) {
667 submit = strtok (NULL, whitespace);
669 report (R_WARNING, "ignoring tag for submission");
673 logname = strtok (NULL, whitespace);
676 tag = strtok (NULL, whitespace);
677 if (strlen (tag) > MAXTAGLEN)
678 report (R_FATAL, "tag is too long (maximum %d characters)",
680 cp = findbadtagchar (tag);
682 report (R_ERROR, "invalid char in tag: %c", *cp);
688 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
692 cmdLine = strtok (NULL, whitespace);
695 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
696 platform_wine[] = "WINETEST_PLATFORM=wine",
697 debug_yes[] = "WINETEST_DEBUG=1",
698 interactive_no[] = "WINETEST_INTERACTIVE=0",
699 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
702 report (R_STATUS, "Starting up");
704 if (!running_on_visible_desktop ())
705 report (R_FATAL, "Tests must be run on a visible desktop");
707 platform = running_under_wine () ? platform_wine : platform_windows;
709 if (reset_env && (putenv (platform) ||
710 putenv (debug_yes) ||
711 putenv (interactive_no) ||
712 putenv (report_success_no)))
713 report (R_FATAL, "Could not reset environment: %d", errno);
717 report (R_FATAL, "Please specify a tag (-t option) if "
718 "running noninteractive!");
719 if (guiAskTag () == IDABORT) exit (1);
724 logname = run_tests (NULL);
725 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
726 "test results?") == IDYES)
727 if (!send_file (logname) && remove (logname))
728 report (R_WARNING, "Can't remove logfile: %d.", errno);
730 } else run_tests (logname);
731 report (R_STATUS, "Finished");
736 TOKEN_PRIVILEGES npr;
738 /* enable the shutdown privilege for the current process */
739 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
741 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
742 npr.PrivilegeCount = 1;
743 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
744 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
747 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);