llext: tests: re-initialize variables
Some tests depend on global initialized variables, which are then modified during the test. When enabling user mode, the functions are called multiple times but the variables are not reinitialized, resulting in a test failure. This patch adds a run_id variable to the tests to reinitialize the variables when the test is called multiple times. It is purposefully initialized to 41 at startup to detect if the variable is not set up properly by the llext loader. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
parent
42a0d18ecf
commit
d25563f59a
2 changed files with 36 additions and 0 deletions
|
|
@ -18,8 +18,24 @@ int number = 0x42;
|
|||
extern int ext_number;
|
||||
int ext_sum_fn(int arg);
|
||||
|
||||
int run_id = 41;
|
||||
|
||||
void test_entry(void)
|
||||
{
|
||||
switch (run_id) {
|
||||
case 41:
|
||||
/* initial run: test variable initialization */
|
||||
break;
|
||||
case 42:
|
||||
/* user-mode run: reinit number */
|
||||
number = 0x42;
|
||||
break;
|
||||
default:
|
||||
/* possible llext loader issue */
|
||||
zassert_unreachable("unexpected run_id %d", run_id);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("initial: local %d plus external %d equals %d\n",
|
||||
number, ext_number, ext_sum_fn(ext_number));
|
||||
zassert_equal(number, 0x42);
|
||||
|
|
@ -31,5 +47,7 @@ void test_entry(void)
|
|||
zassert_equal(ext_number, 0x42);
|
||||
printk("updated: local %d plus external %d equals %d\n",
|
||||
number, ext_number, ext_sum_fn(ext_number));
|
||||
|
||||
run_id += 1;
|
||||
}
|
||||
LL_EXTENSION_SYMBOL(test_entry);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,24 @@
|
|||
int number = 42;
|
||||
const char *string = "hello";
|
||||
|
||||
int run_id = 41;
|
||||
|
||||
void test_entry(void)
|
||||
{
|
||||
switch (run_id) {
|
||||
case 41:
|
||||
/* initial run: test variable initialization */
|
||||
break;
|
||||
case 42:
|
||||
/* user-mode run: reinit number */
|
||||
number = 42;
|
||||
break;
|
||||
default:
|
||||
/* possible llext loader issue */
|
||||
zassert_unreachable("unexpected run_id %d", run_id);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("number: %d\n", number);
|
||||
zassert_equal(number, 42);
|
||||
number = 0;
|
||||
|
|
@ -26,5 +42,7 @@ void test_entry(void)
|
|||
zassert_equal(number, 0);
|
||||
printk("string: %s\n", string);
|
||||
zassert_ok(strcmp(string, "hello"));
|
||||
|
||||
run_id += 1;
|
||||
}
|
||||
LL_EXTENSION_SYMBOL(test_entry);
|
||||
|
|
|
|||
Loading…
Reference in a new issue