Skip to content
Permalink
Browse files

tests: queue: test k_queue_alloc_*pend()

These were never getting called anywhere from user mode,
except for k_queue_alloc_append(), but only by virtue of
some workqueue tests.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information...
andrewboie authored and nashif committed Jun 12, 2019
1 parent 3f97424 commit 682a53db285a9346722ba74d7aedf486b16af54f
@@ -17,13 +17,28 @@ static void test_auto_free(void)
{
ztest_test_skip();
}

static void test_queue_alloc_prepend_user(void)
{
ztest_test_skip();
}

static void test_queue_alloc_append_user(void)
{
ztest_test_skip();
}
#endif
K_MEM_POOL_DEFINE(test_pool, 16, 96, 4, 4);

/*test case main entry*/
void test_main(void)
{
k_thread_resource_pool_assign(k_current_get(), &test_pool);

ztest_test_suite(queue_api,
ztest_unit_test(test_queue_supv_to_user),
ztest_user_unit_test(test_queue_alloc_prepend_user),
ztest_user_unit_test(test_queue_alloc_append_user),
ztest_unit_test(test_auto_free),
ztest_unit_test(test_queue_thread2thread),
ztest_unit_test(test_queue_thread2isr),
@@ -19,8 +19,11 @@ extern void test_queue_loop(void);
#ifdef CONFIG_USERSPACE
extern void test_queue_supv_to_user(void);
extern void test_auto_free(void);
extern void test_queue_alloc_prepend_user(void);
extern void test_queue_alloc_append_user(void);
#endif
extern void test_queue_alloc(void);
extern struct k_mem_pool test_pool;

typedef struct qdata {
sys_snode_t snode;
@@ -227,6 +227,8 @@ void test_queue_get_2threads(void)

static void tqueue_alloc(struct k_queue *pqueue)
{
k_thread_resource_pool_assign(k_current_get(), NULL);

/* Alloc append without resource pool */
k_queue_alloc_append(pqueue, (void *)&data_append);

@@ -15,8 +15,6 @@ static K_THREAD_STACK_DEFINE(child_stack, STACK_SIZE);
static struct k_thread child_thread;
static ZTEST_BMEM struct qdata qdata[LIST_LEN * 2];

K_MEM_POOL_DEFINE(test_pool, 16, 96, 4, 4);

/**
* @brief Tests for queue
* @defgroup kernel_queue_tests Queues
@@ -76,8 +74,6 @@ void test_queue_supv_to_user(void)
struct k_queue *q;
struct k_sem *sem;

k_thread_resource_pool_assign(k_current_get(), &test_pool);

q = k_object_alloc(K_OBJ_QUEUE);
zassert_not_null(q, "no memory for allocated queue object");
k_queue_init(q);
@@ -113,6 +109,50 @@ void test_queue_supv_to_user(void)
k_sem_take(sem, K_FOREVER);
}

void test_queue_alloc_prepend_user(void)
{
struct k_queue *q;

q = k_object_alloc(K_OBJ_QUEUE);
zassert_not_null(q, "no memory for allocated queue object");
k_queue_init(q);

for (int i = 0; i < LIST_LEN * 2; i++) {
qdata[i].data = i;
zassert_false(k_queue_alloc_prepend(q, &qdata[i]), NULL);
}

for (int i = (LIST_LEN * 2) - 1; i >= 0; i--) {
struct qdata *qd;

qd = k_queue_get(q, K_NO_WAIT);
zassert_true(qd != NULL, NULL);
zassert_equal(qd->data, i, NULL);
}
}

void test_queue_alloc_append_user(void)
{
struct k_queue *q;

q = k_object_alloc(K_OBJ_QUEUE);
zassert_not_null(q, "no memory for allocated queue object");
k_queue_init(q);

for (int i = 0; i < LIST_LEN * 2; i++) {
qdata[i].data = i;
zassert_false(k_queue_alloc_append(q, &qdata[i]), NULL);
}

for (int i = 0; i < LIST_LEN * 2; i++) {
struct qdata *qd;

qd = k_queue_get(q, K_NO_WAIT);
zassert_true(qd != NULL, NULL);
zassert_equal(qd->data, i, NULL);
}
}

/**
* @brief Test to verify free of allocated elements of queue
* @ingroup kernel_queue_tests

0 comments on commit 682a53d

Please sign in to comment.
You can’t perform that action at this time.