Imported Upstream version 2.9.0
[debian/cc1111] / 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
7 #include <testfwk.h>
8
9 /*--------------------------------------------------
10    regression test for #1864582:
11    multiple definition of char cons w. --model-large
12    compile-time test only */
13 char *c = (char *) "Booting";
14 /*------------------------------------------------*/
15
16 static {type} smallDense[] = {
17     1, 2, 3, 4, 5, 6
18 };
19
20 static void
21 testSmallDense(void)
22 {
23     ASSERT(smallDense[0] == 1);
24     ASSERT(smallDense[1] == 2);
25     ASSERT(smallDense[2] == 3);
26     ASSERT(smallDense[3] == 4);
27     ASSERT(smallDense[4] == 5);
28     ASSERT(smallDense[5] == 6);
29 }
30
31 #ifdef SDCC_mcs51
32 idata at 0xa0   /* leave space for the stack */
33 #endif
34 static {type} smallSparse[] = {
35     1, 1, 1, 1, 1, 1, 1, 1, 1
36 };
37
38 static void
39 testSmallSparse(void)
40 {
41     ASSERT(smallSparse[0] == 1);
42     ASSERT(smallSparse[1] == 1);
43     ASSERT(smallSparse[2] == 1);
44     ASSERT(smallSparse[3] == 1);
45     ASSERT(smallSparse[4] == 1);
46     ASSERT(smallSparse[5] == 1);
47     ASSERT(smallSparse[6] == 1);
48     ASSERT(smallSparse[7] == 1);
49     ASSERT(smallSparse[8] == 1);
50 }
51
52 #ifdef SDCC_mcs51
53 idata at 0xd0
54 #endif
55 static {type} smallSparseZero[] = {
56     0, 0, 0, 0, 0, 0, 0, 0, 0
57 };
58
59 static {type} smallSparseZeroTail[] = {
60     1, 2, 3
61 };
62
63 static void
64 testSmallSparseZero(void)
65 {
66     ASSERT(smallSparseZero[0] == 0);
67     ASSERT(smallSparseZero[1] == 0);
68     ASSERT(smallSparseZero[2] == 0);
69     ASSERT(smallSparseZero[3] == 0);
70     ASSERT(smallSparseZero[4] == 0);
71     ASSERT(smallSparseZero[5] == 0);
72     ASSERT(smallSparseZero[6] == 0);
73     ASSERT(smallSparseZero[7] == 0);
74     ASSERT(smallSparseZero[8] == 0);
75
76     // Make the compiler happy
77     ASSERT(smallSparseZeroTail[0] == 1);
78 }
79
80 #ifdef SDCC_mcs51
81 xdata
82 #elif SDCC_pic16
83 code
84 #endif
85 static {type} largeMixed[] = {
86     1, 2, 3, 4, 5, 6, 7,        /* 0-6 */
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,
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     1, 1, 1, 1, 1, 1, 1, 1,
95     1, 1, 1, 1, 1, 1, 1, 1,
96     1, 1, 1, 1, 1, 1, 1, 1,
97     1, 1, 1, 1, 1, 1, 1, 1,
98     1, 1, 1, 1, 1, 1, 1, 1,
99     1, 1, 1, 1, 1, 1, 1, 1,
100     1, 1, 1, 1, 1, 1, 1, 1,     /* 8*12 = 96+7 = -102 */
101     1, 1, 1, 1, 1, 1, 1, 1,
102     1, 1, 1, 1, 1, 1, 1, 1,
103     1, 1, 1, 1, 1, 1, 1, 1,
104     3, 4, 5, 6, 3, 4, 5, 6,     /* 8*17 = 136+7 */
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     3, 4, 5, 6, 3, 4, 5, 6,
112     3, 4, 5, 6, 3, 4, 5, 6,
113     3, 4, 5, 6, 3, 4, 5, 6,
114     3, 4, 5, 6, 3, 4, 5, 6,
115     3, 4, 5, 6, 3, 4, 5, 6,
116     3, 4, 5, 6, 3, 4, 5, 6,
117     3, 4, 5, 6, 3, 4, 5, 6,
118     3, 4, 5, 6, 3, 4, 5, 6,
119     3, 4, 5, 6, 3, 4, 5, 6,
120     3, 4, 5, 6, 3, 4, 5, 6
121 };
122
123 static void
124 testLargeMixed(void)
125 {
126     ASSERT(largeMixed[0] == 1);
127     ASSERT(largeMixed[1] == 2);
128     ASSERT(largeMixed[7] == 1);
129     ASSERT(largeMixed[102] == 1);
130     ASSERT(largeMixed[143] == 3);
131     ASSERT(largeMixed[143+8] == 3);
132     ASSERT(largeMixed[143+16] == 3);
133     ASSERT(largeMixed[143+1] == 4);
134     ASSERT(largeMixed[143+8+1] == 4);
135     ASSERT(largeMixed[143+16+1] == 4);
136 }