ReactOS 0.4.15-dev-8339-g4028de8
main.c File Reference
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <windows.h>
#include "winetest.h"
#include "resource.h"
#include <reason.h>
Include dependency graph for main.c:

Go to the source code of this file.

Classes

struct  wine_test
 
struct  rev_info
 

Functions

static charget_file_version (char *file_name)
 
static int running_under_wine (void)
 
static int running_on_visible_desktop (void)
 
static void print_version (void)
 
static int is_dot_dir (const char *x)
 
static void remove_dir (const char *dir)
 
static const charget_test_source_file (const char *test, const char *subtest)
 
static const charget_file_rev (const char *file)
 
static void extract_rev_infos (void)
 
static voidextract_rcdata (LPTSTR name, int type, DWORD *size)
 
static void extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
 
static int run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
 
static void get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
 
static void run_test (struct wine_test *test, const char *subtest, const char *tempdir)
 
static BOOL CALLBACK EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
 
static BOOL CALLBACK extract_test_proc (HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
 
static charrun_tests (char *logname)
 
static void usage (void)
 
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdLine, int cmdShow)
 

Variables

chartag = NULL
 
static struct wine_testwine_tests
 
static int nr_of_files
 
static int nr_of_tests
 
static struct rev_inforev_infos = NULL
 
static const char whitespace [] = " \t\r\n"
 
static const char testexe [] = "_test.exe"
 

Function Documentation

◆ EnumTestFileProc()

static BOOL CALLBACK EnumTestFileProc ( HMODULE  hModule,
LPCTSTR  lpszType,
LPTSTR  lpszName,
LONG_PTR  lParam 
)
static

Definition at line 462 of file main.c.

464{
465 (*(int*)lParam)++;
466 return TRUE;
467}
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120

Referenced by run_tests().

◆ extract_rcdata()

static void * extract_rcdata ( LPTSTR  name,
int  type,
DWORD size 
)
static

Definition at line 260 of file main.c.

261{
262 HRSRC rsrc;
263 HGLOBAL hdl;
264 LPVOID addr;
265
266 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
267 !(*size = SizeofResource (0, rsrc)) ||
268 !(hdl = LoadResource (0, rsrc)) ||
269 !(addr = LockResource (hdl)))
270 return NULL;
271 return addr;
272}
#define NULL
Definition: types.h:112
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLenum const GLvoid * addr
Definition: glext.h:9621
Definition: name.c:39
#define FindResource
Definition: winbase.h:3793
#define MAKEINTRESOURCE
Definition: winuser.h:591

Referenced by extract_test(), and run_tests().

◆ extract_rev_infos()

static void extract_rev_infos ( void  )
static

Definition at line 234 of file main.c.

235{
236 char revinfo[256], *p;
237 int size = 0, i;
238 unsigned int len;
240
241 for (i = 0; TRUE; i++) {
242 if (i >= size) {
243 size += 100;
244 rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
245 }
246 memset(rev_infos + i, 0, sizeof(rev_infos[i]));
247
248 len = LoadStringA (module, REV_INFO+i, revinfo, sizeof(revinfo));
249 if (len == 0) break; /* end of revision info */
250 if (len >= sizeof(revinfo) - 1)
251 report (R_FATAL, "Revision info too long.");
252 if(!(p = strrchr(revinfo, ':')))
253 report (R_FATAL, "Revision info malformed (i=%d)", i);
254 *p = 0;
255 rev_infos[i].file = strdup(revinfo);
256 rev_infos[i].rev = strdup(p + 1);
257 }
258}
void * xrealloc(void *oldmem, size_t size)
Definition: uimain.c:736
static void report(const DATA_BLOB *pDataIn, const DATA_BLOB *pOptionalEntropy, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags)
Definition: protectdata.c:769
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static struct rev_info * rev_infos
Definition: main.c:62
#define REV_INFO
Definition: resource.h:59
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define memset(x, y, z)
Definition: compat.h:39
#define GetModuleHandle
Definition: winbase.h:3827
@ R_FATAL
Definition: winetest.h:56
int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPSTR lpBuffer, _In_ int cchBufferMax)

