Skip to content

Commit 5b9c626

Browse files
LixinGuoXnashif
authored andcommitted
tests: userspace: add a test for code coverage
Add a test case for getting all the kernel objects in kobject list. Signed-off-by: Lixin Guo <[email protected]>
1 parent cbb0585 commit 5b9c626

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

tests/kernel/mem_protect/mem_protect/src/kobject.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,3 +1366,32 @@ void test_kobject_perm_error(void)
13661366
k_thread_join(tid, K_FOREVER);
13671367
}
13681368
}
1369+
1370+
extern const char *otype_to_str(enum k_objects otype);
1371+
1372+
/**
1373+
* @brief Test get all kernel object list
1374+
*
1375+
* @details Get all of the kernel object in kobject list.
1376+
*
1377+
* @ingroup kernel_memprotect_tests
1378+
*/
1379+
void test_all_kobjects_str(void)
1380+
{
1381+
enum k_objects otype = K_OBJ_ANY;
1382+
const char *c;
1383+
int cmp;
1384+
1385+
do {
1386+
c = otype_to_str(otype);
1387+
cmp = strcmp(c, "?");
1388+
if (otype != K_OBJ_LAST) {
1389+
zassert_true(cmp != 0,
1390+
"otype %d unexpectedly maps to last entry \"?\"", otype);
1391+
} else {
1392+
zassert_true(cmp == 0,
1393+
"otype %d does not map to last entry \"?\"", otype);
1394+
}
1395+
otype++;
1396+
} while (otype <= K_OBJ_LAST);
1397+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ void test_main(void)
8686
ztest_unit_test(test_thread_alloc_out_of_idx),
8787
ztest_unit_test(test_kobj_create_out_of_memory),
8888
ztest_unit_test(test_kobject_perm_error),
89-
ztest_unit_test(test_kobject_free_error)
89+
ztest_unit_test(test_kobject_free_error),
90+
ztest_unit_test(test_all_kobjects_str)
9091
);
9192

9293
ztest_run_test_suite(memory_protection_test_suite);

tests/kernel/mem_protect/mem_protect/src/mem_protect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ extern void test_kobj_create_out_of_memory(void);
7070
extern void test_thread_alloc_out_of_idx(void);
7171
extern void test_alloc_kobjects(void);
7272
extern void test_kobject_perm_error(void);
73+
extern void test_all_kobjects_str(void);
7374

7475

7576
/* Flag needed to figure out if the fault was expected or not. */

0 commit comments

Comments
 (0)