Fixed tests on Windows (including out-of-tree problems)

Modified tcctest.c so that it uses 'double' in place of 'long double'
with MinGW since this is what TCC does, and what Visual C++ does. Added
an option -norunsrc to tcc to allow argv[0] to be set independently of
the compiled source when using tcc -run, which allows tests that rely on
the value of argv[0] to work in out-of-tree builds.

Also added Makefile rules to automatically update out-of-tree build
Makefiles when in-tree Makefiles have changed.
This commit is contained in:
James Lyon
2013-04-17 20:32:07 +01:00
parent 1d673cbfd6
commit e31579b076
7 changed files with 64 additions and 30 deletions

View File

@ -4,7 +4,8 @@
TOP = ..
include $(TOP)/Makefile
VPATH = $(top_srcdir)/tests
SRCDIR = $(top_srcdir)/tests
VPATH = $(SRCDIR)
# what tests to run
TESTS = \
@ -41,13 +42,13 @@ ifeq ($(TARGETOS),Darwin)
endif
# run local version of tcc with local libraries and includes
TCCFLAGS = -B$(TOP)
TCCFLAGS = -B$(TOP) -I$(TOP)
ifdef CONFIG_WIN32
TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP)
TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -I$(TOP) -L$(TOP)
endif
TCC = $(TOP)/tcc $(TCCFLAGS)
RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOP)/tcc.c $(TCCFLAGS)
RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
DISAS = objdump -d
@ -71,7 +72,7 @@ libtest: libtcc_test$(EXESUF) $(LIBTCC1)
./libtcc_test$(EXESUF) lib_path=..
libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
moretests:
@echo ------------ $@ ------------
@ -80,26 +81,26 @@ moretests:
# test.ref - generate using gcc
# copy only tcclib.h so GCC's stddef and stdarg will be used
test.ref: tcctest.c
cp ../include/tcclib.h .
cp $(top_srcdir)/include/tcclib.h .
gcc -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
./tcctest.gcc > $@
# auto test
test1: test.ref
@echo ------------ $@ ------------
$(TCC) -run tcctest.c > test.out1
$(TCC) -run $(SRCDIR)/tcctest.c > test.out1
@if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
# iterated test2 (compile tcc then compile tcctest.c !)
test2: test.ref
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
$(TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out2
@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
test3: test.ref
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out3
@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
# binary output test
@ -197,3 +198,5 @@ clean:
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
Makefile: $(SRCDIR)/Makefile
cp $< $@

View File

@ -1,7 +1,7 @@
/*
* TCC auto test program
*/
#include "../config.h"
#include "config.h"
#if GCC_MAJOR >= 3
@ -16,6 +16,15 @@
#endif
// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC
#if defined(_WIN32) && defined(__GNUC__)
#define LONG_DOUBLE double
#define LONG_DOUBLE_LITERAL(x) x
#else
#define LONG_DOUBLE long double
#define LONG_DOUBLE_LITERAL(x) x ## L
#endif
/* deprecated and no longer supported in gcc 3.3 */
//#define ACCEPT_CR_IN_STRINGS
@ -1547,10 +1556,16 @@ void bitfield_test(void)
/* declare strto* functions as they are C99 */
double strtod(const char *nptr, char **endptr);
float strtof(const char *nptr, char **endptr);
long double strtold(const char *nptr, char **endptr);
#define FTEST(prefix, type, fmt)\
#if defined(_WIN32)
float strtof(const char *nptr, char **endptr) {return (float)strtod(nptr, endptr);}
LONG_DOUBLE strtold(const char *nptr, char **endptr) {return (LONG_DOUBLE)strtod(nptr, endptr);}
#else
float strtof(const char *nptr, char **endptr);
LONG_DOUBLE strtold(const char *nptr, char **endptr);
#endif
#define FTEST(prefix, typename, type, fmt)\
void prefix ## cmp(type a, type b)\
{\
printf("%d %d %d %d %d %d\n",\
@ -1578,7 +1593,7 @@ void prefix ## fcast(type a)\
{\
float fa;\
double da;\
long double la;\
LONG_DOUBLE la;\
int ia;\
unsigned int ua;\
type b;\
@ -1599,7 +1614,7 @@ void prefix ## fcast(type a)\
\
float prefix ## retf(type a) { return a; }\
double prefix ## retd(type a) { return a; }\
long double prefix ## retld(type a) { return a; }\
LONG_DOUBLE prefix ## retld(type a) { return a; }\
\
void prefix ## call(void)\
{\
@ -1611,7 +1626,7 @@ void prefix ## call(void)\
\
void prefix ## test(void)\
{\
printf("testing '%s'\n", #type);\
printf("testing '%s'\n", #typename);\
prefix ## cmp(1, 2.5);\
prefix ## cmp(2, 1.5);\
prefix ## cmp(1, 1);\
@ -1620,9 +1635,9 @@ void prefix ## test(void)\
prefix ## call();\
}
FTEST(f, float, "%f")
FTEST(d, double, "%f")
FTEST(ld, long double, "%Lf")
FTEST(f, float, float, "%f")
FTEST(d, double, double, "%f")
FTEST(ld, long double, LONG_DOUBLE, "%Lf")
double ftab1[3] = { 1.2, 3.4, -5.6 };
@ -1637,7 +1652,7 @@ void float_test(void)
printf("float_test:\n");
printf("sizeof(float) = %d\n", sizeof(float));
printf("sizeof(double) = %d\n", sizeof(double));
printf("sizeof(long double) = %d\n", sizeof(long double));
printf("sizeof(long double) = %d\n", sizeof(LONG_DOUBLE));
ftest();
dtest();
ldtest();
@ -1761,7 +1776,7 @@ void llfloat(void)
{
float fa;
double da;
long double lda;
LONG_DOUBLE lda;
long long la, lb, lc;
unsigned long long ula, ulb, ulc;
la = 0x12345678;
@ -1870,7 +1885,7 @@ void longlong_test(void)
void manyarg_test(void)
{
long double ld = 1234567891234LL;
LONG_DOUBLE ld = 1234567891234LL;
printf("manyarg_test:\n");
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1, 2, 3, 4, 5, 6, 7, 8,
@ -1913,7 +1928,7 @@ void vprintf1(const char *fmt, ...)
int c, i;
double d;
long long ll;
long double ld;
LONG_DOUBLE ld;
va_start(aq, fmt);
va_copy(ap, aq);
@ -1942,7 +1957,7 @@ void vprintf1(const char *fmt, ...)
printf("%Ld", ll);
break;
case 'F':
ld = va_arg(ap, long double);
ld = va_arg(ap, LONG_DOUBLE);
printf("%Lf", ld);
break;
}
@ -1977,13 +1992,13 @@ void stdarg_for_struct(struct myspace bob, ...)
void stdarg_test(void)
{
long double ld = 1234567891234LL;
LONG_DOUBLE ld = 1234567891234LL;
struct myspace bob;
vprintf1("%d %d %d\n", 1, 2, 3);
vprintf1("%f %d %f\n", 1.0, 2, 3.0);
vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
vprintf1("%F %F %F\n", LONG_DOUBLE_LITERAL(1.2), LONG_DOUBLE_LITERAL(2.3), LONG_DOUBLE_LITERAL(3.4));
#ifdef __x86_64__
/* a bug of x86's TCC */
vprintf1("%d %f %l %F %d %f %l %F\n",

View File

@ -13,7 +13,7 @@ ifeq ($(TARGETOS),Darwin)
export MACOSX_DEPLOYMENT_TARGET:=10.2
endif
TCC_RUN = $(TOP)/tcc $(TCCFLAGS) -run
TCC = $(TOP)/tcc $(TCCFLAGS)
TESTS = \
00_assignment.test \
@ -84,8 +84,8 @@ endif
%.test: %.c %.expect
@echo Test: $*...
@if [ "x`echo $* | grep args`" != "x" ]; \
then $(TCC_RUN) $< - arg1 arg2 arg3 arg4 >$*.output; \
else $(TCC_RUN) $< >$*.output; \
then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output; \
else $(TCC) -run $< >$*.output; \
fi
@if diff -bu $(<:.c=.expect) $*.output ; \
then rm -f $*.output; \
@ -96,3 +96,6 @@ all test: $(TESTS)
clean:
rm -vf fred.txt *.output
Makefile: $(top_srcdir)/tests/tests2/Makefile
cp $< $@