annotate test/call_suite_aggrs/main.c @ 597:0179c25fd855

- test/call_suite_aggrs: LL-suffixed long long int constant to avoid side-effects and warning
author Tassilo Philipp
date Tue, 20 Sep 2022 10:44:57 +0200
parents 806e415df417
children 57ad31f924bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
1 /*
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
2
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
3 Package: dyncall
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
4 Library: test
485
0c68b3f91367 - renamed suite_aggrs to call_suite_aggrs for consistency (callback version will be called callback_suite_aggrs)
Tassilo Philipp
parents: 482
diff changeset
5 File: test/call_suite_aggrs/main.c
527
ed8835abe05f - cosmetics
Tassilo Philipp
parents: 521
diff changeset
6 Description:
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
7 License:
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
8
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
9 Copyright (c) 2022 Tassilo Philipp <tphilipp@potion-studios.com>
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
10
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
11 Permission to use, copy, modify, and distribute this software for any
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
12 purpose with or without fee is hereby granted, provided that the above
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
13 copyright notice and this permission notice appear in all copies.
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
14
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
22
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
23 */
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
24
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
25 #include "dyncall.h"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
26 #include "globals.h"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
27 #include <string.h>
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
28 #include <signal.h>
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
29 #include <setjmp.h>
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
30 #include "../common/platformInit.h"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
32
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
33
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
34 static void* G_callvm;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
35
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
36
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
37 static int find_agg_idx(int* len, const char* sig)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
38 {
451
Tassilo Philipp
parents: 445
diff changeset
39 int i;
Tassilo Philipp
parents: 445
diff changeset
40 for(i=0; i<G_naggs; ++i) {
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
41 const char* agg_sig = G_agg_sigs[i];
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
42 int l = strlen(agg_sig);
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
43 if(len)
527
ed8835abe05f - cosmetics
Tassilo Philipp
parents: 521
diff changeset
44 *len = l;
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
45 if(strncmp(agg_sig, sig, l) == 0)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
46 return i;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
47 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
48 return -1;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
49 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
50
506
ed7d1f5e7973 - test cases: cosmetics for consistency
Tassilo Philipp
parents: 501
diff changeset
51 static int invoke(const char *signature, void* t)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
52 {
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
53 DCCallVM * p = (DCCallVM*) G_callvm;
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
54 const char * sig = signature;
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
55 const char * rtype;
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
56 DCaggr * rtype_a = NULL;
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
57 int rtype_size = 0;
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
58 funptr rtype_a_cmp = NULL;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
59 char atype;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
60 int pos = 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
61 int s = 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
62
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
63 clear_V();
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
64
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
65 dcReset(p);
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
66
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
67 /* locate return type in sig; if no ')' separator, test failed */
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
68 rtype = strchr(sig, ')');
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
69 if(!rtype) {
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
70 printf("cannot locate rtype in sig '%s' ;", signature);
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
71 return 0;
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
72 }
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
73
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
74 ++rtype;
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
75 if(*rtype == '{' || *rtype == '<') {
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
76 int i = find_agg_idx(NULL, rtype);
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
77 if(i == -1) {
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 515
diff changeset
78 printf("unknown rtype aggr sig at '%s' ;", rtype);
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
79 return 0;
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
80 }
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
81
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
82 rtype_size = G_agg_sizes[i];
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
83 rtype_a_cmp = G_agg_cmpfuncs[i];
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
84 rtype_a = ((DCaggr*(*)())G_agg_touchAfuncs[i])();
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
85 dcBeginCallAggr(p, rtype_a);
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
86 }
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
87
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
88
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
89 while ( (atype = *sig) != ')') {
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
90 switch(atype) {
515
c9c546f8598b - added _Bool type to call_suite* tests
Tassilo Philipp
parents: 510
diff changeset
91 case 'B': dcArgBool (p,K_B[pos]); break;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
92 case 'c': dcArgChar (p,K_c[pos]); break;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
93 case 's': dcArgShort (p,K_s[pos]); break;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
94 case 'i': dcArgInt (p,K_i[pos]); break;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
95 case 'j': dcArgLong (p,K_j[pos]); break;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
96 case 'l': dcArgLongLong(p,K_l[pos]); break;
492
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
97 case 'C': dcArgChar (p,K_C[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
98 case 'S': dcArgShort (p,K_S[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
99 case 'I': dcArgInt (p,K_I[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
100 case 'J': dcArgLong (p,K_J[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
101 case 'L': dcArgLongLong(p,K_L[pos]); break;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
102 case 'p': dcArgPointer (p,K_p[pos]); break;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
103 case 'f': dcArgFloat (p,K_f[pos]); break;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
104 case 'd': dcArgDouble (p,K_d[pos]); break;
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
105 case '<': /* union */
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
106 case '{': /* struct */
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
107 {
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
108 /* find aggregate sig */
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
109 int len;
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
110 DCaggr *ag;
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
111 int i = find_agg_idx(&len, sig);
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
112 if(i == -1) {
519
99819b874bac test/call_suite_aggrs:
Tassilo Philipp
parents: 515
diff changeset
113 printf("unknown aggr sig at '%s' ;", sig);
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
114 return 0;
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
115 }
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
116 ag = ((DCaggr*(*)())G_agg_touchAfuncs[i])();
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
117 dcArgAggr(p, ag, K_a[pos]);
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
118 sig += len-1; /* advance to next arg char */
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
119 break;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
120 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
121 default: printf("unknown atype '%c' (1) ;", atype); return 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
122 }
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
123 ++pos;
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
124 ++sig;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
125 }
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
126
527
ed8835abe05f - cosmetics
Tassilo Philipp
parents: 521
diff changeset
127 switch(*rtype)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
128 {
492
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
129 case 'v': dcCallVoid(p,t); s=1; break; /*TODO:check that no return-arg was touched.*/
515
c9c546f8598b - added _Bool type to call_suite* tests
Tassilo Philipp
parents: 510
diff changeset
130 case 'B': s = ( dcCallBool (p,t) == K_B[pos]); break;
492
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
131 case 'c': s = ( dcCallChar (p,t) == K_c[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
132 case 's': s = ( dcCallShort (p,t) == K_s[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
133 case 'i': s = ( dcCallInt (p,t) == K_i[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
134 case 'j': s = ( dcCallLong (p,t) == K_j[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
135 case 'l': s = ( dcCallLongLong(p,t) == K_l[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
136 case 'C': s = ((unsigned char) dcCallChar (p,t) == K_C[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
137 case 'S': s = ((unsigned short) dcCallShort (p,t) == K_S[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
138 case 'I': s = ((unsigned int) dcCallInt (p,t) == K_I[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
139 case 'J': s = ((unsigned long) dcCallLong (p,t) == K_J[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
140 case 'L': s = ((unsigned long long)dcCallLongLong(p,t) == K_L[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
141 case 'p': s = ( dcCallPointer (p,t) == K_p[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
142 case 'f': s = ( dcCallFloat (p,t) == K_f[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
143 case 'd': s = ( dcCallDouble (p,t) == K_d[pos]); break;
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
144 case '<': /* union */
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
145 case '{': /* struct */
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
146 {
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 462
diff changeset
147 /* bound check memory adjacent to returned aggregate, to check for overflows by dcCallAggr */
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
148 long long* adj_ll = (get_max_aggr_size() - rtype_size) > sizeof(long long) ? (long long*)((char*)V_a[pos] + rtype_size) : NULL;
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
149 if(adj_ll)
597
0179c25fd855 - test/call_suite_aggrs: LL-suffixed long long int constant to avoid side-effects and warning
Tassilo Philipp
parents: 593
diff changeset
150 *adj_ll = 0x0123456789abcdefLL;
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
151
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
152 s = ((int(*)(const void*,const void*))rtype_a_cmp)(dcCallAggr(p, t, rtype_a, V_a[pos]), K_a[pos]);
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
153
597
0179c25fd855 - test/call_suite_aggrs: LL-suffixed long long int constant to avoid side-effects and warning
Tassilo Philipp
parents: 593
diff changeset
154 if(adj_ll && *adj_ll != 0x0123456789abcdefLL) {
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
155 printf("writing rval overflowed into adjacent memory;");
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
156 return 0;
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 456
diff changeset
157 }
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
158 break;
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
159 }
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
160 default: printf("unknown rtype '%s'", rtype); return 0;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
161 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
162
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
163 if (!s) { printf("rval wrong;"); return 0; }
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
164
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
165 /* test V_* array against values passed to func: */
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
166 sig = signature;
510
f0080b53635d test/call_suite_aggrs:
Tassilo Philipp
parents: 506
diff changeset
167 pos = 0;
501
62c3746390da - call_suite_aggrs: simplified and made output more consistent with dyncall sig style
Tassilo Philipp
parents: 492
diff changeset
168 while ( (atype = *sig) != ')') {
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
169 switch(atype) {
515
c9c546f8598b - added _Bool type to call_suite* tests
Tassilo Philipp
parents: 510
diff changeset
170 case 'B': s = ( V_B[pos] == K_B[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_B[pos], K_B[pos]); break;
492
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
171 case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_c[pos], K_c[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
172 case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_s[pos], K_s[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
173 case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_i[pos], K_i[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
174 case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'%c':%d: %ld != %ld ; ", atype, pos, V_j[pos], K_j[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
175 case 'l': s = ( V_l[pos] == K_l[pos] ); if (!s) printf("'%c':%d: %lld != %lld ; ", atype, pos, V_l[pos], K_l[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
176 case 'C': s = ( V_C[pos] == K_C[pos] ); if (!s) printf("'%c':%d: %u != %u ; ", atype, pos, V_C[pos], K_C[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
177 case 'S': s = ( V_S[pos] == K_S[pos] ); if (!s) printf("'%c':%d: %u != %u ; ", atype, pos, V_S[pos], K_S[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
178 case 'I': s = ( V_I[pos] == K_I[pos] ); if (!s) printf("'%c':%d: %u != %u ; ", atype, pos, V_I[pos], K_I[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
179 case 'J': s = ( V_J[pos] == K_J[pos] ); if (!s) printf("'%c':%d: %lu != %lu ; ", atype, pos, V_J[pos], K_J[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
180 case 'L': s = ( V_L[pos] == K_L[pos] ); if (!s) printf("'%c':%d: %llu != %llu ; ", atype, pos, V_L[pos], K_L[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
181 case 'p': s = ( V_p[pos] == K_p[pos] ); if (!s) printf("'%c':%d: %p != %p ; ", atype, pos, V_p[pos], K_p[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
182 case 'f': s = ( V_f[pos] == K_f[pos] ); if (!s) printf("'%c':%d: %f != %f ; ", atype, pos, V_f[pos], K_f[pos]); break;
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
183 case 'd': s = ( V_d[pos] == K_d[pos] ); if (!s) printf("'%c':%d: %f != %f ; ", atype, pos, V_d[pos], K_d[pos]); break;
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
184 case '<': /* union */
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
185 case '{': /* struct */
462
653b65580cb4 suite_aggr:
Tassilo Philipp
parents: 461
diff changeset
186 {
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
187 /* no check: guaranteed to exist, or invoke func would've exited when passing args, above */
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
188 int len;
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
189 int i = find_agg_idx(&len, sig);
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
190 s = ((int(*)(const void*,const void*))G_agg_cmpfuncs[i])(V_a[pos], K_a[pos]);
461
236015fdf7a8 suite_aggrs:
Tassilo Philipp
parents: 460
diff changeset
191 if (!s) printf("'%c':%d: *%p != *%p ; ", atype, pos, V_a[pos], K_a[pos]);
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
192 sig += len-1; /* advance to next arg char */
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
193 break;
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
194 }
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
195 default: printf("unknown atype '%c' ; ", atype); return 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
196 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
197 if (!s) {
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
198 printf("arg mismatch at %d ; ", pos);
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
199 return 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
200 }
433
45662241d9cd suite_aggrs now handling struct by value return types, also
Tassilo Philipp
parents: 432
diff changeset
201 ++sig;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
202 ++pos;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
203 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
204 return 1;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
205 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
206
506
ed7d1f5e7973 - test cases: cosmetics for consistency
Tassilo Philipp
parents: 501
diff changeset
207 static int run_test(int i)
527
ed8835abe05f - cosmetics
Tassilo Philipp
parents: 521
diff changeset
208 {
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
209 char const * sig;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
210 void * target;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
211 int success;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
212 sig = G_sigtab[i];
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
213 target = (void*) G_funtab[i];
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
214 printf("%d:%s:",i,sig);
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
215 success = invoke(sig,target);
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
216 printf("%d\n",success);
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
217 return success;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
218 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
219
506
ed7d1f5e7973 - test cases: cosmetics for consistency
Tassilo Philipp
parents: 501
diff changeset
220 static int run_all()
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
221 {
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
222 int i;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
223 int failure = 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
224 for(i=0;i<G_ncases;++i)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
225 failure |= !( run_test(i) );
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
226
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
227 return !failure;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
228 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
229
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
230
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
231 jmp_buf jbuf;
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
232 void segv_handler(int sig)
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
233 {
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
234 longjmp(jbuf, 1);
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
235 }
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
236
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
237
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
238 int main(int argc, char* argv[])
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
239 {
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
240 int r = 0, i;
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
241
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
242 signal(SIGSEGV, segv_handler);
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
243 #if !defined(DC_WINDOWS)
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
244 signal(SIGBUS, segv_handler);
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
245 #endif
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
246
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
247 dcTest_initPlatform();
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
248
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
249 init_test_data(G_maxargs);
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
250 G_callvm = (DCCallVM*) dcNewCallVM(32768);
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
251
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
252 dcReset(G_callvm);
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
253 if(setjmp(jbuf) == 0)
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
254 r = run_all();
593
806e415df417 - aggr test suites output cosmetics on exceptions
Tassilo Philipp
parents: 592
diff changeset
255 else
806e415df417 - aggr test suites output cosmetics on exceptions
Tassilo Philipp
parents: 592
diff changeset
256 printf("\n"); /* new line as current might be filled with garbage */
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
257
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
258 /* free all DCaggrs created on the fly (backwards b/c they are interdependency-ordered */
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
259 for(i=G_naggs-1; i>=0; --i)
521
a2de1d0a73f3 - more test code generator code sharing/abstraction/simplifications
Tassilo Philipp
parents: 519
diff changeset
260 dcFreeAggr(((DCaggr*(*)())G_agg_touchAfuncs[i])());
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
261
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
262 dcFree(G_callvm);
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
263 deinit_test_data(G_maxargs);
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 435
diff changeset
264
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
265 printf("result: call_suite_aggrs: %d\n", r);
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
266
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
267 dcTest_deInitPlatform();
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
268
592
f29db2bf3c0e - added exception handling to test/call{,back}_suite_aggrs
Tassilo Philipp
parents: 527
diff changeset
269 return !r;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
270 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
271