Skip to content

Commit

Permalink
tests: msgq_api: move to new ztest API
Browse files Browse the repository at this point in the history
test cases in tests/kernel/msgq/msgq_api/ are move to new ztest API

Signed-off-by: Meng xianglin <[email protected]>
  • Loading branch information
mengxianglinx authored and carlescufi committed Aug 12, 2022
1 parent d9ed093 commit cd66ee6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 73 deletions.
1 change: 1 addition & 0 deletions tests/kernel/msgq/msgq_api/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y
61 changes: 5 additions & 56 deletions tests/kernel/msgq/msgq_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,6 @@

#include "test_msgq.h"

extern void test_msgq_thread(void);
extern void test_msgq_thread_overflow(void);
extern void test_msgq_isr(void);
extern void test_msgq_put_fail(void);
extern void test_msgq_get_fail(void);
extern void test_msgq_purge_when_put(void);
extern void test_msgq_attrs_get(void);
extern void test_msgq_alloc(void);
extern void test_msgq_pend_thread(void);
extern void test_msgq_empty(void);
extern void test_msgq_full(void);
#ifdef CONFIG_USERSPACE
extern void test_msgq_user_thread(void);
extern void test_msgq_user_thread_overflow(void);
extern void test_msgq_user_put_fail(void);
extern void test_msgq_user_get_fail(void);
extern void test_msgq_user_attrs_get(void);
extern void test_msgq_user_purge_when_put(void);
#else
#define dummy_test(_name) \
static void _name(void) \
{ \
ztest_test_skip(); \
}

dummy_test(test_msgq_user_thread);
dummy_test(test_msgq_user_thread_overflow);
dummy_test(test_msgq_user_put_fail);
dummy_test(test_msgq_user_get_fail);
dummy_test(test_msgq_user_attrs_get);
dummy_test(test_msgq_user_purge_when_put);
#endif /* CONFIG_USERSPACE */

#ifdef CONFIG_64BIT
#define MAX_SZ 256
#else
Expand All @@ -62,31 +29,13 @@ extern struct k_sem end_sema;
extern struct k_thread tdata;
K_THREAD_STACK_DECLARE(tstack, STACK_SIZE);

