Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/Panama/panamatest.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2017, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
24
#include "stdio.h"
25
#include "stdbool.h"
26
#include "stdlib.h"
27
28
typedef struct {
29
int x;
30
int y;
31
} Point;
32
33
typedef struct {
34
Point st;
35
Point en;
36
} Line;
37
38
typedef struct {
39
Point v;
40
int n;
41
} ScalarVector;
42
43
typedef struct {
44
char *n;
45
Point v;
46
} PointerVector;
47
48
typedef struct {
49
char *m;
50
char *n;
51
} PointerPointer;
52
53
typedef struct {
54
int64_t a;
55
double b;
56
} Complex;
57
58
typedef struct {
59
int64_t x;
60
int32_t y;
61
/* there will be 32bits of padding here */
62
int64_t z;
63
} Padding;
64
65
typedef struct {
66
char *pc;
67
Point *pp;
68
char **ppc;
69
Point **ppp;
70
} PointerStruct;
71
72
typedef struct {
73
Line triangle[3];
74
int arr[4];
75
} ArrayStruct;
76
77
typedef struct {
78
int8_t n;
79
} SmallStruct;
80
81
typedef struct {
82
char **pp;
83
char *p;
84
int n;
85
void *x;
86
Line *ln;
87
Point pt;
88
int arr[3];
89
double d;
90
} LargeStruct;
91
92
char addTwoByte(char val1, char val2) {
93
return val1 + val2;
94
}
95
96
char addTwoChar(char val1, char val2) {
97
return val1 + val2 - 'a' + 1;
98
}
99
100
double addTwoDouble(double val1, double val2) {
101
return val1 + val2;
102
}
103
104
float addTwoFloat(float val1, float val2) {
105
return val1 + val2;
106
}
107
108
int addTwoInt(int val1, int val2) {
109
return val1 + val2;
110
}
111
112
long addTwoLong(long val1, long val2) {
113
return val1 + val2;
114
}
115
116
short addTwoShort(short val1, short val2) {
117
return val1 + val2;
118
}
119
120
bool testBoolean(bool val1) {
121
return !val1;
122
}
123
124
int returnFour(void) {
125
return 4;
126
}
127
128
void voidWithArgs(int val1) {
129
printf("voidWithArgs(%d) success\n", val1);
130
}
131
132
void voidNoArgs(void) {
133
printf("voidNoArgs success\n");
134
}
135
136
double manyArgs(int val1, float val2, long val3, double val4) {
137
return val3 + val1 * 10 + val2 * 0.1 + val4 * 0.001;
138
}
139
140
int* getIntPtr(void) {
141
int *arr = (int*) malloc(sizeof(int) * 4);
142
arr[0] = 4;
143
arr[1] = 3;
144
arr[2] = 2;
145
arr[3] = 1;
146
return arr;
147
}
148
149
bool checkIntPtr(int *arr) {
150
return (4 == arr[0] && 3 == arr[1] && 2 == arr[2] && 1 == arr[3]);
151
}
152
153
void freeIntPtr(int *arr) {
154
free(arr);
155
}
156
157
Point getPoint(int x, int y) {
158
Point* p = (Point*) malloc(sizeof(Point));
159
p->x = x;
160
p->y = y;
161
return *p;
162
}
163
164
bool checkPoint(Point p, int x, int y) {
165
return (p.x == x && p.y == y);
166
}
167
168
Point* getPointPtr(int x, int y) {
169
Point* p = (Point*) malloc(sizeof(Point));
170
p->x = x;
171
p->y = y;
172
return p;
173
}
174
175
bool checkPointPtr(Point *p, int x, int y) {
176
return (p->x == x && p->y == y);
177
}
178
179
void freePointPtr(Point *p) {
180
free(p);
181
}
182
183
Line getLine(Point st, Point en) {
184
Line* ln = (Line*) malloc(sizeof(Line));
185
ln->st = st;
186
ln->en = en;
187
return *ln;
188
}
189
190
bool checkLine(Line ln, Point st, Point en) {
191
return (ln.st.x == st.x && ln.st.y == st.y && ln.en.x == en.x && ln.en.y == en.y);
192
}
193
194
ScalarVector getScalarVector(int n, Point pt) {
195
ScalarVector* s = (ScalarVector*) malloc(sizeof(ScalarVector));
196
s->n = n;
197
s->v = pt;
198
return *s;
199
}
200
201
bool checkScalarVector(ScalarVector s, int n, Point pt) {
202
return (s.n == n && s.v.x == pt.x && s.v.y == pt.y);
203
}
204
205
PointerVector getPointerVector(char *n, Point pt) {
206
PointerVector* s = (PointerVector*) malloc(sizeof(PointerVector));
207
s->n = n;
208
s->v = pt;
209
return *s;
210
}
211
212
bool checkPointerVector(PointerVector s, char *n, Point pt) {
213
return (0 == strcmp(s.n, n) && s.v.x == pt.x && s.v.y == pt.y);
214
}
215
216
PointerPointer getPointerPointer(char *m, char *n) {
217
PointerPointer* s = (PointerPointer*) malloc(sizeof(PointerPointer));
218
s->m = m;
219
s->n = n;
220
return *s;
221
}
222
223
bool checkPointerPointer(PointerPointer s, char *m, char *n) {
224
return (0 == strcmp(s.m, m) && 0 == strcmp(s.n, n));
225
}
226
227
Complex getComplex(int64_t n, double f) {
228
Complex* s = (Complex*) malloc(sizeof(Complex));
229
s->a = n;
230
s->b = f;
231
return *s;
232
}
233
234
bool checkComplex(Complex s, int64_t n, double f) {
235
return (s.a == n && s.b == f);
236
}
237
238
Padding getPadding(int64_t a, int32_t b, int64_t c) {
239
Padding* s = (Padding*) malloc(sizeof(Padding));
240
s->x = a;
241
s->y = b;
242
s->z = c;
243
return *s;
244
}
245
246
bool checkPadding(Padding s, int64_t a, int32_t b, int64_t c) {
247
return (s.x == a && s.y == b && s.z == c);
248
}
249
250
PointerStruct getPointerStruct(char *pc, Point *pp, char **ppc, Point **ppp) {
251
PointerStruct* s = (PointerStruct*) malloc(sizeof(PointerStruct));
252
s->pc = pc;
253
s->pp = pp;
254
s->ppc = ppc;
255
s->ppp = ppp;
256
return *s;
257
}
258
259
bool checkPointerStruct(PointerStruct s, char *pc, Point pp, char *ppc, Point ppp) {
260
return (0 == strcmp(s.pc, pc) && 0 == strcmp(*(s.ppc), ppc) && s.pp->x == pp.x && s.pp->y == pp.y && (*s.ppp)->x == ppp.x && (*s.ppp)->y == ppp.y);
261
}
262
263
ArrayStruct getArrayStruct(Line ln0, Line ln1, Line ln2, int a0, int a1, int a2, int a3) {
264
ArrayStruct* s = (ArrayStruct*) malloc(sizeof(ArrayStruct));
265
s->triangle[0] = ln0;
266
s->triangle[1] = ln1;
267
s->triangle[2] = ln2;
268
269
s->arr[0] = a0;
270
s->arr[1] = a1;
271
s->arr[2] = a2;
272
s->arr[3] = a3;
273
return *s;
274
}
275
276
bool checkArrayStruct(ArrayStruct s, Line ln0, Line ln1, Line ln2, int a0, int a1, int a2, int a3) {
277
return (s.triangle[0].st.x == ln0.st.x && s.triangle[0].st.y == ln0.st.y && s.triangle[0].en.x == ln0.en.x && s.triangle[0].en.y == ln0.en.y
278
&& s.triangle[1].st.x == ln1.st.x && s.triangle[1].st.y == ln1.st.y && s.triangle[1].en.x == ln1.en.x && s.triangle[1].en.y == ln1.en.y
279
&& s.triangle[2].st.x == ln2.st.x && s.triangle[2].st.y == ln2.st.y && s.triangle[2].en.x == ln2.en.x && s.triangle[2].en.y == ln2.en.y
280
&& s.arr[0] == a0 && s.arr[1] == a1 && s.arr[2] == a2 && s.arr[3] == a3 );
281
}
282
283
SmallStruct getSmallStruct(int8_t n) {
284
SmallStruct* s = (SmallStruct*) malloc(sizeof(SmallStruct));
285
s->n = n;
286
return *s;
287
}
288
289
bool checkSmallStruct(SmallStruct s, int8_t n) {
290
return (s.n == n);
291
}
292
293
LargeStruct getLargeStruct(char *p, int n, Line *ln, Point pt, int a0, int a1, int a2, double d) {
294
LargeStruct* s = (LargeStruct*) malloc(sizeof(LargeStruct));
295
s->pp = (char**) malloc(sizeof(char*));
296
*(s->pp) = p;
297
s->p = p;
298
s->n = n;
299
s->x = (void *) p;
300
s->ln = ln;
301
s->pt = pt;
302
s->arr[0] = a0;
303
s->arr[1] = a1;
304
s->arr[2] = a2;
305
s->d = d;
306
return *s;
307
}
308
309
bool checkLargeStruct(LargeStruct s, char *p, int n, Line ln, Point pt, int a0, int a1, int a2, double d) {
310
return (0 == strcmp(*(s.pp), p) && 0 == strcmp(s.p, p) && s.n == n && s.x == p
311
&& s.ln->st.x == ln.st.x && s.ln->st.y == ln.st.y && s.ln->en.x == ln.en.x && s.ln->en.y == ln.en.y
312
&& s.pt.x == pt.x && s.pt.y == pt.y && s.arr[0] == a0 && s.arr[1] == a1 && s.arr[2] == a2 && s.d == d);
313
}
314
315
Point* getStructArray(void) {
316
Point* p1 = (Point*) malloc(sizeof(Point));
317
Point* p2 = (Point*) malloc(sizeof(Point));
318
p1->x = 2;
319
p1->y = 3;
320
p2->x = 4;
321
p2->y = 6;
322
323
Point* arr = (Point*) malloc(sizeof(Point) * 2);
324
arr[0] = *p1;
325
arr[1] = *p2;
326
return arr;
327
}
328
329
bool checkStructArray(Point *arr) {
330
return (2 == arr[0].x && 3 == arr[0].y && 4 == arr[1].x && 6 == arr[1].y);
331
}
332
333
void freeStructArray(Point *arr) {
334
free(arr);
335
}
336
337