Referenced by WinMain().

◆ extract_test()

static void extract_test ( struct wine_test test,
const char dir,
LPTSTR  res_name 
)
static

Definition at line 276 of file main.c.

277{
278 BYTE* code;
279 DWORD size;
280 FILE* fout;
281 char *exepos;
282
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);
293
294 if (!(fout = fopen (test->exename, "wb")) ||
295 (fwrite (code, size, 1, fout) != 1) ||
296 fclose (fout)) report (R_FATAL, "Failed to write file %s.",
297 test->exename);
298}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
unsigned int dir
Definition: maze.c:112
char * xstrdup(const char *s)
Definition: uimain.c:768
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
static void * extract_rcdata(LPTSTR name, int type, DWORD *size)
Definition: main.c:260
static const char testexe[]
Definition: main.c:64
#define TESTRES
Definition: resource.h:49
char * strmake(size_t *lenp,...)
Definition: util.c:82
#define test
Definition: rosglue.h:37
Definition: inflate.c:139
char * name
Definition: compiler.c:66
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
@ R_STEP
Definition: winetest.h:49
unsigned char BYTE
Definition: xxhash.c:193

Referenced by get_subtests().

◆ extract_test_proc()

static BOOL CALLBACK extract_test_proc ( HMODULE  hModule,
LPCTSTR  lpszType,
LPTSTR  lpszName,
LONG_PTR  lParam 
)
static

Definition at line 470 of file main.c.

472{
473 const char *tempdir = (const char *)lParam;
474 char dllname[MAX_PATH];
475 HMODULE dll;
476
477 /* Check if the main dll is present on this system */
478 CharLowerA(lpszName);
479 strcpy(dllname, lpszName);
480 *strstr(dllname, testexe) = 0;
481
483 if (!dll) {
484 xprintf (" %s=dll is missing\n", dllname);
485 return TRUE;
486 }
488
489 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
490
491 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
492 nr_of_tests += wine_tests[nr_of_files].subtest_count;
493 nr_of_files++;
494 return TRUE;
495}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:159
static HMODULE dll
Definition: str.c:188
static char * get_file_version(char *file_name)
Definition: main.c:66
static struct wine_test * wine_tests
Definition: main.c:60
static int nr_of_tests
Definition: main.c:61
static int nr_of_files
Definition: main.c:61
static void get_subtests(const char *tempdir, struct wine_test *test, LPTSTR res_name)
Definition: main.c:383
void xprintf(const char *fmt,...)
Definition: shimdbg.c:16
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
LPSTR WINAPI CharLowerA(_Inout_ LPSTR)

Referenced by run_tests().

◆ get_file_rev()

static const char * get_file_rev ( const char file)
static

Definition at line 223 of file main.c.

224{
225 const struct rev_info* rev;
226
227 for(rev = rev_infos; rev->file; rev++) {
228 if (strcmp(rev->file, file) == 0) return rev->rev;
229 }
230
231 return "-";
232}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int rev
Definition: sort.c:17
Definition: fci.c:127
Definition: main.c:54

Referenced by run_test().

◆ get_file_version()

static char * get_file_version ( char file_name)
static

Definition at line 66 of file main.c.

