On November 21, 2003 12:16 pm, Ferenc Wagner wrote:
I would be grateful for a review.
OK,
One more time, this round with a patch incorporating most of my suggestions. What it does: -- better integration in the build system -- supports out of tree builds -- cleans up file when winetests fails -- more uniform naming convention in the Makefile -- tested on Linux, it builds just fine -- cross compilation not tested at this point -- fix indentation and a few cosmetic things in main.c -- indent util.c to 4-space indent -- send.c not indented, I'll let you deal with it :) -- supplies an automatic build label for unattended builds -- remove the WINELIB flag (was always present anyway) -- tries to deal with the mkdir() problem -- renames removeDir to remove_dir for consistency -- rename IsDotDir to is_dot_dir for the same reason -- turn is_dot_dir into an inline function for neatness -- merge all headers into winetests.h
And here is the patch (relative to what you've send):
Index: configure.ac =================================================================== RCS file: /var/cvs/wine/configure.ac,v retrieving revision 1.210 diff -u -r1.210 configure.ac --- configure.ac 22 Nov 2003 00:08:26 -0000 1.210 +++ configure.ac 22 Nov 2003 02:33:16 -0000 @@ -1638,6 +1638,7 @@ programs/winemenubuilder/Makefile programs/winemine/Makefile programs/winepath/Makefile +programs/winetests/Makefile programs/winevdm/Makefile programs/winhelp/Makefile programs/winver/Makefile Index: Make.rules.in =================================================================== RCS file: /var/cvs/wine/Make.rules.in,v retrieving revision 1.163 diff -u -r1.163 Make.rules.in --- Make.rules.in 11 Oct 2003 01:05:18 -0000 1.163 +++ Make.rules.in 21 Nov 2003 19:44:04 -0000 @@ -53,6 +53,8 @@ MV = mv LINT = @LINT@ LINTFLAGS = @LINTFLAGS@ +CROSSCC = @CROSSCC@ +CROSSWINDRES = @CROSSWINDRES@ INCLUDES = -I$(SRCDIR) -I. -I$(TOPSRCDIR)/include -I$(TOPOBJDIR)/include $(EXTRAINCL) EXTRACFLAGS = @EXTRACFLAGS@ ALLCFLAGS = $(INCLUDES) $(DEFS) $(DLLFLAGS) $(EXTRACFLAGS) $(CPPFLAGS) $(CFLAGS) @@ -105,18 +107,22 @@ CLEAN_FILES = *.o *.a *.so *.ln *.$(LIBEXT) \#*\# *~ *% .\#* *.bak *.orig *.rej \ *.flc *.spec.c *.spec.def *.dbg.c y.tab.c y.tab.h @LEX_OUTPUT_ROOT@.c core
-OBJS = $(C_SRCS:.c=.o) $(EXTRA_OBJS) +OBJS = $(C_SRCS:.c=.o) $(EXTRA_OBJS) +CROSSOBJS = $(C_SRCS:.c=.cross.o) $(EXTRA_OBJS:.o=.cross.o) $(RC_SRCS:.rc=.res.cross.o)
RCOBJS = $(RC_SRCS:.rc=.res.o) LINTS = $(C_SRCS:.c=.ln)
# Implicit rules
-.SUFFIXES: .mc .rc .mc.rc .res .res.o .spec .spec.c .spec.def .ok +.SUFFIXES: .mc .rc .mc.rc .res .res.o .spec .spec.c .spec.def .ok .cross.o .res.cross.o
.c.o: $(CC) -c $(ALLCFLAGS) -o $@ $<
+.c.cross.o: + $(CROSSCC) -c $(ALLCFLAGS) -o $@ $< + .s.o: $(AS) -o $@ $<
@@ -128,6 +134,9 @@
.res.res.o: $(WINDRES) -i $< -o $@ + +.res.res.cross.o: + $(CROSSWINDRES) -i $< -o $@
.spec.spec.c: $(WINEBUILD) $(DEFS) -o $@ --main-module $(MODULE) --spec $< Index: dlls/Maketest.rules.in =================================================================== RCS file: /var/cvs/wine/dlls/Maketest.rules.in,v retrieving revision 1.28 diff -u -r1.28 Maketest.rules.in --- dlls/Maketest.rules.in 11 Oct 2003 01:05:18 -0000 1.28 +++ dlls/Maketest.rules.in 21 Nov 2003 19:50:35 -0000 @@ -25,9 +25,6 @@ IMPORTLIBS = $(IMPORTS:%=$(DLLDIR)/lib%.$(IMPLIBEXT))
CROSSTEST = $(TESTDLL:%.dll=%)_crosstest.exe -CROSSOBJS = $(C_SRCS:.c=.cross.o) $(RC_SRCS:.rc=.res.cross.o) $(TESTLIST:.c=.cross.o) -CROSSCC = @CROSSCC@ -CROSSWINDRES = @CROSSWINDRES@
@MAKE_RULES@
@@ -62,14 +59,6 @@ $(TESTRESULTS): $(MODULE)$(DLLEXT) $(DLLDIR)/$(TESTDLL)$(DLLEXT)
# Rules for cross-compiling tests - -.SUFFIXES: .cross.o .res.cross.o - -.c.cross.o: - $(CROSSCC) -c $(ALLCFLAGS) -o $@ $< - -.res.res.cross.o: - $(CROSSWINDRES) -i $< -o $@
crosstest:: @CROSSTEST@
diff -uN programs/winetests.feri/main.c programs/winetests/main.c --- programs/winetests.feri/main.c 2003-11-20 11:46:23.000000000 -0500 +++ programs/winetests/main.c 2003-11-21 19:10:02.000000000 -0500 @@ -23,22 +23,22 @@ * */
-#ifdef WINELIB -# include "config.h" -# include "wine/port.h" -# define mkdir(d) mkdir (d, 0777) -# include <errno.h> -#else -# include <stdlib.h> -# include <unistd.h> -#endif +#include "config.h" +#include "wine/port.h"
#include <stdio.h> +#include <stdlib.h> #include <wtypes.h> +#include <errno.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif
#include "winetests.h" -#include "send.h" -#include "util.h" + +#ifndef _WIN32 +# define mkdir(d) mkdir (d, 0777) +#endif
void print_version () { @@ -58,43 +58,46 @@ 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); -} - -#define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0)))) - -void removeDir (const char *dir) -{ - HANDLE hFind; - WIN32_FIND_DATAA wfd; - char path[MAX_PATH]; - size_t dirlen = strlen (dir); - - /* Make sure the directory exists before going further */ - memcpy (path, dir, dirlen); - strcpy (path + dirlen++, "\*"); - hFind = FindFirstFileA (path, &wfd); - if (hFind == INVALID_HANDLE_VALUE) - return; - - do { - char *lp = wfd.cFileName; - - if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */ - if (IsDotDir (lp)) continue; - strcpy (path + dirlen, lp); - if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) - removeDir(path); - else if (!DeleteFileA (path)) - fatal (strmake (NULL, "Can't delete file %s: error %d", path, GetLastError ())); - } while (FindNextFileA (hFind, &wfd)); - FindClose (hFind); - if (!RemoveDirectoryA (dir)) - fatal (strmake (NULL, "Can't remove directory %s: error %d", dir, GetLastError ())); + if (!ext) return; + + 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); +} + +static inline int is_dot_dir(const char* x) +{ + return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0)))); +} + +void remove_dir (const char *dir) +{ + HANDLE hFind; + WIN32_FIND_DATA wfd; + char path[MAX_PATH]; + size_t dirlen = strlen (dir); + + /* Make sure the directory exists before going further */ + memcpy (path, dir, dirlen); + strcpy (path + dirlen++, "\*"); + hFind = FindFirstFile (path, &wfd); + if (hFind == INVALID_HANDLE_VALUE) return; + + do { + char *lp = wfd.cFileName; + + if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */ + if (is_dot_dir (lp)) continue; + strcpy (path + dirlen, lp); + if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) + remove_dir(path); + else if (!DeleteFile (path)) + fatal (strmake (NULL, "Can't delete file %s: error %d", path, GetLastError ())); + } while (FindNextFile (hFind, &wfd)); + FindClose (hFind); + if (!RemoveDirectory (dir)) + fatal (strmake (NULL, "Can't remove directory %s: error %d", dir, GetLastError ())); }
int count_tests() @@ -108,7 +111,7 @@ return total; }
-LPVOID extract_rcdata (const char *name, DWORD* size) +void* extract_rcdata (const char *name, DWORD* size) { HRSRC rsrc; HGLOBAL hdl; @@ -147,9 +150,9 @@
xprintf ("%s:%s start\n", test->name, subtest); if (test->is_elf) - status = spawnvp (_P_WAIT, "/usr/local/src/wine/wine", argv); + status = spawnvp (_P_WAIT, "/usr/local/src/wine/wine", argv); else - status = spawnvp (_P_WAIT, test->exename, argv+1); + status = spawnvp (_P_WAIT, test->exename, argv+1); if (status) xprintf ("Exit status: %d, errno=%d: %s\n", status, errno, strerror (errno)); xprintf ("%s:%s done\n", test->name, subtest); @@ -196,13 +199,13 @@ fclose (fp); close (1); /* Avoid sharing violation on Win */
- removeDir (tempdir); + remove_dir (tempdir);
if (send_file (logfile)) - fatal ("Can't submit logfile (network of file error)."); + fatal ("Can't submit logfile (network of file error).");
if (remove (logfile)) - fatal (strmake (NULL, "Can't remove logfile: %d.", errno)); + fatal (strmake (NULL, "Can't remove logfile: %d.", errno));
return 0; } diff -uN programs/winetests.feri/Makefile.in programs/winetests/Makefile.in --- programs/winetests.feri/Makefile.in 2003-11-19 22:01:05.000000000 -0500 +++ programs/winetests/Makefile.in 2003-11-22 03:21:49.000000000 -0500 @@ -5,48 +5,36 @@ MODULE = winetests.exe APPMODE = gui IMPORTS = user32 ws2_32 -EXTRADEFS = -DWINELIB
C_SRCS = main.c send.c util.c EXTRA_OBJS = winetests.o -RC_SRCS = winetests.rc - -CROSS_GCC = i586-mingw32msvc-gcc -CROSS_RC = i586-mingw32msvc-windres -CROSS_CFLAGS = -Wall -W -O2 -CROSS_OBJS = $(C_SRCS:.c=_cross.o) winetests_cross.o +RC_SRCS = winetests_so.rc
@MAKE_PROG_RULES@
# Special rules
-winetests.rc: maketests tests.list - $(SRCDIR)/maketests -r_so > $@ +winetests_so.rc: maketests tests.list + $(SRCDIR)/maketests -r_so $(SRCDIR)/tests.list > $@ || ( $(RM) $@ && exit 1 ) + +winetests_pe.rc: maketests tests.list + $(SRCDIR)/maketests -r_so $(SRCDIR)/tests.list > $@ || ( $(RM) $@ && exit 1 )
winetests.subtests: maketests tests.list - $(SRCDIR)/maketests -s > $@ + $(SRCDIR)/maketests -s $(SRCDIR)/tests.list > $@ || ( $(RM) $@ && exit 1 )
winetests.tests: maketests tests.list - $(SRCDIR)/maketests -t $(BUILD) > $@ + $(SRCDIR)/maketests -t $(SRCDIR)/tests.list > $@ || ( $(RM) $@ && exit 1 )
winetests.c: winetests.tests winetests.subtests (echo '#include "winetests.h"'; cat winetests.{sub,}tests) > $@
-res_cross.rc: maketests tests.list - $(SRCDIR)/maketests -r_pe > $@ - -$(CROSS_OBJS): %_cross.o: %.c - $(CROSS_GCC) $(CROSS_CFLAGS) -o $@ -c $< - -res_cross.o: res_cross.rc - $(CROSS_RC) -o $@ $< - -winetests_cross.exe: $(CROSS_OBJS) res_cross.o - $(CROSS_GCC) $^ -lws2_32 -o $@ +winetests_cross.exe: $(CROSSOBJS:_so.res.cross.o=_pe.res.cross.o) + $(CROSSCC) $^ -o $@ $(IMPORTS:%=-l%) $(LIBS)
clean:: rm -f winetests.c winetests.rc winetests.subtests \ - winetests.tests winetests_cross.exe $(CROSS_OBJS) \ - res_cross.rc res_cross.o + winetests.tests winetests_cross.exe $(CROSSOBJS) \ + winetests_pe.rc winetests_pe.res.cross.o
### Dependencies: diff -uN programs/winetests.feri/maketests programs/winetests/maketests --- programs/winetests.feri/maketests 2003-11-21 08:15:09.000000000 -0500 +++ programs/winetests/maketests 2003-11-22 03:20:52.000000000 -0500 @@ -3,16 +3,16 @@ MODE="$1"
BINDIR="../.." -TEST_EXES=`sed 's/#.*//' tests.list` +TEST_EXES=`sed 's/#.*//' "$2"`
echo "/* Automatically generated -- do not edit! */" case $MODE in -t) - if [ -z "$2" ]; then - echo Please supply a build tag. >/dev/stderr - exit 1 + if [ -z "$WINE_BUILD" ]; then + WINE_BUILD="`date`" + echo "warning: using automatically generated BUILD tag: $WINE_BUILD" >/dev/stderr fi - echo "const char build_tag[] = "$2";" + echo "const char build_tag[] = "$WINE_BUILD";" echo "struct wine_test wine_tests[] = {" ;; esac diff -uN programs/winetests.feri/send.c programs/winetests/send.c --- programs/winetests.feri/send.c 2003-11-19 21:12:21.000000000 -0500 +++ programs/winetests/send.c 2003-11-21 19:11:01.000000000 -0500 @@ -1,8 +1,7 @@ #include <winsock.h> #include <stdio.h>
-#include "util.h" -#include "send.h" +#include "winetests.h"
SOCKET open_http (const char *ipnum) diff -uN programs/winetests.feri/send.h programs/winetests/send.h --- programs/winetests.feri/send.h 2003-11-15 09:31:51.000000000 -0500 +++ programs/winetests/send.h 1969-12-31 19:00:00.000000000 -0500 @@ -1,6 +0,0 @@ -#ifndef __SEND_H -#define __SEND_H - -int send_file (const char *name); - -#endif /* __SEND_H */ diff -uN programs/winetests.feri/util.c programs/winetests/util.c --- programs/winetests.feri/util.c 2003-11-17 14:36:33.000000000 -0500 +++ programs/winetests/util.c 2003-11-22 03:33:15.000000000 -0500 @@ -1,70 +1,70 @@ #include <windows.h>
-#include "util.h" +#include "winetests.h"
void fatal (const char* msg) { - MessageBox (NULL, msg, "Fatal Error", MB_ICONERROR | MB_OK); - exit (1); + MessageBox (NULL, msg, "Fatal Error", MB_ICONERROR | MB_OK); + exit (1); }
void *xmalloc (size_t len) { - void *p = malloc (len); + void *p = malloc (len);
- if (!p) fatal ("Out of memory."); - return p; + if (!p) fatal ("Out of memory."); + return p; }
void *xrealloc (void *op, size_t len) { - void *p = realloc (op, len); + void *p = realloc (op, len);
- if (!p) fatal ("Out of memory."); - return p; + if (!p) fatal ("Out of memory."); + return p; }
void xprintf (const char *fmt, ...) { - va_list ap; + va_list ap;
- va_start (ap, fmt); - if (vprintf (fmt, ap) < 0) fatal ("Can't write logs."); - va_end (ap); + va_start (ap, fmt); + if (vprintf (fmt, ap) < 0) fatal ("Can't write logs."); + va_end (ap); }
char *vstrmake (size_t *lenp, const char *fmt, va_list ap) { - size_t size = 1000; - char *p, *q; - int n; - - p = malloc (size); - if (!p) return NULL; - while (1) { - n = vsnprintf (p, size, fmt, ap); - if (n < 0) size *= 2; /* Windows */ - else if ((unsigned)n >= size) size = n+1; /* glibc */ - else break; - q = realloc (p, size); - if (!q) { - free (p); - return NULL; + size_t size = 1000; + char *p, *q; + int n; + + p = malloc (size); + if (!p) return NULL; + while (1) { + n = vsnprintf (p, size, fmt, ap); + if (n < 0) size *= 2; /* Windows */ + else if ((unsigned)n >= size) size = n+1; /* glibc */ + else break; + q = realloc (p, size); + if (!q) { + free (p); + return NULL; + } + p = q; } - p = q; - } - if (lenp) *lenp = n; - return p; + if (lenp) *lenp = n; + return p; }
char *strmake (size_t *lenp, const char *fmt, ...) { - va_list ap; - char *p; + va_list ap; + char *p;
- va_start (ap, fmt); - p = vstrmake (lenp, fmt, ap); - if (!p) fatal ("Out of memory."); - va_end (ap); - return p; + va_start (ap, fmt); + p = vstrmake (lenp, fmt, ap); + if (!p) fatal ("Out of memory."); + va_end (ap); + return p; } diff -uN programs/winetests.feri/util.h programs/winetests/util.h --- programs/winetests.feri/util.h 2003-11-17 14:36:43.000000000 -0500 +++ programs/winetests/util.h 1969-12-31 19:00:00.000000000 -0500 @@ -1,16 +0,0 @@ -#ifndef __UTIL_H -#define __UTIL_H - -#include <stdio.h> -#ifndef WINELIB -# include <stdlib.h> -#endif - -void fatal (const char* msg); -void *xmalloc (size_t len); -void *xrealloc (void *op, size_t len); -void xprintf (const char *fmt, ...); -char *vstrmake (size_t *lenp, const char *fmt, va_list ap); -char *strmake (size_t *lenp, const char *fmt, ...); - -#endif /* __UTIL_H */ diff -uN programs/winetests.feri/winetests.h programs/winetests/winetests.h --- programs/winetests.feri/winetests.h 2003-11-21 08:15:59.000000000 -0500 +++ programs/winetests/winetests.h 2003-11-22 03:05:10.000000000 -0500 @@ -1,6 +1,10 @@ #ifndef __WINETESTS_H #define __WINETESTS_H
+#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + struct wine_test { const char *name; @@ -17,4 +21,13 @@
extern const char build_tag[];
+void fatal (const char* msg); +void *xmalloc (size_t len); +void *xrealloc (void *op, size_t len); +void xprintf (const char *fmt, ...); +char *vstrmake (size_t *lenp, const char *fmt, va_list ap); +char *strmake (size_t *lenp, const char *fmt, ...); + +int send_file (const char *name); + #endif /* __WINETESTS_H */