Skip to content

Commit 9375aae

Browse files
ioannisgcarlescufi
authored andcommitted
tests: kernel: fatal: add a test-case for arbitrary error reason
We add a test-case in kernel/fatal test suite, to test that the application developer can induce a SW-generated exception with any 'reason' value. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent c86073c commit 9375aae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/kernel/fatal/src/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ void alt_thread4(void)
124124
rv = TC_FAIL;
125125
}
126126

127+
void alt_thread5(void)
128+
{
129+
unsigned int key;
130+
131+
expected_reason = INT_MAX;
132+
133+
key = irq_lock();
134+
z_except_reason(INT_MAX);
135+
TC_ERROR("SHOULD NEVER SEE THIS\n");
136+
rv = TC_FAIL;
137+
irq_unlock(key);
138+
}
139+
127140
#ifndef CONFIG_ARCH_POSIX
128141
#ifdef CONFIG_STACK_SENTINEL
129142
void blow_up_stack(void)
@@ -297,6 +310,14 @@ void test_fatal(void)
297310
k_thread_abort(&alt_thread);
298311
zassert_not_equal(rv, TC_FAIL, "thread was not aborted");
299312

313+
TC_PRINT("test alt thread 5: initiate arbitrary SW exception\n");
314+
k_thread_create(&alt_thread, alt_stack,
315+
K_THREAD_STACK_SIZEOF(alt_stack),
316+
(k_thread_entry_t)alt_thread5,
317+
NULL, NULL, NULL, K_PRIO_COOP(PRIORITY), 0,
318+
K_NO_WAIT);
319+
k_thread_abort(&alt_thread);
320+
zassert_not_equal(rv, TC_FAIL, "thread was not aborted");
300321

301322
#ifndef CONFIG_ARCH_POSIX
302323

0 commit comments

Comments
 (0)