ntdll: move relocations from mapping into loader
[wine/kumbayo.git] / programs / winetest / main.c
blob41879b4ef418acb41790b2c99471b805ac933259
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;
136 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
137 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
139 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
140 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
141 report (R_FATAL, "Can't get OS version.");
144 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
145 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
146 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
147 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
148 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
149 ver.dwPlatformId, ver.szCSDVersion);
151 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
152 if(is_win2k3_r2)
153 xprintf(" R2 build number=%d\n", is_win2k3_r2);
155 if (!ext) return;
157 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
158 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
159 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
160 ver.wProductType, ver.wReserved);
163 static inline int is_dot_dir(const char* x)
165 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
168 static void remove_dir (const char *dir)
170 HANDLE hFind;
171 WIN32_FIND_DATA wfd;
172 char path[MAX_PATH];
173 size_t dirlen = strlen (dir);
175 /* Make sure the directory exists before going further */
176 memcpy (path, dir, dirlen);
177 strcpy (path + dirlen++, "\\*");
178 hFind = FindFirstFile (path, &wfd);
179 if (hFind == INVALID_HANDLE_VALUE) return;
181 do {
182 char *lp = wfd.cFileName;
184 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
185 if (is_dot_dir (lp)) continue;
186 strcpy (path + dirlen, lp);
187 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
188 remove_dir(path);
189 else if (!DeleteFile (path))
190 report (R_WARNING, "Can't delete file %s: error %d",
191 path, GetLastError ());
192 } while (FindNextFile (hFind, &wfd));
193 FindClose (hFind);
194 if (!RemoveDirectory (dir))
195 report (R_WARNING, "Can't remove directory %s: error %d",
196 dir, GetLastError ());
199 static const char* get_test_source_file(const char* test, const char* subtest)
201 static const char* special_dirs[][2] = {
202 { 0, 0 }
204 static char buffer[MAX_PATH];
205 int i;
207 for (i = 0; special_dirs[i][0]; i++) {
208 if (strcmp(test, special_dirs[i][0]) == 0) {
209 test = special_dirs[i][1];
210 break;
214 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
215 return buffer;
218 static const char* get_file_rev(const char* file)
220 const struct rev_info* rev;
222 for(rev = rev_infos; rev->file; rev++) {
223 if (strcmp(rev->file, file) == 0) return rev->rev;
226 return "-";
229 static void extract_rev_infos (void)
231 char revinfo[256], *p;
232 int size = 0, i;
233 unsigned int len;
234 HMODULE module = GetModuleHandle (NULL);
236 for (i = 0; TRUE; i++) {
237 if (i >= size) {
238 size += 100;
239 rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
241 memset(rev_infos + i, 0, sizeof(rev_infos[i]));
243 len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo));
244 if (len == 0) break; /* end of revision info */
245 if (len >= sizeof(revinfo) - 1)
246 report (R_FATAL, "Revision info too long.");
247 if(!(p = strrchr(revinfo, ':')))
248 report (R_FATAL, "Revision info malformed (i=%d)", i);
249 *p = 0;
250 rev_infos[i].file = strdup(revinfo);
251 rev_infos[i].rev = strdup(p + 1);
255 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
257 HRSRC rsrc;
258 HGLOBAL hdl;
259 LPVOID addr;
261 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
262 !(*size = SizeofResource (0, rsrc)) ||
263 !(hdl = LoadResource (0, rsrc)) ||
264 !(addr = LockResource (hdl)))
265 return NULL;
266 return addr;
269 /* Fills in the name and exename fields */
270 static void
271 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
273 BYTE* code;
274 DWORD size;
275 FILE* fout;
276 char *exepos;
278 code = extract_rcdata (res_name, TESTRES, &size);
279 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
280 res_name, GetLastError ());
281 test->name = xstrdup( res_name );
282 test->exename = strmake (NULL, "%s/%s", dir, test->name);
283 exepos = strstr (test->name, testexe);
284 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
285 *exepos = 0;
286 test->name = xrealloc (test->name, exepos - test->name + 1);
287 report (R_STEP, "Extracting: %s", test->name);
289 if (!(fout = fopen (test->exename, "wb")) ||
290 (fwrite (code, size, 1, fout) != 1) ||
291 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
292 test->exename);
295 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
296 stdout to there.
298 Return the exit status, -2 if can't create process or the return
299 value of WaitForSingleObject.
301 static int
302 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
304 STARTUPINFO si;
305 PROCESS_INFORMATION pi;
306 int fd, oldstdout = -1;
307 DWORD wait, status;
309 GetStartupInfo (&si);
310 si.dwFlags = 0;
312 if (out) {
313 fd = open (out, O_WRONLY | O_CREAT, 0666);
314 if (-1 == fd)
315 report (R_FATAL, "Can't open '%s': %d", out, errno);
316 oldstdout = dup (1);
317 if (-1 == oldstdout)
318 report (R_FATAL, "Can't save stdout: %d", errno);
319 if (-1 == dup2 (fd, 1))
320 report (R_FATAL, "Can't redirect stdout: %d", errno);
321 close (fd);
324 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, 0,
325 NULL, tempdir, &si, &pi)) {
326 status = -2;
327 } else {
328 CloseHandle (pi.hThread);
329 wait = WaitForSingleObject (pi.hProcess, ms);
330 if (wait == WAIT_OBJECT_0) {
331 GetExitCodeProcess (pi.hProcess, &status);
332 } else {
333 switch (wait) {
334 case WAIT_FAILED:
335 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
336 GetLastError ());
337 break;
338 case WAIT_TIMEOUT:
339 report (R_ERROR, "Process '%s' timed out.", cmd);
340 break;
341 default:
342 report (R_ERROR, "Wait returned %d", wait);
344 status = wait;
345 if (!TerminateProcess (pi.hProcess, 257))
346 report (R_ERROR, "TerminateProcess failed: %d",
347 GetLastError ());
348 wait = WaitForSingleObject (pi.hProcess, 5000);
349 switch (wait) {
350 case WAIT_FAILED:
351 report (R_ERROR,
352 "Wait for termination of '%s' failed: %d",
353 cmd, GetLastError ());
354 break;
355 case WAIT_OBJECT_0:
356 break;
357 case WAIT_TIMEOUT:
358 report (R_ERROR, "Can't kill process '%s'", cmd);
359 break;
360 default:
361 report (R_ERROR, "Waiting for termination: %d",
362 wait);
365 CloseHandle (pi.hProcess);
368 if (out) {
369 close (1);
370 if (-1 == dup2 (oldstdout, 1))
371 report (R_FATAL, "Can't recover stdout: %d", errno);
372 close (oldstdout);
374 return status;
377 static void
378 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
380 char *subname, *cmd;
381 FILE *subfile;
382 size_t total;
383 char buffer[8192], *index;
384 static const char header[] = "Valid test names:";
385 int allocated;
387 test->subtest_count = 0;
389 subname = tempnam (0, "sub");
390 if (!subname) report (R_FATAL, "Can't name subtests file.");
392 extract_test (test, tempdir, res_name);
393 cmd = strmake (NULL, "%s --list", test->exename);
394 run_ex (cmd, subname, tempdir, 5000);
395 free (cmd);
397 subfile = fopen (subname, "r");
398 if (!subfile) {
399 report (R_ERROR, "Can't open subtests output of %s: %d",
400 test->name, errno);
401 goto quit;
403 total = fread (buffer, 1, sizeof buffer, subfile);
404 fclose (subfile);
405 if (sizeof buffer == total) {
406 report (R_ERROR, "Subtest list of %s too big.",
407 test->name, sizeof buffer);
408 goto quit;
410 buffer[total] = 0;
412 index = strstr (buffer, header);
413 if (!index) {
414 report (R_ERROR, "Can't parse subtests output of %s",
415 test->name);
416 goto quit;
418 index += sizeof header;
420 allocated = 10;
421 test->subtests = xmalloc (allocated * sizeof(char*));
422 index = strtok (index, whitespace);
423 while (index) {
424 if (test->subtest_count == allocated) {
425 allocated *= 2;
426 test->subtests = xrealloc (test->subtests,
427 allocated * sizeof(char*));
429 test->subtests[test->subtest_count++] = strdup (index);
430 index = strtok (NULL, whitespace);
432 test->subtests = xrealloc (test->subtests,
433 test->subtest_count * sizeof(char*));
435 quit:
436 if (remove (subname))
437 report (R_WARNING, "Can't delete file '%s': %d",
438 subname, errno);
439 free (subname);
442 static void
443 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
445 int status;
446 const char* file = get_test_source_file(test->name, subtest);
447 const char* rev = get_file_rev(file);
448 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
450 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
451 status = run_ex (cmd, NULL, tempdir, 120000);
452 free (cmd);
453 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
456 static BOOL CALLBACK
457 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
458 LPTSTR lpszName, LONG_PTR lParam)
460 (*(int*)lParam)++;
461 return TRUE;
464 static BOOL CALLBACK
465 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
466 LPTSTR lpszName, LONG_PTR lParam)
468 const char *tempdir = (const char *)lParam;
469 char dllname[MAX_PATH];
470 HMODULE dll;
472 /* Check if the main dll is present on this system */
473 CharLowerA(lpszName);
474 strcpy(dllname, lpszName);
475 *strstr(dllname, testexe) = 0;
477 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
478 if (!dll) {
479 xprintf (" %s=dll is missing\n", dllname);
480 return TRUE;
482 FreeLibrary(dll);
484 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
486 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
487 nr_of_tests += wine_tests[nr_of_files].subtest_count;
488 nr_of_files++;
489 return TRUE;
492 static char *
493 run_tests (char *logname)
495 int i;
496 char *tempdir, *shorttempdir;
497 int logfile;
498 char *strres, *eol, *nextline;
499 DWORD strsize;
501 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
503 if (!logname) {
504 logname = tempnam (0, "res");
505 if (!logname) report (R_FATAL, "Can't name logfile.");
507 report (R_OUT, logname);
509 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
510 0666);
511 if (-1 == logfile) {
512 if (EEXIST == errno)
513 report (R_FATAL, "File %s already exists.", logname);
514 else report (R_FATAL, "Could not open logfile: %d", errno);
516 if (-1 == dup2 (logfile, 1))
517 report (R_FATAL, "Can't redirect stdout: %d", errno);
518 close (logfile);
520 tempdir = tempnam (0, "wct");
521 if (!tempdir)
522 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
523 shorttempdir = strdup (tempdir);
524 if (shorttempdir) { /* try stable path for ZoneAlarm */
525 strstr (shorttempdir, "wct")[3] = 0;
526 if (CreateDirectoryA (shorttempdir, NULL)) {
527 free (tempdir);
528 tempdir = shorttempdir;
529 } else free (shorttempdir);
531 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
532 report (R_FATAL, "Could not create directory: %s", tempdir);
533 report (R_DIR, tempdir);
535 xprintf ("Version 4\n");
536 strres = extract_rcdata (MAKEINTRESOURCE(WINE_BUILD), STRINGRES, &strsize);
537 xprintf ("Tests from build ");
538 if (strres) xprintf ("%.*s", strsize, strres);
539 else xprintf ("-\n");
540 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
541 xprintf ("Archive: ");
542 if (strres) xprintf ("%.*s", strsize, strres);
543 else xprintf ("-\n");
544 xprintf ("Tag: %s\n", tag);
545 xprintf ("Build info:\n");
546 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
547 while (strres) {
548 eol = memchr (strres, '\n', strsize);
549 if (!eol) {
550 nextline = NULL;
551 eol = strres + strsize;
552 } else {
553 strsize -= eol - strres + 1;
554 nextline = strsize?eol+1:NULL;
555 if (eol > strres && *(eol-1) == '\r') eol--;
557 xprintf (" %.*s\n", eol-strres, strres);
558 strres = nextline;
560 xprintf ("Operating system version:\n");
561 print_version ();
562 xprintf ("Dll info:\n" );
564 report (R_STATUS, "Counting tests");
565 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
566 EnumTestFileProc, (LPARAM)&nr_of_files))
567 report (R_FATAL, "Can't enumerate test files: %d",
568 GetLastError ());
569 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
571 report (R_STATUS, "Extracting tests");
572 report (R_PROGRESS, 0, nr_of_files);
573 nr_of_files = 0;
574 nr_of_tests = 0;
575 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
576 extract_test_proc, (LPARAM)tempdir))
577 report (R_FATAL, "Can't enumerate test files: %d",
578 GetLastError ());
580 xprintf ("Test output:\n" );
582 report (R_DELTA, 0, "Extracting: Done");
584 report (R_STATUS, "Running tests");
585 report (R_PROGRESS, 1, nr_of_tests);
586 for (i = 0; i < nr_of_files; i++) {
587 struct wine_test *test = wine_tests + i;
588 int j;
590 for (j = 0; j < test->subtest_count; j++) {
591 report (R_STEP, "Running: %s:%s", test->name,
592 test->subtests[j]);
593 run_test (test, test->subtests[j], tempdir);
596 report (R_DELTA, 0, "Running: Done");
598 report (R_STATUS, "Cleaning up");
599 close (1);
600 remove_dir (tempdir);
601 free (tempdir);
602 free (wine_tests);
604 return logname;
607 static void
608 usage (void)
610 fprintf (stderr,
611 "Usage: winetest [OPTION]...\n\n"
612 " -c console mode, no GUI\n"
613 " -e preserve the environment\n"
614 " -h print this message and exit\n"
615 " -p shutdown when the tests are done\n"
616 " -q quiet mode, no output at all\n"
617 " -o FILE put report into FILE, do not submit\n"
618 " -s FILE submit FILE, do not run tests\n"
619 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
622 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
623 LPSTR cmdLine, int cmdShow)
625 char *logname = NULL;
626 const char *cp, *submit = NULL;
627 int reset_env = 1;
628 int poweroff = 0;
629 int interactive = 1;
631 /* initialize the revision information first */
632 extract_rev_infos();
634 cmdLine = strtok (cmdLine, whitespace);
635 while (cmdLine) {
636 if (cmdLine[0] != '-' || cmdLine[2]) {
637 report (R_ERROR, "Not a single letter option: %s", cmdLine);
638 usage ();
639 exit (2);
641 switch (cmdLine[1]) {
642 case 'c':
643 report (R_TEXTMODE);
644 interactive = 0;
645 break;
646 case 'e':
647 reset_env = 0;
648 break;
649 case 'h':
650 case '?':
651 usage ();
652 exit (0);
653 case 'p':
654 poweroff = 1;
655 break;
656 case 'q':
657 report (R_QUIET);
658 interactive = 0;
659 break;
660 case 's':
661 submit = strtok (NULL, whitespace);
662 if (tag)
663 report (R_WARNING, "ignoring tag for submission");
664 send_file (submit);
665 break;
666 case 'o':
667 logname = strtok (NULL, whitespace);
668 break;
669 case 't':
670 tag = strtok (NULL, whitespace);
671 if (strlen (tag) > MAXTAGLEN)
672 report (R_FATAL, "tag is too long (maximum %d characters)",
673 MAXTAGLEN);
674 cp = findbadtagchar (tag);
675 if (cp) {
676 report (R_ERROR, "invalid char in tag: %c", *cp);
677 usage ();
678 exit (2);
680 break;
681 default:
682 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
683 usage ();
684 exit (2);
686 cmdLine = strtok (NULL, whitespace);
688 if (!submit) {
689 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
690 platform_wine[] = "WINETEST_PLATFORM=wine",
691 debug_yes[] = "WINETEST_DEBUG=1",
692 interactive_no[] = "WINETEST_INTERACTIVE=0",
693 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
694 CHAR *platform;
696 report (R_STATUS, "Starting up");
698 if (!running_on_visible_desktop ())
699 report (R_FATAL, "Tests must be run on a visible desktop");
701 platform = running_under_wine () ? platform_wine : platform_windows;
703 if (reset_env && (putenv (platform) ||
704 putenv (debug_yes) ||
705 putenv (interactive_no) ||
706 putenv (report_success_no)))
707 report (R_FATAL, "Could not reset environment: %d", errno);
709 if (!tag) {
710 if (!interactive)
711 report (R_FATAL, "Please specify a tag (-t option) if "
712 "running noninteractive!");
713 if (guiAskTag () == IDABORT) exit (1);
715 report (R_TAG);
717 if (!logname) {
718 logname = run_tests (NULL);
719 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
720 "test results?") == IDYES)
721 if (!send_file (logname) && remove (logname))
722 report (R_WARNING, "Can't remove logfile: %d.", errno);
723 free (logname);
724 } else run_tests (logname);
725 report (R_STATUS, "Finished");
727 if (poweroff)
729 HANDLE hToken;
730 TOKEN_PRIVILEGES npr;
732 /* enable the shutdown privilege for the current process */
733 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
735 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
736 npr.PrivilegeCount = 1;
737 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
738 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
739 CloseHandle(hToken);
741 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
743 exit (0);