comparison test/suite_aggrs/main.c @ 482:0f3b6898078d

suite_aggrs (still ahead of checked in version of dyncall, sorry): - renaming struct -> aggr - added knobs to: * control struct packing * whether to test immutability of aggr-by-val params * how to copy aggrs (field by field or via = op (which might do a memcpy and thus copy padding garbage, also)) - some macros to reduce file sizes of generated cases - setting default misalignment to 1
author Tassilo Philipp
date Wed, 16 Mar 2022 16:27:50 +0100
parents 653b65580cb4
children
comparison
equal deleted inserted replaced
481:0fc22b5feac7 482:0f3b6898078d
48 { 48 {
49 DCCallVM * p = (DCCallVM*) G_callvm; 49 DCCallVM * p = (DCCallVM*) G_callvm;
50 char const * sig = signature; 50 char const * sig = signature;
51 char const * sig_args; 51 char const * sig_args;
52 char rtype; 52 char rtype;
53 DCstruct * rtype_st = NULL; 53 DCaggr * rtype_a = NULL;
54 int rtype_size = 0; 54 int rtype_size = 0;
55 funptr rtype_st_cmp = NULL; 55 funptr rtype_a_cmp = NULL;
56 char atype; 56 char atype;
57 int pos = 0; 57 int pos = 0;
58 int s = 0; 58 int s = 0;
59 59
60 clear_V(); 60 clear_V();
70 } 70 }
71 rtype = *sig; 71 rtype = *sig;
72 sig += len; 72 sig += len;
73 73
74 rtype_size = G_agg_sizes[i]; 74 rtype_size = G_agg_sizes[i];
75 rtype_st_cmp = G_agg_cmpfuncs[i]; 75 rtype_a_cmp = G_agg_cmpfuncs[i];
76 rtype_st = ((DCstruct*(*)())G_agg_touchdcstfuncs[i])(); 76 rtype_a = ((DCaggr*(*)())G_agg_touchdcstfuncs[i])();
77 dcBeginCallStruct(p, rtype_st); 77 dcBeginCallAggr(p, rtype_a);
78 } 78 }
79 else 79 else
80 rtype = *sig++; 80 rtype = *sig++;
81 81
82 sig_args = sig; 82 sig_args = sig;
95 case '<': /* union */ 95 case '<': /* union */
96 case '{': /* struct */ 96 case '{': /* struct */
97 { 97 {
98 /* find aggregate sig */ 98 /* find aggregate sig */
99 int len; 99 int len;
100 DCstruct *st; 100 DCaggr *ag;
101 int i = find_agg_idx(&len, sig); 101 int i = find_agg_idx(&len, sig);
102 if(i == -1) { 102 if(i == -1) {
103 printf("unknown sig at '%s' ;", sig); 103 printf("unknown sig at '%s' ;", sig);
104 return 0; 104 return 0;
105 } 105 }
106 st = ((DCstruct*(*)())G_agg_touchdcstfuncs[i])(); 106 ag = ((DCaggr*(*)())G_agg_touchdcstfuncs[i])();
107 dcArgStruct(p, st, K_a[pos]); 107 dcArgAggr(p, ag, K_a[pos]);
108 sig += len-1; /* advance to next arg char */ 108 sig += len-1; /* advance to next arg char */
109 break; 109 break;
110 } 110 }
111 default: printf("unknown atype '%c' (1) ;", atype); return 0; 111 default: printf("unknown atype '%c' (1) ;", atype); return 0;
112 } 112 }
125 case 'f': s = (dcCallFloat (p,t) == K_f[pos]) ; break; 125 case 'f': s = (dcCallFloat (p,t) == K_f[pos]) ; break;
126 case 'd': s = (dcCallDouble (p,t) == K_d[pos]) ; break; 126 case 'd': s = (dcCallDouble (p,t) == K_d[pos]) ; break;
127 case '<': /* union */ 127 case '<': /* union */
128 case '{': /* struct */ 128 case '{': /* struct */
129 { 129 {
130 /* bound check memory adjacent to returned aggregate, to check for overflows by dcCallStruct */ 130 /* bound check memory adjacent to returned aggregate, to check for overflows by dcCallAggr */
131 long long* adj_ll = (get_max_aggr_size() - rtype_size) > sizeof(long long) ? (long long*)((char*)V_a[0] + rtype_size) : NULL; 131 long long* adj_ll = (get_max_aggr_size() - rtype_size) > sizeof(long long) ? (long long*)((char*)V_a[0] + rtype_size) : NULL;
132 if(adj_ll) 132 if(adj_ll)
133 *adj_ll = 0x0123456789abcdef; 133 *adj_ll = 0x0123456789abcdef;
134 134
135 s = ((int(*)(const void*,const void*))rtype_st_cmp)(dcCallStruct(p, t, rtype_st, V_a[0]), K_a[pos]); 135 s = ((int(*)(const void*,const void*))rtype_a_cmp)(dcCallAggr(p, t, rtype_a, V_a[0]), K_a[pos]);
136 136
137 if(adj_ll && *adj_ll != 0x0123456789abcdef) { 137 if(adj_ll && *adj_ll != 0x0123456789abcdef) {
138 printf("writing rval overflowed into adjacent memory;"); 138 printf("writing rval overflowed into adjacent memory;");
139 return 0; 139 return 0;
140 } 140 }
214 G_callvm = (DCCallVM*) dcNewCallVM(32768); 214 G_callvm = (DCCallVM*) dcNewCallVM(32768);
215 215
216 dcReset(G_callvm); 216 dcReset(G_callvm);
217 total = run_all(); 217 total = run_all();
218 218
219 /* free all DCstructs created on the fly */ 219 /* free all DCaggrs created on the fly */
220 for(i=0; i<G_naggs; ++i) 220 for(i=0; i<G_naggs; ++i)
221 dcFreeStruct(((DCstruct*(*)())G_agg_touchdcstfuncs[i])()); 221 dcFreeAggr(((DCaggr*(*)())G_agg_touchdcstfuncs[i])());
222 222
223 dcFree(G_callvm); 223 dcFree(G_callvm);
224 deinit_test_data(G_maxargs); 224 deinit_test_data(G_maxargs);
225 225
226 printf("result: suite_aggrs: %d\n", total); 226 printf("result: suite_aggrs: %d\n", total);