/*test case main entry*/
void test_main(void)
void *msgq_api_setup(void)
{
k_thread_access_grant(k_current_get(), &kmsgq, &msgq, &end_sema,
&tdata, &tstack);

k_thread_heap_assign(k_current_get(), &test_pool);

ztest_test_suite(msgq_api,
ztest_1cpu_unit_test(test_msgq_thread),
ztest_unit_test(test_msgq_thread_overflow),
ztest_user_unit_test(test_msgq_user_thread),
ztest_user_unit_test(test_msgq_user_thread_overflow),
ztest_unit_test(test_msgq_isr),
ztest_1cpu_unit_test(test_msgq_put_fail),
ztest_1cpu_unit_test(test_msgq_get_fail),
ztest_user_unit_test(test_msgq_user_put_fail),
ztest_user_unit_test(test_msgq_user_get_fail),
ztest_unit_test(test_msgq_attrs_get),
ztest_user_unit_test(test_msgq_user_attrs_get),
ztest_1cpu_unit_test(test_msgq_purge_when_put),
ztest_user_unit_test(test_msgq_user_purge_when_put),
ztest_1cpu_unit_test(test_msgq_pend_thread),
ztest_1cpu_unit_test(test_msgq_empty),
ztest_1cpu_unit_test(test_msgq_full),
ztest_unit_test(test_msgq_alloc));
ztest_run_test_suite(msgq_api);
return NULL;
}
ZTEST_SUITE(msgq_api, NULL, msgq_api_setup, NULL, NULL, NULL);
ZTEST_SUITE(msgq_api_1cpu, NULL, msgq_api_setup,
ztest_simple_1cpu_before, ztest_simple_1cpu_after, NULL);
4 changes: 2 additions & 2 deletions tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void attrs_get(struct k_msgq *q)
*
* @see k_msgq_get_attrs()
*/
void test_msgq_attrs_get(void)
ZTEST(msgq_api, test_msgq_attrs_get)
{
k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);
attrs_get(&msgq);
Expand All @@ -59,7 +59,7 @@ void test_msgq_attrs_get(void)
*
* @see k_msgq_get_attrs()
*/
void test_msgq_user_attrs_get(void)
ZTEST_USER(msgq_api, test_msgq_user_attrs_get)
{
struct k_msgq *q;

Expand Down
18 changes: 9 additions & 9 deletions tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static void put_full_entry(void *p1, void *p2, void *p3)
* @brief Test thread to thread data passing via message queue
* @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge()
*/
void test_msgq_thread(void)
ZTEST(msgq_api_1cpu, test_msgq_thread)
{
int ret;

Expand All @@ -267,7 +267,7 @@ void test_msgq_thread(void)
* @brief Test thread to thread data passing via message queue
* @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge()
*/
void test_msgq_thread_overflow(void)
ZTEST(msgq_api, test_msgq_thread_overflow)
{
int ret;

Expand All @@ -292,7 +292,7 @@ void test_msgq_thread_overflow(void)
* @brief Test user thread to kernel thread data passing via message queue
* @see k_msgq_alloc_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge()
*/
void test_msgq_user_thread(void)
ZTEST_USER(msgq_api, test_msgq_user_thread)
{
struct k_msgq *q;
int ret;
Expand All @@ -310,7 +310,7 @@ void test_msgq_user_thread(void)
* @brief Test thread to thread data passing via message queue
* @see k_msgq_alloc_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge()
*/
void test_msgq_user_thread_overflow(void)
ZTEST_USER(msgq_api, test_msgq_user_thread_overflow)
{
struct k_msgq *q;
int ret;
Expand All @@ -329,7 +329,7 @@ void test_msgq_user_thread_overflow(void)
* @brief Test thread to isr data passing via message queue
* @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge()
*/
void test_msgq_isr(void)
ZTEST(msgq_api, test_msgq_isr)
{
static struct k_msgq stack_msgq;

Expand All @@ -344,7 +344,7 @@ void test_msgq_isr(void)
* @brief Test pending writer in msgq
* @see k_msgq_init(), k_msgq_get(), k_msgq_put(), k_msgq_purge()
*/
void test_msgq_pend_thread(void)
ZTEST(msgq_api_1cpu, test_msgq_pend_thread)
{
int ret;

Expand All @@ -361,7 +361,7 @@ void test_msgq_pend_thread(void)
* pool with various parameters
* @see k_msgq_alloc_init(), k_msgq_cleanup()
*/
void test_msgq_alloc(void)
ZTEST(msgq_api, test_msgq_alloc)
{
int ret;

Expand Down Expand Up @@ -390,7 +390,7 @@ void test_msgq_alloc(void)
*
* @see k_msgq_get()
*/
void test_msgq_empty(void)
ZTEST(msgq_api_1cpu, test_msgq_empty)
{
int pri = k_thread_priority_get(k_current_get()) - 1;
int ret;
Expand Down Expand Up @@ -430,7 +430,7 @@ void test_msgq_empty(void)
*
* @see k_msgq_put()
*/
void test_msgq_full(void)
ZTEST(msgq_api_1cpu, test_msgq_full)
{
int pri = k_thread_priority_get(k_current_get()) - 1;
int ret;
Expand Down
8 changes: 4 additions & 4 deletions tests/kernel/msgq/msgq_api/src/test_msgq_fail.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void get_fail(struct k_msgq *q)
* @brief Test returned error code during writing in msgq
* @see k_msgq_init()
*/
void test_msgq_put_fail(void)
ZTEST(msgq_api_1cpu, test_msgq_put_fail)
{
k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);
put_fail(&msgq);
Expand All @@ -59,7 +59,7 @@ void test_msgq_put_fail(void)
* @brief Test returned error code during writing in msgq
* @see k_msgq_alloc_init()
*/
void test_msgq_user_put_fail(void)
ZTEST_USER(msgq_api, test_msgq_user_put_fail)
{
struct k_msgq *q;

Expand All @@ -74,7 +74,7 @@ void test_msgq_user_put_fail(void)
* @brief Test returned error code during reading from msgq
* @see k_msgq_init(), k_msgq_put()
*/
void test_msgq_get_fail(void)
ZTEST(msgq_api_1cpu, test_msgq_get_fail)
{
k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);
get_fail(&msgq);
Expand All @@ -85,7 +85,7 @@ void test_msgq_get_fail(void)
* @brief Test returned error code during reading from msgq
* @see k_msgq_alloc_init(), k_msgq_get()
*/
void test_msgq_user_get_fail(void)
ZTEST_USER(msgq_api, test_msgq_user_get_fail)
{
struct k_msgq *q;

Expand Down
4 changes: 2 additions & 2 deletions tests/kernel/msgq/msgq_api/src/test_msgq_purge.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void purge_when_put(struct k_msgq *q)
* @brief Test purge a message queue
* @see k_msgq_init(), k_msgq_purge(), k_msgq_put()
*/
void test_msgq_purge_when_put(void)
ZTEST(msgq_api_1cpu, test_msgq_purge_when_put)
{
k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);

Expand All @@ -67,7 +67,7 @@ void test_msgq_purge_when_put(void)
* @brief Test purge a message queue
* @see k_msgq_init(), k_msgq_purge(), k_msgq_put()
*/
void test_msgq_user_purge_when_put(void)
ZTEST_USER(msgq_api, test_msgq_user_purge_when_put)
{
struct k_msgq *q;

Expand Down

0 comments on commit cd66ee6

Please sign in to comment.