67{
68 static char version[32];
69 DWORD size;
71
73 if (size) {
74 char * data = xmalloc(size);
75 if (data) {
77 static char backslash[] = "\\";
78 VS_FIXEDFILEINFO *pFixedVersionInfo;
79 UINT len;
80 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
81 sprintf(version, "%d.%d.%d.%d",
82 pFixedVersionInfo->dwFileVersionMS >> 16,
83 pFixedVersionInfo->dwFileVersionMS & 0xffff,
84 pFixedVersionInfo->dwFileVersionLS >> 16,
85 pFixedVersionInfo->dwFileVersionLS & 0xffff);
86 } else
87 sprintf(version, "version not available");
88 } else
89 sprintf(version, "unknown");
90 free(data);
91 } else
92 sprintf(version, "failed");
93 } else
94 sprintf(version, "version not available");
95
96 return version;
97}
void * xmalloc(int size)
Definition: uimain.c:747
#define free
Definition: debug_ros.c:5
static const WCHAR version[]
Definition: asmname.c:66
DWORD WINAPI GetFileVersionInfoSizeA(LPCSTR filename, LPDWORD handle)
Definition: version.c:619
BOOL WINAPI VerQueryValueA(LPCVOID pBlock, LPCSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:993
BOOL WINAPI GetFileVersionInfoA(LPCSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:853
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static LPCWSTR file_name
Definition: protocol.c:147
unsigned int UINT
Definition: ndis.h:50

Referenced by extract_test_proc().

◆ get_subtests()

static void get_subtests ( const char tempdir,
struct wine_test test,
LPTSTR  res_name 
)
static

Definition at line 383 of file main.c.

384{
385 char *subname, *cmd;
386 FILE *subfile;
387 size_t total;
388 char buffer[8192], *index;
389 static const char header[] = "Valid test names:";
390 int allocated;
391
392 test->subtest_count = 0;
393
394 subname = tempnam (0, "sub");
395 if (!subname) report (R_FATAL, "Can't name subtests file.");
396
397 extract_test (test, tempdir, res_name);
398 cmd = strmake (NULL, "%s --list", test->exename);
399 run_ex (cmd, subname, tempdir, 5000);
400 free (cmd);
401
402 subfile = fopen (subname, "r");
403 if (!subfile) {
404 report (R_ERROR, "Can't open subtests output of %s: %d",
405 test->name, errno);
406 goto quit;
407 }
408 total = fread (buffer, 1, sizeof buffer, subfile);
409 fclose (subfile);
410 if (sizeof buffer == total) {
411 report (R_ERROR, "Subtest list of %s too big.",
412 test->name, sizeof buffer);
413 goto quit;
414 }
415 buffer[total] = 0;
416
418 if (!index) {
419 report (R_ERROR, "Can't parse subtests output of %s",
420 test->name);
421 goto quit;
422 }
423 index += sizeof header;
424
425 allocated = 10;
426 test->subtests = xmalloc (allocated * sizeof(char*));
428 while (index) {
429 if (test->subtest_count == allocated) {
430 allocated *= 2;
431 test->subtests = xrealloc (test->subtests,
432 allocated * sizeof(char*));
433 }
434 test->subtests[test->subtest_count++] = strdup (index);
436 }
437 test->subtests = xrealloc (test->subtests,
438 test->subtest_count * sizeof(char*));
439
440 quit:
441 if (remove (subname))
442 report (R_WARNING, "Can't delete file '%s': %d",
443 subname, errno);
444 free (subname);
445}
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
#define index(s, c)
Definition: various.h:29
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
size_t total
GLuint buffer
Definition: glext.h:5915
GLuint index
Definition: glext.h:6031
_CRTIMP char *__cdecl tempnam(_In_opt_z_ const char *_Directory, _In_opt_z_ const char *_FilePrefix)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
static int run_ex(char *cmd, const char *out, const char *tempdir, DWORD ms)
Definition: main.c:307
static const char whitespace[]
Definition: main.c:63
static void extract_test(struct wine_test *test, const char *dir, LPTSTR res_name)
Definition: main.c:276
int remove
Definition: msacm.c:1366
#define errno
Definition: errno.h:18
Definition: ftp_var.h:139
@ R_ERROR
Definition: winetest.h:55
@ R_WARNING
Definition: winetest.h:54

Referenced by extract_test_proc().

◆ get_test_source_file()

static const char * get_test_source_file ( const char test,
const char subtest 
)
static

Definition at line 204 of file main.c.

205{
206 static const char* special_dirs[][2] = {
207 { 0, 0 }
208 };
209 static char buffer[MAX_PATH];
210 int i;
211
212 for (i = 0; special_dirs[i][0]; i++) {
213 if (strcmp(test, special_dirs[i][0]) == 0) {
214 test = special_dirs[i][1];
215 break;
216 }
217 }
218
219 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
220 return buffer;
221}
Definition: pseh.c:2763
#define snprintf
Definition: wintirpc.h:48

Referenced by run_test().

◆ is_dot_dir()

static int is_dot_dir ( const char x)
inlinestatic

Definition at line 168 of file main.c.

169{
170 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
171}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

◆ print_version()

static void print_version ( void  )
static

Definition at line 131 of file main.c.

132{
133 OSVERSIONINFOEX ver;
134 BOOL ext;
135 int is_win2k3_r2;
136 const char *(*wine_get_build_id)(void);
137
139 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
140 {
142 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
143 report (R_FATAL, "Can't get OS version.");
144 }
145
146 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
147 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
148 xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
149 " dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
151 ver.dwPlatformId, ver.szCSDVersion);
152
153 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
154 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
155
156 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
157 if(is_win2k3_r2)
158 xprintf(" R2 build number=%d\n", is_win2k3_r2);
159
160 if (!ext) return;
161
162 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
163 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
164 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
165 ver.wProductType, ver.wReserved);
166}
#define GetProcAddress(x, y)
Definition: compat.h:753
static const WCHAR *const ext[]
Definition: module.c:53
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
unsigned int BOOL
Definition: ntddk_ex.h:94
static int running_on_visible_desktop(void)
Definition: main.c:107
static int running_under_wine(void)
Definition: main.c:99
CHAR szCSDVersion[128]
Definition: rtltypes.h:242
ULONG dwPlatformId
Definition: rtltypes.h:241
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwBuildNumber
Definition: rtltypes.h:240
ULONG dwMinorVersion
Definition: rtltypes.h:239
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:255
#define GetVersionEx
Definition: winbase.h:3852
int WINAPI GetSystemMetrics(_In_ int)
OSVERSIONINFOEXA OSVERSIONINFOEX
Definition: rtltypes.h:303
OSVERSIONINFOA OSVERSIONINFO
Definition: rtltypes.h:306

