Skip to content

Commit 777336e

Browse files
Andrew Boieandrewboie
authored andcommitted
tests: userspace: cover missing/bad syscalls
We were missing code coverage for bad or unimplemented system call IDs. Signed-off-by: Andrew Boie <[email protected]>
1 parent 31c4cc5 commit 777336e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

kernel/userspace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,15 +762,15 @@ static u32_t handler_bad_syscall(u32_t bad_id, u32_t arg2, u32_t arg3,
762762
{
763763
printk("Bad system call id %u invoked\n", bad_id);
764764
z_arch_syscall_oops(ssf);
765-
CODE_UNREACHABLE;
765+
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
766766
}
767767

768768
static u32_t handler_no_syscall(u32_t arg1, u32_t arg2, u32_t arg3,
769769
u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
770770
{
771771
printk("Unimplemented system call\n");
772772
z_arch_syscall_oops(ssf);
773-
CODE_UNREACHABLE;
773+
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
774774
}
775775

776776
#include <syscall_dispatch.c>

tests/kernel/mem_protect/userspace/src/main.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,29 @@ void test_stack_buffer(void)
10851085

10861086
}
10871087

1088+
void z_impl_missing_syscall(void)
1089+
{
1090+
/* Shouldn't ever get here; no handler function compiled */
1091+
k_panic();
1092+
}
1093+
1094+
void test_unimplemented_syscall(void)
1095+
{
1096+
expect_fault = true;
1097+
expected_reason = REASON_KERNEL_OOPS;
1098+
1099+
missing_syscall();
1100+
}
1101+
1102+
void test_bad_syscall(void)
1103+
{
1104+
expect_fault = true;
1105+
expected_reason = REASON_KERNEL_OOPS;
1106+
1107+
z_arch_syscall_invoke0(INT_MAX);
1108+
1109+
}
1110+
10881111
void test_main(void)
10891112
{
10901113
struct k_mem_partition *parts[] = {&part0, &part1,
@@ -1134,7 +1157,9 @@ void test_main(void)
11341157
ztest_unit_test(domain_add_part_context_switch),
11351158
ztest_unit_test(domain_remove_part_context_switch),
11361159
ztest_unit_test(domain_remove_thread_context_switch),
1137-
ztest_unit_test(test_stack_buffer)
1160+
ztest_unit_test(test_stack_buffer),
1161+
ztest_user_unit_test(test_unimplemented_syscall),
1162+
ztest_user_unit_test(test_bad_syscall)
11381163
);
11391164
ztest_run_test_suite(userspace);
11401165
}

tests/kernel/mem_protect/userspace/src/test_syscall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
__syscall void stack_info_get(u32_t *start_addr, u32_t *size);
1111
__syscall int check_perms(void *addr, size_t size, int write);
12+
__syscall void missing_syscall(void);
1213

1314
#include <syscalls/test_syscall.h>
1415

0 commit comments

Comments
 (0)