Add several test cases.

This commit is contained in:
Shinichiro Hamaji 2008-12-02 03:22:57 +09:00 committed by grischka
parent 0a9873aa22
commit aa8d22e38e

141
tcctest.c
View File

@ -70,6 +70,7 @@ void bitfield_test(void);
void c99_bool_test(void); void c99_bool_test(void);
void float_test(void); void float_test(void);
void longlong_test(void); void longlong_test(void);
void manyarg_test(void);
void stdarg_test(void); void stdarg_test(void);
void whitespace_test(void); void whitespace_test(void);
void relocation_test(void); void relocation_test(void);
@ -527,6 +528,7 @@ int main(int argc, char **argv)
c99_bool_test(); c99_bool_test();
float_test(); float_test();
longlong_test(); longlong_test();
manyarg_test();
stdarg_test(); stdarg_test();
whitespace_test(); whitespace_test();
relocation_test(); relocation_test();
@ -699,6 +701,7 @@ int tab4[10];
void expr_ptr_test() void expr_ptr_test()
{ {
int *p, *q; int *p, *q;
int i = -1;
printf("expr_ptr:\n"); printf("expr_ptr:\n");
p = tab4; p = tab4;
@ -714,6 +717,37 @@ void expr_ptr_test()
printf("dec=%d\n", p - tab4); printf("dec=%d\n", p - tab4);
printf("add=%d\n", p + 3 - tab4); printf("add=%d\n", p + 3 - tab4);
printf("add=%d\n", 3 + p - tab4); printf("add=%d\n", 3 + p - tab4);
/* check if 64bit support is ok */
q = p = 0;
q += i;
printf("%p %p %ld\n", q, p, p-q);
printf("%d %d %d %d %d %d\n",
p == q, p != q, p < q, p <= q, p >= q, p > q);
i = 0xf0000000;
p += i;
printf("%p %p %ld\n", q, p, p-q);
printf("%d %d %d %d %d %d\n",
p == q, p != q, p < q, p <= q, p >= q, p > q);
p = (int *)((char *)p + 0xf0000000);
printf("%p %p %ld\n", q, p, p-q);
printf("%d %d %d %d %d %d\n",
p == q, p != q, p < q, p <= q, p >= q, p > q);
p += 0xf0000000;
printf("%p %p %ld\n", q, p, p-q);
printf("%d %d %d %d %d %d\n",
p == q, p != q, p < q, p <= q, p >= q, p > q);
{
struct size12 {
int i, j, k;
};
struct size12 s[2], *sp = s;
int i, j;
sp->i = 42;
sp++;
j = -1;
printf("%d\n", sp[j].i);
}
} }
void expr_cmp_test() void expr_cmp_test()
@ -1347,6 +1381,13 @@ void bitfield_test(void)
printf("st1.f2 != -1\n"); printf("st1.f2 != -1\n");
} }
#ifdef __x86_64__
#define FLOAT_FMT "%f\n"
#else
/* x86's float isn't compatible with GCC */
#define FLOAT_FMT "%.5f\n"
#endif
#define FTEST(prefix, type, fmt)\ #define FTEST(prefix, type, fmt)\
void prefix ## cmp(type a, type b)\ void prefix ## cmp(type a, type b)\
{\ {\
@ -1392,6 +1433,17 @@ void prefix ## fcast(type a)\
printf("utof: " fmt "\n", b);\ printf("utof: " fmt "\n", b);\
}\ }\
\ \
float prefix ## retf(type a) { return a; }\
double prefix ## retd(type a) { return a; }\
long double prefix ## retld(type a) { return a; }\
\
void prefix ## call(void)\
{\
printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\
printf("double: %f\n", prefix ## retd(42.123456789));\
printf("long double: %Lf\n", prefix ## retld(42.123456789));\
}\
\
void prefix ## test(void)\ void prefix ## test(void)\
{\ {\
printf("testing '%s'\n", #type);\ printf("testing '%s'\n", #type);\
@ -1400,6 +1452,7 @@ void prefix ## test(void)\
prefix ## cmp(1, 1);\ prefix ## cmp(1, 1);\
prefix ## fcast(234.6);\ prefix ## fcast(234.6);\
prefix ## fcast(-2334.6);\ prefix ## fcast(-2334.6);\
prefix ## call();\
} }
FTEST(f, float, "%f") FTEST(f, float, "%f")
@ -1640,6 +1693,48 @@ void longlong_test(void)
p[0]++; p[0]++;
printf("%lld\n", *p); printf("%lld\n", *p);
} }
a = 68719476720LL;
b = 4294967295LL;
printf("%d %d %d %d\n", a > b, a < b, a >= b, a <= b);
}
void manyarg_test(void)
{
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,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%Ld %Ld %f %f\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1234567891234LL, 987654321986LL,
42.0, 43.0);
printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%Ld %Ld %f %f\n",
ld, 1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1234567891234LL, 987654321986LL,
42.0, 43.0);
/* XXX: known bug of x86-64 */
#ifndef __x86_64__
printf("%d %d %d %d %d %d %d %d %Lf\n",
1, 2, 3, 4, 5, 6, 7, 8, ld);
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%Ld %Ld %f %f %Lf\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1234567891234LL, 987654321986LL,
42.0, 43.0, ld);
printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%Lf %Ld %Ld %f %f %Lf\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
ld, 1234567891234LL, 987654321986LL,
42.0, 43.0, ld);
#endif
} }
void vprintf1(const char *fmt, ...) void vprintf1(const char *fmt, ...)
@ -1649,6 +1744,7 @@ void vprintf1(const char *fmt, ...)
int c, i; int c, i;
double d; double d;
long long ll; long long ll;
long double ld;
va_start(ap, fmt); va_start(ap, fmt);
@ -1675,6 +1771,10 @@ void vprintf1(const char *fmt, ...)
ll = va_arg(ap, long long); ll = va_arg(ap, long long);
printf("%Ld", ll); printf("%Ld", ll);
break; break;
case 'F':
ld = va_arg(ap, long double);
printf("%Lf", ld);
break;
} }
p++; p++;
} else { } else {
@ -1688,9 +1788,48 @@ void vprintf1(const char *fmt, ...)
void stdarg_test(void) void stdarg_test(void)
{ {
long double ld = 1234567891234LL;
vprintf1("%d %d %d\n", 1, 2, 3); vprintf1("%d %d %d\n", 1, 2, 3);
vprintf1("%f %d %f\n", 1.0, 2, 3.0); vprintf1("%f %d %f\n", 1.0, 2, 3.0);
vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0); vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
#ifdef __x86_64__
/* a bug of x86's TCC */
vprintf1("%d %f %l %F %d %f %l %F\n",
1, 1.2, 3L, 4.5L, 6, 7.8, 9L, 0.1L);
#endif
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8);
vprintf1("%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,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%l %l %f %f\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1234567891234LL, 987654321986LL,
42.0, 43.0);
vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%l %l %f %f\n",
ld, 1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1234567891234LL, 987654321986LL,
42.0, 43.0);
vprintf1("%d %d %d %d %d %d %d %d %F\n",
1, 2, 3, 4, 5, 6, 7, 8, ld);
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%l %l %f %f %F\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1234567891234LL, 987654321986LL,
42.0, 43.0, ld);
vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
"%F %l %l %f %f %F\n",
1, 2, 3, 4, 5, 6, 7, 8,
0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
ld, 1234567891234LL, 987654321986LL,
42.0, 43.0, ld);
} }
void whitespace_test(void) void whitespace_test(void)
@ -1768,6 +1907,8 @@ void sizeof_test(void)
printf("sizeof(int) = %d\n", sizeof(int)); printf("sizeof(int) = %d\n", sizeof(int));
printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int)); printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
printf("sizeof(long) = %d\n", sizeof(long));
printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
printf("sizeof(short) = %d\n", sizeof(short)); printf("sizeof(short) = %d\n", sizeof(short));
printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short)); printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
printf("sizeof(char) = %d\n", sizeof(char)); printf("sizeof(char) = %d\n", sizeof(char));