Referenced by run_tests().

◆ remove_dir()

static void remove_dir ( const char dir)
static

Definition at line 173 of file main.c.

174{
175 HANDLE hFind;
176 WIN32_FIND_DATA wfd;
177 char path[MAX_PATH];
178 size_t dirlen = strlen (dir);
179
180 /* Make sure the directory exists before going further */
181 memcpy (path, dir, dirlen);
182 strcpy (path + dirlen++, "\\*");
183 hFind = FindFirstFile (path, &wfd);
184 if (hFind == INVALID_HANDLE_VALUE) return;
185
186 do {
187 char *lp = wfd.cFileName;
188
189 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
190 if (is_dot_dir (lp)) continue;
191 strcpy (path + dirlen, lp);
192 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
194 else if (!DeleteFile (path))
195 report (R_WARNING, "Can't delete file %s: error %d",
196 path, GetLastError ());
197 } while (FindNextFile (hFind, &wfd));
198 FindClose (hFind);
199 if (!RemoveDirectory (dir))
200 report (R_WARNING, "Can't remove directory %s: error %d",
201 dir, GetLastError ());
202}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
#define is_dot_dir(x)
Definition: files.c:873
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void remove_dir(const char *dir)
Definition: main.c:173
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define RemoveDirectory
Definition: winbase.h:3895
#define DeleteFile
Definition: winbase.h:3764
#define FindNextFile
Definition: winbase.h:3788
#define FindFirstFile
Definition: winbase.h:3782

Referenced by remove_dir(), and run_tests().

◆ run_ex()

static int run_ex ( char cmd,
const char out,
const char tempdir,
DWORD  ms 
)
static

Definition at line 307 of file main.c.

