testsuite: Add ABIs to the test matrix; unify tests across ABIs

This eliminates all the *_win32.c tests in favor of the tests they were
branched from, and expands test coverage to run many more tests on
stdcall, thiscall, and fastcall.

This same mechanism also supports testing any other target that has
multiple ABIs.
This commit is contained in:
Josh Triplett
2014-03-16 20:29:27 -07:00
parent 4d4d368e5a
commit e48918ecf8
25 changed files with 90 additions and 423 deletions

View File

@@ -31,6 +31,11 @@
#define __FASTCALL__ __fastcall
#endif
#ifndef ABI_NUM
#define ABI_NUM FFI_DEFAULT_ABI
#define ABI_ATTR
#endif
/* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
file open. */
#ifdef HAVE_MMAP_ANON

View File

@@ -11,19 +11,7 @@
#include <float.h>
#include <math.h>
static float many(float f1,
float f2,
float f3,
float f4,
float f5,
float f6,
float f7,
float f8,
float f9,
float f10,
float f11,
float f12,
float f13)
static float ABI_ATTR many(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13)
{
#if 0
printf("%f %f %f %f %f %f %f %f %f %f %f %f %f\n",
@@ -52,7 +40,7 @@ int main (void)
}
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 13,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 13,
&ffi_type_float, args) == FFI_OK);
ffi_call(&cif, FFI_FN(many), &f, values);

View File

@@ -22,7 +22,7 @@ foo (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
return a + b + c + d + e + f + g;
}
uint8_t
uint8_t ABI_ATTR
bar (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
uint8_t e, uint8_t f, uint8_t g)
{
@@ -42,7 +42,7 @@ main (void)
for (i = 0; i < NARGS; ++i)
ffitypes[i] = &ffi_type_uint8;
CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, NARGS,
CHECK (ffi_prep_cif (&cif, ABI_NUM, NARGS,
&ffi_type_uint8, ffitypes) == FFI_OK);
for (i = 0; i < NARGS; ++i)

View File

@@ -1,63 +0,0 @@
/* Area: ffi_call
Purpose: Check stdcall many call on X86_WIN32 systems.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
#include "ffitest.h"
#include <float.h>
static float __attribute__((fastcall)) fastcall_many(float f1,
float f2,
float f3,
float f4,
float f5,
float f6,
float f7,
float f8,
float f9,
float f10,
float f11,
float f12,
float f13)
{
return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13);
}
int main (void)
{
ffi_cif cif;
ffi_type *args[13];
void *values[13];
float fa[13];
float f, ff;
unsigned long ul;
for (ul = 0; ul < 13; ul++)
{
args[ul] = &ffi_type_float;
values[ul] = &fa[ul];
fa[ul] = (float) ul;
}
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 13,
&ffi_type_float, args) == FFI_OK);
ff = fastcall_many(fa[0], fa[1],
fa[2], fa[3],
fa[4], fa[5],
fa[6], fa[7],
fa[8], fa[9],
fa[10], fa[11], fa[12]);
ffi_call(&cif, FFI_FN(fastcall_many), &f, values);
if (f - ff < FLT_EPSILON)
printf("fastcall many arg tests ok!\n");
else
CHECK(0);
exit(0);
}

View File

@@ -1,63 +0,0 @@
/* Area: ffi_call
Purpose: Check stdcall many call on X86_WIN32 systems.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
#include "ffitest.h"
#include <float.h>
static float __attribute__((stdcall)) stdcall_many(float f1,
float f2,
float f3,
float f4,
float f5,
float f6,
float f7,
float f8,
float f9,
float f10,
float f11,
float f12,
float f13)
{
return f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13;
}
int main (void)
{
ffi_cif cif;
ffi_type *args[13];
void *values[13];
float fa[13];
float f, ff;
unsigned long ul;
for (ul = 0; ul < 13; ul++)
{
args[ul] = &ffi_type_float;
values[ul] = &fa[ul];
fa[ul] = (float) ul;
}
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 13,
&ffi_type_float, args) == FFI_OK);
ff = stdcall_many(fa[0], fa[1],
fa[2], fa[3],
fa[4], fa[5],
fa[6], fa[7],
fa[8], fa[9],
fa[10], fa[11], fa[12]);
ffi_call(&cif, FFI_FN(stdcall_many), &f, values);
if (f - ff < FLT_EPSILON)
printf("stdcall many arg tests ok!\n");
else
CHECK(0);
exit(0);
}

View File

@@ -7,7 +7,7 @@
/* { dg-do run } */
#include "ffitest.h"
static size_t my_strlen(char *s)
static size_t ABI_ATTR my_strlen(char *s)
{
return (strlen(s));
}
@@ -24,7 +24,7 @@ int main (void)
values[0] = (void*) &s;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
&ffi_type_sint, args) == FFI_OK);
s = "a";

View File

@@ -1,14 +1,14 @@
/* Area: ffi_call
Purpose: Check fastcall fct call on X86_WIN32 systems.
Purpose: Check strlen function call with additional arguments.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
/* { dg-do run } */
#include "ffitest.h"
static size_t __FASTCALL__ my_fastcall_f(char *s, float a)
static size_t ABI_ATTR my_f(char *s, float a)
{
return (size_t) ((int) strlen(s) + (int) a);
}
@@ -27,24 +27,23 @@ int main (void)
values[1] = (void*) &v2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 2,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 2,
&ffi_type_sint, args) == FFI_OK);
s = "a";
v2 = 0.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 1);
s = "1234567";
v2 = -1.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 6);
s = "1234567890123456789012345";
v2 = 1.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 26);
printf("fastcall fct1 tests passed\n");
exit(0);
}

View File

@@ -1,44 +0,0 @@
/* Area: ffi_call
Purpose: Check fastcall strlen call on X86_WIN32 systems.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
#include "ffitest.h"
static size_t __FASTCALL__ my_fastcall_strlen(char *s)
{
return (strlen(s));
}
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
char *s;
args[0] = &ffi_type_pointer;
values[0] = (void*) &s;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 1,
&ffi_type_sint, args) == FFI_OK);
s = "a";
ffi_call(&cif, FFI_FN(my_fastcall_strlen), &rint, values);
CHECK(rint == 1);
s = "1234567";
ffi_call(&cif, FFI_FN(my_fastcall_strlen), &rint, values);
CHECK(rint == 7);
s = "1234567890123456789012345";
ffi_call(&cif, FFI_FN(my_fastcall_strlen), &rint, values);
CHECK(rint == 25);
printf("fastcall strlen tests passed\n");
exit(0);
}

View File

@@ -1,14 +1,14 @@
/* Area: ffi_call
Purpose: Check fastcall fct call on X86_WIN32 systems.
Purpose: Check strlen function call with additional arguments.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
/* { dg-do run } */
#include "ffitest.h"
static size_t __FASTCALL__ my_fastcall_f(float a, char *s)
static size_t ABI_ATTR my_f(float a, char *s)
{
return (size_t) ((int) strlen(s) + (int) a);
}
@@ -27,24 +27,23 @@ int main (void)
values[0] = (void*) &v2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 2,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 2,
&ffi_type_sint, args) == FFI_OK);
s = "a";
v2 = 0.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 1);
s = "1234567";
v2 = -1.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 6);
s = "1234567890123456789012345";
v2 = 1.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 26);
printf("fastcall fct2 tests passed\n");
exit(0);
}

View File

@@ -1,14 +1,14 @@
/* Area: ffi_call
Purpose: Check fastcall f call on X86_WIN32 systems.
Purpose: Check strlen function call with additional arguments.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
/* { dg-do run } */
#include "ffitest.h"
static size_t __FASTCALL__ my_fastcall_f(float a, char *s, int i)
static size_t ABI_ATTR my_f(float a, char *s, int i)
{
return (size_t) ((int) strlen(s) + (int) a + i);
}
@@ -30,27 +30,26 @@ int main (void)
values[0] = (void*) &v2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 3,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 3,
&ffi_type_sint, args) == FFI_OK);
s = "a";
v1 = 1;
v2 = 0.0;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 2);
s = "1234567";
v2 = -1.0;
v1 = -2;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 4);
s = "1234567890123456789012345";
v2 = 1.0;
v1 = 2;
ffi_call(&cif, FFI_FN(my_fastcall_f), &rint, values);
ffi_call(&cif, FFI_FN(my_f), &rint, values);
CHECK(rint == 28);
printf("fastcall fct3 tests passed\n");
exit(0);
}

View File

@@ -1,44 +0,0 @@
/* Area: ffi_call
Purpose: Check stdcall strlen call on X86_WIN32 systems.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
#include "ffitest.h"
static size_t __attribute__((stdcall)) my_stdcall_strlen(char *s)
{
return (strlen(s));
}
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_arg rint;
char *s;
args[0] = &ffi_type_pointer;
values[0] = (void*) &s;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 1,
&ffi_type_sint, args) == FFI_OK);
s = "a";
ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values);
CHECK(rint == 1);
s = "1234567";
ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values);
CHECK(rint == 7);
s = "1234567890123456789012345";
ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values);
CHECK(rint == 25);
printf("stdcall strlen tests passed\n");
exit(0);
}

View File

@@ -14,7 +14,7 @@ typedef struct
unsigned int ui;
} test_structure_1;
static test_structure_1 struct1(test_structure_1 ts)
static test_structure_1 ABI_ATTR struct1(test_structure_1 ts)
{
ts.uc++;
ts.d--;
@@ -50,7 +50,7 @@ int main (void)
values[0] = &ts1_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
&ts1_type, args) == FFI_OK);
ts1_arg.uc = '\x01';

View File

@@ -1,67 +0,0 @@
/* Area: ffi_call
Purpose: Check structures with fastcall/thiscall convention.
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
#include "ffitest.h"
typedef struct
{
unsigned char uc;
double d;
unsigned int ui;
} test_structure_1;
static test_structure_1 __FASTCALL__ struct1(test_structure_1 ts)
{
ts.uc++;
ts.d--;
ts.ui++;
return ts;
}
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
ffi_type ts1_type;
ffi_type *ts1_type_elements[4];
test_structure_1 ts1_arg;
/* This is a hack to get a properly aligned result buffer */
test_structure_1 *ts1_result =
(test_structure_1 *) malloc (sizeof(test_structure_1));
ts1_type.size = 0;
ts1_type.alignment = 0;
ts1_type.type = FFI_TYPE_STRUCT;
ts1_type.elements = ts1_type_elements;
ts1_type_elements[0] = &ffi_type_uchar;
ts1_type_elements[1] = &ffi_type_double;
ts1_type_elements[2] = &ffi_type_uint;
ts1_type_elements[3] = NULL;
args[0] = &ts1_type;
values[0] = &ts1_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 1,
&ts1_type, args) == FFI_OK);
ts1_arg.uc = '\x01';
ts1_arg.d = 3.14159;
ts1_arg.ui = 555;
ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
CHECK(ts1_result->ui == 556);
CHECK(ts1_result->d == 3.14159 - 1);
free (ts1_result);
exit(0);
}

View File

@@ -13,7 +13,7 @@ typedef struct
double d2;
} test_structure_2;
static test_structure_2 struct2(test_structure_2 ts)
static test_structure_2 ABI_ATTR struct2(test_structure_2 ts)
{
ts.d1--;
ts.d2--;
@@ -46,7 +46,7 @@ int main (void)
values[0] = &ts2_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts2_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts2_type, args) == FFI_OK);
ts2_arg.d1 = 5.55;
ts2_arg.d2 = 6.66;

View File

@@ -1,67 +0,0 @@
/* Area: ffi_call
Purpose: Check structures in fastcall/stdcall function
Limitations: none.
PR: none.
Originator: From the original ffitest.c */
/* { dg-do run { target i?86-*-* } } */
#include "ffitest.h"
typedef struct
{
double d1;
double d2;
} test_structure_2;
static test_structure_2 __FASTCALL__ struct2(test_structure_2 ts)
{
ts.d1--;
ts.d2--;
return ts;
}
int main (void)
{
ffi_cif cif;
ffi_type *args[MAX_ARGS];
void *values[MAX_ARGS];
test_structure_2 ts2_arg;
ffi_type ts2_type;
ffi_type *ts2_type_elements[3];
/* This is a hack to get a properly aligned result buffer */
test_structure_2 *ts2_result =
(test_structure_2 *) malloc (sizeof(test_structure_2));
ts2_type.size = 0;
ts2_type.alignment = 0;
ts2_type.type = FFI_TYPE_STRUCT;
ts2_type.elements = ts2_type_elements;
ts2_type_elements[0] = &ffi_type_double;
ts2_type_elements[1] = &ffi_type_double;
ts2_type_elements[2] = NULL;
args[0] = &ts2_type;
values[0] = &ts2_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 1, &ts2_type, args) == FFI_OK);
ts2_arg.d1 = 5.55;
ts2_arg.d2 = 6.66;
printf ("%g\n", ts2_arg.d1);
printf ("%g\n", ts2_arg.d2);
ffi_call(&cif, FFI_FN(struct2), ts2_result, values);
printf ("%g\n", ts2_result->d1);
printf ("%g\n", ts2_result->d2);
CHECK(ts2_result->d1 == 5.55 - 1);
CHECK(ts2_result->d2 == 6.66 - 1);
free (ts2_result);
exit(0);
}

View File

@@ -12,7 +12,7 @@ typedef struct
int si;
} test_structure_3;
static test_structure_3 struct3(test_structure_3 ts)
static test_structure_3 ABI_ATTR struct3(test_structure_3 ts)
{
ts.si = -(ts.si*2);
@@ -43,7 +43,7 @@ int main (void)
values[0] = &ts3_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
&ts3_type, args) == FFI_OK);
ts3_arg.si = -123;

View File

@@ -14,7 +14,7 @@ typedef struct
unsigned ui3;
} test_structure_4;
static test_structure_4 struct4(test_structure_4 ts)
static test_structure_4 ABI_ATTR struct4(test_structure_4 ts)
{
ts.ui3 = ts.ui1 * ts.ui2 * ts.ui3;
@@ -48,7 +48,7 @@ int main (void)
values[0] = &ts4_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts4_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts4_type, args) == FFI_OK);
ts4_arg.ui1 = 2;
ts4_arg.ui2 = 3;

View File

@@ -12,7 +12,7 @@ typedef struct
char c2;
} test_structure_5;
static test_structure_5 struct5(test_structure_5 ts1, test_structure_5 ts2)
static test_structure_5 ABI_ATTR struct5(test_structure_5 ts1, test_structure_5 ts2)
{
ts1.c1 += ts2.c1;
ts1.c2 -= ts2.c2;
@@ -48,7 +48,7 @@ int main (void)
values[1] = &ts5_arg2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ts5_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK);
ts5_arg1.c1 = 2;
ts5_arg1.c2 = 6;

View File

@@ -12,7 +12,7 @@ typedef struct
double d;
} test_structure_6;
static test_structure_6 struct6 (test_structure_6 ts)
static test_structure_6 ABI_ATTR struct6 (test_structure_6 ts)
{
ts.f += 1;
ts.d += 1;
@@ -46,7 +46,7 @@ int main (void)
values[0] = &ts6_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts6_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts6_type, args) == FFI_OK);
ts6_arg.f = 5.55f;
ts6_arg.d = 6.66;

View File

@@ -13,7 +13,7 @@ typedef struct
double d;
} test_structure_7;
static test_structure_7 struct7 (test_structure_7 ts)
static test_structure_7 ABI_ATTR struct7 (test_structure_7 ts)
{
ts.f1 += 1;
ts.f2 += 1;
@@ -49,7 +49,7 @@ int main (void)
values[0] = &ts7_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts7_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts7_type, args) == FFI_OK);
ts7_arg.f1 = 5.55f;
ts7_arg.f2 = 55.5f;

View File

@@ -14,7 +14,7 @@ typedef struct
float f4;
} test_structure_8;
static test_structure_8 struct8 (test_structure_8 ts)
static test_structure_8 ABI_ATTR struct8 (test_structure_8 ts)
{
ts.f1 += 1;
ts.f2 += 1;
@@ -52,7 +52,7 @@ int main (void)
values[0] = &ts8_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts8_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts8_type, args) == FFI_OK);
ts8_arg.f1 = 5.55f;
ts8_arg.f2 = 55.5f;

View File

@@ -13,7 +13,7 @@ typedef struct
int i;
} test_structure_9;
static test_structure_9 struct9 (test_structure_9 ts)
static test_structure_9 ABI_ATTR struct9 (test_structure_9 ts)
{
ts.f += 1;
ts.i += 1;
@@ -47,7 +47,7 @@ int main (void)
values[0] = &ts9_arg;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts9_type, args) == FFI_OK);
CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts9_type, args) == FFI_OK);
ts9_arg.f = 5.55f;
ts9_arg.i = 5;

View File

@@ -8,7 +8,7 @@
#include "ffitest.h"
void
void ABI_ATTR
closure_test_fn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
void** args __UNUSED__, void* userdata __UNUSED__)
{