changeset 429:2b708397bba1

- simplified and decluttered test/call_suite
author Tassilo Philipp
date Mon, 17 Jan 2022 11:36:09 +0100
parents 72024b0957c2
children 8e22b70d3ee4
files test/call_suite/CMakeLists.txt test/call_suite/Makefile.embedded test/call_suite/Makefile.generic test/call_suite/Nmakefile test/call_suite/globals.c test/call_suite/globals.h test/call_suite/invoke.c test/call_suite/main.c test/call_suite/mkfile
diffstat 9 files changed, 87 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- a/test/call_suite/CMakeLists.txt	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/CMakeLists.txt	Mon Jan 17 11:36:09 2022 +0100
@@ -1,4 +1,4 @@
-add_executable(call_suite globals.c invoke.c cases.c main.c)
+add_executable(call_suite globals.c cases.c main.c)
 target_link_libraries(call_suite dyncall_s)
 
 
--- a/test/call_suite/Makefile.embedded	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/Makefile.embedded	Mon Jan 17 11:36:09 2022 +0100
@@ -1,5 +1,5 @@
 TARGET	= call_suite ${OBJS} 
-OBJS	= globals.o invoke.o cases.o main.o
+OBJS	= globals.o cases.o main.o
 
 SRCDIR 	= ../..
 BLDDIR 	= ${SRCDIR}
--- a/test/call_suite/Makefile.generic	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/Makefile.generic	Mon Jan 17 11:36:09 2022 +0100
@@ -1,5 +1,5 @@
 APP     = call_suite
-OBJS    = globals.o invoke.o cases.o main.o
+OBJS    = globals.o cases.o main.o
 SRCTOP  = ${VPATH}/../..
 BLDTOP  = ../..
 CFLAGS += -I${SRCTOP}/dyncall
--- a/test/call_suite/Nmakefile	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/Nmakefile	Mon Jan 17 11:36:09 2022 +0100
@@ -36,7 +36,7 @@
 !IF "$(BUILD_OS)" == "windows"
 
 TARGETS = call_suite.exe
-OBJS = main.obj cases.obj globals.obj invoke.obj
+OBJS = main.obj cases.obj globals.obj
 
 $(TARGETS): $(OBJS)
 	echo Linking $@ ...
@@ -46,7 +46,7 @@
 !ELSE IF "$(BUILD_OS)" == "nds"
 
 TARGETS = call_suite.nds
-OBJS = main.o cases.o globals.o invoke.o
+OBJS = main.o cases.o globals.o
 
 $(TARGETS): $(OBJS)
 	echo Linking $@ ...
--- a/test/call_suite/globals.c	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/globals.c	Mon Jan 17 11:36:09 2022 +0100
@@ -27,7 +27,7 @@
 #include "globals.h"
 #include <float.h>
 
-#define X(CH,T,QCH) T *V_##CH; T *K_##CH; 
+#define X(CH,T) T *V_##CH; T *K_##CH; 
 DEF_TYPES
 #undef X
 
@@ -38,7 +38,7 @@
 void init_K()
 {
   int i;
-#define X(CH,T,QCH) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1));
+#define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1));
 DEF_TYPES
 #undef X
   for(i=0;i<G_maxargs+1;++i) {
@@ -48,7 +48,7 @@
     K_j[i] = (long)      (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
     K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
     K_p[i] = (void*)     (long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1)));
-    K_f[i] = (float)     (rand_d() * FLT_MAX);	/* Plan9 doesn't know the macro. */
+    K_f[i] = (float)     (rand_d() * FLT_MAX);
     K_d[i] = (double)    (((rand_d()-0.5)*2) * 1.7976931348623157E+308/*__DBL_MAX__*/);	/* Plan9 doesn't know the macro. */
   }
 }
