Message ID | 1418904708-1412-2-git-send-email-taras.kondratiuk@linaro.org |
---|---|
State | New |
Headers | show |
On Thu, Dec 18, 2014 at 6:11 AM, Taras Kondratiuk < taras.kondratiuk@linaro.org> wrote: > > Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> > Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> > --- > test/validation/.gitignore | 1 + > test/validation/Makefile.am | 5 +- > test/validation/buffer/odp_buffer_pool_test.c | 212 > +++++++++++++++++++++++++ > test/validation/buffer/odp_buffer_testsuites.h | 21 +++ > test/validation/odp_buffer.c | 14 ++ > 5 files changed, 252 insertions(+), 1 deletion(-) > create mode 100644 test/validation/buffer/odp_buffer_pool_test.c > create mode 100644 test/validation/buffer/odp_buffer_testsuites.h > create mode 100644 test/validation/odp_buffer.c > > diff --git a/test/validation/.gitignore b/test/validation/.gitignore > index 32834ae..cc05f30 100644 > --- a/test/validation/.gitignore > +++ b/test/validation/.gitignore > @@ -5,3 +5,4 @@ odp_queue > odp_crypto > odp_schedule > odp_shm > +odp_buffer > diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am > index d616c8c..d2ca969 100644 > --- a/test/validation/Makefile.am > +++ b/test/validation/Makefile.am > @@ -6,8 +6,9 @@ AM_LDFLAGS += -static > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule > +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule > odp_buffer > odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto > +odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer > endif > > dist_odp_init_SOURCES = odp_init.c > @@ -18,6 +19,8 @@ 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_schedule_SOURCES = odp_schedule.c common/odp_cunit_common.c > +dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \ > + odp_buffer.c common/odp_cunit_common.c > > #For Linux generic the unimplemented crypto API functions break the > #regression TODO: https://bugs.linaro.org/show_bug.cgi?id=975 > diff --git a/test/validation/buffer/odp_buffer_pool_test.c > b/test/validation/buffer/odp_buffer_pool_test.c > new file mode 100644 > index 0000000..b41fe4d > --- /dev/null > +++ b/test/validation/buffer/odp_buffer_pool_test.c > @@ -0,0 +1,212 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include "odp_buffer_testsuites.h" > + > +static int pool_name_number = 1; > +static const int default_buffer_size = 1500; > +static const int default_buffer_num = 1000; > + > +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type) > +{ > + odp_buffer_pool_t pool; > + char pool_name[ODP_BUFFER_POOL_NAME_LEN]; > + odp_buffer_pool_param_t params = { > + .buf_size = buf_size, > + .buf_align = ODP_CACHE_LINE_SIZE, > + .num_bufs = buf_num, > + .buf_type = buf_type, > + }; > + > + snprintf(pool_name, sizeof(pool_name), > + "test_buffer_pool-%d", pool_name_number++); > + > + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + return pool; > +} > + > +static void pool_create_destroy_type(int type) > +{ > + odp_buffer_pool_t pool; > + pool = pool_create(default_buffer_num, default_buffer_size, type); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +static void pool_create_destroy_raw(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_RAW); > +} > + > +static void pool_create_destroy_packet(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_PACKET); > +} > + > +static void pool_create_destroy_timeout(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_TIMEOUT); > +} > + > +static void pool_create_destroy_any(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_ANY); > +} > + > +static void pool_create_destroy_raw_shm(void) > +{ > + odp_buffer_pool_t pool; > + odp_shm_t test_shm; > + odp_buffer_pool_param_t params = { > + .buf_size = 1500, > + .buf_align = ODP_CACHE_LINE_SIZE, > + .num_bufs = 10, > + .buf_type = ODP_BUFFER_TYPE_RAW, > + }; > + > + test_shm = odp_shm_reserve("test_shm", > + params.buf_size * params.num_bufs * 2, > + ODP_CACHE_LINE_SIZE, > + 0); > + CU_ASSERT_FATAL(test_shm != ODP_SHM_INVALID); > + > + pool = odp_buffer_pool_create("test_shm_pool", test_shm, ¶ms); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > + CU_ASSERT(odp_shm_free(test_shm) == 0); > +} > + > +static void pool_lookup_info_print(void) > +{ > + odp_buffer_pool_t pool; > + const char pool_name[] = "pool_for_lookup_test"; > + odp_buffer_pool_info_t info; > + odp_buffer_pool_param_t params = { > + .buf_size = default_buffer_size, > + .buf_align = ODP_CACHE_LINE_SIZE, > + .num_bufs = default_buffer_num, > + .buf_type = ODP_BUFFER_TYPE_RAW, > + }; > + > + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + pool = odp_buffer_pool_lookup(pool_name); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + CU_ASSERT_FATAL(odp_buffer_pool_info(pool, &info) == 0); > + CU_ASSERT(strncmp(pool_name, info.name, sizeof(pool_name)) == 0); > + CU_ASSERT(info.shm == ODP_SHM_INVALID); > + CU_ASSERT(params.buf_size <= info.params.buf_size); > + CU_ASSERT(params.buf_align <= info.params.buf_align); > + CU_ASSERT(params.num_bufs <= info.params.num_bufs); > + CU_ASSERT(params.buf_type == info.params.buf_type); > + > + odp_buffer_pool_print(pool); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +static void pool_alloc_buffer_type(int type) > +{ > + odp_buffer_pool_t pool; > + const int buf_num = 3; > + const size_t buf_size = 1500; > + odp_buffer_t buffer[buf_num]; > + int buf_index; > + char wrong_type = 0, wrong_size = 0; > + > + pool = pool_create(buf_num, buf_size, type); > + odp_buffer_pool_print(pool); > + > + /* Try to allocate buf_num buffers from the pool */ > + for (buf_index = 0; buf_index < buf_num; buf_index++) { > + buffer[buf_index] = odp_buffer_alloc(pool); > + if (buffer[buf_index] == ODP_BUFFER_INVALID) > + break; > + if (odp_buffer_type(buffer[buf_index]) != type) > + wrong_type = 1; > + if (odp_buffer_size(buffer[buf_index]) < buf_size) > + wrong_size = 1; > + if (wrong_type || wrong_size) > + odp_buffer_print(buffer[buf_index]); > + } > + > + /* Check that the pool had at least buf_num buffers */ > + CU_ASSERT(buf_index == buf_num); > + /* buf_index points out of buffer[] or it point to an invalid > buffer */ > + buf_index--; > + > + /* Check that the pool had correct buffers */ > + CU_ASSERT(wrong_type == 0); > + CU_ASSERT(wrong_size == 0); > + > + for (; buf_index >= 0; buf_index--) > + odp_buffer_free(buffer[buf_index]); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +static void pool_alloc_buffer_raw(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_RAW); > +} > + > +static void pool_alloc_buffer_packet(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_PACKET); > +} > + > +static void pool_alloc_buffer_timeout(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_TIMEOUT); > +} > + > +static void pool_alloc_buffer_any(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_ANY); > +} > + > +static void pool_free_buffer(void) > +{ > + odp_buffer_pool_t pool; > + odp_buffer_t buffer; > + pool = pool_create(1, 64, ODP_BUFFER_TYPE_RAW); > + > + /* Allocate the only buffer from the pool */ > + buffer = odp_buffer_alloc(pool); > + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); > + > + /** @todo: is it correct to assume the pool had only one buffer? */ > + CU_ASSERT_FATAL(odp_buffer_alloc(pool) == ODP_BUFFER_INVALID) > + > + odp_buffer_free(buffer); > + > + /* Check that the buffer was returned back to the pool */ > + buffer = odp_buffer_alloc(pool); > + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); > + > + odp_buffer_free(buffer); > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +CU_TestInfo buffer_pool_tests[] = { > + _CU_TEST_INFO(pool_create_destroy_raw), > + _CU_TEST_INFO(pool_create_destroy_packet), > + _CU_TEST_INFO(pool_create_destroy_timeout), > + _CU_TEST_INFO(pool_create_destroy_any), > + _CU_TEST_INFO(pool_create_destroy_raw_shm), > + _CU_TEST_INFO(pool_lookup_info_print), > + _CU_TEST_INFO(pool_alloc_buffer_raw), > + _CU_TEST_INFO(pool_alloc_buffer_packet), > + _CU_TEST_INFO(pool_alloc_buffer_timeout), > + _CU_TEST_INFO(pool_alloc_buffer_any), > + _CU_TEST_INFO(pool_free_buffer), > + CU_TEST_INFO_NULL, > +}; > diff --git a/test/validation/buffer/odp_buffer_testsuites.h > b/test/validation/buffer/odp_buffer_testsuites.h > new file mode 100644 > index 0000000..08fb4e0 > --- /dev/null > +++ b/test/validation/buffer/odp_buffer_testsuites.h > @@ -0,0 +1,21 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#ifndef ODP_BUFFER_TESTSUITES_H_ > +#define ODP_BUFFER_TESTSUITES_H_ > + > +#include <odp.h> > +#include <odp_packet.h> > +#include "odp_cunit_common.h" > + > +/* Helper macro for CU_TestInfo initialization */ > +#define _CU_TEST_INFO(test_func) {#test_func, test_func} > + > +extern CU_TestInfo buffer_pool_tests[]; > + > +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type); > + > +#endif /* ODP_BUFFER_TESTSUITES_H_ */ > diff --git a/test/validation/odp_buffer.c b/test/validation/odp_buffer.c > new file mode 100644 > index 0000000..bfd9f6d > --- /dev/null > +++ b/test/validation/odp_buffer.c > @@ -0,0 +1,14 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include "odp_buffer_testsuites.h" > + > +CU_SuiteInfo odp_testsuites[] = { > + { .pName = "buffer Pool tests", > + .pTests = buffer_pool_tests, > + }, > + CU_SUITE_INFO_NULL, > +}; > -- > 1.9.1 > >
On 18 December 2014 at 07:11, Taras Kondratiuk <taras.kondratiuk@linaro.org> wrote: > Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> > --- > test/validation/.gitignore | 1 + > test/validation/Makefile.am | 5 +- > test/validation/buffer/odp_buffer_pool_test.c | 212 > +++++++++++++++++++++++++ > test/validation/buffer/odp_buffer_testsuites.h | 21 +++ > Should be odp_buffer_test_suites.h > test/validation/odp_buffer.c | 14 ++ > 5 files changed, 252 insertions(+), 1 deletion(-) > create mode 100644 test/validation/buffer/odp_buffer_pool_test.c > create mode 100644 test/validation/buffer/odp_buffer_testsuites.h > create mode 100644 test/validation/odp_buffer.c > > diff --git a/test/validation/.gitignore b/test/validation/.gitignore > index 32834ae..cc05f30 100644 > --- a/test/validation/.gitignore > +++ b/test/validation/.gitignore > @@ -5,3 +5,4 @@ odp_queue > odp_crypto > odp_schedule > odp_shm > +odp_buffer > diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am > index d616c8c..d2ca969 100644 > --- a/test/validation/Makefile.am > +++ b/test/validation/Makefile.am > @@ -6,8 +6,9 @@ AM_LDFLAGS += -static > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule > +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule > odp_buffer > odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto > +odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer > endif > > dist_odp_init_SOURCES = odp_init.c > @@ -18,6 +19,8 @@ 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_schedule_SOURCES = odp_schedule.c common/odp_cunit_common.c > +dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \ > + odp_buffer.c common/odp_cunit_common.c > > #For Linux generic the unimplemented crypto API functions break the > #regression TODO: https://bugs.linaro.org/show_bug.cgi?id=975 > diff --git a/test/validation/buffer/odp_buffer_pool_test.c > b/test/validation/buffer/odp_buffer_pool_test.c > new file mode 100644 > index 0000000..b41fe4d > --- /dev/null > +++ b/test/validation/buffer/odp_buffer_pool_test.c > @@ -0,0 +1,212 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include "odp_buffer_testsuites.h" > + > +static int pool_name_number = 1; > +static const int default_buffer_size = 1500; > +static const int default_buffer_num = 1000; > + > +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type) > +{ > + odp_buffer_pool_t pool; > + char pool_name[ODP_BUFFER_POOL_NAME_LEN]; > + odp_buffer_pool_param_t params = { > + .buf_size = buf_size, > + .buf_align = ODP_CACHE_LINE_SIZE, > + .num_bufs = buf_num, > + .buf_type = buf_type, > + }; > + > + snprintf(pool_name, sizeof(pool_name), > + "test_buffer_pool-%d", pool_name_number++); > + > + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + return pool; > +} > + > +static void pool_create_destroy_type(int type) > +{ > + odp_buffer_pool_t pool; > + pool = pool_create(default_buffer_num, default_buffer_size, type); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +static void pool_create_destroy_raw(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_RAW); > +} > + > +static void pool_create_destroy_packet(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_PACKET); > +} > + > +static void pool_create_destroy_timeout(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_TIMEOUT); > +} > + > +static void pool_create_destroy_any(void) > +{ > + pool_create_destroy_type(ODP_BUFFER_TYPE_ANY); > +} > + > +static void pool_create_destroy_raw_shm(void) > +{ > + odp_buffer_pool_t pool; > + odp_shm_t test_shm; > + odp_buffer_pool_param_t params = { > + .buf_size = 1500, > + .buf_align = ODP_CACHE_LINE_SIZE, > + .num_bufs = 10, > + .buf_type = ODP_BUFFER_TYPE_RAW, > + }; > + > + test_shm = odp_shm_reserve("test_shm", > + params.buf_size * params.num_bufs * 2, > + ODP_CACHE_LINE_SIZE, > + 0); > + CU_ASSERT_FATAL(test_shm != ODP_SHM_INVALID); > + > + pool = odp_buffer_pool_create("test_shm_pool", test_shm, ¶ms); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > + CU_ASSERT(odp_shm_free(test_shm) == 0); > +} > + > +static void pool_lookup_info_print(void) > +{ > + odp_buffer_pool_t pool; > + const char pool_name[] = "pool_for_lookup_test"; > + odp_buffer_pool_info_t info; > + odp_buffer_pool_param_t params = { > + .buf_size = default_buffer_size, > + .buf_align = ODP_CACHE_LINE_SIZE, > + .num_bufs = default_buffer_num, > + .buf_type = ODP_BUFFER_TYPE_RAW, > + }; > + > + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + pool = odp_buffer_pool_lookup(pool_name); > + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); > + > + CU_ASSERT_FATAL(odp_buffer_pool_info(pool, &info) == 0); > + CU_ASSERT(strncmp(pool_name, info.name, sizeof(pool_name)) == 0); > + CU_ASSERT(info.shm == ODP_SHM_INVALID); > + CU_ASSERT(params.buf_size <= info.params.buf_size); > + CU_ASSERT(params.buf_align <= info.params.buf_align); > + CU_ASSERT(params.num_bufs <= info.params.num_bufs); > + CU_ASSERT(params.buf_type == info.params.buf_type); > + > + odp_buffer_pool_print(pool); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +static void pool_alloc_buffer_type(int type) > +{ > + odp_buffer_pool_t pool; > + const int buf_num = 3; > + const size_t buf_size = 1500; > + odp_buffer_t buffer[buf_num]; > + int buf_index; > + char wrong_type = 0, wrong_size = 0; > + > + pool = pool_create(buf_num, buf_size, type); > + odp_buffer_pool_print(pool); > + > + /* Try to allocate buf_num buffers from the pool */ > + for (buf_index = 0; buf_index < buf_num; buf_index++) { > + buffer[buf_index] = odp_buffer_alloc(pool); > + if (buffer[buf_index] == ODP_BUFFER_INVALID) > + break; > + if (odp_buffer_type(buffer[buf_index]) != type) > + wrong_type = 1; > + if (odp_buffer_size(buffer[buf_index]) < buf_size) > + wrong_size = 1; > + if (wrong_type || wrong_size) > + odp_buffer_print(buffer[buf_index]); > + } > + > + /* Check that the pool had at least buf_num buffers */ > + CU_ASSERT(buf_index == buf_num); > + /* buf_index points out of buffer[] or it point to an invalid > buffer */ > + buf_index--; > + > + /* Check that the pool had correct buffers */ > + CU_ASSERT(wrong_type == 0); > + CU_ASSERT(wrong_size == 0); > + > + for (; buf_index >= 0; buf_index--) > + odp_buffer_free(buffer[buf_index]); > + > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +static void pool_alloc_buffer_raw(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_RAW); > +} > + > +static void pool_alloc_buffer_packet(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_PACKET); > +} > + > +static void pool_alloc_buffer_timeout(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_TIMEOUT); > +} > + > +static void pool_alloc_buffer_any(void) > +{ > + pool_alloc_buffer_type(ODP_BUFFER_TYPE_ANY); > +} > + > +static void pool_free_buffer(void) > +{ > + odp_buffer_pool_t pool; > + odp_buffer_t buffer; > + pool = pool_create(1, 64, ODP_BUFFER_TYPE_RAW); > + > + /* Allocate the only buffer from the pool */ > + buffer = odp_buffer_alloc(pool); > + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); > + > + /** @todo: is it correct to assume the pool had only one buffer? */ > + CU_ASSERT_FATAL(odp_buffer_alloc(pool) == ODP_BUFFER_INVALID) > + > + odp_buffer_free(buffer); > + > + /* Check that the buffer was returned back to the pool */ > + buffer = odp_buffer_alloc(pool); > + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); > + > + odp_buffer_free(buffer); > + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); > +} > + > +CU_TestInfo buffer_pool_tests[] = { > + _CU_TEST_INFO(pool_create_destroy_raw), > + _CU_TEST_INFO(pool_create_destroy_packet), > + _CU_TEST_INFO(pool_create_destroy_timeout), > + _CU_TEST_INFO(pool_create_destroy_any), > + _CU_TEST_INFO(pool_create_destroy_raw_shm), > + _CU_TEST_INFO(pool_lookup_info_print), > + _CU_TEST_INFO(pool_alloc_buffer_raw), > + _CU_TEST_INFO(pool_alloc_buffer_packet), > + _CU_TEST_INFO(pool_alloc_buffer_timeout), > + _CU_TEST_INFO(pool_alloc_buffer_any), > + _CU_TEST_INFO(pool_free_buffer), > + CU_TEST_INFO_NULL, > +}; > diff --git a/test/validation/buffer/odp_buffer_testsuites.h > b/test/validation/buffer/odp_buffer_testsuites.h > new file mode 100644 > index 0000000..08fb4e0 > --- /dev/null > +++ b/test/validation/buffer/odp_buffer_testsuites.h > @@ -0,0 +1,21 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#ifndef ODP_BUFFER_TESTSUITES_H_ > +#define ODP_BUFFER_TESTSUITES_H_ > + > +#include <odp.h> > +#include <odp_packet.h> > +#include "odp_cunit_common.h" > + > +/* Helper macro for CU_TestInfo initialization */ > +#define _CU_TEST_INFO(test_func) {#test_func, test_func} > + > +extern CU_TestInfo buffer_pool_tests[]; > + > +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type); > + > +#endif /* ODP_BUFFER_TESTSUITES_H_ */ > diff --git a/test/validation/odp_buffer.c b/test/validation/odp_buffer.c > new file mode 100644 > index 0000000..bfd9f6d > --- /dev/null > +++ b/test/validation/odp_buffer.c > @@ -0,0 +1,14 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include "odp_buffer_testsuites.h" > + > +CU_SuiteInfo odp_testsuites[] = { > + { .pName = "buffer Pool tests", > + .pTests = buffer_pool_tests, > + }, > + CU_SUITE_INFO_NULL, > +}; > -- > 1.9.1 > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/lng-odp >
diff --git a/test/validation/.gitignore b/test/validation/.gitignore index 32834ae..cc05f30 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -5,3 +5,4 @@ odp_queue odp_crypto odp_schedule odp_shm +odp_buffer diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index d616c8c..d2ca969 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,8 +6,9 @@ AM_LDFLAGS += -static if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_buffer odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto +odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer endif dist_odp_init_SOURCES = odp_init.c @@ -18,6 +19,8 @@ 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_schedule_SOURCES = odp_schedule.c common/odp_cunit_common.c +dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \ + odp_buffer.c common/odp_cunit_common.c #For Linux generic the unimplemented crypto API functions break the #regression TODO: https://bugs.linaro.org/show_bug.cgi?id=975 diff --git a/test/validation/buffer/odp_buffer_pool_test.c b/test/validation/buffer/odp_buffer_pool_test.c new file mode 100644 index 0000000..b41fe4d --- /dev/null +++ b/test/validation/buffer/odp_buffer_pool_test.c @@ -0,0 +1,212 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp_buffer_testsuites.h" + +static int pool_name_number = 1; +static const int default_buffer_size = 1500; +static const int default_buffer_num = 1000; + +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type) +{ + odp_buffer_pool_t pool; + char pool_name[ODP_BUFFER_POOL_NAME_LEN]; + odp_buffer_pool_param_t params = { + .buf_size = buf_size, + .buf_align = ODP_CACHE_LINE_SIZE, + .num_bufs = buf_num, + .buf_type = buf_type, + }; + + snprintf(pool_name, sizeof(pool_name), + "test_buffer_pool-%d", pool_name_number++); + + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + return pool; +} + +static void pool_create_destroy_type(int type) +{ + odp_buffer_pool_t pool; + pool = pool_create(default_buffer_num, default_buffer_size, type); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +static void pool_create_destroy_raw(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_RAW); +} + +static void pool_create_destroy_packet(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_PACKET); +} + +static void pool_create_destroy_timeout(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_TIMEOUT); +} + +static void pool_create_destroy_any(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_ANY); +} + +static void pool_create_destroy_raw_shm(void) +{ + odp_buffer_pool_t pool; + odp_shm_t test_shm; + odp_buffer_pool_param_t params = { + .buf_size = 1500, + .buf_align = ODP_CACHE_LINE_SIZE, + .num_bufs = 10, + .buf_type = ODP_BUFFER_TYPE_RAW, + }; + + test_shm = odp_shm_reserve("test_shm", + params.buf_size * params.num_bufs * 2, + ODP_CACHE_LINE_SIZE, + 0); + CU_ASSERT_FATAL(test_shm != ODP_SHM_INVALID); + + pool = odp_buffer_pool_create("test_shm_pool", test_shm, ¶ms); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); + CU_ASSERT(odp_shm_free(test_shm) == 0); +} + +static void pool_lookup_info_print(void) +{ + odp_buffer_pool_t pool; + const char pool_name[] = "pool_for_lookup_test"; + odp_buffer_pool_info_t info; + odp_buffer_pool_param_t params = { + .buf_size = default_buffer_size, + .buf_align = ODP_CACHE_LINE_SIZE, + .num_bufs = default_buffer_num, + .buf_type = ODP_BUFFER_TYPE_RAW, + }; + + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + pool = odp_buffer_pool_lookup(pool_name); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + CU_ASSERT_FATAL(odp_buffer_pool_info(pool, &info) == 0); + CU_ASSERT(strncmp(pool_name, info.name, sizeof(pool_name)) == 0); + CU_ASSERT(info.shm == ODP_SHM_INVALID); + CU_ASSERT(params.buf_size <= info.params.buf_size); + CU_ASSERT(params.buf_align <= info.params.buf_align); + CU_ASSERT(params.num_bufs <= info.params.num_bufs); + CU_ASSERT(params.buf_type == info.params.buf_type); + + odp_buffer_pool_print(pool); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +static void pool_alloc_buffer_type(int type) +{ + odp_buffer_pool_t pool; + const int buf_num = 3; + const size_t buf_size = 1500; + odp_buffer_t buffer[buf_num]; + int buf_index; + char wrong_type = 0, wrong_size = 0; + + pool = pool_create(buf_num, buf_size, type); + odp_buffer_pool_print(pool); + + /* Try to allocate buf_num buffers from the pool */ + for (buf_index = 0; buf_index < buf_num; buf_index++) { + buffer[buf_index] = odp_buffer_alloc(pool); + if (buffer[buf_index] == ODP_BUFFER_INVALID) + break; + if (odp_buffer_type(buffer[buf_index]) != type) + wrong_type = 1; + if (odp_buffer_size(buffer[buf_index]) < buf_size) + wrong_size = 1; + if (wrong_type || wrong_size) + odp_buffer_print(buffer[buf_index]); + } + + /* Check that the pool had at least buf_num buffers */ + CU_ASSERT(buf_index == buf_num); + /* buf_index points out of buffer[] or it point to an invalid buffer */ + buf_index--; + + /* Check that the pool had correct buffers */ + CU_ASSERT(wrong_type == 0); + CU_ASSERT(wrong_size == 0); + + for (; buf_index >= 0; buf_index--) + odp_buffer_free(buffer[buf_index]); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +static void pool_alloc_buffer_raw(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_RAW); +} + +static void pool_alloc_buffer_packet(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_PACKET); +} + +static void pool_alloc_buffer_timeout(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_TIMEOUT); +} + +static void pool_alloc_buffer_any(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_ANY); +} + +static void pool_free_buffer(void) +{ + odp_buffer_pool_t pool; + odp_buffer_t buffer; + pool = pool_create(1, 64, ODP_BUFFER_TYPE_RAW); + + /* Allocate the only buffer from the pool */ + buffer = odp_buffer_alloc(pool); + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); + + /** @todo: is it correct to assume the pool had only one buffer? */ + CU_ASSERT_FATAL(odp_buffer_alloc(pool) == ODP_BUFFER_INVALID) + + odp_buffer_free(buffer); + + /* Check that the buffer was returned back to the pool */ + buffer = odp_buffer_alloc(pool); + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); + + odp_buffer_free(buffer); + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +CU_TestInfo buffer_pool_tests[] = { + _CU_TEST_INFO(pool_create_destroy_raw), + _CU_TEST_INFO(pool_create_destroy_packet), + _CU_TEST_INFO(pool_create_destroy_timeout), + _CU_TEST_INFO(pool_create_destroy_any), + _CU_TEST_INFO(pool_create_destroy_raw_shm), + _CU_TEST_INFO(pool_lookup_info_print), + _CU_TEST_INFO(pool_alloc_buffer_raw), + _CU_TEST_INFO(pool_alloc_buffer_packet), + _CU_TEST_INFO(pool_alloc_buffer_timeout), + _CU_TEST_INFO(pool_alloc_buffer_any), + _CU_TEST_INFO(pool_free_buffer), + CU_TEST_INFO_NULL, +}; diff --git a/test/validation/buffer/odp_buffer_testsuites.h b/test/validation/buffer/odp_buffer_testsuites.h new file mode 100644 index 0000000..08fb4e0 --- /dev/null +++ b/test/validation/buffer/odp_buffer_testsuites.h @@ -0,0 +1,21 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_BUFFER_TESTSUITES_H_ +#define ODP_BUFFER_TESTSUITES_H_ + +#include <odp.h> +#include <odp_packet.h> +#include "odp_cunit_common.h" + +/* Helper macro for CU_TestInfo initialization */ +#define _CU_TEST_INFO(test_func) {#test_func, test_func} + +extern CU_TestInfo buffer_pool_tests[]; + +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type); + +#endif /* ODP_BUFFER_TESTSUITES_H_ */ diff --git a/test/validation/odp_buffer.c b/test/validation/odp_buffer.c new file mode 100644 index 0000000..bfd9f6d --- /dev/null +++ b/test/validation/odp_buffer.c @@ -0,0 +1,14 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp_buffer_testsuites.h" + +CU_SuiteInfo odp_testsuites[] = { + { .pName = "buffer Pool tests", + .pTests = buffer_pool_tests, + }, + CU_SUITE_INFO_NULL, +};
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> --- test/validation/.gitignore | 1 + test/validation/Makefile.am | 5 +- test/validation/buffer/odp_buffer_pool_test.c | 212 +++++++++++++++++++++++++ test/validation/buffer/odp_buffer_testsuites.h | 21 +++ test/validation/odp_buffer.c | 14 ++ 5 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 test/validation/buffer/odp_buffer_pool_test.c create mode 100644 test/validation/buffer/odp_buffer_testsuites.h create mode 100644 test/validation/odp_buffer.c