308{
309 STARTUPINFO si;
311 int fd, oldstdout = -1;
312 DWORD wait, status;
313
314 GetStartupInfo (&si);
315 si.dwFlags = 0;
316
317 if (out) {
318 fd = open (out, O_WRONLY | O_CREAT, 0666);
319 if (-1 == fd)
320 report (R_FATAL, "Can't open '%s': %d", out, errno);
321 oldstdout = dup (1);
322 if (-1 == oldstdout)
323 report (R_FATAL, "Can't save stdout: %d", errno);
324 if (-1 == dup2 (fd, 1))
325 report (R_FATAL, "Can't redirect stdout: %d", errno);
326 close (fd);
327 }
328
330 NULL, tempdir, &si, &pi)) {
331 status = -2;
332 } else {
333 CloseHandle (pi.hThread);
334 wait = WaitForSingleObject (pi.hProcess, ms);
335 if (wait == WAIT_OBJECT_0) {
336 GetExitCodeProcess (pi.hProcess, &status);
337 } else {
338 switch (wait) {
339 case WAIT_FAILED:
340 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
341 GetLastError ());
342 break;
343 case WAIT_TIMEOUT:
344 report (R_ERROR, "Process '%s' timed out.", cmd);
345 break;
346 default:
347 report (R_ERROR, "Wait returned %d", wait);
348 }
349 status = wait;
350 if (!TerminateProcess (pi.hProcess, 257))
351 report (R_ERROR, "TerminateProcess failed: %d",
352 GetLastError ());
353 wait = WaitForSingleObject (pi.hProcess, 5000);
354 switch (wait) {
355 case WAIT_FAILED:
357 "Wait for termination of '%s' failed: %d",
358 cmd, GetLastError ());
359 break;
360 case WAIT_OBJECT_0:
361 break;
362 case WAIT_TIMEOUT:
363 report (R_ERROR, "Can't kill process '%s'", cmd);
364 break;
365 default:
366 report (R_ERROR, "Waiting for termination: %d",
367 wait);
368 }
369 }
370 CloseHandle (pi.hProcess);
371 }
372
373 if (out) {
374 close (1);
375 if (-1 == dup2 (oldstdout, 1))
376 report (R_FATAL, "Can't recover stdout: %d", errno);
377 close (oldstdout);
378 }
379 return status;
380}
#define O_WRONLY
Definition: acwin.h:111
#define O_CREAT
Definition: acwin.h:110
#define open
Definition: acwin.h:95
#define close
Definition: acwin.h:98
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4741
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
#define dup
Definition: syshdrs.h:51
static refpint_t pi[]
Definition: server.c:96
static FILE * out
Definition: regtests2xml.c:44
_Check_return_ _CRTIMP int __cdecl dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst)
static int fd
Definition: io.c:51
DWORD dwFlags
Definition: winbase.h:842
Definition: ps.c:97
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define GetStartupInfo
Definition: winbase.h:3841
#define CREATE_DEFAULT_ERROR_MODE
Definition: winbase.h:194
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WAIT_FAILED
Definition: winbase.h:413

Referenced by get_subtests(), and run_test().

◆ run_test()

static void run_test ( struct wine_test test,
const char subtest,
const char tempdir 
)
static

Definition at line 448 of file main.c.

449{
450 int status;
451 const char* file = get_test_source_file(test->name, subtest);
452 const char* rev = get_file_rev(file);
453 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
454
455 xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev);
456 status = run_ex (cmd, NULL, tempdir, 120000);
457 free (cmd);
458 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
459}
static const char * get_test_source_file(const char *test, const char *subtest)
Definition: main.c:204
static const char * get_file_rev(const char *file)
Definition: main.c:223

◆ run_tests()

static char * run_tests ( char logname)
static

Definition at line 498 of file main.c.

