small changes for mcs51
[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
69 #ifdef __mcs51
70 xdata
71 #endif
72 static {type} largeMixed[] = {
73     1, 2, 3, 4, 5, 6, 7,        /* 0-6 */
74     1, 1, 1, 1, 1, 1, 1, 1,
75     1, 1, 1, 1, 1, 1, 1, 1,
76     1, 1, 1, 1, 1, 1, 1, 1,
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,     /* 8*12 = 96+7 = -102 */
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     3, 4, 5, 6, 3, 4, 5, 6,     /* 8*17 = 136+7 */
92     3, 4, 5, 6, 3, 4, 5, 6,
93     3, 4, 5, 6, 3, 4, 5, 6,
94     3, 4, 5, 6, 3, 4, 5, 6,
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 };
109
110 static void
111 testLargeMixed(void)
112 {
113     ASSERT(largeMixed[0] == 1);
114     ASSERT(largeMixed[1] == 2);
115     ASSERT(largeMixed[7] == 1);
116     ASSERT(largeMixed[102] == 1);
117     ASSERT(largeMixed[143] == 3);
118     ASSERT(largeMixed[143+8] == 3);
119     ASSERT(largeMixed[143+16] == 3);
120     ASSERT(largeMixed[143+1] == 4);
121     ASSERT(largeMixed[143+8+1] == 4);
122     ASSERT(largeMixed[143+16+1] == 4);
123 }