annotate test/callback_suite/main.c @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents f3d44195dbdf
children e7ffb0fb1520
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/callback_suite/main.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
9 Copyright (c) 2011-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
26 #include <stdio.h>
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 #include <stdlib.h>
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
28 #include <assert.h>
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
29 #include "dyncall_callback.h"
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
30 #include "globals.h"
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 #include "../common/platformInit.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
35
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
36
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
37 static void print_usage(const char* appName)
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
38 {
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
39 printf("usage:\n\
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
40 %s [ from [to] ]\n\
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
41 where\n\
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
42 from, to: test range (0-based, runs single test if \"to\" is omitted)\n\
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
43 options\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
44 -h help on usage\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
45 \n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
46 ", appName);
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
47 }
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
48
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
49
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
50 static int cmp(const char* signature)
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
51 {
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
52 char atype;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
53 const char* sig = signature;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
54 int pos = 0;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
55 int s = 0;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
56 while ( (atype = *sig++) != '\0') {
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
57 switch(atype) {
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
58 case ')': /* skip cconv prefix or ret type separator */ continue;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
59 case 'v': s = (sig > signature+1) && sig[-2] == ')'; /* assure this was the return type */ break; /*TODO:check that no return-arg was touched.*/
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
60 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
61 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
62 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
63 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
64 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
65 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
66 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
67 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
68 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
69 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
70 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
71 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
72 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
73 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;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
74 default: printf("unknown atype '%c' ; ", atype); return 0;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
75 }
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
76 if (!s) {
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
77 printf("arg mismatch at %d ; ", pos);
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
78 return 0;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
79 }
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
80 pos++;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
81 }
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
82 return 1;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
83 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
84
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
85
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
86 /* handler just copies all received args as well as return value into V_* */
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
87 static char handler(DCCallback* that, DCArgs* input, DCValue* output, void* userdata)
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
88 {
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
89 const char* signature = (const char*) userdata;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
90 int pos = 0;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
91 char ch;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
93 for(;;) {
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
94 ch = *signature++;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
95 if (!ch || ch == DC_SIGCHAR_ENDARG) break;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
96 switch(ch) {
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
97 case DC_SIGCHAR_BOOL: V_B[pos] = dcbArgBool (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
98 case DC_SIGCHAR_CHAR: V_c[pos] = dcbArgChar (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
99 case DC_SIGCHAR_UCHAR: V_C[pos] = dcbArgUChar (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
100 case DC_SIGCHAR_SHORT: V_s[pos] = dcbArgShort (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
101 case DC_SIGCHAR_USHORT: V_S[pos] = dcbArgUShort (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
102 case DC_SIGCHAR_INT: V_i[pos] = dcbArgInt (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
103 case DC_SIGCHAR_UINT: V_I[pos] = dcbArgUInt (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
104 case DC_SIGCHAR_LONG: V_j[pos] = dcbArgLong (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
105 case DC_SIGCHAR_ULONG: V_J[pos] = dcbArgULong (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
106 case DC_SIGCHAR_LONGLONG: V_l[pos] = dcbArgLongLong (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
107 case DC_SIGCHAR_ULONGLONG:V_L[pos] = dcbArgULongLong(input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
108 case DC_SIGCHAR_FLOAT: V_f[pos] = dcbArgFloat (input); break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
109 case DC_SIGCHAR_DOUBLE: V_d[pos] = dcbArgDouble (input); break;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
110 case DC_SIGCHAR_STRING:
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
111 case DC_SIGCHAR_POINTER: V_p[pos] = dcbArgPointer (input); break;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
112 case DC_SIGCHAR_CC_PREFIX: ++signature; /* skip cconv prefix */ continue;
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
113 default: assert(0);
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
114 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
115 ++pos;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
116 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
117
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
118 if(ch == DC_SIGCHAR_ENDARG)
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
119 ch = *signature;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
120
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
121 /* write retval */
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
122 switch(ch) {
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
123 case DC_SIGCHAR_VOID: /* nothing to set */ break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
124 case DC_SIGCHAR_BOOL: output->B = K_B[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
125 case DC_SIGCHAR_CHAR: output->c = K_c[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
126 case DC_SIGCHAR_UCHAR: output->C = K_C[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
127 case DC_SIGCHAR_SHORT: output->s = K_s[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
128 case DC_SIGCHAR_USHORT: output->S = K_S[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
129 case DC_SIGCHAR_INT: output->i = K_i[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
130 case DC_SIGCHAR_UINT: output->I = K_I[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
131 case DC_SIGCHAR_LONG: output->j = K_j[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
132 case DC_SIGCHAR_ULONG: output->J = K_J[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
133 case DC_SIGCHAR_LONGLONG: output->l = K_l[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
134 case DC_SIGCHAR_ULONGLONG:output->L = K_L[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
135 case DC_SIGCHAR_FLOAT: output->f = K_f[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
136 case DC_SIGCHAR_DOUBLE: output->d = K_d[pos]; break;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
137 case DC_SIGCHAR_STRING:
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
138 case DC_SIGCHAR_POINTER: output->p = K_p[pos]; break;
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
139 default: assert(0);
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
140 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
141
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
142 /* return type info for dyncallback */
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
143 return ch;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
144 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
145
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
146
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
147
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
148
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
149 static int run_test(int id)
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
150 {
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
151 const char* signature;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
152 DCCallback* pcb;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
153 int result;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
154
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
155 /* index range: [0,nsigs[ */
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
156 signature = G_sigtab[id];
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
157 printf("%d:%s", id, signature);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
158
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 509
diff changeset
159 pcb = dcbNewCallback(signature, handler, (void*)signature);
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
160 assert(pcb != NULL);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
161
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
162 clear_V();
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
163
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
164 /* invoke call */
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
165 G_funtab[id]((void*)pcb);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
166
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
167 result = cmp(signature);
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
168
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
169 printf(":%d\n", result);
509
f3d44195dbdf callback_suite:
Tassilo Philipp
parents: 507
diff changeset
170
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
171 dcbFreeCallback(pcb);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
172
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
173 return result;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
174 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
175
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
176
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
177 static int run_all(int from, int to)
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
178 {
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
179 int i;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
180 int failure = 0;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
181 for(i=from; i<=to ;++i)
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
182 failure |= !( run_test(i) );
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
183
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
184 return !failure;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
185 }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
186
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
187
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
188 #define Error(X, Y, N) { fprintf(stderr, X, Y); print_usage(N); exit(1); }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
189
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
190 int main(int argc, char* argv[])
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191 {
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
192 int from = 0, to = G_ncases-1;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
193 int i, pos = 0, total;
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
194
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
195 dcTest_initPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
196
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
197
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
198 /* parse args */
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
199 for(i=1; i<argc; ++i)
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
200 {
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
201 if(argv[i][0] == '-')
495
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
202 {
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
203 switch(argv[i][1]) {
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
204 case 'h':
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
205 case '?':
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
206 print_usage(argv[0]);
495
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
207 return 0;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
208 default:
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
209 Error("invalid option: %s\n\n", argv[i], argv[0]);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
210 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
211 }
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
212 switch(pos++) {
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
213 case 0: from = to = atoi(argv[i]); break;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
214 case 1: to = atoi(argv[i]); break;
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
215 default: Error("too many arguments (%d given, 2 allowed)\n\n", pos, argv[0]);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
216 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
217 }
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
218 if(from < 0 || to >= G_ncases || from > to)
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
219 Error("invalid arguments (provided from or to not in order or outside of range [0,%d])\n\n", G_ncases-1, argv[0]);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
220
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
221
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
222 init_test_data();
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
223 total = run_all(from, to);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
224 deinit_test_data();
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
225
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
226 printf("result: callback_suite: %d\n", total);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
227
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
228 dcTest_deInitPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
229
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 495
diff changeset
230 return !total;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
231 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
232