499{
500 int i;
501 char *tempdir, *shorttempdir;
502 int logfile;
503 char *strres, *eol, *nextline;
504 DWORD strsize;
505 char build[64];
506
508
509 if (!logname) {
510 logname = tempnam (0, "res");
511 if (!logname) report (R_FATAL, "Can't name logfile.");
512 }
513 report (R_OUT, logname);
514
515 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
516 0666);
517 if (-1 == logfile) {
518 if (EEXIST == errno)
519 report (R_FATAL, "File %s already exists.", logname);
520 else report (R_FATAL, "Could not open logfile: %d", errno);
521 }
522 if (-1 == dup2 (logfile, 1))
523 report (R_FATAL, "Can't redirect stdout: %d", errno);
524 close (logfile);
525
526 tempdir = tempnam (0, "wct");
527 if (!tempdir)
528 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
529 shorttempdir = strdup (tempdir);
530 if (shorttempdir) { /* try stable path for ZoneAlarm */
531 strstr (shorttempdir, "wct")[3] = 0;
532 if (CreateDirectoryA (shorttempdir, NULL)) {
533 free (tempdir);
534 tempdir = shorttempdir;
535 } else free (shorttempdir);
536 }
537 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
538 report (R_FATAL, "Could not create directory: %s", tempdir);
539 report (R_DIR, tempdir);
540
541 xprintf ("Version 4\n");
542 strres = extract_rcdata (MAKEINTRESOURCE(WINE_BUILD), STRINGRES, &strsize);
543 xprintf ("Tests from build ");
544 if (LoadStringA( 0, IDS_BUILD_ID, build, sizeof(build) )) xprintf( "%s\n", build );
545 else if (strres) xprintf ("%.*s", strsize, strres);
546 else xprintf ("-\n");
547 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
548 xprintf ("Archive: ");
549 if (strres) xprintf ("%.*s", strsize, strres);
550 else xprintf ("-\n");
551 xprintf ("Tag: %s\n", tag);
552 xprintf ("Build info:\n");
553 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
554 while (strres) {
555 eol = memchr (strres, '\n', strsize);
556 if (!eol) {
557 nextline = NULL;
558 eol = strres + strsize;
559 } else {
560 strsize -= eol - strres + 1;
561 nextline = strsize?eol+1:NULL;
562 if (eol > strres && *(eol-1) == '\r') eol--;
563 }
564 xprintf (" %.*s\n", eol-strres, strres);
565 strres = nextline;
566 }
567 xprintf ("Operating system version:\n");
568 print_version ();
569 xprintf ("Dll info:\n" );
570
571 report (R_STATUS, "Counting tests");
574 report (R_FATAL, "Can't enumerate test files: %d",
575 GetLastError ());
577
578 report (R_STATUS, "Extracting tests");
580 nr_of_files = 0;
581 nr_of_tests = 0;
583 extract_test_proc, (LPARAM)tempdir))
584 report (R_FATAL, "Can't enumerate test files: %d",
585 GetLastError ());
586
587 xprintf ("Test output:\n" );
588
589 report (R_DELTA, 0, "Extracting: Done");
590
591 report (R_STATUS, "Running tests");
593 for (i = 0; i < nr_of_files; i++) {
594 struct wine_test *test = wine_tests + i;
595 int j;
596
597 for (j = 0; j < test->subtest_count; j++) {
598 report (R_STEP, "Running: %s:%s", test->name,
599 test->subtests[j]);
600 run_test (test, test->subtests[j], tempdir);
601 }
602 }
603 report (R_DELTA, 0, "Running: Done");
604
605 report (R_STATUS, "Cleaning up");
606 close (1);
607 remove_dir (tempdir);
608 free (tempdir);
610
611 return logname;
612}
#define EEXIST
Definition: acclib.h:88
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:751
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define O_EXCL
Definition: fcntl.h:40
#define O_APPEND
Definition: fcntl.h:37
#define memchr(s, c, n)
Definition: mkisofs.h:875
static void print_version(void)
Definition: main.c:131
static BOOL CALLBACK extract_test_proc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
Definition: main.c:470
static BOOL CALLBACK EnumTestFileProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam)
Definition: main.c:462
#define WINE_BUILD
Definition: resource.h:54
#define STRINGRES
Definition: resource.h:50
#define TESTS_URL
Definition: resource.h:56
#define BUILD_INFO
Definition: resource.h:55
#define IDS_BUILD_ID
Definition: resource.h:45
#define run_test(test)
Definition: ms_seh.c:71
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define SEM_NOGPFAULTERRORBOX
Definition: rtltypes.h:70
Definition: ecma_167.h:138
Definition: main.c:45
#define EnumResourceNames
Definition: winbase.h:3772
LONG_PTR LPARAM
Definition: windef.h:208
@ R_DELTA
Definition: winetest.h:50
@ R_PROGRESS
Definition: winetest.h:48
@ R_STATUS
Definition: winetest.h:47
@ R_OUT
Definition: winetest.h:53
@ R_DIR
Definition: winetest.h:52

