winetest: Use the win32 API to extract the tests.
[wine.git] / programs / winetest / main.c
blob90c44491ddc4a242643009c3d7eb36ab64d276d8
1 /*
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.
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <errno.h>
35 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38 #include <windows.h>
40 #include "winetest.h"
41 #include "resource.h"
43 struct wine_test
45 char *name;
46 int resource;
47 int subtest_count;
48 char **subtests;
49 char *exename;
52 struct rev_info
54 const char* file;
55 const char* rev;
58 char *tag = NULL;
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];
68 DWORD size;
69 DWORD handle;
71 size = GetFileVersionInfoSizeA(file_name, &handle);
72 if (size) {
73 char * data = xmalloc(size);
74 if (data) {
75 if (GetFileVersionInfoA(file_name, handle, size, data)) {
76 static char backslash[] = "\\";
77 VS_FIXEDFILEINFO *pFixedVersionInfo;
78 UINT len;
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);
85 } else
86 sprintf(version, "version not available");
87 } else
88 sprintf(version, "unknown");
89 free(data);
90 } else
91 sprintf(version, "failed");
92 } else
93 sprintf(version, "version not available");
95 return version;
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)
108 HWND desktop;
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)
119 DWORD len;
120 HWINSTA wstation;
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)
132 OSVERSIONINFOEX ver;
133 BOOL ext;
134 int is_win2k3_r2;
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);
156 if(is_win2k3_r2)
157 xprintf(" R2 build number=%d\n", is_win2k3_r2);
159 if (!ext) return;
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)
174 HANDLE hFind;
175 WIN32_FIND_DATA wfd;
176 char path[MAX_PATH];
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;
185 do {
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)
192 remove_dir(path);
193 else if (!DeleteFile (path))
194 report (R_WARNING, "Can't delete file %s: error %d",
195 path, GetLastError ());
196 } while (FindNextFile (hFind, &wfd));
197 FindClose (hFind);
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] = {
206 { 0, 0 }
208 static char buffer[MAX_PATH];
209 int i;
211 for (i = 0; special_dirs[i][0]; i++) {
212 if (strcmp(test, special_dirs[i][0]) == 0) {
213 test = special_dirs[i][1];
214 break;
218 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
219 return buffer;
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;
230 return "-";
233 static void extract_rev_infos (void)
235 char revinfo[256], *p;
236 int size = 0, i;
237 unsigned int len;
238 HMODULE module = GetModuleHandle (NULL);
240 for (i = 0; TRUE; i++) {
241 if (i >= size) {
242 size += 100;
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);
253 *p = 0;
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)
261 HRSRC rsrc;
262 HGLOBAL hdl;
263 LPVOID addr;
265 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
266 !(*size = SizeofResource (0, rsrc)) ||
267 !(hdl = LoadResource (0, rsrc)) ||
268 !(addr = LockResource (hdl)))
269 return NULL;
270 return addr;
273 /* Fills in the name and exename fields */
274 static void
275 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
277 BYTE* code;
278 DWORD size;
279 char *exepos;
280 HANDLE hfile;
281 DWORD written;
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);
290 *exepos = 0;
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);
302 CloseHandle(hfile);
305 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
306 stdout to there.
308 Return the exit status, -2 if can't create process or the return
309 value of WaitForSingleObject.
311 static int
312 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
314 STARTUPINFO si;
315 PROCESS_INFORMATION pi;
316 int fd, oldstdout = -1;
317 DWORD wait, status;
319 GetStartupInfo (&si);
320 si.dwFlags = 0;
322 if (out) {
323 fd = open (out, O_WRONLY | O_CREAT, 0666);
324 if (-1 == fd)
325 report (R_FATAL, "Can't open '%s': %d", out, errno);
326 oldstdout = dup (1);
327 if (-1 == oldstdout)
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);
331 close (fd);
334 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
335 NULL, tempdir, &si, &pi)) {
336 status = -2;
337 } else {
338 CloseHandle (pi.hThread);
339 wait = WaitForSingleObject (pi.hProcess, ms);
340 if (wait == WAIT_OBJECT_0) {
341 GetExitCodeProcess (pi.hProcess, &status);
342 } else {
343 switch (wait) {
344 case WAIT_FAILED:
345 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
346 GetLastError ());
347 break;
348 case WAIT_TIMEOUT:
349 report (R_ERROR, "Process '%s' timed out.", cmd);
350 break;
351 default:
352 report (R_ERROR, "Wait returned %d", wait);
354 status = wait;
355 if (!TerminateProcess (pi.hProcess, 257))
356 report (R_ERROR, "TerminateProcess failed: %d",
357 GetLastError ());
358 wait = WaitForSingleObject (pi.hProcess, 5000);
359 switch (wait) {
360 case WAIT_FAILED:
361 report (R_ERROR,
362 "Wait for termination of '%s' failed: %d",
363 cmd, GetLastError ());
364 break;
365 case WAIT_OBJECT_0:
366 break;
367 case WAIT_TIMEOUT:
368 report (R_ERROR, "Can't kill process '%s'", cmd);
369 break;
370 default:
371 report (R_ERROR, "Waiting for termination: %d",
372 wait);
375 CloseHandle (pi.hProcess);
378 if (out) {
379 close (1);
380 if (-1 == dup2 (oldstdout, 1))
381 report (R_FATAL, "Can't recover stdout: %d", errno);
382 close (oldstdout);
384 return status;
387 static void
388 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
390 char *subname, *cmd;
391 FILE *subfile;
392 size_t total;
393 char buffer[8192], *index;
394 static const char header[] = "Valid test names:";
395 int allocated;
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);
405 free (cmd);
407 subfile = fopen (subname, "r");
408 if (!subfile) {
409 report (R_ERROR, "Can't open subtests output of %s: %d",
410 test->name, errno);
411 goto quit;
413 total = fread (buffer, 1, sizeof buffer, subfile);
414 fclose (subfile);
415 if (sizeof buffer == total) {
416 report (R_ERROR, "Subtest list of %s too big.",
417 test->name, sizeof buffer);
418 goto quit;
420 buffer[total] = 0;
422 index = strstr (buffer, header);
423 if (!index) {
424 report (R_ERROR, "Can't parse subtests output of %s",
425 test->name);
426 goto quit;
428 index += sizeof header;
430 allocated = 10;
431 test->subtests = xmalloc (allocated * sizeof(char*));
432 index = strtok (index, whitespace);
433 while (index) {
434 if (test->subtest_count == allocated) {
435 allocated *= 2;
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*));
445 quit:
446 if (remove (subname))
447 report (R_WARNING, "Can't delete file '%s': %d",
448 subname, errno);
449 free (subname);
452 static void
453 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
455 int status;
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);
462 free (cmd);
463 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
466 static BOOL CALLBACK
467 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
468 LPTSTR lpszName, LONG_PTR lParam)
470 (*(int*)lParam)++;
471 return TRUE;
474 static BOOL CALLBACK
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];
480 HMODULE dll;
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);
488 if (!dll) {
489 xprintf (" %s=dll is missing\n", dllname);
490 return TRUE;
492 FreeLibrary(dll);
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;
498 nr_of_files++;
499 return TRUE;
502 static char *
503 run_tests (char *logname)
505 int i;
506 char *tempdir, *shorttempdir;
507 int logfile;
508 char *strres, *eol, *nextline;
509 DWORD strsize;
510 char build[64];
512 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
514 if (!logname) {
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,
521 0666);
522 if (-1 == logfile) {
523 if (EEXIST == errno)
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);
529 close (logfile);
531 tempdir = tempnam (0, "wct");
532 if (!tempdir)
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)) {
538 free (tempdir);
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);
559 while (strres) {
560 eol = memchr (strres, '\n', strsize);
561 if (!eol) {
562 nextline = NULL;
563 eol = strres + strsize;
564 } else {
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);
570 strres = nextline;
572 xprintf ("Operating system version:\n");
573 print_version ();
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",
580 GetLastError ());
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);
585 nr_of_files = 0;
586 nr_of_tests = 0;
587 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
588 extract_test_proc, (LPARAM)tempdir))
589 report (R_FATAL, "Can't enumerate test files: %d",
590 GetLastError ());
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;
600 int j;
602 for (j = 0; j < test->subtest_count; j++) {
603 report (R_STEP, "Running: %s:%s", test->name,
604 test->subtests[j]);
605 run_test (test, test->subtests[j], tempdir);
608 report (R_DELTA, 0, "Running: Done");
610 report (R_STATUS, "Cleaning up");
611 close (1);
612 remove_dir (tempdir);
613 free (tempdir);
614 free (wine_tests);
616 return logname;
619 static void
620 usage (void)
622 fprintf (stderr,
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;
639 int reset_env = 1;
640 int poweroff = 0;
641 int interactive = 1;
643 /* initialize the revision information first */
644 extract_rev_infos();
646 cmdLine = strtok (cmdLine, whitespace);
647 while (cmdLine) {
648 if (cmdLine[0] != '-' || cmdLine[2]) {
649 report (R_ERROR, "Not a single letter option: %s", cmdLine);
650 usage ();
651 exit (2);
653 switch (cmdLine[1]) {
654 case 'c':
655 report (R_TEXTMODE);
656 interactive = 0;
657 break;
658 case 'e':
659 reset_env = 0;
660 break;
661 case 'h':
662 case '?':
663 usage ();
664 exit (0);
665 case 'p':
666 poweroff = 1;
667 break;
668 case 'q':
669 report (R_QUIET);
670 interactive = 0;
671 break;
672 case 's':
673 submit = strtok (NULL, whitespace);
674 if (tag)
675 report (R_WARNING, "ignoring tag for submission");
676 send_file (submit);
677 break;
678 case 'o':
679 logname = strtok (NULL, whitespace);
680 break;
681 case 't':
682 tag = strtok (NULL, whitespace);
683 if (strlen (tag) > MAXTAGLEN)
684 report (R_FATAL, "tag is too long (maximum %d characters)",
685 MAXTAGLEN);
686 cp = findbadtagchar (tag);
687 if (cp) {
688 report (R_ERROR, "invalid char in tag: %c", *cp);
689 usage ();
690 exit (2);
692 break;
693 default:
694 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
695 usage ();
696 exit (2);
698 cmdLine = strtok (NULL, whitespace);
700 if (!submit) {
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";
706 CHAR *platform;
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);
721 if (!tag) {
722 if (!interactive)
723 report (R_FATAL, "Please specify a tag (-t option) if "
724 "running noninteractive!");
725 if (guiAskTag () == IDABORT) exit (1);
727 report (R_TAG);
729 if (!logname) {
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);
735 free (logname);
736 } else run_tests (logname);
737 report (R_STATUS, "Finished");
739 if (poweroff)
741 HANDLE hToken;
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);
751 CloseHandle(hToken);
753 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
755 exit (0);