Mercurial > pub > dyncall > dyncall
annotate test/suite2/main.cc @ 663:127b569978cc default tip
- another tweak handling clang trying to be too smart (see last commit)
author | Tassilo Philipp |
---|---|
date | Sun, 24 Mar 2024 13:52:44 +0100 |
parents | 85b7a117b807 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/suite2/main.cc | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
6 Description: |
0 | 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:
605
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 "funcinfo.h" | |
32 #include <stdlib.h> | |
33 #include "../common/platformInit.h" | |
34 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
35 | |
36 int getId(); | |
37 DCpointer getFunc(int x); | |
38 DCValue* getArg(int pos); | |
39 | |
40 | |
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:
605
diff
changeset
|
41 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:
605
diff
changeset
|
42 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:
605
diff
changeset
|
43 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:
605
diff
changeset
|
44 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:
605
diff
changeset
|
45 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:
605
diff
changeset
|
46 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:
605
diff
changeset
|
47 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:
605
diff
changeset
|
48 static DCfloat valueFloat [MAXARGS]; |
0 | 49 |
50 | |
51 void clearValues(); | |
52 | |
53 void error(const char* message) | |
54 { | |
55 fprintf(stderr, "error: %s\n", message); | |
56 exit(-1); | |
57 } | |
58 | |
59 void init() | |
60 { | |
61 for (int i = 0 ; i < MAXARGS ; ++i ) { | |
62 | |
63 valueBool[i] = DCbool( (i % 1) ? DC_TRUE : DC_FALSE ); | |
64 valueChar[i] = DCchar(i); | |
65 valueShort[i] = DCshort(i); | |
66 valueInt[i] = DCint(i); | |
67 valueLongLong[i] = DClonglong(i); | |
68 valueDouble[i] = DCdouble(i); | |
69 valuePointer[i] = DCpointer( (ptrdiff_t) i); | |
70 valueFloat[i] = DCfloat(i); | |
71 } | |
72 } | |
73 | |
74 | |
75 bool test(int x) | |
76 { | |
77 bool r = true; | |
78 clearValues(); | |
79 | |
80 DCCallVM* pCall; | |
81 | |
82 funcinfo* fi = &gFuncInfos[x]; | |
83 | |
84 const DCsigchar* sig = &fi->sig[2]; | |
85 const DCsigchar* ptr = sig; | |
86 DCsigchar ch; | |
87 int pos; | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
88 |
0 | 89 pos = 0; |
90 | |
91 pCall = dcNewCallVM(4096); | |
92 dcReset(pCall); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
93 |
0 | 94 while ( (ch=*ptr++) != '\0' ) { |
95 switch(ch) { | |
96 case DC_SIGCHAR_BOOL: dcArgBool ( pCall, valueBool [pos] ); break; | |
97 case DC_SIGCHAR_CHAR: dcArgChar ( pCall, valueChar [pos] ); break; | |
98 case DC_SIGCHAR_SHORT: dcArgShort ( pCall, valueShort [pos] ); break; | |
99 case DC_SIGCHAR_INT: dcArgInt ( pCall, valueInt [pos] ); break; | |
100 case DC_SIGCHAR_LONGLONG: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
101 case DC_SIGCHAR_FLOAT: dcArgFloat ( pCall, valueFloat [pos] ); break; | |
102 case DC_SIGCHAR_DOUBLE: dcArgDouble ( pCall, valueDouble [pos] ); break; | |
103 case DC_SIGCHAR_POINTER: dcArgPointer ( pCall, valuePointer [pos] ); break; | |
104 default: error("unsupported signature character"); break; | |
105 } | |
106 ++pos; | |
107 } | |
108 | |
109 dcCallVoid( pCall, fi->funcptr ); | |
110 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
111 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
112 if ( getId() == x ) { |
0 | 113 |
114 ptr = sig; | |
115 pos = 0; | |
116 while( ( ch=*ptr++ ) != '\0' ) { | |
117 | |
118 switch(ch) { | |
119 case DC_SIGCHAR_BOOL: if ( getArg(pos)->B != valueBool [pos] ) r = false; break; | |
120 case DC_SIGCHAR_CHAR: if ( getArg(pos)->c != valueChar [pos] ) r = false; break; | |
121 case DC_SIGCHAR_SHORT: if ( getArg(pos)->s != valueShort [pos] ) r = false; break; | |
122 case DC_SIGCHAR_INT: if ( getArg(pos)->i != valueInt [pos] ) r = false; break; | |
123 case DC_SIGCHAR_LONGLONG: if ( getArg(pos)->L != valueLongLong [pos] ) r = false; break; | |
124 case DC_SIGCHAR_FLOAT: if ( getArg(pos)->f != valueFloat [pos] ) r = false; break; | |
125 case DC_SIGCHAR_DOUBLE: if ( getArg(pos)->d != valueDouble[pos] ) r = false; break; | |
126 case DC_SIGCHAR_POINTER: if ( getArg(pos)->p != valuePointer [pos] ) r = false; break; | |
127 default: error("unsupported signature character"); break; | |
128 } | |
129 ++pos; | |
130 } | |
131 | |
132 } else { | |
133 r = false; | |
134 } | |
135 | |
136 printf("%d-%s:%d\n", x, sig, r); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
137 |
0 | 138 dcFree(pCall); |
139 | |
140 return r; | |
141 } | |
142 | |
143 | |
144 bool run_range(int from, int to) | |
145 { | |
146 bool r = true; | |
147 for (int i = from ; i < to ; ++i ) | |
148 r &= test(i); | |
149 return r; | |
150 } | |
151 | |
152 extern "C" { | |
153 | |
154 int main(int argc, char* argv[]) | |
155 { | |
156 dcTest_initPlatform(); | |
157 | |
158 bool success = false; | |
159 init(); | |
160 if (argc == 2) { | |
161 int index = atoi(argv[1]); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
162 success = run_range( index, index+1 ); |
0 | 163 } else if (argc == 3) { |
164 int from = atoi(argv[1]); | |
165 int to = atoi(argv[2])+1; | |
166 success = run_range(from,to); | |
167 } else { | |
168 success = run_range(0,NCASES); | |
169 } | |
170 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
171 printf("result: suite2: %d\n", success); |
0 | 172 |
173 dcTest_deInitPlatform(); | |
174 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
175 return !success; |
0 | 176 } |
177 | |
178 } // extern "C" | |
179 |