winetests: new addition
Ferenc Wagner
wferi at afavant.elte.hu
Wed Oct 29 22:45:40 CST 2003
Hi there,
below is my present vision of main.c. It does not work:
seems like the spawnvp call does nothing. Can you give me a
clue?
Feri.
/*
* Wine Conformance Test EXE
*
* Copyright 2003 Jakob Eriksson (for Solid Form Sweden AB)
* Copyright 2003 Dimitrie O. Paun
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
*
* This program is dedicated to Anna Lindh,
* Swedish Minister of Foreign Affairs.
* Anna was murdered September 11, 2003.
*
*/
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <wtypes.h>
#include <shellapi.h>
#include "winetests.h"
void fatal(const char* msg) /* Funny when out of memory... */
{
MessageBox( NULL, msg, "Fatal Error", MB_ICONERROR | MB_OK );
exit(1);
}
void *xmalloc (size_t len)
{
void *p;
p = malloc (len);
if (!p) fatal ("Out of memory.");
return p;
}
void xprintf (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
if (vprintf (fmt, ap) < 0) fatal ("Can't write logs.");
va_end (ap);
}
char *strmake(const char *fmt, ...)
{
int n;
size_t size = 100;
char *p = xmalloc (size);
va_list ap;
va_start(ap, fmt);
while (1)
{
n = vsnprintf (p, size, fmt, ap);
if (n > -1 && n < size) break;
size = (n < 0) ? size*2 : n + 1;
if(!(p = realloc (p, size))) fatal("Out of memory.");
}
va_end(ap);
return p;
}
void print_version ()
{
OSVERSIONINFOEX ver;
BOOL ext;
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
{
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx ((OSVERSIONINFO *) &ver))
fatal("Can't get OS version.");
}
xprintf (" dwMajorVersion=%ld\n dwMinorVersion=%ld\n"
" dwBuildNumber=%ld\n PlatformId=%ld\n szCSDVersion=%s\n",
ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
ver.dwPlatformId, ver.szCSDVersion);
if (ext)
xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
" wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
ver.wProductType, ver.wReserved);
}
void deletePath( const char *path )
{
SHFILEOPSTRUCT fileop;
size_t len = strlen (path);
char *paths = xmalloc (len+1);
memcpy (paths, path, len);
paths[len] = 0;
fileop.hwnd = NULL;
fileop.wFunc = FO_DELETE;
fileop.pFrom = paths;
fileop.pTo = NULL;
fileop.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
if (SHFileOperation( &fileop )) /* FIXME not present in NT3 */
fatal (strmake ("Can't delete temporary directory: %s.", path));
}
int count_tests()
{
struct wine_test* test;
int total = 0;
for (test = wine_tests; test->name; test++)
total += test->subtest_count;
return total;
}
LPVOID extract_rcdata (const char *name, DWORD* size)
{
HRSRC rsrc;
HGLOBAL hdl;
if (!(rsrc = FindResource( 0, name, RT_RCDATA ))) return 0;
if (!(*size = SizeofResource( 0, rsrc ))) return 0;
if (!(hdl = LoadResource( 0, rsrc ))) return 0;
return LockResource(hdl);
}
void extract_test (const char *dir, struct wine_test* test)
{
BYTE* code;
DWORD size;
FILE* fout;
if (!(code = extract_rcdata(test->name, &size)))
fatal (strmake ("Can't get resource %s.", test->name));
test->is_elf = (code[1] == 'E' && code[2] == 'L' && code[3] == 'F');
test->exename = strmake("%s/%s.exe%s", dir, test->name,
test->is_elf ? ".so" : "");
if (!(fout = fopen(test->exename, "wb")) ||
(fwrite (code, size, 1, fout) != 1) ||
fclose (fout)) fatal (strmake("Failed to write file %s.", test->name));
}
void run_test (struct wine_test* test, const char* subtest)
{
int status;
const char *argv[]={test->exename, subtest, NULL};
xprintf ("%s:%s start\n", test->name, subtest);
status = spawnvp (_P_WAIT, test->exename, argv);
if (status)
xprintf ("Exit status: %d, errno=%d: %m\n", status, errno);
xprintf ("%s:%s done\n", test->name, subtest);
}
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdline, int cmdshow )
{
struct wine_test* test;
int nr_of_tests, subtest;
char *tempdir, *logfile;
FILE *fp;
SetErrorMode( SEM_FAILCRITICALERRORS );
if (!(tempdir = tempnam(0, "wct"))) fatal("Can't name temporary dir (check TMP).");
fprintf (stderr, "tempdir=%s\n", tempdir);
if (mkdir( tempdir, 0777 )) fatal(strmake("Could not create directory: %s", tempdir));
if (chdir( tempdir )) fatal(strmake("Could not make %s current directory.", tempdir));
if (!(logfile = tempnam(0, "res"))) fatal("Can't name log file.");
fprintf (stderr, "logfile=%s\n", logfile);
if (!(fp = fopen( logfile, "a" ))) fatal("Could not open log file.");
if (-1 == dup2 (fileno (fp), 1)) fatal ("Can't redirect stdout.");
xprintf ("Tests from build %s\n", "FIXME" );
xprintf ("Operating system version:\n");
print_version ();
xprintf ("Test output:\n" );
for (test = wine_tests; test->name; test++)
extract_test (tempdir, test);
nr_of_tests = count_tests();
for (test = wine_tests; test->name; test++)
for (subtest = 0; subtest < test->subtest_count; subtest++)
run_test (test, test->subtests[subtest]);
fflush (stdout);
fclose (fp);
deletePath( tempdir );
return 0;
}
More information about the wine-devel
mailing list