zephyr/tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c
Andrew Boie 525065dd8b tests: convert to use app shared memory
CONFIG_APPLICATION_MEMORY was a stopgap feature that is
being removed from the kernel. Convert tests and samples
to use the application shared memory feature instead,
in most cases using the domain set up by ztest.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00

76 lines
1.5 KiB
C

/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "test_msgq.h"
extern struct k_msgq msgq;
static ZTEST_BMEM char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
static ZTEST_DMEM u32_t send_buf[MSGQ_LEN] = { MSG0, MSG1 };
static ZTEST_DMEM u32_t rec_buf[MSGQ_LEN] = { MSG0, MSG1 };
static void attrs_get(struct k_msgq *q)
{
int ret;
struct k_msgq_attrs attrs;
k_msgq_get_attrs(q, &attrs);
zassert_equal(attrs.used_msgs, 0, NULL);
/*fill the queue to full*/
for (int i = 0; i < MSGQ_LEN; i++) {
ret = k_msgq_put(q, (void *)&send_buf[i], K_NO_WAIT);
zassert_equal(ret, 0, NULL);
}
k_msgq_get_attrs(q, &attrs);
zassert_equal(attrs.used_msgs, MSGQ_LEN, NULL);
for (int i = 0; i < MSGQ_LEN; i++) {
ret = k_msgq_get(q, (void *)&rec_buf[i], K_NO_WAIT);
zassert_equal(ret, 0, NULL);
}
k_msgq_get_attrs(q, &attrs);
zassert_equal(attrs.used_msgs, 0, NULL);
}
/**
* @addtogroup kernel_message_queue_tests
* @{
*/
/**
* @brief Test basic attributes of a message queue
*
* @see k_msgq_get_attrs()
*/
void test_msgq_attrs_get(void)
{
k_msgq_init(&msgq, tbuffer, MSG_SIZE, MSGQ_LEN);
attrs_get(&msgq);
}
#ifdef CONFIG_USERSPACE
/**
* @brief Test basic attributes of a message queue
*
* @see k_msgq_get_attrs()
*/
void test_msgq_user_attrs_get(void)
{
struct k_msgq *q;
q = k_object_alloc(K_OBJ_MSGQ);
zassert_not_null(q, "couldn't alloc message queue");
zassert_false(k_msgq_alloc_init(q, MSG_SIZE, MSGQ_LEN), NULL);
attrs_get(q);
}
#endif
/**
* @}
*/