From 116998c677d23ef481aa43616758f57ea72abea6 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 8 Feb 2023 13:26:19 -0800 Subject: [PATCH] tests: kernel: print FAILED when wrong faults caught For some kernel tests, faults and exceptions are expected. They are caught and the test would continue if the reasons for faults are as expected. However, when the unexpected reasons are encountered, the code simply prints a message and calls k_fatal_halt(). When running under twister, these messages are not the expected failed messages so twister will spin till timeout although the execution has already been halted. This adds another printk() before halt to signal twister that the test has failed and bails early. Signed-off-by: Daniel Leung --- tests/kernel/fatal/exception/src/main.c | 3 +++ tests/kernel/fatal/message_capture/src/main.c | 2 ++ tests/kernel/mem_protect/demand_paging/src/main.c | 1 + tests/kernel/mem_protect/mem_map/src/main.c | 3 ++- tests/kernel/mem_protect/mem_protect/src/common.c | 1 + tests/kernel/mem_protect/stackprot/src/main.c | 1 + tests/kernel/mem_protect/userspace/src/main.c | 2 ++ tests/kernel/pipe/pipe/src/test_pipe.c | 1 + tests/kernel/smp/src/main.c | 1 + tests/kernel/threads/dynamic_thread/src/main.c | 2 ++ 10 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/kernel/fatal/exception/src/main.c b/tests/kernel/fatal/exception/src/main.c index 8c2bb897ce9..51b338183e6 100644 --- a/tests/kernel/fatal/exception/src/main.c +++ b/tests/kernel/fatal/exception/src/main.c @@ -52,17 +52,20 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) if (expected_reason == -1) { printk("Was not expecting a crash\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } if (k_current_get() != &alt_thread) { printk("Wrong thread crashed\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } if (reason != expected_reason) { printk("Wrong crash type got %d expected %d\n", reason, expected_reason); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } diff --git a/tests/kernel/fatal/message_capture/src/main.c b/tests/kernel/fatal/message_capture/src/main.c index 13379e70f48..a9f8519c1d1 100644 --- a/tests/kernel/fatal/message_capture/src/main.c +++ b/tests/kernel/fatal/message_capture/src/main.c @@ -17,12 +17,14 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) if (expected_reason == -1) { printk("Was not expecting a crash\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } if (reason != expected_reason) { printk("Wrong crash type got %d expected %d\n", reason, expected_reason); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } diff --git a/tests/kernel/mem_protect/demand_paging/src/main.c b/tests/kernel/mem_protect/demand_paging/src/main.c index e6dc71397bd..ed90e0fbe97 100644 --- a/tests/kernel/mem_protect/demand_paging/src/main.c +++ b/tests/kernel/mem_protect/demand_paging/src/main.c @@ -72,6 +72,7 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) ztest_test_pass(); } else { printk("Unexpected fault during test"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } diff --git a/tests/kernel/mem_protect/mem_map/src/main.c b/tests/kernel/mem_protect/mem_map/src/main.c index 07c5cb2f341..6db32356440 100644 --- a/tests/kernel/mem_protect/mem_map/src/main.c +++ b/tests/kernel/mem_protect/mem_map/src/main.c @@ -38,7 +38,8 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) expect_fault = false; ztest_test_pass(); } else { - printk("Unexpected fault during test"); + printk("Unexpected fault during test\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } diff --git a/tests/kernel/mem_protect/mem_protect/src/common.c b/tests/kernel/mem_protect/mem_protect/src/common.c index 4fa016f514f..3a89e45a15a 100644 --- a/tests/kernel/mem_protect/mem_protect/src/common.c +++ b/tests/kernel/mem_protect/mem_protect/src/common.c @@ -20,6 +20,7 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) post_fatal_error_handler(reason, pEsf); } else { printk("fatal error was unexpected, aborting\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } diff --git a/tests/kernel/mem_protect/stackprot/src/main.c b/tests/kernel/mem_protect/stackprot/src/main.c index 6a74b83b524..b73af140925 100644 --- a/tests/kernel/mem_protect/stackprot/src/main.c +++ b/tests/kernel/mem_protect/stackprot/src/main.c @@ -19,6 +19,7 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) { if (reason != K_ERR_STACK_CHK_FAIL) { printk("wrong error type\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index 33c14d83709..07cc58f64c2 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -76,10 +76,12 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) } else { printk("Wrong fault reason, expecting %d\n", expected_reason); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } else { printk("Unexpected fault during test\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } diff --git a/tests/kernel/pipe/pipe/src/test_pipe.c b/tests/kernel/pipe/pipe/src/test_pipe.c index 2ad23a2091e..37cb78fb0b1 100644 --- a/tests/kernel/pipe/pipe/src/test_pipe.c +++ b/tests/kernel/pipe/pipe/src/test_pipe.c @@ -681,6 +681,7 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) valid_fault = false; /* reset back to normal */ ztest_test_pass(); } else { + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } } diff --git a/tests/kernel/smp/src/main.c b/tests/kernel/smp/src/main.c index 8bed52c9e18..4b227239f85 100644 --- a/tests/kernel/smp/src/main.c +++ b/tests/kernel/smp/src/main.c @@ -679,6 +679,7 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) if (reason != K_ERR_KERNEL_OOPS) { printk("wrong error reason\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } diff --git a/tests/kernel/threads/dynamic_thread/src/main.c b/tests/kernel/threads/dynamic_thread/src/main.c index 84b9805e76b..8db6a32c4c5 100644 --- a/tests/kernel/threads/dynamic_thread/src/main.c +++ b/tests/kernel/threads/dynamic_thread/src/main.c @@ -20,10 +20,12 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) { if (reason != K_ERR_KERNEL_OOPS) { printk("wrong error reason\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } if (k_current_get() != dyn_thread) { printk("wrong thread crashed\n"); + printk("PROJECT EXECUTION FAILED\n"); k_fatal_halt(reason); } }