◆ running_on_visible_desktop()

static int running_on_visible_desktop ( void  )
static

Definition at line 107 of file main.c.

108{
109 HWND desktop;
110 HMODULE huser32 = GetModuleHandle("user32.dll");
111 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
112 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
113
114 desktop = GetDesktopWindow();
115 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
116 return IsWindowVisible(desktop);
117
118 if (pGetProcessWindowStation && pGetUserObjectInformationA)
119 {
120 DWORD len;
121 HWINSTA wstation;
122 USEROBJECTFLAGS uoflags;
123
124 wstation = (HWINSTA)pGetProcessWindowStation();
125 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
126 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
127 }
128 return IsWindowVisible(desktop);
129}
int(* FARPROC)()
Definition: compat.h:36
#define assert(x)
Definition: debug.h:53
static HMODULE huser32
Definition: profile.c:34
#define GWLP_WNDPROC
Definition: treelist.c:66
#define GetWindowLongPtrW
Definition: winuser.h:4829
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:628
#define WSF_VISIBLE
Definition: winuser.h:2452
#define UOI_FLAGS
Definition: winuser.h:1083
BOOL WINAPI IsWindowVisible(_In_ HWND)

Referenced by print_version(), and WinMain().

◆ running_under_wine()

static int running_under_wine ( void  )
static

Definition at line 99 of file main.c.

100{
101 HMODULE module = GetModuleHandleA("ntdll.dll");
102
103 if (!module) return 0;
104 return (GetProcAddress(module, "wine_server_call") != NULL);
105}

Referenced by print_version(), and WinMain().

◆ usage()

static void usage ( void  )
static

Definition at line 615 of file main.c.

616{
618"Usage: winetest [OPTION]...\n\n"
619" -c console mode, no GUI\n"
620" -e preserve the environment\n"
621" -h print this message and exit\n"
622" -p shutdown when the tests are done\n"
623" -q quiet mode, no output at all\n"
624" -o FILE put report into FILE, do not submit\n"
625" -s FILE submit FILE, do not run tests\n"
626" -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
627}
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  hInst,
HINSTANCE  hPrevInst,
LPSTR  cmdLine,
int  cmdShow 
)

Definition at line 629 of file main.c.

