diff mbox

[PATCHv3,2/3] validation: buffer: add initial buffer tests

Message ID 1419022611-28989-3-git-send-email-taras.kondratiuk@linaro.org
State Accepted
Commit 14a7dc3d456c6950f7fc0859b614d6fffc0024f7
Headers show

Commit Message

Taras Kondratiuk Dec. 19, 2014, 8:56 p.m. UTC
Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 test/validation/Makefile.am               |  1 +
 test/validation/buffer/odp_buffer_test.c  | 52 +++++++++++++++++++++++++++++++
 test/validation/buffer/odp_buffer_tests.h |  4 +++
 test/validation/odp_buffer.c              |  5 +++
 4 files changed, 62 insertions(+)
 create mode 100644 test/validation/buffer/odp_buffer_test.c
diff mbox

Patch

diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am
index e7e6fec..7baada4 100644
--- a/test/validation/Makefile.am
+++ b/test/validation/Makefile.am
@@ -20,4 +20,5 @@  dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \
 dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c
 dist_odp_schedule_SOURCES = odp_schedule.c common/odp_cunit_common.c
 dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \
+			  buffer/odp_buffer_test.c \
 			  odp_buffer.c common/odp_cunit_common.c
diff --git a/test/validation/buffer/odp_buffer_test.c b/test/validation/buffer/odp_buffer_test.c
new file mode 100644
index 0000000..219a9ef
--- /dev/null
+++ b/test/validation/buffer/odp_buffer_test.c
@@ -0,0 +1,52 @@ 
+/* Copyright (c) 2014, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:	BSD-3-Clause
+ */
+
+#include "odp_buffer_tests.h"
+
+static odp_buffer_pool_t raw_pool;
+static odp_buffer_t raw_buffer = ODP_BUFFER_INVALID;
+static const size_t raw_buffer_size = 1500;
+
+int buffer_testsuite_init(void)
+{
+	odp_buffer_pool_param_t params = {
+			.buf_size  = raw_buffer_size,
+			.buf_align = ODP_CACHE_LINE_SIZE,
+			.num_bufs  = 100,
+			.buf_type  = ODP_BUFFER_TYPE_RAW,
+	};
+
+	raw_pool = odp_buffer_pool_create("raw_pool", ODP_SHM_INVALID, &params);
+	if (raw_pool == ODP_BUFFER_POOL_INVALID)
+		return -1;
+	raw_buffer = odp_buffer_alloc(raw_pool);
+	if (raw_buffer == ODP_BUFFER_INVALID)
+		return -1;
+	return 0;
+}
+
+int buffer_testsuite_finalize(void)
+{
+	odp_buffer_free(raw_buffer);
+	if (odp_buffer_pool_destroy(raw_pool) != 0)
+		return -1;
+	return 0;
+}
+
+static void buffer_management_basic(void)
+{
+	CU_ASSERT(odp_buffer_is_valid(raw_buffer) == 1);
+	CU_ASSERT(odp_buffer_pool(raw_buffer) != ODP_BUFFER_POOL_INVALID);
+	CU_ASSERT(odp_buffer_type(raw_buffer) == ODP_BUFFER_TYPE_RAW);
+	CU_ASSERT(odp_buffer_size(raw_buffer) >= raw_buffer_size);
+	CU_ASSERT(odp_buffer_addr(raw_buffer) != NULL);
+	odp_buffer_print(raw_buffer);
+}
+
+CU_TestInfo buffer_tests[] = {
+	_CU_TEST_INFO(buffer_management_basic),
+	CU_TEST_INFO_NULL,
+};
diff --git a/test/validation/buffer/odp_buffer_tests.h b/test/validation/buffer/odp_buffer_tests.h
index 4184fb5..8de9a57 100644
--- a/test/validation/buffer/odp_buffer_tests.h
+++ b/test/validation/buffer/odp_buffer_tests.h
@@ -15,6 +15,10 @@ 
 #define _CU_TEST_INFO(test_func) {#test_func, test_func}
 
 extern CU_TestInfo buffer_pool_tests[];
+extern CU_TestInfo buffer_tests[];
+
+extern int buffer_testsuite_init(void);
+extern int buffer_testsuite_finalize(void);
 
 odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type);
 
diff --git a/test/validation/odp_buffer.c b/test/validation/odp_buffer.c
index daa30ca..7503fc9 100644
--- a/test/validation/odp_buffer.c
+++ b/test/validation/odp_buffer.c
@@ -10,5 +10,10 @@  CU_SuiteInfo odp_testsuites[] = {
 	{ .pName = "buffer Pool tests",
 			.pTests = buffer_pool_tests,
 	},
+	{ .pName = "buffer tests",
+			.pTests = buffer_tests,
+			.pInitFunc = buffer_testsuite_init,
+			.pCleanupFunc = buffer_testsuite_finalize,
+	},
 	CU_SUITE_INFO_NULL,
 };