@@ -57,7 +57,7 @@
 {
   int i;
   for(i=0;i<G_maxargs+1;++i) {
-#define X(CH,T,QCH) V_##CH[i] = (T) 0;
+#define X(CH,T) V_##CH[i] = (T) 0;
 DEF_TYPES
 #undef X
   }
--- a/test/call_suite/globals.h	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/globals.h	Mon Jan 17 11:36:09 2022 +0100
@@ -24,15 +24,14 @@
 */
 
 
-#define DEF_TYPES X(c,char,'c') X(s,short,'s') X(i,int,'i') X(j,long,'j') X(l,long long,'l') X(p,void*,'p') X(f,float,'f') X(d,double,'d')
+#define DEF_TYPES X(c,char) X(s,short) X(i,int) X(j,long) X(l,long long) X(p,void*) X(f,float) X(d,double)
 
-#define X(CH,T,QCH) extern T *K_##CH; extern T *V_##CH;
+#define X(CH,T) extern T *K_##CH; extern T *V_##CH;
 DEF_TYPES
 #undef X
 
 typedef void (*funptr)();
 
-extern void       * G_callvm;
 extern funptr       G_funtab[];
 extern char const * G_sigtab[];
 extern int          G_ncases;
@@ -41,25 +40,4 @@
 void init_K();
 void init_T();
 void clear_V();
-int  invoke(char const* signature, void* target);
 
-#if 0
-extern const char      *K_c;
-extern const short     *K_s;
-extern const int       *K_i;
-extern const long      *K_j;
-extern const long long *K_l;
-extern void* const     *K_p;
-extern const float     *K_f;
-extern const double    *K_d;
-
-extern char      *V_c;
-extern short     *V_s;
-extern int       *V_i;
-extern long      *V_j;
-extern long long *V_l;
-extern void*     *V_p;
-extern float     *V_f;
-extern double    *V_d;
-#endif 
-
--- a/test/call_suite/invoke.c	Mon Jan 17 10:25:33 2022 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,102 +0,0 @@
-/*
-
- Package: dyncall
- Library: test
- File: test/call_suite/invoke.c
- Description: 
- License:
-
-   Copyright (c) 2011-2018 Daniel Adler <dadler@uni-goettingen.de>,
-                           Tassilo Philipp <tphilipp@potion-studios.com>
-
-   Permission to use, copy, modify, and distribute this software for any
-   purpose with or without fee is hereby granted, provided that the above
-   copyright notice and this permission notice appear in all copies.
-
-   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-*/
-
-#include "dyncall.h"
-#include "globals.h"
-#include "../common/platformInit.h"
-
-int invoke(char const* signature, void* t)
-{
-  DCCallVM   * p = (DCCallVM*) G_callvm;
-  char const * sig = signature;
-  char         rtype;
-  char         atype;
-  int          pos = 0;
-  int          s = 0;
-
-  clear_V();
-  
-  rtype = *sig++;
-  dcReset(p);
-
-  while ( (atype = *sig++) != '\0') {
-    pos++;
-    switch(atype) {
-      case 'c': dcArgChar    (p,K_c[pos]); break;
-      case 's': dcArgShort   (p,K_s[pos]); break;
-      case 'i': dcArgInt     (p,K_i[pos]); break;
-      case 'j': dcArgLong    (p,K_j[pos]); break;
-      case 'l': dcArgLongLong(p,K_l[pos]); break;
-      case 'p': dcArgPointer (p,K_p[pos]); break;
-      case 'f': dcArgFloat   (p,K_f[pos]); break;
-      case 'd': dcArgDouble  (p,K_d[pos]); break;
-      default: printf("unknown atype '%c' (1) ;", atype); return 0;
-    }
-  }
-  
-  switch(rtype) 
-  {
-    case 'v': dcCallVoid(p,t); s=1; /*TODO:check that no return-arg was touched.*/ break;
-    case 'c': s = (dcCallChar    (p,t) == K_c[pos]) ; break;
-    case 's': s = (dcCallShort   (p,t) == K_s[pos]) ; break;
-    case 'i': s = (dcCallInt     (p,t) == K_i[pos]) ; break;
-    case 'j': s = (dcCallLong    (p,t) == K_j[pos]) ; break;
-    case 'l': s = (dcCallLongLong(p,t) == K_l[pos]) ; break;
-    case 'p': s = (dcCallPointer (p,t) == K_p[pos]) ; break;
-    case 'f': s = (dcCallFloat   (p,t) == K_f[pos]) ; break;
-    case 'd': s = (dcCallDouble  (p,t) == K_d[pos]) ; break;
-    default: printf("unknown rtype '%c'", rtype); return 0;
-  }
-
-  if (!s) { printf("rval wrong;"); return 0; }
-  /* test: */
-  sig = signature+1;
-  pos = 1;
-  while ( (atype = *sig++) != '\0') {
-    switch(atype) {
-#if 0
-#define X(CH,T,QCH) case QCH: s = (V_##CH[pos] == K_##CH[pos]); break;
-DEF_TYPES
-#undef X
-#endif
-      case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'c':%d: %d != %d ; ", pos, V_c[pos], K_c[pos]); break;
-      case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'s':%d: %d != %d ; ", pos, V_s[pos], K_s[pos]); break;
-      case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'i':%d: %d != %d ; ", pos, V_i[pos], K_i[pos]); break;
-      case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'j':%d: %ld != %ld ; ", pos, V_j[pos], K_j[pos]); break;
-      case 'l': s = ( V_l[pos] == K_l[pos] ); if (!s) printf("'l':%d: %lld != %lld ; ", pos, V_l[pos], K_l[pos]); break;
-      case 'p': s = ( V_p[pos] == K_p[pos] ); if (!s) printf("'p':%d: %lld != %lld ; ", pos, (long long) V_p[pos], (long long) K_p[pos]); break;
-      case 'f': s = ( V_f[pos] == K_f[pos] ); if (!s) printf("'f':%d: %f != %f ; ", pos, V_f[pos], K_f[pos]); break;
-      case 'd': s = ( V_d[pos] == K_d[pos] ); if (!s) printf("'d':%d: %f != %f ; ", pos, V_d[pos], K_d[pos]); break;
-      default: printf("unknown atype '%c' ; ", atype); return 0;
-    }
-    if (!s) {
-      printf("arg mismatch at %d ; ", pos);
-      return 0;
-    }
-    pos++;
-  }
-  return 1;
-}
-
--- a/test/call_suite/main.c	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/main.c	Mon Jan 17 11:36:09 2022 +0100
@@ -30,10 +30,79 @@
 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
 
 
-char  linebuf[1024];
 void* G_callvm;
+
+
+int invoke(char const* signature, void* t)
+{
+  DCCallVM   * p = (DCCallVM*) G_callvm;
+  char const * sig = signature;
+  char         rtype;
+  char         atype;
+  int          pos = 0;
+  int          s = 0;
+
+  clear_V();
   
-int run_test(int i) {  
+  rtype = *sig++;
+  dcReset(p);
+
+  while ( (atype = *sig++) != '\0') {
+    pos++;
+    switch(atype) {
+      case 'c': dcArgChar    (p,K_c[pos]); break;
+      case 's': dcArgShort   (p,K_s[pos]); break;
+      case 'i': dcArgInt     (p,K_i[pos]); break;
+      case 'j': dcArgLong    (p,K_j[pos]); break;
+      case 'l': dcArgLongLong(p,K_l[pos]); break;
+      case 'p': dcArgPointer (p,K_p[pos]); break;
+      case 'f': dcArgFloat   (p,K_f[pos]); break;
+      case 'd': dcArgDouble  (p,K_d[pos]); break;
+      default: printf("unknown atype '%c' (1) ;", atype); return 0;
+    }
+  }
+  
+  switch(rtype) 
+  {
+    case 'v': dcCallVoid(p,t); s=1; /*TODO:check that no return-arg was touched.*/ break;
+    case 'c': s = (dcCallChar    (p,t) == K_c[pos]) ; break;
+    case 's': s = (dcCallShort   (p,t) == K_s[pos]) ; break;
+    case 'i': s = (dcCallInt     (p,t) == K_i[pos]) ; break;
+    case 'j': s = (dcCallLong    (p,t) == K_j[pos]) ; break;
+    case 'l': s = (dcCallLongLong(p,t) == K_l[pos]) ; break;
+    case 'p': s = (dcCallPointer (p,t) == K_p[pos]) ; break;
+    case 'f': s = (dcCallFloat   (p,t) == K_f[pos]) ; break;
+    case 'd': s = (dcCallDouble  (p,t) == K_d[pos]) ; break;
+    default: printf("unknown rtype '%c'", rtype); return 0;
+  }
+
+  if (!s) { printf("rval wrong;"); return 0; }
+  /* test: */
+  sig = signature+1;
+  pos = 1;
+  while ( (atype = *sig++) != '\0') {
+    switch(atype) {
+      case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'c':%d: %d != %d ; ", pos, V_c[pos], K_c[pos]); break;
+      case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'s':%d: %d != %d ; ", pos, V_s[pos], K_s[pos]); break;
+      case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'i':%d: %d != %d ; ", pos, V_i[pos], K_i[pos]); break;
+      case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'j':%d: %ld != %ld ; ", pos, V_j[pos], K_j[pos]); break;
+      case 'l': s = ( V_l[pos] == K_l[pos] ); if (!s) printf("'l':%d: %lld != %lld ; ", pos, V_l[pos], K_l[pos]); break;
+      case 'p': s = ( V_p[pos] == K_p[pos] ); if (!s) printf("'p':%d: %lld != %lld ; ", pos, (long long) V_p[pos], (long long) K_p[pos]); break;
+      case 'f': s = ( V_f[pos] == K_f[pos] ); if (!s) printf("'f':%d: %f != %f ; ", pos, V_f[pos], K_f[pos]); break;
+      case 'd': s = ( V_d[pos] == K_d[pos] ); if (!s) printf("'d':%d: %f != %f ; ", pos, V_d[pos], K_d[pos]); break;
+      default: printf("unknown atype '%c' ; ", atype); return 0;
+    }
+    if (!s) {
+      printf("arg mismatch at %d ; ", pos);
+      return 0;
+    }
+    pos++;
+  }
+  return 1;
+}
+
+int run_test(int i)
+{  
   char const * sig;
   void * target;
   int success;
@@ -45,12 +114,13 @@
   return success;
 }
 
-int run_all() {
+int run_all()
+{
   int i;
   int failure = 0;
-  for(i=0;i<G_ncases;++i) {
+  for(i=0;i<G_ncases;++i)
     failure |= !( run_test(i) );
-  }
+
   return !failure;
 }
 
--- a/test/call_suite/mkfile	Mon Jan 17 10:25:33 2022 +0100
+++ b/test/call_suite/mkfile	Mon Jan 17 11:36:09 2022 +0100
@@ -22,7 +22,7 @@
 <$TOP/buildsys/mk/prolog.mk
 
 
-UNITS       = globals invoke cases main
+UNITS       = globals cases main
 APPLICATION = call_suite
 LIBS        = $TOP/dyncall/libdyncall_s.a$O