diff mbox series

[API-NEXT,v4,3/8] validation: pool: add subparam test

Message ID 1509091212-14398-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v4,1/8] api: pool: relax packet pool param num | expand

Commit Message

Github ODP bot Oct. 27, 2017, 8 a.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Test packet pool subparameters when those are supported.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 234 (psavol:next-pool-param)
 ** https://github.com/Linaro/odp/pull/234
 ** Patch: https://github.com/Linaro/odp/pull/234.patch
 ** Base sha: d61d32590d1772b70b8dcd0d0ec44d29029d7443
 ** Merge commit sha: 436021e0a0bff8bda38fa420ebbc4545c97a7fc8
 **/
 test/validation/api/pool/pool.c | 98 +++++++++++++++++++++++++++++++++++++++++
 test/validation/api/pool/pool.h |  3 +-
 2 files changed, 100 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/test/validation/api/pool/pool.c b/test/validation/api/pool/pool.c
index e633137ab..c38a336ce 100644
--- a/test/validation/api/pool/pool.c
+++ b/test/validation/api/pool/pool.c
@@ -10,6 +10,9 @@ 
 #include "odp_cunit_common.h"
 #include "pool.h"
 
+#define PKT_LEN 400
+#define PKT_NUM 500
+
 static const int default_buffer_size = 1500;
 static const int default_buffer_num = 1000;
 
@@ -96,10 +99,105 @@  void pool_test_lookup_info_print(void)
 	CU_ASSERT(odp_pool_destroy(pool) == 0);
 }
 
+void pool_test_alloc_packet(void)
+{
+	odp_pool_t pool;
+	odp_pool_param_t param;
+	uint32_t i, num;
+	odp_packet_t pkt[PKT_NUM];
+
+	odp_pool_param_init(&param);
+
+	param.type    = ODP_POOL_PACKET,
+	param.pkt.num = PKT_NUM;
+	param.pkt.len = PKT_LEN;
+
+	pool = odp_pool_create(NULL, &param);
+
+	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
+
+	num = 0;
+
+	for (i = 0; i < PKT_NUM; i++) {
+		pkt[num] = odp_packet_alloc(pool, PKT_LEN);
+		CU_ASSERT(pkt[num] != ODP_PACKET_INVALID);
+
+		if (pkt[num] != ODP_PACKET_INVALID)
+			num++;
+	}
+
+	for (i = 0; i < num; i++)
+		odp_packet_free(pkt[i]);
+
+	CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
+void pool_test_alloc_packet_subparam(void)
+{
+	odp_pool_t pool;
+	odp_pool_capability_t capa;
+	odp_pool_param_t param;
+	uint32_t i, j, num, num_sub;
+	odp_packet_t pkt[PKT_NUM];
+
+	CU_ASSERT_FATAL(odp_pool_capability(&capa) == 0);
+	num_sub = capa.pkt.max_num_subparam;
+
+	CU_ASSERT_FATAL(num_sub <= ODP_POOL_MAX_SUBPARAMS);
+
+	odp_pool_param_init(&param);
+
+	param.type             = ODP_POOL_PACKET,
+	param.pkt.num          = PKT_NUM;
+	param.pkt.len          = PKT_LEN;
+	param.pkt.num_subparam = num_sub;
+
+	for (i = 0; i < num_sub; i++) {
+		param.pkt.sub[i].num = PKT_NUM;
+		param.pkt.sub[i].len = PKT_LEN + (i * 100);
+	}
+
+	pool = odp_pool_create(NULL, &param);
+
+	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
+
+	num = 0;
+
+	for (i = 0; i < PKT_NUM; i++) {
+		pkt[num] = odp_packet_alloc(pool, PKT_LEN);
+		CU_ASSERT(pkt[num] != ODP_PACKET_INVALID);
+
+		if (pkt[num] != ODP_PACKET_INVALID)
+			num++;
+	}
+
+	for (i = 0; i < num; i++)
+		odp_packet_free(pkt[i]);
+
+	for (j = 0; j < num_sub; j++) {
+		num = 0;
+
+		for (i = 0; i < param.pkt.sub[j].num; i++) {
+			pkt[num] = odp_packet_alloc(pool, param.pkt.sub[j].len);
+			CU_ASSERT(pkt[num] != ODP_PACKET_INVALID);
+
+			if (pkt[num] != ODP_PACKET_INVALID)
+				num++;
+		}
+
+		for (i = 0; i < num; i++)
+			odp_packet_free(pkt[i]);
+	}
+
+	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),
 	ODP_TEST_INFO(pool_test_create_destroy_timeout),
+	ODP_TEST_INFO(pool_test_alloc_packet),
+	ODP_TEST_INFO(pool_test_alloc_packet_subparam),
 	ODP_TEST_INFO(pool_test_lookup_info_print),
 	ODP_TEST_INFO_NULL,
 };
diff --git a/test/validation/api/pool/pool.h b/test/validation/api/pool/pool.h
index 29e517633..3f8f5ebce 100644
--- a/test/validation/api/pool/pool.h
+++ b/test/validation/api/pool/pool.h
@@ -13,8 +13,9 @@ 
 void pool_test_create_destroy_buffer(void);
 void pool_test_create_destroy_packet(void);
 void pool_test_create_destroy_timeout(void);
-void pool_test_create_destroy_buffer_shm(void);
 void pool_test_lookup_info_print(void);
+void pool_test_alloc_packet(void);
+void pool_test_alloc_packet_subparam(void);
 
 /* test arrays: */
 extern odp_testinfo_t pool_suite[];