annotate test/call_suite_aggrs/globals.c @ 515:c9c546f8598b

- added _Bool type to call_suite* tests
author Tassilo Philipp
date Sun, 10 Apr 2022 21:05:33 +0200
parents 29d09d10ecd9
children d60f741e5eae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
1 /*
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
2
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
3 Package: dyncall
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
4 Library: test
485
0c68b3f91367 - renamed suite_aggrs to call_suite_aggrs for consistency (callback version will be called callback_suite_aggrs)
Tassilo Philipp
parents: 482
diff changeset
5 File: test/call_suite_aggrs/globals.c
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
6 Description:
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
7 License:
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
8
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
9 Copyright (c) 2022 Tassilo Philipp <tphilipp@potion-studios.com>
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
10
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
11 Permission to use, copy, modify, and distribute this software for any
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
12 purpose with or without fee is hereby granted, provided that the above
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
13 copyright notice and this permission notice appear in all copies.
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
14
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
22
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
23 */
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
24
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
25 #include <stdlib.h>
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
26 #include "globals.h"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
27 #include <float.h>
459
8b6a39592f86 missed an include
Tassilo Philipp
parents: 458
diff changeset
28 #include <string.h>
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
29
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
30 #define X(CH,T) T *V_##CH; T *K_##CH;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
31 DEF_TYPES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
32 #undef X
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
33
482
0f3b6898078d suite_aggrs (still ahead of checked in version of dyncall, sorry):
Tassilo Philipp
parents: 459
diff changeset
34 #define AGGR_MISALIGN 1
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
35
457
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
36 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); }
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
37
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
38 /* fill mem with random values, make sure no float aligned memory location
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
39 * results in a NaN, as they always compare to false; so avaid all ones in
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
40 * exporent (for simplicity we just look at first 7 exponent bits and make sure
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
41 * they aren't all set, which would work for all IEEE754 precision formats) */
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
42 static void rand_mem__fp_friendly(void* p, size_t s)
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
43 {
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
44 int i;
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
45 for(i = 0; i<s; ++i) {
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
46 char* c = (char*)p;
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
47 c[i] = (char)rand(); /* slowish, byte by byte, but whatev */
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
48 if((c[i]&0x7f) == 0x7f)
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
49 c[i] ^= 1;
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
50 }
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
51 }
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
52
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
53 int get_max_aggr_size()
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
54 {
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
55 static int s = 0;
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
56 int i;
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
57 if(s == 0) {
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
58 for(i=0; i<G_naggs; ++i)
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
59 if(G_agg_sizes[i] > s)
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
60 s = G_agg_sizes[i];
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
61 }
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
62 return s;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
63 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
64
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
65 void init_test_data()
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
66 {
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
67 int i;
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
68 int maxaggrsize = get_max_aggr_size();
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
69 #define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1));
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
70 DEF_TYPES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
71 #undef X
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
72
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
73 for(i=0;i<G_maxargs+1;++i) {
515
c9c546f8598b - added _Bool type to call_suite* tests
Tassilo Philipp
parents: 492
diff changeset
74 K_B[i] = (DCbool) ((int)rand_d() & 1);
492
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
75 K_c[i] = (char) (((rand_d()-0.5)*2) * (1<<7));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
76 K_s[i] = (short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
77 K_i[i] = (int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
78 K_j[i] = (long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
79 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
80 K_C[i] = (unsigned char) (((rand_d()-0.5)*2) * (1<<7));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
81 K_S[i] = (unsigned short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
82 K_I[i] = (unsigned int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
83 K_J[i] = (unsigned long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
84 K_L[i] = (unsigned long long)(((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
85 K_p[i] = (void*)(long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1)));
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
86 K_f[i] = (float) (rand_d() * FLT_MAX);
29d09d10ecd9 - added unsigned types to call_suite_aggrs
Tassilo Philipp
parents: 485
diff changeset
87 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX);
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
88 K_a[i] = malloc(maxaggrsize+AGGR_MISALIGN);
457
90b1d927912a - suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
Tassilo Philipp
parents: 450
diff changeset
89 rand_mem__fp_friendly(K_a[i], maxaggrsize+AGGR_MISALIGN);
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
90 K_a[i] = (char*)K_a[i]+AGGR_MISALIGN;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
91 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
92 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
93
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
94 void clear_V()
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
95 {
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
96 static int aggr_init = 0;
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
97 int maxaggrsize = get_max_aggr_size();
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
98
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
99 int i;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
100 for(i=0;i<G_maxargs+1;++i) {
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
101 if(aggr_init)
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
102 free((char*)V_a[i]-AGGR_MISALIGN);
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
103 #define X(CH,T) V_##CH[i] = (T) 0;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
104 DEF_TYPES
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
105 #undef X
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
106 V_a[i] = malloc(maxaggrsize+AGGR_MISALIGN);
458
1c18c2377c24 suite_aggr:
Tassilo Philipp
parents: 457
diff changeset
107 memset(V_a[i], 0, maxaggrsize+AGGR_MISALIGN);
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
108 V_a[i] = (char*)V_a[i]+AGGR_MISALIGN;
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
109 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
110 aggr_init = 1;
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
111 }
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
112
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
113 void deinit_test_data()
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
114 {
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
115 int i;
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
116 for(i=0;i<G_maxargs+1;++i) {
439
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
117 free((char*)V_a[i]-AGGR_MISALIGN);
252f32fa59d8 - suite_aggrs: added compile time knob to enforce intentional struct instance misalignment (should maybe be part of generator)
Tassilo Philipp
parents: 438
diff changeset
118 free((char*)K_a[i]-AGGR_MISALIGN);
438
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
119 }
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
120
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
121 #define X(CH,T) free(V_##CH); free(K_##CH);
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
122 DEF_TYPES
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
123 #undef X
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
124 }
b4ddad459690 suite_aggr;
Tassilo Philipp
parents: 432
diff changeset
125