Signed-off-by: Nicolas Morey-Chaisemartin <[email protected]>
Reviewed-by: Petri Savolainen <[email protected]>
---
test/validation/buffer/buffer.c | 106 ++++++++++++++++++++++++++++++++++++++++
test/validation/buffer/buffer.h | 2 +
2 files changed, 108 insertions(+)
diff --git a/test/validation/buffer/buffer.c b/test/validation/buffer/buffer.c
index 257e95c..9c8da81 100644
--- a/test/validation/buffer/buffer.c
+++ b/test/validation/buffer/buffer.c
@@ -92,6 +92,71 @@ void buffer_test_pool_alloc(void)
CU_ASSERT(odp_pool_destroy(pool) == 0);
}
+/* Wrapper to call odp_buffer_alloc_multi multiple times until
+ * either no mure buffers are returned, or num buffers were alloced */
+static int buffer_alloc_multi(odp_pool_t pool, odp_buffer_t buffer[], int num)
+{
+ int ret, total = 0;
+
+ do {
+ ret = odp_buffer_alloc_multi(pool, buffer + total, num - total);
+ CU_ASSERT(ret >= 0);
+ CU_ASSERT(ret <= num - total);
+ total += ret;
+ } while (total < num && ret);
+
+ return total;
+}
+
+void buffer_test_pool_alloc_multi(void)
+{
+ odp_pool_t pool;
+ const int num = 3;
+ const size_t size = 1500;
+ odp_buffer_t buffer[num + 1];
+ odp_event_t ev;
+ int index;
+ char wrong_type = 0, wrong_size = 0;
+ odp_pool_param_t params = {
+ .buf = {
+ .size = size,
+ .align = ODP_CACHE_LINE_SIZE,
+ .num = num,
+ },
+ .type = ODP_POOL_BUFFER,
+ };
+
+ pool = odp_pool_create("buffer_pool_alloc_multi", ¶ms);
+ odp_pool_print(pool);
+
+ /* Try to allocate num + 1 items from the pool */
+ CU_ASSERT_FATAL(buffer_alloc_multi(pool, buffer, num + 1) == num);
+
+ for (index = 0; index < num; index++) {
+ if (buffer[index] == ODP_BUFFER_INVALID)
+ break;
+
+ ev = odp_buffer_to_event(buffer[index]);
+ if (odp_event_type(ev) != ODP_EVENT_BUFFER)
+ wrong_type = 1;
+ if (odp_buffer_size(buffer[index]) < size)
+ wrong_size = 1;
+ if (wrong_type || wrong_size)
+ odp_buffer_print(buffer[index]);
+ }
+
+ /* Check that the pool had at least num items */
+ CU_ASSERT(index == num);
+
+ /* Check that the pool had correct buffers */
+ CU_ASSERT(wrong_type == 0);
+ CU_ASSERT(wrong_size == 0);
+
+ odp_buffer_free_multi(buffer, num);
+
+ CU_ASSERT(odp_pool_destroy(pool) == 0);
+}
+
void buffer_test_pool_free(void)
{
odp_pool_t pool;
@@ -124,6 +189,45 @@ void buffer_test_pool_free(void)
CU_ASSERT(odp_pool_destroy(pool) == 0);
}
+void buffer_test_pool_free_multi(void)
+{
+ odp_pool_t pool[2];
+ odp_buffer_t buffer[4];
+ odp_buffer_t buf_inval[2];
+ odp_pool_param_t params = {
+ .buf = {
+ .size = 64,
+ .align = ODP_CACHE_LINE_SIZE,
+ .num = 2,
+ },
+ .type = ODP_POOL_BUFFER,
+ };
+
+ pool[0] = odp_pool_create("buffer_pool_free_multi_0", ¶ms);
+ pool[1] = odp_pool_create("buffer_pool_free_multi_1", ¶ms);
+ CU_ASSERT_FATAL(pool[0] != ODP_POOL_INVALID);
+ CU_ASSERT_FATAL(pool[1] != ODP_POOL_INVALID);
+
+ /* Allocate all the buffers from the pools */
+ CU_ASSERT_FATAL(buffer_alloc_multi(pool[0], &buffer[0], 2) == 2);
+ CU_ASSERT_FATAL(buffer_alloc_multi(pool[1], &buffer[2], 2) == 2);
+
+ /* Pools should have no more buffer */
+ CU_ASSERT(odp_buffer_alloc_multi(pool[0], buf_inval, 2) == 0);
+ CU_ASSERT(odp_buffer_alloc_multi(pool[1], buf_inval, 2) == 0);
+
+ /* Try to free both buffers from both pools at once */
+ odp_buffer_free_multi(buffer, 4);
+
+ /* Check that all buffers were returned back to the pools */
+ CU_ASSERT_FATAL(buffer_alloc_multi(pool[0], &buffer[0], 2) == 2);
+ CU_ASSERT_FATAL(buffer_alloc_multi(pool[1], &buffer[2], 2) == 2);
+
+ odp_buffer_free_multi(buffer, 4);
+ CU_ASSERT(odp_pool_destroy(pool[0]) == 0);
+ CU_ASSERT(odp_pool_destroy(pool[1]) == 0);
+}
+
void buffer_test_management_basic(void)
{
odp_event_t ev = odp_buffer_to_event(raw_buffer);
@@ -142,6 +246,8 @@ void buffer_test_management_basic(void)
odp_testinfo_t buffer_suite[] = {
ODP_TEST_INFO(buffer_test_pool_alloc),
ODP_TEST_INFO(buffer_test_pool_free),
+ ODP_TEST_INFO(buffer_test_pool_alloc_multi),
+ ODP_TEST_INFO(buffer_test_pool_free_multi),
ODP_TEST_INFO(buffer_test_management_basic),
ODP_TEST_INFO_NULL,
};
diff --git a/test/validation/buffer/buffer.h b/test/validation/buffer/buffer.h
index 8b61bf5..b50bcc8 100644
--- a/test/validation/buffer/buffer.h
+++ b/test/validation/buffer/buffer.h
@@ -12,6 +12,8 @@
/* test functions: */
void buffer_test_pool_alloc(void);
void buffer_test_pool_free(void);
+void buffer_test_pool_alloc_multi(void);
+void buffer_test_pool_free_multi(void);
void buffer_test_management_basic(void);
/* test arrays: */
--
2.6.1.3.g8d02103
_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp