This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libffi test for closures


Does it make sense for others to add these testcases to ffitest.c?
I used them to verify libffi closure functionality on darwin/AIX. The number of args is due to the boundary between GPR's and FPR's I had to test.


Regards,
Andreas
--- ffitest.c.orig	Sun Sep 15 17:33:42 2002
+++ ffitest.c	Sun Sep 15 18:20:45 2002
@@ -259,13 +259,98 @@
 /* Take an int and a float argument, together with int userdata, and 	*/
 /* return the sum.							*/
 #if FFI_CLOSURES
+
 static void
 closure_test_fn(ffi_cif* cif,void* resp,void** args, void* userdata)
 {
-  *(int*)resp = *(int*)args[0] + (int)(*(float*)args[1]) + (int)(long)userdata;
+    *(int*)resp =
+        (int)*(unsigned long long *)args[0] +(int)(*(int *)args[1]) + (int)(*(unsigned long long *)args[2]) +
+        (int)*(int *)args[3] +(int)(*(signed short *)args[4]) + (int)(*(unsigned long long*)args[5]) +
+        (int)*(int *)args[6] +(int)(*(int*)args[7]) + (int)(*(double*)args[8]) +
+        (int)*(int *)args[9] +(int)(*(int*)args[10]) + (int)(*(float*)args[11])
+         + (int)*(int *)args[12] + (int)(*(int*)args[13]) +
+       (int)(*(int*)args[14]) +  *(int *)args[15] + (int)(long)userdata;
+    printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
+
+    (int)*(unsigned long long *)args[0], (int)(*(int *)args[1]), (int)(*(unsigned long long *)args[2]),
+       (int)*(int *)args[3], (int)(*(signed short *)args[4]), (int)(*(unsigned long long *)args[5]),
+       (int)*(int *)args[6], (int)(*(int*)args[7]), (int)(*(double*)args[8]),
+       (int)*(int *)args[9], (int)(*(int*)args[10]), (int)(*(float*)args[11]),
+       (int)*(int *)args[12], (int)(*(int*)args[13]), (int)(*(int*)args[14]),
+       *(int *)args[15], (int)(long)userdata, *(int*)resp);
+}
+
+typedef int (*closure_test_type)(unsigned long long, int, unsigned long long, int, signed short, unsigned long long, int, int, double, int, int, float, int, int, int, int);
+
+static void closure_test_fn1(ffi_cif* cif,void* resp,void** args, void* userdata)
+ {
+    *(int*)resp =
+        (int)*(float *)args[0] +(int)(*(float *)args[1]) + (int)(*(float *)args[2]) +
+        (int)*(float *)args[3] +(int)(*(signed short *)args[4]) + (int)(*(float *)args[5]) +
+        (int)*(float *)args[6] +(int)(*(int*)args[7]) + (int)(*(double*)args[8]) +
+        (int)*(int *)args[9] +(int)(*(int*)args[10]) + (int)(*(float*)args[11])
+         + (int)*(int *)args[12] + (int)(*(int*)args[13]) +
+       (int)(*(int*)args[14]) +  *(int *)args[15] + (int)(long)userdata;
+
+
+    printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
+
+    (int)*(float *)args[0], (int)(*(float *)args[1]), (int)(*(float *)args[2]),
+       (int)*(float *)args[3], (int)(*(signed short *)args[4]), (int)(*(float *)args[5]),
+       (int)*(float *)args[6], (int)(*(int*)args[7]), (int)(*(double*)args[8]),
+       (int)*(int *)args[9], (int)(*(int*)args[10]), (int)(*(float*)args[11]),
+       (int)*(int *)args[12], (int)(*(int*)args[13]), (int)(*(int*)args[14]),
+       *(int *)args[15], (int)(long)userdata, *(int*)resp);
 }
 
-typedef int (*closure_test_type)(int, float);
+typedef int (*closure_test_type1)(float, float, float, float, signed short, float, float, int, double, int, int, float, int, int, int, int);
+
+static void closure_test_fn2(ffi_cif* cif,void* resp,void** args, void* userdata)
+ {
+    *(int*)resp =
+        (int)*(double *)args[0] +(int)(*(double *)args[1]) + (int)(*(double *)args[2]) +
+        (int)*(double *)args[3] +(int)(*(signed short *)args[4]) + (int)(*(double *)args[5]) +
+        (int)*(double *)args[6] +(int)(*(int*)args[7]) + (int)(*(double*)args[8]) +
+        (int)*(int *)args[9] +(int)(*(int*)args[10]) + (int)(*(float*)args[11])
+         + (int)*(int *)args[12] + (int)(*(float*)args[13]) +
+       (int)(*(int*)args[14]) +  *(int *)args[15] + (int)(long)userdata;
+
+
+    printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
+
+    (int)*(double *)args[0], (int)(*(double *)args[1]), (int)(*(double *)args[2]),
+       (int)*(double *)args[3], (int)(*(signed short *)args[4]), (int)(*(double *)args[5]),
+       (int)*(double *)args[6], (int)(*(int*)args[7]), (int)(*(double*)args[8]),
+       (int)*(int *)args[9], (int)(*(int*)args[10]), (int)(*(float*)args[11]),
+       (int)*(int *)args[12], (int)(*(float*)args[13]), (int)(*(int*)args[14]),
+       *(int *)args[15], (int)(long)userdata, *(int*)resp);
+ }
+
+typedef int (*closure_test_type2)(double, double, double, double, signed short, double, double, int, double, int, int, float, int, float, int, int);
+
+static void closure_test_fn3(ffi_cif* cif,void* resp,void** args, void* userdata)
+ {
+    *(int*)resp =
+        (int)*(float *)args[0] +(int)(*(float *)args[1]) + (int)(*(float *)args[2]) +
+        (int)*(float *)args[3] +(int)(*(float *)args[4]) + (int)(*(float *)args[5]) +
+        (int)*(float *)args[6] +(int)(*(float*)args[7]) + (int)(*(double*)args[8]) +
+        (int)*(int *)args[9] +(int)(*(float*)args[10]) + (int)(*(float*)args[11])
+         + (int)*(int *)args[12] + (int)(*(float*)args[13]) +
+       (int)(*(float*)args[14]) +  *(int *)args[15] + (int)(long)userdata;
+
+
+    printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
+
+    (int)*(float *)args[0], (int)(*(float *)args[1]), (int)(*(float *)args[2]),
+       (int)*(float *)args[3], (int)(*(float *)args[4]), (int)(*(float *)args[5]),
+       (int)*(float *)args[6], (int)(*(float*)args[7]), (int)(*(double*)args[8]),
+       (int)*(int *)args[9], (int)(*(float*)args[10]), (int)(*(float*)args[11]),
+       (int)*(int *)args[12], (int)(*(float*)args[13]), (int)(*(float*)args[14]),
+       *(int *)args[15], (int)(long)userdata, *(int*)resp);
+ }
+
+typedef int (*closure_test_type3)(float, float, float, float, float, float, float, float, double, int, float, float, int, float, float, int);
+
 #endif
 
 int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
@@ -288,6 +373,8 @@
 
   ffi_arg rint;
   long long rlonglong;
+  ffi_closure cl;
+  ffi_type * cl_arg_types[17];
 
   ffi_type ts1_type;
   ffi_type ts2_type;
@@ -957,22 +1044,131 @@
 # if FFI_CLOSURES
   /* A simple closure test */
     {
-      ffi_closure cl;
-      ffi_type * cl_arg_types[3];
 
-      cl_arg_types[0] = &ffi_type_sint;
-      cl_arg_types[1] = &ffi_type_float;
-      cl_arg_types[2] = NULL;
-      
+      (void) puts("\nEnter FFI_CLOSURES\n");
+	
+      cl_arg_types[0] = &ffi_type_uint64;
+      cl_arg_types[1] = &ffi_type_uint;
+      cl_arg_types[2] = &ffi_type_uint64;
+      cl_arg_types[3] = &ffi_type_uint;
+      cl_arg_types[4] = &ffi_type_sshort;
+      cl_arg_types[5] = &ffi_type_uint64;
+      cl_arg_types[6] = &ffi_type_uint;
+      cl_arg_types[7] = &ffi_type_uint;
+      cl_arg_types[8] = &ffi_type_double;
+      cl_arg_types[9] = &ffi_type_uint;
+      cl_arg_types[10] = &ffi_type_uint;
+      cl_arg_types[11] = &ffi_type_float;
+      cl_arg_types[12] = &ffi_type_uint;
+      cl_arg_types[13] = &ffi_type_uint;
+      cl_arg_types[14] = &ffi_type_uint;
+      cl_arg_types[15] = &ffi_type_uint;
+      cl_arg_types[16] = NULL;
       /* Initialize the cif */
-      CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 
-	    	         &ffi_type_sint, cl_arg_types) == FFI_OK);
+      CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
+                         &ffi_type_sint, cl_arg_types) == FFI_OK);
 
       CHECK(ffi_prep_closure(&cl, &cif, closure_test_fn,
-			     (void *) 3 /* userdata */)
-	    == FFI_OK);
-      CHECK((*((closure_test_type)(&cl)))(1, 2.0) == 6);
+                             (void *) 3 /* userdata */)
+            == FFI_OK);
+      CHECK((*((closure_test_type)(&cl)))
+      (1LL, 2, 3LL, 4, 127, 429LL, 7, 8, 9.5, 10, 11, 12, 13,
+      19, 21, 1) == 680);
+    }
+    {
+
+      cl_arg_types[0] = &ffi_type_float;
+      cl_arg_types[1] = &ffi_type_float;
+      cl_arg_types[2] = &ffi_type_float;
+      cl_arg_types[3] = &ffi_type_float;
+      cl_arg_types[4] = &ffi_type_sshort;
+      cl_arg_types[5] = &ffi_type_float;
+      cl_arg_types[6] = &ffi_type_float;
+      cl_arg_types[7] = &ffi_type_uint;
+      cl_arg_types[8] = &ffi_type_double;
+      cl_arg_types[9] = &ffi_type_uint;
+      cl_arg_types[10] = &ffi_type_uint;
+      cl_arg_types[11] = &ffi_type_float;
+      cl_arg_types[12] = &ffi_type_uint;
+      cl_arg_types[13] = &ffi_type_uint;
+      cl_arg_types[14] = &ffi_type_uint;
+      cl_arg_types[15] = &ffi_type_uint;
+      cl_arg_types[16] = NULL;
+      /* Initialize the cif */
+      CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
+                         &ffi_type_sint, cl_arg_types) == FFI_OK);
+
+      CHECK(ffi_prep_closure(&cl, &cif, closure_test_fn1,
+                             (void *) 3 /* userdata */)
+            == FFI_OK);
+      CHECK((*((closure_test_type1)(&cl)))
+      (1.1, 2.2, 3.3, 4.4, 127, 5.5, 6.6, 8, 9, 10, 11, 12.0, 13,
+      19, 21, 1) == 255);
+    }
+
+    {
+
+      cl_arg_types[0] = &ffi_type_double;
+      cl_arg_types[1] = &ffi_type_double;
+      cl_arg_types[2] = &ffi_type_double;
+      cl_arg_types[3] = &ffi_type_double;
+      cl_arg_types[4] = &ffi_type_sshort;
+      cl_arg_types[5] = &ffi_type_double;
+      cl_arg_types[6] = &ffi_type_double;
+      cl_arg_types[7] = &ffi_type_uint;
+      cl_arg_types[8] = &ffi_type_double;
+      cl_arg_types[9] = &ffi_type_uint;
+      cl_arg_types[10] = &ffi_type_uint;
+      cl_arg_types[11] = &ffi_type_float;
+      cl_arg_types[12] = &ffi_type_uint;
+      cl_arg_types[13] = &ffi_type_float;
+      cl_arg_types[14] = &ffi_type_uint;
+      cl_arg_types[15] = &ffi_type_uint;
+      cl_arg_types[16] = NULL;
+      /* Initialize the cif */
+      CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
+                         &ffi_type_sint, cl_arg_types) == FFI_OK);
+
+      CHECK(ffi_prep_closure(&cl, &cif, closure_test_fn2,
+                             (void *) 3 /* userdata */)
+            == FFI_OK);
+      CHECK((*((closure_test_type2)(&cl)))
+      (1, 2, 3, 4, 127, 5, 6, 8, 9, 10, 11, 12.0, 13,
+      19.0, 21, 1) == 255);
+
+    }
+
+    {
+
+      cl_arg_types[0] = &ffi_type_float;
+      cl_arg_types[1] = &ffi_type_float;
+      cl_arg_types[2] = &ffi_type_float;
+      cl_arg_types[3] = &ffi_type_float;
+      cl_arg_types[4] = &ffi_type_float;
+      cl_arg_types[5] = &ffi_type_float;
+      cl_arg_types[6] = &ffi_type_float;
+      cl_arg_types[7] = &ffi_type_float;
+      cl_arg_types[8] = &ffi_type_double;
+      cl_arg_types[9] = &ffi_type_uint;
+      cl_arg_types[10] = &ffi_type_float;
+      cl_arg_types[11] = &ffi_type_float;
+      cl_arg_types[12] = &ffi_type_uint;
+      cl_arg_types[13] = &ffi_type_float;
+      cl_arg_types[14] = &ffi_type_float;
+      cl_arg_types[15] = &ffi_type_uint;
+      cl_arg_types[16] = NULL;
+      /* Initialize the cif */
+      CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
+                         &ffi_type_sint, cl_arg_types) == FFI_OK);
+
+      CHECK(ffi_prep_closure(&cl, &cif, closure_test_fn3,
+                             (void *) 3 /* userdata */)
+            == FFI_OK);
+      CHECK((*((closure_test_type3)(&cl)))
+      (1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9, 10, 11.11, 12.0, 13,
+      19.19, 21.21, 1) == 135);
     }
+    (void) puts("\nFinished FFI_CLOSURES\n");
 # endif
 
   /* If we arrived here, all is good */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]