~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/winetest/main.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Wine Conformance Test EXE
  3  *
  4  * Copyright 2003, 2004 Jakob Eriksson   (for Solid Form Sweden AB)
  5  * Copyright 2003 Dimitrie O. Paun
  6  * Copyright 2003 Ferenc Wagner
  7  *
  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.
 12  *
 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.
 17  *
 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
 21  *
 22  * This program is dedicated to Anna Lindh,
 23  * Swedish Minister of Foreign Affairs.
 24  * Anna was murdered September 11, 2003.
 25  *
 26  */
 27 
 28 #include "config.h"
 29 #include "wine/port.h"
 30 
 31 #define COBJMACROS
 32 #include <stdio.h>
 33 #include <assert.h>
 34 #include <windows.h>
 35 #include <mshtml.h>
 36 
 37 #include "winetest.h"
 38 #include "resource.h"
 39 
 40 struct wine_test
 41 {
 42     char *name;
 43     int resource;
 44     int subtest_count;
 45     char **subtests;
 46     char *exename;
 47     char *maindllpath;
 48 };
 49 
 50 char *tag = NULL;
 51 static struct wine_test *wine_tests;
 52 static int nr_of_files, nr_of_tests;
 53 static int nr_native_dlls;
 54 static const char whitespace[] = " \t\r\n";
 55 static const char testexe[] = "_test.exe";
 56 static char build_id[64];
 57 
 58 /* filters for running only specific tests */
 59 static char *filters[64];
 60 static unsigned int nb_filters = 0;
 61 
 62 /* Needed to check for .NET dlls */
 63 static HMODULE hmscoree;
 64 static HRESULT (WINAPI *pLoadLibraryShim)(LPCWSTR, LPCWSTR, LPVOID, HMODULE *);
 65 
 66 /* To store the current PATH setting (related to .NET only provided dlls) */
 67 static char *curpath;
 68 
 69 /* check if test is being filtered out */
 70 static BOOL test_filtered_out( LPCSTR module, LPCSTR testname )
 71 {
 72     char *p, dllname[MAX_PATH];
 73     unsigned int i, len;
 74 
 75     strcpy( dllname, module );
 76     CharLowerA( dllname );
 77     p = strstr( dllname, testexe );
 78     if (p) *p = 0;
 79     len = strlen(dllname);
 80 
 81     if (!nb_filters) return FALSE;
 82     for (i = 0; i < nb_filters; i++)
 83     {
 84         if (!strncmp( dllname, filters[i], len ))
 85         {
 86             if (!filters[i][len]) return FALSE;
 87             if (filters[i][len] != ':') continue;
 88             if (!testname || !strcmp( testname, &filters[i][len+1] )) return FALSE;
 89         }
 90     }
 91     return TRUE;
 92 }
 93 
 94 static char * get_file_version(char * file_name)
 95 {
 96     static char version[32];
 97     DWORD size;
 98     DWORD handle;
 99 
100     size = GetFileVersionInfoSizeA(file_name, &handle);
101     if (size) {
102         char * data = heap_alloc(size);
103         if (data) {
104             if (GetFileVersionInfoA(file_name, handle, size, data)) {
105                 static char backslash[] = "\\";
106                 VS_FIXEDFILEINFO *pFixedVersionInfo;
107                 UINT len;
108                 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
109                     sprintf(version, "%d.%d.%d.%d",
110                             pFixedVersionInfo->dwFileVersionMS >> 16,
111                             pFixedVersionInfo->dwFileVersionMS & 0xffff,
112                             pFixedVersionInfo->dwFileVersionLS >> 16,
113                             pFixedVersionInfo->dwFileVersionLS & 0xffff);
114                 } else
115                     sprintf(version, "version not available");
116             } else
117                 sprintf(version, "unknown");
118             heap_free(data);
119         } else
120             sprintf(version, "failed");
121     } else
122         sprintf(version, "version not available");
123 
124     return version;
125 }
126 
127 static int running_under_wine (void)
128 {
129     HMODULE module = GetModuleHandleA("ntdll.dll");
130 
131     if (!module) return 0;
132     return (GetProcAddress(module, "wine_server_call") != NULL);
133 }
134 
135 static int running_on_visible_desktop (void)
136 {
137     HWND desktop;
138     HMODULE huser32 = GetModuleHandle("user32.dll");
139     HWINSTA (WINAPI *pGetProcessWindowStation)(void);
140     BOOL (WINAPI *pGetUserObjectInformationA)(HANDLE,INT,LPVOID,DWORD,LPDWORD);
141 
142     pGetProcessWindowStation = (void *)GetProcAddress(huser32, "GetProcessWindowStation");
143     pGetUserObjectInformationA = (void *)GetProcAddress(huser32, "GetUserObjectInformationA");
144 
145     desktop = GetDesktopWindow();
146     if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
147         return IsWindowVisible(desktop);
148 
149     if (pGetProcessWindowStation && pGetUserObjectInformationA)
150     {
151         DWORD len;
152         HWINSTA wstation;
153         USEROBJECTFLAGS uoflags;
154 
155         wstation = (HWINSTA)pGetProcessWindowStation();
156         assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
157         return (uoflags.dwFlags & WSF_VISIBLE) != 0;
158     }
159     return IsWindowVisible(desktop);
160 }
161 
162 /* check for native dll when running under wine */
163 static BOOL is_native_dll( HMODULE module )
164 {
165     static const char fakedll_signature[] = "Wine placeholder DLL";
166     const IMAGE_DOS_HEADER *dos;
167 
168     if (!running_under_wine()) return FALSE;
169     if (!((ULONG_PTR)module & 1)) return FALSE;  /* not loaded as datafile */
170     /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
171     dos = (const IMAGE_DOS_HEADER *)((const char *)module - 1);
172     if (dos->e_magic != IMAGE_DOS_SIGNATURE) return FALSE;
173     if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
174         !memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return FALSE;
175     return TRUE;
176 }
177 
178 /* check if Gecko is present, trying to trigger the install if not */
179 static BOOL gecko_check(void)
180 {
181     IHTMLDocument2 *doc;
182     IHTMLElement *body;
183     BOOL ret = FALSE;
184 
185     CoInitialize( NULL );
186     if (FAILED( CoCreateInstance( &CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
187                                   &IID_IHTMLDocument2, (void **)&doc ))) return FALSE;
188     if ((ret = SUCCEEDED( IHTMLDocument2_get_body( doc, &body )))) IHTMLElement_Release( body );
189     IHTMLDocument_Release( doc );
190     return ret;
191 }
192 
193 static void print_version (void)
194 {
195 #ifdef __i386__
196     static const char platform[] = "i386";
197 #elif defined(__x86_64__)
198     static const char platform[] = "x86_64";
199 #elif defined(__sparc__)
200     static const char platform[] = "sparc";
201 #elif defined(__ALPHA__)
202     static const char platform[] = "alpha";
203 #elif defined(__powerpc__)
204     static const char platform[] = "powerpc";
205 #endif
206     OSVERSIONINFOEX ver;
207     BOOL ext, wow64;
208     int is_win2k3_r2;
209     const char *(CDECL *wine_get_build_id)(void);
210     void (CDECL *wine_get_host_version)( const char **sysname, const char **release );
211     BOOL (WINAPI *pIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process);
212 
213     ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
214     if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
215     {
216         ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
217         if (!GetVersionEx ((OSVERSIONINFO *) &ver))
218             report (R_FATAL, "Can't get OS version.");
219     }
220     pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
221     if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &wow64 )) wow64 = FALSE;
222 
223     xprintf ("    Platform=%s%s\n", platform, wow64 ? " (WOW64)" : "");
224     xprintf ("    bRunningUnderWine=%d\n", running_under_wine ());
225     xprintf ("    bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
226     xprintf ("    dwMajorVersion=%u\n    dwMinorVersion=%u\n"
227              "    dwBuildNumber=%u\n    PlatformId=%u\n    szCSDVersion=%s\n",
228              ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
229              ver.dwPlatformId, ver.szCSDVersion);
230 
231     wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
232     wine_get_host_version = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_host_version");
233     if (wine_get_build_id) xprintf( "    WineBuild=%s\n", wine_get_build_id() );
234     if (wine_get_host_version)
235     {
236         const char *sysname, *release;
237         wine_get_host_version( &sysname, &release );
238         xprintf( "    Host system=%s\n    Host version=%s\n", sysname, release );
239     }
240     is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
241     if(is_win2k3_r2)
242         xprintf("    R2 build number=%d\n", is_win2k3_r2);
243 
244     if (!ext) return;
245 
246     xprintf ("    wServicePackMajor=%d\n    wServicePackMinor=%d\n"
247              "    wSuiteMask=%d\n    wProductType=%d\n    wReserved=%d\n",
248              ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
249              ver.wProductType, ver.wReserved);
250 }
251 
252 static inline int is_dot_dir(const char* x)
253 {
254     return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
255 }
256 
257 static void remove_dir (const char *dir)
258 {
259     HANDLE  hFind;
260     WIN32_FIND_DATA wfd;
261     char path[MAX_PATH];
262     size_t dirlen = strlen (dir);
263 
264     /* Make sure the directory exists before going further */
265     memcpy (path, dir, dirlen);
266     strcpy (path + dirlen++, "\\*");
267     hFind = FindFirstFile (path, &wfd);
268     if (hFind == INVALID_HANDLE_VALUE) return;
269 
270     do {
271         char *lp = wfd.cFileName;
272 
273         if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
274         if (is_dot_dir (lp)) continue;
275         strcpy (path + dirlen, lp);
276         if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
277             remove_dir(path);
278         else if (!DeleteFile (path))
279             report (R_WARNING, "Can't delete file %s: error %d",
280                     path, GetLastError ());
281     } while (FindNextFile (hFind, &wfd));
282     FindClose (hFind);
283     if (!RemoveDirectory (dir))
284         report (R_WARNING, "Can't remove directory %s: error %d",
285                 dir, GetLastError ());
286 }
287 
288 static const char* get_test_source_file(const char* test, const char* subtest)
289 {
290     static const char* special_dirs[][2] = {
291         { 0, 0 }
292     };
293     static char buffer[MAX_PATH];
294     int i;
295 
296     for (i = 0; special_dirs[i][0]; i++) {
297         if (strcmp(test, special_dirs[i][0]) == 0) {
298             test = special_dirs[i][1];
299             break;
300         }
301     }
302 
303     snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
304     return buffer;
305 }
306 
307 static void* extract_rcdata (LPCTSTR name, LPCTSTR type, DWORD* size)
308 {
309     HRSRC rsrc;
310     HGLOBAL hdl;
311     LPVOID addr;
312     
313     if (!(rsrc = FindResource (NULL, name, type)) ||
314         !(*size = SizeofResource (0, rsrc)) ||
315         !(hdl = LoadResource (0, rsrc)) ||
316         !(addr = LockResource (hdl)))
317         return NULL;
318     return addr;
319 }
320 
321 /* Fills in the name and exename fields */
322 static void
323 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
324 {
325     BYTE* code;
326     DWORD size;
327     char *exepos;
328     HANDLE hfile;
329     DWORD written;
330 
331     code = extract_rcdata (res_name, "TESTRES", &size);
332     if (!code) report (R_FATAL, "Can't find test resource %s: %d",
333                        res_name, GetLastError ());
334     test->name = heap_strdup( res_name );
335     test->exename = strmake (NULL, "%s\\%s", dir, test->name);
336     exepos = strstr (test->name, testexe);
337     if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
338     *exepos = 0;
339     test->name = heap_realloc (test->name, exepos - test->name + 1);
340     report (R_STEP, "Extracting: %s", test->name);
341 
342     hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
343                         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
344     if (hfile == INVALID_HANDLE_VALUE)
345         report (R_FATAL, "Failed to open file %s.", test->exename);
346 
347     if (!WriteFile(hfile, code, size, &written, NULL))
348         report (R_FATAL, "Failed to write file %s.", test->exename);
349 
350     CloseHandle(hfile);
351 }
352 
353 static DWORD wait_process( HANDLE process, DWORD timeout )
354 {
355     DWORD wait, diff = 0, start = GetTickCount();
356     MSG msg;
357 
358     while (diff < timeout)
359     {
360         wait = MsgWaitForMultipleObjects( 1, &process, FALSE, timeout - diff, QS_ALLINPUT );
361         if (wait != WAIT_OBJECT_0 + 1) return wait;
362         while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
363         diff = GetTickCount() - start;
364     }
365     return WAIT_TIMEOUT;
366 }
367 
368 static void append_path( const char *path)
369 {
370     char *newpath;
371 
372     newpath = heap_alloc(strlen(curpath) + 1 + strlen(path) + 1);
373     strcpy(newpath, curpath);
374     strcat(newpath, ";");
375     strcat(newpath, path);
376     SetEnvironmentVariableA("PATH", newpath);
377 
378     heap_free(newpath);
379 }
380 
381 /* Run a command for MS milliseconds.  If OUT != NULL, also redirect
382    stdout to there.
383 
384    Return the exit status, -2 if can't create process or the return
385    value of WaitForSingleObject.
386  */
387 static int
388 run_ex (char *cmd, HANDLE out_file, const char *tempdir, DWORD ms)
389 {
390     STARTUPINFO si;
391     PROCESS_INFORMATION pi;
392     DWORD wait, status;
393 
394     GetStartupInfo (&si);
395     si.dwFlags    = STARTF_USESTDHANDLES;
396     si.hStdInput  = GetStdHandle( STD_INPUT_HANDLE );
397     si.hStdOutput = out_file ? out_file : GetStdHandle( STD_OUTPUT_HANDLE );
398     si.hStdError  = out_file ? out_file : GetStdHandle( STD_ERROR_HANDLE );
399 
400     if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
401                          NULL, tempdir, &si, &pi))
402         return -2;
403 
404     CloseHandle (pi.hThread);
405     status = wait_process( pi.hProcess, ms );
406     switch (status)
407     {
408     case WAIT_OBJECT_0:
409         GetExitCodeProcess (pi.hProcess, &status);
410         CloseHandle (pi.hProcess);
411         return status;
412     case WAIT_FAILED:
413         report (R_ERROR, "Wait for '%s' failed: %d", cmd, GetLastError ());
414         break;
415     case WAIT_TIMEOUT:
416         break;
417     default:
418         report (R_ERROR, "Wait returned %d", status);
419         break;
420     }
421     if (!TerminateProcess (pi.hProcess, 257))
422         report (R_ERROR, "TerminateProcess failed: %d", GetLastError ());
423     wait = wait_process( pi.hProcess, 5000 );
424     switch (wait)
425     {
426     case WAIT_OBJECT_0:
427         break;
428     case WAIT_FAILED:
429         report (R_ERROR, "Wait for termination of '%s' failed: %d", cmd, GetLastError ());
430         break;
431     case WAIT_TIMEOUT:
432         report (R_ERROR, "Can't kill process '%s'", cmd);
433         break;
434     default:
435         report (R_ERROR, "Waiting for termination: %d", wait);
436         break;
437     }
438     CloseHandle (pi.hProcess);
439     return status;
440 }
441 
442 static DWORD
443 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
444 {
445     char *cmd;
446     HANDLE subfile;
447     DWORD err, total;
448     char buffer[8192], *index;
449     static const char header[] = "Valid test names:";
450     int status, allocated;
451     char tmpdir[MAX_PATH], subname[MAX_PATH];
452     SECURITY_ATTRIBUTES sa;
453 
454     test->subtest_count = 0;
455 
456     if (!GetTempPathA( MAX_PATH, tmpdir ) ||
457         !GetTempFileNameA( tmpdir, "sub", 0, subname ))
458         report (R_FATAL, "Can't name subtests file.");
459 
460     /* make handle inheritable */
461     sa.nLength = sizeof(sa);
462     sa.lpSecurityDescriptor = NULL;
463     sa.bInheritHandle = TRUE;
464 
465     subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
466                            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
467                            &sa, CREATE_ALWAYS, 0, NULL );
468 
469     if ((subfile == INVALID_HANDLE_VALUE) &&
470         (GetLastError() == ERROR_INVALID_PARAMETER)) {
471         /* FILE_SHARE_DELETE not supported on win9x */
472         subfile = CreateFileA( subname, GENERIC_READ|GENERIC_WRITE,
473                            FILE_SHARE_READ | FILE_SHARE_WRITE,
474                            &sa, CREATE_ALWAYS, 0, NULL );
475     }
476     if (subfile == INVALID_HANDLE_VALUE) {
477         err = GetLastError();
478         report (R_ERROR, "Can't open subtests output of %s: %u",
479                 test->name, GetLastError());
480         goto quit;
481     }
482 
483     extract_test (test, tempdir, res_name);
484     cmd = strmake (NULL, "%s --list", test->exename);
485     if (test->maindllpath) {
486         /* We need to add the path (to the main dll) to PATH */
487         append_path(test->maindllpath);
488     }
489     status = run_ex (cmd, subfile, tempdir, 5000);
490     err = GetLastError();
491     if (test->maindllpath) {
492         /* Restore PATH again */
493         SetEnvironmentVariableA("PATH", curpath);
494     }
495     heap_free (cmd);
496 
497     if (status == -2)
498     {
499         report (R_ERROR, "Cannot run %s error %u", test->exename, err);
500         goto quit;
501     }
502 
503     SetFilePointer( subfile, 0, NULL, FILE_BEGIN );
504     ReadFile( subfile, buffer, sizeof(buffer), &total, NULL );
505     CloseHandle( subfile );
506     if (sizeof buffer == total) {
507         report (R_ERROR, "Subtest list of %s too big.",
508                 test->name, sizeof buffer);
509         err = ERROR_OUTOFMEMORY;
510         goto quit;
511     }
512     buffer[total] = 0;
513 
514     index = strstr (buffer, header);
515     if (!index) {
516         report (R_ERROR, "Can't parse subtests output of %s",
517                 test->name);
518         err = ERROR_INTERNAL_ERROR;
519         goto quit;
520     }
521     index += sizeof header;
522 
523     allocated = 10;
524     test->subtests = heap_alloc (allocated * sizeof(char*));
525     index = strtok (index, whitespace);
526     while (index) {
527         if (test->subtest_count == allocated) {
528             allocated *= 2;
529             test->subtests = heap_realloc (test->subtests,
530                                            allocated * sizeof(char*));
531         }
532         if (!test_filtered_out( test->name, index ))
533             test->subtests[test->subtest_count++] = heap_strdup(index);
534         index = strtok (NULL, whitespace);
535     }
536     test->subtests = heap_realloc (test->subtests,
537                                    test->subtest_count * sizeof(char*));
538     err = 0;
539 
540  quit:
541     if (!DeleteFileA (subname))
542         report (R_WARNING, "Can't delete file '%s': %u", subname, GetLastError());
543     return err;
544 }
545 
546 static void
547 run_test (struct wine_test* test, const char* subtest, HANDLE out_file, const char *tempdir)
548 {
549     int status;
550     const char* file = get_test_source_file(test->name, subtest);
551     char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
552 
553     xprintf ("%s:%s start %s -\n", test->name, subtest, file);
554     status = run_ex (cmd, out_file, tempdir, 120000);
555     heap_free (cmd);
556     xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
557 }
558 
559 static BOOL CALLBACK
560 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
561                   LPTSTR lpszName, LONG_PTR lParam)
562 {
563     if (!test_filtered_out( lpszName, NULL )) (*(int*)lParam)++;
564     return TRUE;
565 }
566 
567 static const struct clsid_mapping
568 {
569     const char *name;
570     CLSID clsid;
571 } clsid_list[] =
572 {
573     {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
574     {NULL, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
575 };
576 
577 
578 static BOOL get_main_clsid(const char *name, CLSID *clsid)
579 {
580     const struct clsid_mapping *mapping;
581 
582     for(mapping = clsid_list; mapping->name; mapping++)
583     {
584         if(!strcasecmp(name, mapping->name))
585         {
586             *clsid = mapping->clsid;
587             return TRUE;
588         }
589     }
590     return FALSE;
591 }
592 
593 static HMODULE load_com_dll(const char *name, char **path, char *filename)
594 {
595     HMODULE dll = NULL;
596     HKEY hkey;
597     char keyname[100];
598     char dllname[MAX_PATH];
599     char *p;
600     CLSID clsid;
601 
602     if(!get_main_clsid(name, &clsid)) return NULL;
603 
604     sprintf(keyname, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
605             clsid.Data1, clsid.Data2, clsid.Data3, clsid.Data4[0], clsid.Data4[1],
606             clsid.Data4[2], clsid.Data4[3], clsid.Data4[4], clsid.Data4[5],
607             clsid.Data4[6], clsid.Data4[7]);
608 
609     if(RegOpenKeyA(HKEY_CLASSES_ROOT, keyname, &hkey) == ERROR_SUCCESS)
610     {
611         LONG size = sizeof(dllname);
612         if(RegQueryValueA(hkey, NULL, dllname, &size) == ERROR_SUCCESS)
613         {
614             if ((dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE)))
615             {
616                 strcpy( filename, dllname );
617                 p = strrchr(dllname, '\\');
618                 if (p) *p = 0;
619                 *path = heap_strdup( dllname );
620             }
621         }
622         RegCloseKey(hkey);
623     }
624 
625     return dll;
626 }
627 
628 static void get_dll_path(HMODULE dll, char **path, char *filename)
629 {
630     char dllpath[MAX_PATH];
631 
632     GetModuleFileNameA(dll, dllpath, MAX_PATH);
633     strcpy(filename, dllpath);
634     *strrchr(dllpath, '\\') = '\0';
635     *path = heap_strdup( dllpath );
636 }
637 
638 static BOOL CALLBACK
639 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
640                    LPTSTR lpszName, LONG_PTR lParam)
641 {
642     const char *tempdir = (const char *)lParam;
643     char dllname[MAX_PATH];
644     char filename[MAX_PATH];
645     WCHAR dllnameW[MAX_PATH];
646     HMODULE dll;
647     DWORD err;
648 
649     if (test_filtered_out( lpszName, NULL )) return TRUE;
650 
651     /* Check if the main dll is present on this system */
652     CharLowerA(lpszName);
653     strcpy(dllname, lpszName);
654     *strstr(dllname, testexe) = 0;
655 
656     wine_tests[nr_of_files].maindllpath = NULL;
657     strcpy(filename, dllname);
658     dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
659 
660     if (!dll) dll = load_com_dll(dllname, &wine_tests[nr_of_files].maindllpath, filename);
661 
662     if (!dll && pLoadLibraryShim)
663     {
664         MultiByteToWideChar(CP_ACP, 0, dllname, -1, dllnameW, MAX_PATH);
665         if (SUCCEEDED( pLoadLibraryShim(dllnameW, NULL, NULL, &dll) ) && dll)
666         {
667             get_dll_path(dll, &wine_tests[nr_of_files].maindllpath, filename);
668             FreeLibrary(dll);
669             dll = LoadLibraryExA(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);
670         }
671         else dll = 0;
672     }
673 
674     if (!dll)
675     {
676         xprintf ("    %s=dll is missing\n", dllname);
677         return TRUE;
678     }
679     if (is_native_dll(dll))
680     {
681         FreeLibrary(dll);
682         xprintf ("    %s=load error Configured as native\n", dllname);
683         nr_native_dlls++;
684         return TRUE;
685     }
686     if (!strcmp( dllname, "mshtml" ) && running_under_wine() && !gecko_check())
687     {
688         FreeLibrary(dll);
689         xprintf ("    %s=load error Gecko is not installed\n", dllname);
690         return TRUE;
691     }
692     FreeLibrary(dll);
693 
694     if (!(err = get_subtests( tempdir, &wine_tests[nr_of_files], lpszName )))
695     {
696         xprintf ("    %s=%s\n", dllname, get_file_version(filename));
697         nr_of_tests += wine_tests[nr_of_files].subtest_count;
698         nr_of_files++;
699     }
700     else
701     {
702         xprintf ("    %s=load error %u\n", dllname, err);
703     }
704     return TRUE;
705 }
706 
707 static char *
708 run_tests (char *logname, char *outdir)
709 {
710     int i;
711     char *strres, *eol, *nextline;
712     DWORD strsize;
713     SECURITY_ATTRIBUTES sa;
714     char tmppath[MAX_PATH], tempdir[MAX_PATH+4];
715     DWORD needed;
716 
717     /* Get the current PATH only once */
718     needed = GetEnvironmentVariableA("PATH", NULL, 0);
719     curpath = heap_alloc(needed);
720     GetEnvironmentVariableA("PATH", curpath, needed);
721 
722     SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
723 
724     if (!GetTempPathA( MAX_PATH, tmppath ))
725         report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
726 
727     if (!logname) {
728         static char tmpname[MAX_PATH];
729         if (!GetTempFileNameA( tmppath, "res", 0, tmpname ))
730             report (R_FATAL, "Can't name logfile.");
731         logname = tmpname;
732     }
733     report (R_OUT, logname);
734 
735     /* make handle inheritable */
736     sa.nLength = sizeof(sa);
737     sa.lpSecurityDescriptor = NULL;
738     sa.bInheritHandle = TRUE;
739 
740     logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
741                            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
742                            &sa, CREATE_ALWAYS, 0, NULL );
743 
744     if ((logfile == INVALID_HANDLE_VALUE) &&
745         (GetLastError() == ERROR_INVALID_PARAMETER)) {
746         /* FILE_SHARE_DELETE not supported on win9x */
747         logfile = CreateFileA( logname, GENERIC_READ|GENERIC_WRITE,
748                            FILE_SHARE_READ | FILE_SHARE_WRITE,
749                            &sa, CREATE_ALWAYS, 0, NULL );
750     }
751     if (logfile == INVALID_HANDLE_VALUE)
752         report (R_FATAL, "Could not open logfile: %u", GetLastError());
753 
754     /* try stable path for ZoneAlarm */
755     if (!outdir) {
756         strcpy( tempdir, tmppath );
757         strcat( tempdir, "wct" );
758 
759         if (!CreateDirectoryA( tempdir, NULL ))
760         {
761             if (!GetTempFileNameA( tmppath, "wct", 0, tempdir ))
762                 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
763             DeleteFileA( tempdir );
764             if (!CreateDirectoryA( tempdir, NULL ))
765                 report (R_FATAL, "Could not create directory: %s", tempdir);
766         }
767     }
768     else
769         strcpy( tempdir, outdir);
770 
771     report (R_DIR, tempdir);
772 
773     xprintf ("Version 4\n");
774     xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
775     xprintf ("Archive: -\n");  /* no longer used */
776     xprintf ("Tag: %s\n", tag);
777     xprintf ("Build info:\n");
778     strres = extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize);
779     while (strres) {
780         eol = memchr (strres, '\n', strsize);
781         if (!eol) {
782             nextline = NULL;
783             eol = strres + strsize;
784         } else {
785             strsize -= eol - strres + 1;
786             nextline = strsize?eol+1:NULL;
787             if (eol > strres && *(eol-1) == '\r') eol--;
788         }
789         xprintf ("    %.*s\n", eol-strres, strres);
790         strres = nextline;
791     }
792     xprintf ("Operating system version:\n");
793     print_version ();
794     xprintf ("Dll info:\n" );
795 
796     report (R_STATUS, "Counting tests");
797     if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
798         report (R_FATAL, "Can't enumerate test files: %d",
799                 GetLastError ());
800     wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0]);
801 
802     /* Do this only once during extraction (and version checking) */
803     hmscoree = LoadLibraryA("mscoree.dll");
804     pLoadLibraryShim = NULL;
805     if (hmscoree)
806         pLoadLibraryShim = (void *)GetProcAddress(hmscoree, "LoadLibraryShim");
807 
808     report (R_STATUS, "Extracting tests");
809     report (R_PROGRESS, 0, nr_of_files);
810     nr_of_files = 0;
811     nr_of_tests = 0;
812     if (!EnumResourceNames (NULL, "TESTRES", extract_test_proc, (LPARAM)tempdir))
813         report (R_FATAL, "Can't enumerate test files: %d",
814                 GetLastError ());
815 
816     FreeLibrary(hmscoree);
817 
818     xprintf ("Test output:\n" );
819 
820     report (R_DELTA, 0, "Extracting: Done");
821 
822     if (nr_native_dlls)
823         report( R_WARNING, "Some dlls are configured as native, you won't be able to submit results." );
824 
825     report (R_STATUS, "Running tests");
826     report (R_PROGRESS, 1, nr_of_tests);
827     for (i = 0; i < nr_of_files; i++) {
828         struct wine_test *test = wine_tests + i;
829         int j;
830 
831         if (test->maindllpath) {
832             /* We need to add the path (to the main dll) to PATH */
833             append_path(test->maindllpath);
834         }
835 
836         for (j = 0; j < test->subtest_count; j++) {
837             report (R_STEP, "Running: %s:%s", test->name,
838                     test->subtests[j]);
839             run_test (test, test->subtests[j], logfile, tempdir);
840         }
841 
842         if (test->maindllpath) {
843             /* Restore PATH again */
844             SetEnvironmentVariableA("PATH", curpath);
845         }
846     }
847     report (R_DELTA, 0, "Running: Done");
848 
849     report (R_STATUS, "Cleaning up");
850     CloseHandle( logfile );
851     logfile = 0;
852     if (!outdir)
853         remove_dir (tempdir);
854     heap_free(wine_tests);
855     heap_free(curpath);
856 
857     return logname;
858 }
859 
860 static BOOL WINAPI ctrl_handler(DWORD ctrl_type)
861 {
862     if (ctrl_type == CTRL_C_EVENT) {
863         printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
864         return TRUE;
865     }
866 
867     return FALSE;
868 }
869 
870 
871 static BOOL CALLBACK
872 extract_only_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
873 {
874     const char *target_dir = (const char *)lParam;
875     char filename[MAX_PATH];
876 
877     if (test_filtered_out( lpszName, NULL )) return TRUE;
878 
879     strcpy(filename, lpszName);
880     CharLowerA(filename);
881 
882     extract_test( &wine_tests[nr_of_files], target_dir, filename );
883     nr_of_files++;
884     return TRUE;
885 }
886 
887 static void extract_only (const char *target_dir)
888 {
889     BOOL res;
890 
891     report (R_DIR, target_dir);
892     res = CreateDirectoryA( target_dir, NULL );
893     if (!res && GetLastError() != ERROR_ALREADY_EXISTS)
894         report (R_FATAL, "Could not create directory: %s (%d)", target_dir, GetLastError ());
895 
896     nr_of_files = 0;
897     report (R_STATUS, "Counting tests");
898     if (!EnumResourceNames (NULL, "TESTRES", EnumTestFileProc, (LPARAM)&nr_of_files))
899         report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
900 
901     wine_tests = heap_alloc (nr_of_files * sizeof wine_tests[0] );
902 
903     report (R_STATUS, "Extracting tests");
904     report (R_PROGRESS, 0, nr_of_files);
905     nr_of_files = 0;
906     if (!EnumResourceNames (NULL, "TESTRES", extract_only_proc, (LPARAM)target_dir))
907         report (R_FATAL, "Can't enumerate test files: %d", GetLastError ());
908 
909     report (R_DELTA, 0, "Extracting: Done");
910 }
911 
912 static void
913 usage (void)
914 {
915     fprintf (stderr,
916 "Usage: winetest [OPTION]... [TESTS]\n\n"
917 " --help    print this message and exit\n"
918 " --version print the build version and exit\n"
919 " -c        console mode, no GUI\n"
920 " -d DIR    Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
921 " -e        preserve the environment\n"
922 " -h        print this message and exit\n"
923 " -p        shutdown when the tests are done\n"
924 " -q        quiet mode, no output at all\n"
925 " -o FILE   put report into FILE, do not submit\n"
926 " -s FILE   submit FILE, do not run tests\n"
927 " -t TAG    include TAG of characters [-.0-9a-zA-Z] in the report\n"
928 " -x DIR    Extract tests to DIR (default: .\\wct) and exit\n");
929 }
930 
931 int main( int argc, char *argv[] )
932 {
933     char *logname = NULL, *outdir = NULL;
934     const char *extract = NULL;
935     const char *cp, *submit = NULL;
936     int reset_env = 1;
937     int poweroff = 0;
938     int interactive = 1;
939     int i;
940 
941     if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
942 
943     for (i = 1; i < argc && argv[i]; i++)
944     {
945         if (!strcmp(argv[i], "--help")) {
946             usage ();
947             exit (0);
948         }
949         else if (!strcmp(argv[i], "--version")) {
950             printf("%-12.12s\n", build_id[0] ? build_id : "unknown");
951             exit (0);
952         }
953         else if ((argv[i][0] != '-' && argv[i][0] != '/') || argv[i][2]) {
954             if (nb_filters == sizeof(filters)/sizeof(filters[0]))
955             {
956                 report (R_ERROR, "Too many test filters specified");
957                 exit (2);
958             }
959             filters[nb_filters++] = argv[i];
960         }
961         else switch (argv[i][1]) {
962         case 'c':
963             report (R_TEXTMODE);
964             interactive = 0;
965             break;
966         case 'e':
967             reset_env = 0;
968             break;
969         case 'h':
970         case '?':
971             usage ();
972             exit (0);
973         case 'p':
974             poweroff = 1;
975             break;
976         case 'q':
977             report (R_QUIET);
978             interactive = 0;
979             break;
980         case 's':
981             if (!(submit = argv[++i]))
982             {
983                 usage();
984                 exit( 2 );
985             }
986             if (tag)
987                 report (R_WARNING, "ignoring tag for submission");
988             send_file (submit);
989             break;
990         case 'o':
991             if (!(logname = argv[++i]))
992             {
993                 usage();
994                 exit( 2 );
995             }
996             break;
997         case 't':
998             if (!(tag = argv[++i]))
999             {
1000                 usage();
1001                 exit( 2 );
1002             }
1003             if (strlen (tag) > MAXTAGLEN)
1004                 report (R_FATAL, "tag is too long (maximum %d characters)",
1005                         MAXTAGLEN);
1006             cp = findbadtagchar (tag);
1007             if (cp) {
1008                 report (R_ERROR, "invalid char in tag: %c", *cp);
1009                 usage ();
1010                 exit (2);
1011             }
1012             break;
1013         case 'x':
1014             report (R_TEXTMODE);
1015             if (!(extract = argv[++i]))
1016                 extract = ".\\wct";
1017 
1018             extract_only (extract);
1019             break;
1020         case 'd':
1021             outdir = argv[++i];
1022             break;
1023         default:
1024             report (R_ERROR, "invalid option: -%c", argv[i][1]);
1025             usage ();
1026             exit (2);
1027         }
1028     }
1029     if (!submit && !extract) {
1030         report (R_STATUS, "Starting up");
1031 
1032         if (!running_on_visible_desktop ())
1033             report (R_FATAL, "Tests must be run on a visible desktop");
1034 
1035         SetConsoleCtrlHandler(ctrl_handler, TRUE);
1036 
1037         if (reset_env)
1038         {
1039             SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1040             SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1041             SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "" );
1042             SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "" );
1043         }
1044 
1045         if (!nb_filters)  /* don't submit results when filtering */
1046         {
1047             while (!tag) {
1048                 if (!interactive)
1049                     report (R_FATAL, "Please specify a tag (-t option) if "
1050                             "running noninteractive!");
1051                 if (guiAskTag () == IDABORT) exit (1);
1052             }
1053             report (R_TAG);
1054 
1055             if (!build_id[0])
1056                 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
1057                         "To submit results, winetest needs to be built from a git checkout." );
1058         }
1059 
1060         if (!logname) {
1061             logname = run_tests (NULL, outdir);
1062             if (build_id[0] && !nb_filters && !nr_native_dlls &&
1063                 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
1064                 if (!send_file (logname) && !DeleteFileA(logname))
1065                     report (R_WARNING, "Can't remove logfile: %u", GetLastError());
1066         } else run_tests (logname, outdir);
1067         report (R_STATUS, "Finished");
1068     }
1069     if (poweroff)
1070     {
1071         HANDLE hToken;
1072         TOKEN_PRIVILEGES npr;
1073 
1074         /* enable the shutdown privilege for the current process */
1075         if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1076         {
1077             LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
1078             npr.PrivilegeCount = 1;
1079             npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1080             AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
1081             CloseHandle(hToken);
1082         }
1083         ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
1084     }
1085     exit (0);
1086 }
1087 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.