Skip to content

Commit

Permalink
validation: pool: add max num pool tests
Browse files Browse the repository at this point in the history
Test that pools can be created with maximum number of
events defined in pool capability. Test that all events
can be allocated and freed. Event size is small.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
  • Loading branch information
Petri Savolainen authored and muvarov committed Oct 15, 2018
1 parent 31f9a83 commit 0f6ebf7
Showing 1 changed file with 160 additions and 3 deletions.
163 changes: 160 additions & 3 deletions test/validation/api/pool/pool.c
Expand Up @@ -11,6 +11,7 @@

#define PKT_LEN 400
#define PKT_NUM 500
#define MAX_NUM_DEFAULT (10 * 1024 * 1024)

static const int default_buffer_size = 1500;
static const int default_buffer_num = 1000;
Expand All @@ -32,7 +33,7 @@ static void pool_test_create_destroy_buffer(void)

odp_pool_param_init(&param);

param.type = ODP_POOL_BUFFER,
param.type = ODP_POOL_BUFFER;
param.buf.size = default_buffer_size;
param.buf.align = ODP_CACHE_LINE_SIZE;
param.buf.num = default_buffer_num;
Expand Down Expand Up @@ -106,7 +107,7 @@ static void pool_test_alloc_packet(void)

odp_pool_param_init(&param);

param.type = ODP_POOL_PACKET,
param.type = ODP_POOL_PACKET;
param.pkt.num = PKT_NUM;
param.pkt.len = PKT_LEN;

Expand Down Expand Up @@ -145,7 +146,7 @@ static void pool_test_alloc_packet_subparam(void)

odp_pool_param_init(&param);

param.type = ODP_POOL_PACKET,
param.type = ODP_POOL_PACKET;
param.pkt.num = PKT_NUM;
param.pkt.len = PKT_LEN;
param.pkt.num_subparam = num_sub;
Expand Down Expand Up @@ -270,6 +271,159 @@ static void pool_test_info_data_range(void)
CU_ASSERT(odp_pool_destroy(pool) == 0);
}

static void pool_test_buf_max_num(void)
{
odp_pool_t pool;
odp_pool_param_t param;
odp_pool_capability_t capa;
uint32_t max_num, num, i;
odp_shm_t shm;
odp_buffer_t *buf;

CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);

max_num = MAX_NUM_DEFAULT;
if (capa.buf.max_num)
max_num = capa.buf.max_num;

odp_pool_param_init(&param);

param.type = ODP_POOL_BUFFER;
param.buf.num = max_num;
param.buf.size = 10;

pool = odp_pool_create("test_buf_max_num", &param);

CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

shm = odp_shm_reserve("test_max_num_shm",
max_num * sizeof(odp_buffer_t),
sizeof(odp_buffer_t), 0);

CU_ASSERT_FATAL(shm != ODP_SHM_INVALID);

buf = odp_shm_addr(shm);

num = 0;
for (i = 0; i < max_num; i++) {
buf[num] = odp_buffer_alloc(pool);

if (buf[num] != ODP_BUFFER_INVALID)
num++;
}

CU_ASSERT(num == max_num);

for (i = 0; i < num; i++)
odp_buffer_free(buf[i]);

CU_ASSERT(odp_shm_free(shm) == 0);
CU_ASSERT(odp_pool_destroy(pool) == 0);
}

static void pool_test_pkt_max_num(void)
{
odp_pool_t pool;
odp_pool_param_t param;
odp_pool_capability_t capa;
uint32_t max_num, num, i;
odp_shm_t shm;
odp_packet_t *pkt;
uint32_t len = 10;

CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);

max_num = MAX_NUM_DEFAULT;
if (capa.pkt.max_num)
max_num = capa.pkt.max_num;

odp_pool_param_init(&param);

param.type = ODP_POOL_PACKET;
param.pkt.num = max_num;
param.pkt.max_num = max_num;
param.pkt.len = len;
param.pkt.max_len = len;
param.pkt.headroom = 0;

pool = odp_pool_create("test_packet_max_num", &param);

CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

shm = odp_shm_reserve("test_max_num_shm",
max_num * sizeof(odp_packet_t),
sizeof(odp_packet_t), 0);

CU_ASSERT_FATAL(shm != ODP_SHM_INVALID);

pkt = odp_shm_addr(shm);

num = 0;
for (i = 0; i < max_num; i++) {
pkt[num] = odp_packet_alloc(pool, len);

if (pkt[num] != ODP_PACKET_INVALID)
num++;
}

CU_ASSERT(num == max_num);

for (i = 0; i < num; i++)
odp_packet_free(pkt[i]);

CU_ASSERT(odp_shm_free(shm) == 0);
CU_ASSERT(odp_pool_destroy(pool) == 0);
}

static void pool_test_tmo_max_num(void)
{
odp_pool_t pool;
odp_pool_param_t param;
odp_pool_capability_t capa;
uint32_t max_num, num, i;
odp_shm_t shm;
odp_timeout_t *tmo;

CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);

max_num = MAX_NUM_DEFAULT;
if (capa.tmo.max_num)
max_num = capa.tmo.max_num;

odp_pool_param_init(&param);

param.type = ODP_POOL_TIMEOUT;
param.tmo.num = max_num;

pool = odp_pool_create("test_tmo_max_num", &param);

CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

shm = odp_shm_reserve("test_max_num_shm",
max_num * sizeof(odp_packet_t),
sizeof(odp_packet_t), 0);

CU_ASSERT_FATAL(shm != ODP_SHM_INVALID);

tmo = odp_shm_addr(shm);

num = 0;
for (i = 0; i < max_num; i++) {
tmo[num] = odp_timeout_alloc(pool);

if (tmo[num] != ODP_TIMEOUT_INVALID)
num++;
}

CU_ASSERT(num == max_num);

for (i = 0; i < num; i++)
odp_timeout_free(tmo[i]);

CU_ASSERT(odp_shm_free(shm) == 0);
CU_ASSERT(odp_pool_destroy(pool) == 0);
}

odp_testinfo_t pool_suite[] = {
ODP_TEST_INFO(pool_test_create_destroy_buffer),
ODP_TEST_INFO(pool_test_create_destroy_packet),
Expand All @@ -279,6 +433,9 @@ odp_testinfo_t pool_suite[] = {
ODP_TEST_INFO(pool_test_info_packet),
ODP_TEST_INFO(pool_test_lookup_info_print),
ODP_TEST_INFO(pool_test_info_data_range),
ODP_TEST_INFO(pool_test_buf_max_num),
ODP_TEST_INFO(pool_test_pkt_max_num),
ODP_TEST_INFO(pool_test_tmo_max_num),
ODP_TEST_INFO_NULL,
};

Expand Down

0 comments on commit 0f6ebf7

Please sign in to comment.