|
18 | 18 | * |
19 | 19 | */ |
20 | 20 |
|
21 | | -static int constructor_value; |
| 21 | +static int constructor_number; |
| 22 | +static int constructor_values[3]; |
22 | 23 |
|
23 | | -#define CONSTRUCTOR_VALUE 1 |
| 24 | +void __attribute__((__constructor__)) __constructor_init(void) |
| 25 | +{ |
| 26 | + constructor_values[constructor_number++] = 31415; |
| 27 | +} |
| 28 | + |
| 29 | +void __attribute__((__constructor__(101))) __constructor_init_priority_101(void) |
| 30 | +{ |
| 31 | + constructor_values[constructor_number++] = 101; |
| 32 | +} |
24 | 33 |
|
25 | | -void |
26 | | -__attribute__((__constructor__)) |
27 | | -__constructor_init(void) |
| 34 | +void __attribute__((__constructor__(1000))) __constructor_init_priority_1000(void) |
28 | 35 | { |
29 | | - constructor_value = CONSTRUCTOR_VALUE; |
| 36 | + constructor_values[constructor_number++] = 1000; |
30 | 37 | } |
31 | 38 |
|
32 | 39 | ZTEST(constructor, test_constructor) |
33 | 40 | { |
34 | | - zassert_equal(constructor_value, CONSTRUCTOR_VALUE, |
35 | | - "constructor test failed: constructor not called"); |
| 41 | + zassert_equal(constructor_number, 3, |
| 42 | + "constructor test failed: constructor missing"); |
| 43 | + zassert_equal(constructor_values[0], 101, |
| 44 | + "constructor priority test failed:" |
| 45 | + "constructor 101 not called first"); |
| 46 | + zassert_equal(constructor_values[1], 1000, |
| 47 | + "constructor priority test failed:" |
| 48 | + "constructor 1000 not called second"); |
| 49 | + zassert_equal(constructor_values[2], 31415, |
| 50 | + "constructor priority test failed:" |
| 51 | + "constructor without priority not called last"); |
36 | 52 | } |
37 | 53 |
|
38 | 54 | extern void *common_setup(void); |
|
0 commit comments