winhelp: Get rid of the reuse concept for Windows and refactor the code a bit for...
[wine.git] / programs / winetest / main.c
blob72b744228380f122d290cbcc940cecf61ab91cd2
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 FILE* fout;
280 char *exepos;
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);
289 *exepos = 0;
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.",
296 test->exename);
299 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
300 stdout to there.
302 Return the exit status, -2 if can't create process or the return
303 value of WaitForSingleObject.
305 static int
306 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
308 STARTUPINFO si;
309 PROCESS_INFORMATION pi;
310 int fd, oldstdout = -1;
311 DWORD wait, status;
313 GetStartupInfo (&si);
314 si.dwFlags = 0;
316 if (out) {
317 fd = open (out, O_WRONLY | O_CREAT, 0666);
318 if (-1 == fd)
319 report (R_FATAL, "Can't open '%s': %d", out, errno);
320 oldstdout = dup (1);
321 if (-1 == oldstdout)
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);
325 close (fd);
328 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0,
329 NULL, tempdir, &si, &pi)) {
330 status = -2;
331 } else {
332 CloseHandle (pi.hThread);
333 wait = WaitForSingleObject (pi.hProcess, ms);
334 if (wait == WAIT_OBJECT_0) {
335 GetExitCodeProcess (pi.hProcess, &status);
336 } else {
337 switch (wait) {
338 case WAIT_FAILED:
339 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
340 GetLastError ());
341 break;
342 case WAIT_TIMEOUT:
343 report (R_ERROR, "Process '%s' timed out.", cmd);
344 break;
345 default:
346 report (R_ERROR, "Wait returned %d", wait);
348 status = wait;
349 if (!TerminateProcess (pi.hProcess, 257))
350 report (R_ERROR, "TerminateProcess failed: %d",
351 GetLastError ());
352 wait = WaitForSingleObject (pi.hProcess, 5000);
353 switch (wait) {
354 case WAIT_FAILED:
355 report (R_ERROR,
356 "Wait for termination of '%s' failed: %d",
357 cmd, GetLastError ());
358 break;
359 case WAIT_OBJECT_0:
360 break;
361 case WAIT_TIMEOUT:
362 report (R_ERROR, "Can't kill process '%s'", cmd);
363 break;
364 default:
365 report (R_ERROR, "Waiting for termination: %d",
366 wait);
369 CloseHandle (pi.hProcess);
372 if (out) {
373 close (1);
374 if (-1 == dup2 (oldstdout, 1))
375 report (R_FATAL, "Can't recover stdout: %d", errno);
376 close (oldstdout);
378 return status;
381 static void
382 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
384 char *subname, *cmd;
385 FILE *subfile;
386 size_t total;
387 char buffer[8192], *index;
388 static const char header[] = "Valid test names:";
389 int allocated;
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);
399 free (cmd);
401 subfile = fopen (subname, "r");
402 if (!subfile) {
403 report (R_ERROR, "Can't open subtests output of %s: %d",
404 test->name, errno);
405 goto quit;
407 total = fread (buffer, 1, sizeof buffer, subfile);
408 fclose (subfile);
409 if (sizeof buffer == total) {
410 report (R_ERROR, "Subtest list of %s too big.",
411 test->name, sizeof buffer);
412 goto quit;
414 buffer[total] = 0;
416 index = strstr (buffer, header);
417 if (!index) {
418 report (R_ERROR, "Can't parse subtests output of %s",
419 test->name);
420 goto quit;
422 index += sizeof header;
424 allocated = 10;
425 test->subtests = xmalloc (allocated * sizeof(char*));
426 index = strtok (index, whitespace);
427 while (index) {
428 if (test->subtest_count == allocated) {
429 allocated *= 2;
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*));
439 quit:
440 if (remove (subname))
441 report (R_WARNING, "Can't delete file '%s': %d",
442 subname, errno);
443 free (subname);
446 static void
447 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
449 int status;
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);
456 free (cmd);
457 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
460 static BOOL CALLBACK
461 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
462 LPTSTR lpszName, LONG_PTR lParam)
464 (*(int*)lParam)++;
465 return TRUE;
468 static BOOL CALLBACK
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];
474 HMODULE dll;
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);
482 if (!dll) {
483 xprintf (" %s=dll is missing\n", dllname);
484 return TRUE;
486 FreeLibrary(dll);
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;
492 nr_of_files++;
493 return TRUE;
496 static char *
497 run_tests (char *logname)
499 int i;
500 char *tempdir, *shorttempdir;
501 int logfile;
502 char *strres, *eol, *nextline;
503 DWORD strsize;
504 char build[64];
506 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
508 if (!logname) {
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,
515 0666);
516 if (-1 == logfile) {
517 if (EEXIST == errno)
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);
523 close (logfile);
525 tempdir = tempnam (0, "wct");
526 if (!tempdir)
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)) {
532 free (tempdir);
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);
553 while (strres) {
554 eol = memchr (strres, '\n', strsize);
555 if (!eol) {
556 nextline = NULL;
557 eol = strres + strsize;
558 } else {
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);
564 strres = nextline;
566 xprintf ("Operating system version:\n");
567 print_version ();
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",
574 GetLastError ());
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);
579 nr_of_files = 0;
580 nr_of_tests = 0;
581 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
582 extract_test_proc, (LPARAM)tempdir))
583 report (R_FATAL, "Can't enumerate test files: %d",
584 GetLastError ());
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;
594 int j;
596 for (j = 0; j < test->subtest_count; j++) {
597 report (R_STEP, "Running: %s:%s", test->name,
598 test->subtests[j]);
599 run_test (test, test->subtests[j], tempdir);
602 report (R_DELTA, 0, "Running: Done");
604 report (R_STATUS, "Cleaning up");
605 close (1);
606 remove_dir (tempdir);
607 free (tempdir);
608 free (wine_tests);
610 return logname;
613 static void
614 usage (void)
616 fprintf (stderr,
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;
633 int reset_env = 1;
634 int poweroff = 0;
635 int interactive = 1;
637 /* initialize the revision information first */
638 extract_rev_infos();
640 cmdLine = strtok (cmdLine, whitespace);
641 while (cmdLine) {
642 if (cmdLine[0] != '-' || cmdLine[2]) {
643 report (R_ERROR, "Not a single letter option: %s", cmdLine);
644 usage ();
645 exit (2);
647 switch (cmdLine[1]) {
648 case 'c':
649 report (R_TEXTMODE);
650 interactive = 0;
651 break;
652 case 'e':
653 reset_env = 0;
654 break;
655 case 'h':
656 case '?':
657 usage ();
658 exit (0);
659 case 'p':
660 poweroff = 1;
661 break;
662 case 'q':
663 report (R_QUIET);
664 interactive = 0;
665 break;
666 case 's':
667 submit = strtok (NULL, whitespace);
668 if (tag)
669 report (R_WARNING, "ignoring tag for submission");
670 send_file (submit);
671 break;
672 case 'o':
673 logname = strtok (NULL, whitespace);
674 break;
675 case 't':
676 tag = strtok (NULL, whitespace);
677 if (strlen (tag) > MAXTAGLEN)
678 report (R_FATAL, "tag is too long (maximum %d characters)",
679 MAXTAGLEN);
680 cp = findbadtagchar (tag);
681 if (cp) {
682 report (R_ERROR, "invalid char in tag: %c", *cp);
683 usage ();
684 exit (2);
686 break;
687 default:
688 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
689 usage ();
690 exit (2);
692 cmdLine = strtok (NULL, whitespace);
694 if (!submit) {
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";
700 CHAR *platform;
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);
715 if (!tag) {
716 if (!interactive)
717 report (R_FATAL, "Please specify a tag (-t option) if "
718 "running noninteractive!");
719 if (guiAskTag () == IDABORT) exit (1);
721 report (R_TAG);
723 if (!logname) {
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);
729 free (logname);
730 } else run_tests (logname);
731 report (R_STATUS, "Finished");
733 if (poweroff)
735 HANDLE hToken;
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);
745 CloseHandle(hToken);
747 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
749 exit (0);