tests/kernel: Validate constructor execution order
Check the order of constructors, making sure those with a specified priority are called in numeric order after which those without priority are called. Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
9398174340
commit
db49cd3899
1 changed files with 25 additions and 9 deletions
|
@ -18,21 +18,37 @@
|
|||
*
|
||||
*/
|
||||
|
||||
static int constructor_value;
|
||||
static int constructor_number;
|
||||
static int constructor_values[3];
|
||||
|
||||
#define CONSTRUCTOR_VALUE 1
|
||||
|
||||
void
|
||||
__attribute__((__constructor__))
|
||||
__constructor_init(void)
|
||||
void __attribute__((__constructor__)) __constructor_init(void)
|
||||
{
|
||||
constructor_value = CONSTRUCTOR_VALUE;
|
||||
constructor_values[constructor_number++] = 31415;
|
||||
}
|
||||
|
||||
void __attribute__((__constructor__(101))) __constructor_init_priority_101(void)
|
||||
{
|
||||
constructor_values[constructor_number++] = 101;
|
||||
}
|
||||
|
||||
void __attribute__((__constructor__(1000))) __constructor_init_priority_1000(void)
|
||||
{
|
||||
constructor_values[constructor_number++] = 1000;
|
||||
}
|
||||
|
||||
ZTEST(constructor, test_constructor)
|
||||
{
|
||||
zassert_equal(constructor_value, CONSTRUCTOR_VALUE,
|
||||
"constructor test failed: constructor not called");
|
||||
zassert_equal(constructor_number, 3,
|
||||
"constructor test failed: constructor missing");
|
||||
zassert_equal(constructor_values[0], 101,
|
||||
"constructor priority test failed:"
|
||||
"constructor 101 not called first");
|
||||
zassert_equal(constructor_values[1], 1000,
|
||||
"constructor priority test failed:"
|
||||
"constructor 1000 not called second");
|
||||
zassert_equal(constructor_values[2], 31415,
|
||||
"constructor priority test failed:"
|
||||
"constructor without priority not called last");
|
||||
}
|
||||
|
||||
extern void *common_setup(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue