Skip to content

Commit

Permalink
validation: queue: add test for queue create/destroy multi functions
Browse files Browse the repository at this point in the history
Add validation tests for new odp_queue_create_multi() and
odp_queue_destroy_multi() APIs.

Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
  • Loading branch information
MatiasElo committed Oct 20, 2023
1 parent 319bb59 commit cf839f3
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion test/validation/api/queue/queue.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2014-2018, Linaro Limited
* Copyright (c) 2021-2022, Nokia
* Copyright (c) 2021-2023, Nokia
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
Expand Down Expand Up @@ -208,6 +208,83 @@ static void queue_test_max_plain(void)
CU_ASSERT(odp_queue_destroy(queue[i]) == 0);
}

static int queue_create_multi(const char *name[], const odp_queue_param_t param[],
odp_bool_t share_param, odp_queue_t queue[], uint32_t num)
{
const uint32_t max_retries = 100;
uint32_t num_created = 0;
uint32_t num_retries = 0;

do {
const char **cur_name = name != NULL ? &name[num_created] : NULL;
const odp_queue_param_t *cur_param = share_param ? &param[0] : &param[num_created];
int ret = odp_queue_create_multi(cur_name, cur_param, share_param,
&queue[num_created], num - num_created);
if (ret < 0) {
CU_FAIL("Queue create multi failed");
break;
}
CU_ASSERT_FATAL((uint32_t)ret <= num - num_created);

num_retries = ret == 0 ? num_retries + 1 : 0;
num_created += ret;
} while (num_created < num && num_retries < max_retries);

return num_created;
}

static void queue_destroy_multi(odp_queue_t queue[], uint32_t num)
{
uint32_t num_left = num;
uint32_t num_freed = 0;

while (num_left) {
int ret = odp_queue_destroy_multi(&queue[num_freed], num_left);

CU_ASSERT_FATAL(ret > 0 && (uint32_t)ret <= num_left);

num_left -= ret;
num_freed += ret;
}
CU_ASSERT_FATAL(num_freed == num);
}

static void queue_test_create_destroy_multi(void)
{
odp_queue_capability_t capa;
odp_queue_param_t param_single;
odp_queue_param_t param[MAX_QUEUES];
odp_queue_t queue[MAX_QUEUES];
const char *name[MAX_QUEUES] = {NULL, "aaa", NULL, "bbb", "ccc", NULL, "ddd"};
uint32_t num_queues, num_created;

CU_ASSERT_FATAL(odp_queue_capability(&capa) == 0);
CU_ASSERT_FATAL(capa.plain.max_num != 0);

num_queues = capa.plain.max_num < MAX_QUEUES ? capa.plain.max_num : MAX_QUEUES;
for (uint32_t i = 0; i < num_queues; i++)
odp_queue_param_init(&param[i]);
odp_queue_param_init(&param_single);

/* Create queues using shared parameters */
num_created = queue_create_multi(name, &param_single, true, queue, num_queues);
CU_ASSERT(num_created == num_queues);
queue_destroy_multi(queue, num_created);

num_created = queue_create_multi(NULL, &param_single, true, queue, num_queues);
CU_ASSERT(num_created == num_queues);
queue_destroy_multi(queue, num_created);

/* Use separate parameters for each queue */
num_created = queue_create_multi(name, param, false, queue, num_queues);
CU_ASSERT(num_created == num_queues);
queue_destroy_multi(queue, num_created);

num_created = queue_create_multi(NULL, param, false, queue, num_queues);
CU_ASSERT(num_created == num_queues);
queue_destroy_multi(queue, num_created);
}

static void queue_test_mode(void)
{
odp_queue_param_t qparams;
Expand Down Expand Up @@ -1051,6 +1128,7 @@ odp_testinfo_t queue_suite[] = {
ODP_TEST_INFO(queue_test_param_init),
ODP_TEST_INFO(queue_test_mode),
ODP_TEST_INFO(queue_test_max_plain),
ODP_TEST_INFO(queue_test_create_destroy_multi),
ODP_TEST_INFO(queue_test_burst),
ODP_TEST_INFO(queue_test_burst_spmc),
ODP_TEST_INFO(queue_test_burst_mpsc),
Expand Down

0 comments on commit cf839f3

Please sign in to comment.