Mercurial > pub > dyncall > dyncall
annotate test/suite/main.c @ 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/suite/main.c | |
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 <math.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 | |
37 int getId(); | |
38 DCpointer getFunc(int x); | |
39 DCValue* getArg(int pos); | |
40 | |
41 | |
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
|
42 static DCbool valueBool [NARGS]; |
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 [NARGS]; |
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 DCchar valueChar [NARGS]; |
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 DCint valueInt [NARGS]; |
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 DClonglong valueLongLong[NARGS]; |
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 DCdouble valueDouble [NARGS]; |
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 DCpointer valuePointer [NARGS]; |
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
|
49 static DCfloat valueFloat [NARGS]; |
0 | 50 |
51 enum { | |
52 ID_DOUBLE = 0, | |
53 ID_LONGLONG, | |
54 ID_INT, | |
55 ID_POINTER, | |
56 ID_BOOL, | |
57 ID_FLOAT | |
58 }; | |
59 | |
60 DCbool equals(int select, int pos, void* data) | |
61 { | |
62 switch(select) | |
63 { | |
64 case ID_BOOL: return ( getArg(pos)->B == valueBool [pos] ); break; | |
65 case ID_INT: return ( getArg(pos)->i == valueInt [pos] ); break; | |
66 case ID_LONGLONG: return ( getArg(pos)->l == valueLongLong[pos] ); break; | |
67 case ID_DOUBLE: return ( getArg(pos)->d == valueDouble [pos] ); break; | |
68 case ID_POINTER: return ( getArg(pos)->p == valuePointer [pos] ); break; | |
69 case ID_FLOAT: return ( getArg(pos)->f == valueFloat [pos] ); break; | |
70 } | |
71 return DC_FALSE; | |
72 } | |
73 | |
74 | |
75 void clearValues(); | |
76 | |
77 | |
78 void init() | |
79 { | |
80 int i; | |
81 for(i=0; i<NARGS; ++i) | |
82 { | |
83 valueBool[i] = (DCbool)((i % 1) ? DC_TRUE : DC_FALSE); | |
84 valueInt[i] = (DCint) (i); | |
85 valueLongLong[i] = (DClonglong)(i); | |
86 valueDouble[i] = (DCdouble) (i); | |
87 valuePointer[i] = (DCpointer) (ptrdiff_t) (i); | |
88 valueFloat[i] = (DCfloat) (i); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
89 } |
0 | 90 } |
91 | |
92 | |
93 void push(DCCallVM* pCall, int select, int pos) | |
94 { | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
95 switch(select) |
0 | 96 { |
97 case ID_BOOL: dcArgBool ( pCall, valueBool [pos] ); break; | |
98 case ID_INT: dcArgInt ( pCall, valueInt [pos] ); break; | |
99 case ID_LONGLONG: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
100 case ID_DOUBLE: dcArgDouble ( pCall, valueDouble [pos] ); break; | |
101 case ID_POINTER: dcArgPointer ( pCall, valuePointer [pos] ); break; | |
102 case ID_FLOAT: dcArgFloat ( pCall, valueFloat [pos] ); break; | |
103 } | |
104 } | |
105 | |
106 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
107 #define test(x) if (!(x)) return DC_FALSE |
0 | 108 |
109 | |
413
d73dc7ad37e4
- fix nameclash due to a previous and bad cleanup
Tassilo Philipp
parents:
410
diff
changeset
|
110 DCbool test_case(int x) |
0 | 111 { |
112 int y = x; | |
113 int selects[NARGS] = { 0, }; | |
114 int pos, i; | |
115 | |
116 DCCallVM* pCall = dcNewCallVM(4096); | |
117 dcReset(pCall); | |
118 clearValues(); | |
119 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
120 for(pos = 0; y>0; ++pos) |
0 | 121 { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
122 int select = (y-1) % NTYPES; |
0 | 123 selects[pos] = select; |
124 push(pCall,select,pos); | |
125 y = (y-1) / NTYPES; | |
126 } | |
127 dcCallVoid(pCall,getFunc(x)); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
128 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
129 test( getId() == x ); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
130 |
0 | 131 for(i = 0;i<pos;++i) { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
132 test( equals( selects[i], i, getArg(i) ) ); |
0 | 133 } |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
134 |
0 | 135 dcFree(pCall); |
136 return DC_TRUE; | |
137 } | |
138 | |
139 | |
140 int powerfact(int x, int n) | |
141 { | |
142 if(n==0) return 0; | |
143 return (int)(pow((double)x,n)+powerfact(x,n-1)); | |
144 } | |
145 | |
146 | |
147 DCbool run_range(int from, int to) | |
148 { | |
149 DCbool tr = DC_TRUE, r; | |
150 int i; | |
151 for(i=from; i<to; ++i) { | |
152 printf("%d:",i); | |
413
d73dc7ad37e4
- fix nameclash due to a previous and bad cleanup
Tassilo Philipp
parents:
410
diff
changeset
|
153 r = test_case(i); |
0 | 154 printf("%d\n", r); |
155 tr &= r; | |
156 } | |
157 return tr; | |
158 } | |
159 | |
160 | |
161 int main(int argc, char* argv[]) | |
162 { | |
163 DCbool success = DC_FALSE; | |
164 | |
165 dcTest_initPlatform(); | |
166 | |
167 init(); | |
168 if (argc == 2) { | |
169 int index = atoi(argv[1]); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
170 success = run_range( index, index+1 ); |
0 | 171 } else if (argc == 3) { |
172 int from = atoi(argv[1]); | |
173 int to = atoi(argv[2])+1; | |
174 success = run_range(from,to); | |
175 } else { | |
176 int ncalls = powerfact(NTYPES,NARGS)+1; | |
177 success = run_range(0,ncalls); | |
178 } | |
179 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
180 printf("result: suite: %d\n", success); |
0 | 181 |
182 dcTest_deInitPlatform(); | |
183 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
184 return !success; |
0 | 185 } |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
186 |