Mercurial > pub > dyncall > dyncall
annotate test/suite2_x86win32fast/main.cc @ 606:85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
author | Tassilo Philipp |
---|---|
date | Wed, 21 Sep 2022 15:20:58 +0200 |
parents | 7608e34098b0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/suite2_x86win32fast/main.cc | |
6 Description: | |
7 License: | |
8 | |
606
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 #include "../../dyncall/dyncall.h" | |
29 #include "config.h" | |
30 #include "../../dyncall/dyncall_value.h" | |
31 #include "../../dyncall/dyncall_macros.h" | |
32 #include "funcinfo.h" | |
33 #include <stdlib.h> | |
34 #include "../common/platformInit.h" | |
35 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
36 | |
37 | |
38 int getId(); | |
39 DCpointer getFunc(int x); | |
40 DCValue* getArg(int pos); | |
41 | |
42 | |
606
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
43 static DCbool valueBool [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
44 static DCchar valueChar [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
45 static DCshort valueShort [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
46 static DCint valueInt [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
47 static DClonglong valueLongLong[MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
48 static DCdouble valueDouble [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
49 static DCpointer valuePointer [MAXARGS]; |
85b7a117b807
- more statics in test code (this is partly needed on an experimental freebsd sparc64 build where the elf cleanup code crashes for some reason ... it's probably that experimental build, but a good change to do regardless)
Tassilo Philipp
parents:
410
diff
changeset
|
50 static DCfloat valueFloat [MAXARGS]; |
0 | 51 |
52 | |
53 void clearValues(); | |
54 | |
55 void init() | |
56 { | |
57 for (int i = 0 ; i < MAXARGS ; ++i ) { | |
58 | |
59 valueBool[i] = DCbool( (i % 1) ? DC_TRUE : DC_FALSE ); | |
60 valueChar[i] = DCchar(i); | |
61 valueShort[i] = DCshort(i); | |
62 valueInt[i] = DCint(i); | |
63 valueLongLong[i] = DClonglong(i); | |
64 valueDouble[i] = DCdouble(i); | |
65 valuePointer[i] = DCpointer(i); | |
66 valueFloat[i] = DCfloat(i); | |
67 } | |
68 } | |
69 | |
70 void error(const char* message) | |
71 { | |
72 fprintf(stderr, "error: %s\n", message); | |
73 exit(-1); | |
74 } | |
75 | |
76 | |
77 bool test(int x) | |
78 { | |
79 bool r = true; | |
80 clearValues(); | |
81 | |
82 DCCallVM* pCall; | |
83 | |
84 funcinfo* fi = &gFuncInfos[x]; | |
85 | |
86 const DCsigchar* sig = &fi->sig[2]; | |
87 const DCsigchar* ptr = sig; | |
88 DCsigchar ch; | |
89 int pos; | |
90 | |
91 pos = 0; | |
92 | |
93 pCall = dcNewCallVM(4096); | |
94 #ifdef DC__C_GNU | |
95 dcMode(pCall, DC_CALL_C_X86_WIN32_FAST_GNU); | |
96 #else | |
97 dcMode(pCall, DC_CALL_C_X86_WIN32_FAST_MS); | |
98 #endif | |
99 dcReset(pCall); | |
100 | |
101 while ( (ch=*ptr++) != '\0' ) { | |
102 switch(ch) { | |
103 case DC_SIGCHAR_BOOL: dcArgBool( pCall, valueBool[pos] ); break; | |
104 case DC_SIGCHAR_CHAR: dcArgChar( pCall, valueChar[pos] ); break; | |
105 case DC_SIGCHAR_SHORT: dcArgShort( pCall, valueShort[pos] ); break; | |
106 case DC_SIGCHAR_INT: dcArgInt( pCall, valueInt[pos] ); break; | |
107 case DC_SIGCHAR_LONGLONG: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
108 case DC_SIGCHAR_FLOAT: dcArgFloat( pCall, valueFloat[pos] ); break; | |
109 case DC_SIGCHAR_DOUBLE: dcArgDouble( pCall, valueDouble[pos] ); break; | |
110 case DC_SIGCHAR_POINTER: dcArgPointer( pCall, valuePointer[pos] ); break; | |
111 default: error("unsupported signature character"); break; | |
112 } | |
113 ++pos; | |
114 } | |
115 | |
116 dcCallVoid( pCall, fi->funcptr ); | |
117 | |
118 | |
119 if ( getId() == x ) { | |
120 | |
121 ptr = sig; | |
122 pos = 0; | |
123 while( ( ch=*ptr++ ) != '\0' ) { | |
124 | |
125 switch(ch) { | |
126 case DC_SIGCHAR_BOOL: if ( getArg(pos)->B != valueBool [pos] ) r = false; break; | |
127 case DC_SIGCHAR_CHAR: if ( getArg(pos)->c != valueChar [pos] ) r = false; break; | |
128 case DC_SIGCHAR_SHORT: if ( getArg(pos)->s != valueShort [pos] ) r = false; break; | |
129 case DC_SIGCHAR_INT: if ( getArg(pos)->i != valueInt [pos] ) r = false; break; | |
130 case DC_SIGCHAR_LONGLONG: if ( getArg(pos)->L != valueLongLong [pos] ) r = false; break; | |
131 case DC_SIGCHAR_FLOAT: if ( getArg(pos)->f != valueFloat [pos] ) r = false; break; | |
132 case DC_SIGCHAR_DOUBLE: if ( getArg(pos)->d != valueDouble[pos] ) r = false; break; | |
133 case DC_SIGCHAR_POINTER: if ( getArg(pos)->p != valuePointer [pos] ) r = false; break; | |
134 default: error("unsupported signature character"); break; | |
135 } | |
136 ++pos; | |
137 } | |
138 | |
139 } else { | |
140 r = false; | |
141 } | |
142 | |
143 printf("%d-%s:%d\n", x, sig, r); | |
144 | |
145 dcFree(pCall); | |
146 | |
147 return r; | |
148 } | |
149 | |
150 | |
151 bool run_range(int from, int to) | |
152 { | |
153 bool r = true; | |
154 for (int i = from ; i < to ; ++i ) | |
155 r &= test(i); | |
156 return r; | |
157 } | |
158 | |
159 extern "C" { | |
160 | |
161 int main(int argc, char* argv[]) | |
162 { | |
163 dcTest_initPlatform(); | |
164 | |
165 bool success = false; | |
166 init(); | |
167 if (argc == 2) { | |
168 int index = atoi(argv[1]); | |
169 success = run_range( index, index+1 ); | |
170 } else if (argc == 3) { | |
171 int from = atoi(argv[1]); | |
172 int to = atoi(argv[2])+1; | |
173 success = run_range(from,to); | |
174 } else { | |
175 success = run_range(0,NCASES); | |
176 } | |
177 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
178 printf("result: suite2_x86win32fast: %d\n", success); |
0 | 179 |
180 dcTest_deInitPlatform(); | |
181 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
182 return !success; |
0 | 183 } |
184 | |
185 } // extern "C" | |
186 |