Skip to content

Commit 618a2a7

Browse files
Andrew Boienashif
authored andcommitted
tests: userspace: cover z_object_recycle()
We didn't have code coverage for this function anywhere except indirectly through some network tests; exercise it in the suite of userspace tests. Signed-off-by: Andrew Boie <[email protected]>
1 parent a51247e commit 618a2a7

File tree

1 file changed

+25
-1
lines changed
  • tests/kernel/mem_protect/userspace/src

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,29 @@ void test_bad_syscall(void)
11081108

11091109
}
11101110

1111+
static struct k_sem recycle_sem;
1112+
1113+
1114+
void test_object_recycle(void)
1115+
{
1116+
struct _k_object *ko;
1117+
int perms_count = 0;
1118+
1119+
ko = z_object_find(&recycle_sem);
1120+
(void)memset(ko->perms, 0xFF, sizeof(ko->perms));
1121+
1122+
z_object_recycle(&recycle_sem);
1123+
zassert_true(ko != NULL, "kernel object not found");
1124+
zassert_true(ko->flags & K_OBJ_FLAG_INITIALIZED,
1125+
"object wasn't marked as initialized");
1126+
1127+
for (int i = 0; i < CONFIG_MAX_THREAD_BYTES; i++) {
1128+
perms_count += popcount(ko->perms[i]);
1129+
}
1130+
1131+
zassert_true(perms_count == 1, "invalid number of thread permissions");
1132+
}
1133+
11111134
void test_main(void)
11121135
{
11131136
struct k_mem_partition *parts[] = {&part0, &part1,
@@ -1160,7 +1183,8 @@ void test_main(void)
11601183
ztest_unit_test(domain_remove_thread_context_switch),
11611184
ztest_unit_test(test_stack_buffer),
11621185
ztest_user_unit_test(test_unimplemented_syscall),
1163-
ztest_user_unit_test(test_bad_syscall)
1186+
ztest_user_unit_test(test_bad_syscall),
1187+
ztest_unit_test(test_object_recycle)
11641188
);
11651189
ztest_run_test_suite(userspace);
11661190
}

0 commit comments

Comments
 (0)