e244d4978a855fd82db72f30ea50a902e5c8234c
[fw/sdcc] / support / regression / tests / staticinit.c
1 /** Tests that the static initialiser code works.
2     As the init code is now clever we have to be careful.
3
4     type: char, int, long
5 */
6 #include <testfwk.h>
7
8 static {type} smallDense[] = {
9     1, 2, 3, 4, 5, 6
10 };
11
12 static void
13 testSmallDense(void)
14 {
15     ASSERT(smallDense[0] == 1);
16     ASSERT(smallDense[1] == 2);
17     ASSERT(smallDense[2] == 3);
18     ASSERT(smallDense[3] == 4);
19     ASSERT(smallDense[4] == 5);
20     ASSERT(smallDense[5] == 6);
21 }
22
23 #ifdef __mcs51
24 idata
25 #endif
26 static {type} smallSparse[] = {
27     1, 1, 1, 1, 1, 1, 1, 1, 1
28 };
29
30 static void
31 testSmallSparse(void)
32 {
33     ASSERT(smallSparse[0] == 1);
34     ASSERT(smallSparse[1] == 1);
35     ASSERT(smallSparse[2] == 1);
36     ASSERT(smallSparse[3] == 1);
37     ASSERT(smallSparse[4] == 1);
38     ASSERT(smallSparse[5] == 1);
39     ASSERT(smallSparse[6] == 1);
40     ASSERT(smallSparse[7] == 1);
41     ASSERT(smallSparse[8] == 1);
42 }
43
44 #ifdef __mcs51
45 idata
46 #endif
47 static {type} smallSparseZero[] = {
48     0, 0, 0, 0, 0, 0, 0, 0, 0
49 };
50
51 static {type} smallSparseZeroTail[] = {
52     1, 2, 3
53 };
54
55 static void
56 testSmallSparseZero(void)
57 {
58     ASSERT(smallSparseZero[0] == 0);
59     ASSERT(smallSparseZero[1] == 0);
60     ASSERT(smallSparseZero[2] == 0);
61     ASSERT(smallSparseZero[3] == 0);
62     ASSERT(smallSparseZero[4] == 0);
63     ASSERT(smallSparseZero[5] == 0);
64     ASSERT(smallSparseZero[6] == 0);
65     ASSERT(smallSparseZero[7] == 0);
66     ASSERT(smallSparseZero[8] == 0);
67
68     // Make the compiler happy
69     ASSERT(smallSparseZeroTail[0] == 1);
70 }
71
72 #ifdef __mcs51
73 xdata
74 #endif
75 static {type} largeMixed[] = {
76     1, 2, 3, 4, 5, 6, 7,        /* 0-6 */
77     1, 1, 1, 1, 1, 1, 1, 1,
78     1, 1, 1, 1, 1, 1, 1, 1,
79     1, 1, 1, 1, 1, 1, 1, 1,
80     1, 1, 1, 1, 1, 1, 1, 1,
81     1, 1, 1, 1, 1, 1, 1, 1,
82     1, 1, 1, 1, 1, 1, 1, 1,
83     1, 1, 1, 1, 1, 1, 1, 1,
84     1, 1, 1, 1, 1, 1, 1, 1,
85     1, 1, 1, 1, 1, 1, 1, 1,
86     1, 1, 1, 1, 1, 1, 1, 1,
87     1, 1, 1, 1, 1, 1, 1, 1,
88     1, 1, 1, 1, 1, 1, 1, 1,
89     1, 1, 1, 1, 1, 1, 1, 1,
90     1, 1, 1, 1, 1, 1, 1, 1,     /* 8*12 = 96+7 = -102 */
91     1, 1, 1, 1, 1, 1, 1, 1,
92     1, 1, 1, 1, 1, 1, 1, 1,
93     1, 1, 1, 1, 1, 1, 1, 1,
94     3, 4, 5, 6, 3, 4, 5, 6,     /* 8*17 = 136+7 */
95     3, 4, 5, 6, 3, 4, 5, 6,
96     3, 4, 5, 6, 3, 4, 5, 6,
97     3, 4, 5, 6, 3, 4, 5, 6,
98     3, 4, 5, 6, 3, 4, 5, 6,
99     3, 4, 5, 6, 3, 4, 5, 6,
100     3, 4, 5, 6, 3, 4, 5, 6,
101     3, 4, 5, 6, 3, 4, 5, 6,
102     3, 4, 5, 6, 3, 4, 5, 6,
103     3, 4, 5, 6, 3, 4, 5, 6,
104     3, 4, 5, 6, 3, 4, 5, 6,
105     3, 4, 5, 6, 3, 4, 5, 6,
106     3, 4, 5, 6, 3, 4, 5, 6,
107     3, 4, 5, 6, 3, 4, 5, 6,
108     3, 4, 5, 6, 3, 4, 5, 6,
109     3, 4, 5, 6, 3, 4, 5, 6,
110     3, 4, 5, 6, 3, 4, 5, 6
111 };
112
113 static void
114 testLargeMixed(void)
115 {
116     ASSERT(largeMixed[0] == 1);
117     ASSERT(largeMixed[1] == 2);
118     ASSERT(largeMixed[7] == 1);
119     ASSERT(largeMixed[102] == 1);
120     ASSERT(largeMixed[143] == 3);
121     ASSERT(largeMixed[143+8] == 3);
122     ASSERT(largeMixed[143+16] == 3);
123     ASSERT(largeMixed[143+1] == 4);
124     ASSERT(largeMixed[143+8+1] == 4);
125     ASSERT(largeMixed[143+16+1] == 4);
126 }