Skip to content

Commit

Permalink
tests: userspace: cover missing/bad syscalls
Browse files Browse the repository at this point in the history
We were missing code coverage for bad or unimplemented
system call IDs.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information
Andrew Boie authored and andrewboie committed Jun 26, 2019
1 parent 31c4cc5 commit 777336e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kernel/userspace.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -762,15 +762,15 @@ static u32_t handler_bad_syscall(u32_t bad_id, u32_t arg2, u32_t arg3,
{ {
printk("Bad system call id %u invoked\n", bad_id); printk("Bad system call id %u invoked\n", bad_id);
z_arch_syscall_oops(ssf); z_arch_syscall_oops(ssf);
CODE_UNREACHABLE; CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
} }


static u32_t handler_no_syscall(u32_t arg1, u32_t arg2, u32_t arg3, static u32_t handler_no_syscall(u32_t arg1, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6, void *ssf) u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
{ {
printk("Unimplemented system call\n"); printk("Unimplemented system call\n");
z_arch_syscall_oops(ssf); z_arch_syscall_oops(ssf);
CODE_UNREACHABLE; CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
} }


#include <syscall_dispatch.c> #include <syscall_dispatch.c>
Expand Down
27 changes: 26 additions & 1 deletion tests/kernel/mem_protect/userspace/src/main.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1085,6 +1085,29 @@ void test_stack_buffer(void)


} }


void z_impl_missing_syscall(void)
{
/* Shouldn't ever get here; no handler function compiled */
k_panic();
}

void test_unimplemented_syscall(void)
{
expect_fault = true;
expected_reason = REASON_KERNEL_OOPS;

missing_syscall();
}

void test_bad_syscall(void)
{
expect_fault = true;
expected_reason = REASON_KERNEL_OOPS;

z_arch_syscall_invoke0(INT_MAX);

}

void test_main(void) void test_main(void)
{ {
struct k_mem_partition *parts[] = {&part0, &part1, struct k_mem_partition *parts[] = {&part0, &part1,
Expand Down Expand Up @@ -1134,7 +1157,9 @@ void test_main(void)
ztest_unit_test(domain_add_part_context_switch), ztest_unit_test(domain_add_part_context_switch),
ztest_unit_test(domain_remove_part_context_switch), ztest_unit_test(domain_remove_part_context_switch),
ztest_unit_test(domain_remove_thread_context_switch), ztest_unit_test(domain_remove_thread_context_switch),
ztest_unit_test(test_stack_buffer) ztest_unit_test(test_stack_buffer),
ztest_user_unit_test(test_unimplemented_syscall),
ztest_user_unit_test(test_bad_syscall)
); );
ztest_run_test_suite(userspace); ztest_run_test_suite(userspace);
} }
1 change: 1 addition & 0 deletions tests/kernel/mem_protect/userspace/src/test_syscall.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


__syscall void stack_info_get(u32_t *start_addr, u32_t *size); __syscall void stack_info_get(u32_t *start_addr, u32_t *size);
__syscall int check_perms(void *addr, size_t size, int write); __syscall int check_perms(void *addr, size_t size, int write);
__syscall void missing_syscall(void);


#include <syscalls/test_syscall.h> #include <syscalls/test_syscall.h>


Expand Down

0 comments on commit 777336e

Please sign in to comment.