diff mbox

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

Message ID 1418402325-6798-4-git-send-email-taras.kondratiuk@linaro.org
State New
Headers show

Commit Message

Taras Kondratiuk Dec. 12, 2014, 4:38 p.m. UTC
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_testsuites.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 81fd933..41c48ec 100644
--- a/test/validation/Makefile.am
+++ b/test/validation/Makefile.am
@@ -25,4 +25,5 @@  dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \
 			  odp_crypto.c common/odp_cunit_common.c
 dist_odp_shm_SOURCES = odp_shm.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..73ae4cb
--- /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_testsuites.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_testsuites.h b/test/validation/buffer/odp_buffer_testsuites.h
index 08fb4e0..ca42c2d 100644
--- a/test/validation/buffer/odp_buffer_testsuites.h
+++ b/test/validation/buffer/odp_buffer_testsuites.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 bfd9f6d..8aa61a9 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,
 };