Mercurial > pub > dyncall > dyncall
annotate test/suite_floats/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 | d73dc7ad37e4 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/suite_floats/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:
413
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 | |
56
2cccd38e5e4d
- added -lm in GNU/kFreeBSD config, to build all tests out of the box
cslag
parents:
0
diff
changeset
|
37 int getId(); |
0 | 38 DCpointer getFunc(int x); |
56
2cccd38e5e4d
- added -lm in GNU/kFreeBSD config, to build all tests out of the box
cslag
parents:
0
diff
changeset
|
39 DCValue* getArg(int pos); |
0 | 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:
413
diff
changeset
|
41 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:
413
diff
changeset
|
42 static DCfloat valueFloat [NARGS]; |
0 | 43 |
44 | |
45 bool equals(int select, int pos, void* data) | |
46 { | |
47 switch(select) | |
48 { | |
49 case 0: return ( getArg(pos)->d == valueDouble [pos] ); break; | |
50 case 1: return ( getArg(pos)->f == valueFloat [pos] ); break; | |
51 } | |
52 return false; | |
53 } | |
54 | |
55 | |
56 void clearValues(); | |
57 | |
58 | |
59 void init() | |
60 { | |
61 for (int i = 0 ; i < NARGS ; ++i ) { | |
62 valueDouble[i] = DCdouble(i); | |
63 valueFloat[i] = DCfloat(i); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
64 } |
0 | 65 } |
66 | |
67 | |
68 void push(DCCallVM* pCall, int select, int pos) | |
69 { | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
70 switch(select) |
0 | 71 { |
72 case 0: dcArgDouble ( pCall, valueDouble [pos] ); break; | |
73 case 1: dcArgFloat ( pCall, valueFloat [pos] ); break; | |
74 } | |
75 } | |
76 | |
77 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
78 #define test(x) if (!(x)) return false |
0 | 79 |
80 | |
413
d73dc7ad37e4
- fix nameclash due to a previous and bad cleanup
Tassilo Philipp
parents:
410
diff
changeset
|
81 bool test_case(int x) |
0 | 82 { |
83 clearValues(); | |
84 | |
85 DCCallVM* pCall = dcNewCallVM(4096); | |
86 dcReset(pCall); | |
87 int y = x; | |
88 int selects[NARGS] = { 0, }; | |
89 int pos = 0; | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
90 for(pos = 0;y>0;++pos) |
0 | 91 { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
92 int select = (y-1) % NTYPES; |
0 | 93 selects[pos] = select; |
94 push(pCall,select,pos); | |
95 y = (y-1) / NTYPES; | |
96 } | |
97 dcCallVoid(pCall,getFunc(x)); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
98 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
99 test( getId() == x ); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
100 |
0 | 101 for(int i = 0;i<pos;++i) { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
102 test( equals( selects[i], i, getArg(i) ) ); |
0 | 103 } |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
104 |
0 | 105 dcFree(pCall); |
106 return true; | |
107 } | |
108 | |
109 | |
110 int powerfact(int x, int n) | |
111 { | |
112 if (n==0) return 0; | |
113 return static_cast<int>( pow((double)x,n)+powerfact(x,n-1) ); | |
114 } | |
115 | |
116 | |
117 bool run_range(int from, int to) | |
118 { | |
119 bool tr = true; | |
120 for (int i = from ; i < to ; ++i ) { | |
121 printf("%d:",i); | |
413
d73dc7ad37e4
- fix nameclash due to a previous and bad cleanup
Tassilo Philipp
parents:
410
diff
changeset
|
122 bool r = test_case(i); |
0 | 123 printf("%d\n", r); |
124 tr &= r; | |
125 } | |
126 return tr; | |
127 } | |
128 | |
129 extern "C" { | |
130 | |
131 int main(int argc, char* argv[]) | |
132 { | |
133 dcTest_initPlatform(); | |
134 | |
135 bool success = false; | |
136 init(); | |
137 if (argc == 2) { | |
138 int index = atoi(argv[1]); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
139 success = run_range( index, index+1 ); |
0 | 140 } else if (argc == 3) { |
141 int from = atoi(argv[1]); | |
142 int to = atoi(argv[2])+1; | |
143 success = run_range(from,to); | |
144 } else { | |
145 int ncalls = powerfact(NTYPES,NARGS)+1; | |
146 success = run_range(0,ncalls); | |
147 } | |
148 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
149 printf("result: suite_floats: %d\n", success); |
0 | 150 |
151 dcTest_deInitPlatform(); | |
152 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
153 return !success; |
0 | 154 } |
155 | |
156 } // extern "C" | |
157 |