struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / stack-restore.c.in
blob5389b02e8e67e5e599c67c523f119d0900e9de08
1 /** Check stack restore optimizations for STM8.
2 Should work ok for all other ports as long as enough memory is available for the tests.
3 Check with all levels of optimization (speed, size and balanced).
5 optSize: -1, 0, 1
6 */
8 #include <testfwk.h>
9 #ifdef __sun__
10 #include <inttypes.h>
11 #else
12 #include <stdint.h>
13 #endif
15 #define OPT_SIZE ({optSize})
17 #if OPT_SIZE == -1
18 #pragma opt_code_speed
19 #elif OPT_SIZE == 1
20 #pragma opt_code_size
21 #else
22 #pragma opt_code_balanced
23 #endif
26 // Test for size = 1 byte
27 // It must assign global variable from input param and return 0
28 // The case for STM8 can be triggered by a local array of size 1 or a local volatile
29 static volatile char globalValue;
30 uint8_t
31 stack_restore_test_byte(const char s)
33 char a[1];
34 a[0] = s;
35 globalValue = a[0];
36 //volatile char dummy;
37 //dummy = s;
38 //globalValue = s;
39 return 0;
42 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_pic14) // Lack of memory
43 #if !( (defined (__SDCC_mos6502) || defined(__SDCC_mos65c02 )) && defined(__SDCC_STACK_AUTO) ) // stack too msall
44 // Test for size = 2 bytes
45 // Big stack needed (>256 bytes)
46 // Should assert ok 256 times
47 // Returns number of cases ok for double check
48 #define stack_restore_test_word test_stack_restore_word
50 uint16_t
51 stack_restore_test_word(void)
53 uint16_t x[256];
54 int i;
55 uint16_t casesOk = 0;
57 for (i = 0; i < 256; i++)
59 x[i] = i;
61 for (i = 0; i < 256; i++)
63 ASSERT (x[i] == i);
64 casesOk += x[i] == i;
66 return casesOk;
68 #endif
69 #endif
71 static void
72 testStackRestore(void)
74 globalValue = 0;
75 ASSERT(stack_restore_test_byte(0x5C) == 0);
76 ASSERT(globalValue == 0x5C);
78 #ifdef stack_restore_test_word
79 ASSERT(stack_restore_test_word() == 256);
80 #endif