631{
632 char *logname = NULL;
633 const char *cp, *submit = NULL;
634 int reset_env = 1;
635 int poweroff = 0;
636 int interactive = 1;
637
638 /* initialize the revision information first */
640
641 cmdLine = strtok (cmdLine, whitespace);
642 while (cmdLine) {
643 if (cmdLine[0] != '-' || cmdLine[2]) {
644 report (R_ERROR, "Not a single letter option: %s", cmdLine);
645 usage ();
646 exit (2);
647 }
648 switch (cmdLine[1]) {
649 case 'c':
651 interactive = 0;
652 break;
653 case 'e':
654 reset_env = 0;
655 break;
656 case 'h':
657 case '?':
658 usage ();
659 exit (0);
660 case 'p':
661 poweroff = 1;
662 break;
663 case 'q':
664 report (R_QUIET);
665 interactive = 0;
666 break;
667 case 's':
668 submit = strtok (NULL, whitespace);
669 if (tag)
670 report (R_WARNING, "ignoring tag for submission");
671 send_file (submit);
672 break;
673 case 'o':
674 logname = strtok (NULL, whitespace);
675 break;
676 case 't':
678 if (strlen (tag) > MAXTAGLEN)
679 report (R_FATAL, "tag is too long (maximum %d characters)",
680 MAXTAGLEN);
682 if (cp) {
683 report (R_ERROR, "invalid char in tag: %c", *cp);
684 usage ();
685 exit (2);
686 }
687 break;
688 default:
689 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
690 usage ();
691 exit (2);
692 }
693 cmdLine = strtok (NULL, whitespace);
694 }
695 if (!submit) {
696 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
697 platform_wine[] = "WINETEST_PLATFORM=wine",
698 debug_yes[] = "WINETEST_DEBUG=1",
699 interactive_no[] = "WINETEST_INTERACTIVE=0",
700 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
701 CHAR *platform;
702
703 report (R_STATUS, "Starting up");
704
706 report (R_FATAL, "Tests must be run on a visible desktop");
707
708 platform = running_under_wine () ? platform_wine : platform_windows;
709
710 if (reset_env && (putenv (platform) ||
711 putenv (debug_yes) ||
712 putenv (interactive_no) ||
713 putenv (report_success_no)))
714 report (R_FATAL, "Could not reset environment: %d", errno);
715
716 if (!tag) {
717 if (!interactive)
718 report (R_FATAL, "Please specify a tag (-t option) if "
719 "running noninteractive!");
720 if (guiAskTag () == IDABORT) exit (1);
721 }
722 report (R_TAG);
723
724 if (!logname) {
725 logname = run_tests (NULL);
726 if (report (R_ASK, MB_YESNO, "Do you want to submit the "
727 "test results?") == IDYES)
728 if (!send_file (logname) && remove (logname))
729 report (R_WARNING, "Can't remove logfile: %d.", errno);
730 free (logname);
731 } else run_tests (logname);
732 report (R_STATUS, "Finished");
733 }
734 if (poweroff)
735 {
736 HANDLE hToken;
738
739 /* enable the shutdown privilege for the current process */
741 {
743 npr.PrivilegeCount = 1;
745 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
746 CloseHandle(hToken);
747 }
748 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
749 }
750 exit (0);
751}
int interactive
Definition: main.c:63
#define FALSE
Definition: types.h:117
BOOL WINAPI LookupPrivilegeValueA(LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid)
Definition: misc.c:732
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
_Check_return_ _CRTIMP int __cdecl putenv(_In_z_ const char *_EnvString)
POINT cp
Definition: magnifier.c:59
static BOOL run_tests(void)
Definition: run.c:2756
int guiAskTag(void)
Definition: gui.c:353
static void extract_rev_infos(void)
Definition: main.c:234
int send_file(const char *name)
Definition: send.c:105
const char * findbadtagchar(const char *tag)
Definition: util.c:124
platform
Definition: msipriv.h:364
#define exit(n)
Definition: config.h:202
$ULONG PrivilegeCount
Definition: setypes.h:1023
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:1024
@ R_TEXTMODE
Definition: winetest.h:58
@ R_QUIET
Definition: winetest.h:59
@ R_ASK
Definition: winetest.h:57
@ R_TAG
Definition: winetest.h:51
#define MAXTAGLEN
Definition: winetest.h:62
#define SE_SHUTDOWN_NAME
Definition: winnt_old.h:384
#define EWX_POWEROFF
Definition: winuser.h:637
#define EWX_SHUTDOWN
Definition: winuser.h:639
#define MB_YESNO
Definition: winuser.h:817
#define IDABORT
Definition: winuser.h:832
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
#define IDYES
Definition: winuser.h:835
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
char CHAR
Definition: xmlstorage.h:175

Variable Documentation

◆ nr_of_files

int nr_of_files
static

Definition at line 61 of file main.c.

Referenced by extract_test_proc(), and run_tests().

◆ nr_of_tests

int nr_of_tests
static

Definition at line 61 of file main.c.

Referenced by extract_test_proc(), and run_tests().

◆ rev_infos

struct rev_info* rev_infos = NULL
static

Definition at line 62 of file main.c.

Referenced by extract_rev_infos(), and get_file_rev().

◆ tag

Definition at line 59 of file main.c.

◆ testexe

const char testexe[] = "_test.exe"
static

Definition at line 64 of file main.c.

Referenced by extract_test(), and extract_test_proc().

◆ whitespace

const char whitespace[] = " \t\r\n"
static

Definition at line 63 of file main.c.

Referenced by get_subtests(), and WinMain().

◆ wine_tests

struct wine_test* wine_tests
static

Definition at line 60 of file main.c.

Referenced by extract_test_proc(), and run_tests().