Message ID | 1417442928-20680-5-git-send-email-maxim.uvarov@linaro.org |
---|---|
State | New |
Headers | show |
On 2014-12-01 17:08, Maxim Uvarov wrote: > Add basic check for mtu and promisc modes. > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> > --- > test/validation/Makefile.am | 4 +- > test/validation/odp_pktio.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 167 insertions(+), 1 deletion(-) > create mode 100644 test/validation/odp_pktio.c > > diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am > index 0b831d0..91adc7e 100644 > --- a/test/validation/Makefile.am > +++ b/test/validation/Makefile.am > @@ -6,11 +6,12 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init odp_queue odp_crypto > +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_pktio > odp_init_LDFLAGS = $(AM_LDFLAGS) > odp_queue_LDFLAGS = $(AM_LDFLAGS) > odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto > odp_crypto_LDFLAGS = $(AM_LDFLAGS) > +odp_pktio_LDFLAGS = $(AM_LDFLAGS) > endif > > dist_odp_init_SOURCES = odp_init.c > @@ -18,3 +19,4 @@ dist_odp_queue_SOURCES = odp_queue.c > dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ > crypto/odp_crypto_test_sync_inp.c \ > odp_crypto.c > +dist_odp_pktio_SOURCES = odp_pktio.c > diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c > new file mode 100644 > index 0000000..56fece9 > --- /dev/null > +++ b/test/validation/odp_pktio.c > @@ -0,0 +1,164 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include <odp.h> > +#include "CUnit/Basic.h" > + > +#define SHM_PKT_POOL_SIZE (512 * 2048 * 2) > +#define SHM_PKT_POOL_BUF_SIZE (1024 * 32) > + > +#define SHM_COMPL_POOL_SIZE (128 * 1024) > +#define SHM_COMPL_POOL_BUF_SIZE 128 > + > +static odp_pktio_t pktio; > + > +static void test_pktio_mtu(void) > +{ > + int i; > + int ret; > + int def; > + > + def = odp_pktio_mtu(pktio); > + CU_ASSERT(def > 0); > + > + for (i = 64; i < 9000; i *= 2) { > + printf(" %d ", i); > + > + ret = odp_pktio_set_mtu(pktio, i); > + CU_ASSERT(0 == ret); > + > + ret = odp_pktio_mtu(pktio); > + CU_ASSERT(ret == i); > + } > + > + ret = odp_pktio_set_mtu(pktio, def); > + CU_ASSERT(0 == ret); Please be consistent in how you call CU_ASSERT in a file. I like this way however you've swapped it for other paces in this file. > + > + return; > +} > + > +static void test_pktio_promisc(void) > +{ > + int ret; > + > + ret = odp_pktio_promisc_set(pktio, 1); > + CU_ASSERT(ret == 0); > + > + /* Check */ > + ret = odp_pktio_promisc_enabled(pktio); > + CU_ASSERT(ret == 1); > + > + ret = odp_pktio_promisc_set(pktio, 0); > + CU_ASSERT(ret == 0); > + > + /* Check */ > + ret = odp_pktio_promisc_enabled(pktio); > + CU_ASSERT(ret == 0); > + > + return; > +} > + > +int main(void) > +{ > + odp_shm_t shm; > + void *pool_base; > + odp_buffer_pool_t pool; > + odp_queue_t out_queue; > + CU_pSuite ptr_suite; > + CU_pTest ptest; > + > + if (odp_init_global(NULL, NULL)) { > + printf("ODP global init failed.\n"); > + return -1; > + } > + odp_init_local(); > + > + shm = odp_shm_reserve("shm_packet_pool", > + SHM_PKT_POOL_SIZE, > + ODP_CACHE_LINE_SIZE, 0); > + > + pool_base = odp_shm_addr(shm); > + if (!pool_base) { > + fprintf(stderr, "Packet pool allocation failed.\n"); > + return -1; > + } > + > + pool = odp_buffer_pool_create("packet_pool", pool_base, > + SHM_PKT_POOL_SIZE, > + SHM_PKT_POOL_BUF_SIZE, > + ODP_CACHE_LINE_SIZE, > + ODP_BUFFER_TYPE_PACKET); > + if (ODP_BUFFER_POOL_INVALID == pool) { > + fprintf(stderr, "Packet pool creation failed.\n"); > + return -1; > + } > + out_queue = odp_queue_create("crypto-out", > + ODP_QUEUE_TYPE_POLL, NULL); > + if (ODP_QUEUE_INVALID == out_queue) { > + fprintf(stderr, "Crypto outq creation failed.\n"); > + return -1; > + } > + shm = odp_shm_reserve("shm_compl_pool", > + SHM_COMPL_POOL_SIZE, > + ODP_CACHE_LINE_SIZE, > + ODP_SHM_SW_ONLY); > + pool_base = odp_shm_addr(shm); > + if (!pool_base) { > + fprintf(stderr, "Completion pool allocation failed.\n"); > + return -1; > + } > + pool = odp_buffer_pool_create("compl_pool", pool_base, > + SHM_COMPL_POOL_SIZE, > + SHM_COMPL_POOL_BUF_SIZE, > + ODP_CACHE_LINE_SIZE, > + ODP_BUFFER_TYPE_RAW); > + if (ODP_BUFFER_POOL_INVALID == pool) { > + fprintf(stderr, "Completion pool creation failed.\n"); > + return -1; > + } > + > + /* Open a packet IO instance for this thread */ > + pktio = odp_pktio_open("eth0", pool); > + if (pktio == ODP_PKTIO_INVALID) { > + fprintf(stderr, "Error: pktio create failed\n"); > + return -1; > + } > + > + printf("\tODP version: %s\n", odp_version_api_str()); > + > + /* initialize the CUnit test registry */ > + if (CUE_SUCCESS != CU_initialize_registry()) > + return CU_get_error(); > + > + /* add a suite to the registry */ > + ptr_suite = CU_add_suite(__FILE__, NULL, NULL); > + if (NULL == ptr_suite) { > + CU_cleanup_registry(); > + return CU_get_error(); > + } Didn't we want to use CU_SuiteInfo to register tests, specially when we are going to add more. CU_SuiteInfo suites[] = {...} Cheers, Anders
diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 0b831d0..91adc7e 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,11 +6,12 @@ AM_LDFLAGS += -L$(CUNIT_PATH)/lib -static -lcunit if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_pktio odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) +odp_pktio_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -18,3 +19,4 @@ dist_odp_queue_SOURCES = odp_queue.c dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_sync_inp.c \ odp_crypto.c +dist_odp_pktio_SOURCES = odp_pktio.c diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c new file mode 100644 index 0000000..56fece9 --- /dev/null +++ b/test/validation/odp_pktio.c @@ -0,0 +1,164 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> +#include "CUnit/Basic.h" + +#define SHM_PKT_POOL_SIZE (512 * 2048 * 2) +#define SHM_PKT_POOL_BUF_SIZE (1024 * 32) + +#define SHM_COMPL_POOL_SIZE (128 * 1024) +#define SHM_COMPL_POOL_BUF_SIZE 128 + +static odp_pktio_t pktio; + +static void test_pktio_mtu(void) +{ + int i; + int ret; + int def; + + def = odp_pktio_mtu(pktio); + CU_ASSERT(def > 0); + + for (i = 64; i < 9000; i *= 2) { + printf(" %d ", i); + + ret = odp_pktio_set_mtu(pktio, i); + CU_ASSERT(0 == ret); + + ret = odp_pktio_mtu(pktio); + CU_ASSERT(ret == i); + } + + ret = odp_pktio_set_mtu(pktio, def); + CU_ASSERT(0 == ret); + + return; +} + +static void test_pktio_promisc(void) +{ + int ret; + + ret = odp_pktio_promisc_set(pktio, 1); + CU_ASSERT(ret == 0); + + /* Check */ + ret = odp_pktio_promisc_enabled(pktio); + CU_ASSERT(ret == 1); + + ret = odp_pktio_promisc_set(pktio, 0); + CU_ASSERT(ret == 0); + + /* Check */ + ret = odp_pktio_promisc_enabled(pktio); + CU_ASSERT(ret == 0); + + return; +} + +int main(void) +{ + odp_shm_t shm; + void *pool_base; + odp_buffer_pool_t pool; + odp_queue_t out_queue; + CU_pSuite ptr_suite; + CU_pTest ptest; + + if (odp_init_global(NULL, NULL)) { + printf("ODP global init failed.\n"); + return -1; + } + odp_init_local(); + + shm = odp_shm_reserve("shm_packet_pool", + SHM_PKT_POOL_SIZE, + ODP_CACHE_LINE_SIZE, 0); + + pool_base = odp_shm_addr(shm); + if (!pool_base) { + fprintf(stderr, "Packet pool allocation failed.\n"); + return -1; + } + + pool = odp_buffer_pool_create("packet_pool", pool_base, + SHM_PKT_POOL_SIZE, + SHM_PKT_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_PACKET); + if (ODP_BUFFER_POOL_INVALID == pool) { + fprintf(stderr, "Packet pool creation failed.\n"); + return -1; + } + out_queue = odp_queue_create("crypto-out", + ODP_QUEUE_TYPE_POLL, NULL); + if (ODP_QUEUE_INVALID == out_queue) { + fprintf(stderr, "Crypto outq creation failed.\n"); + return -1; + } + shm = odp_shm_reserve("shm_compl_pool", + SHM_COMPL_POOL_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_SHM_SW_ONLY); + pool_base = odp_shm_addr(shm); + if (!pool_base) { + fprintf(stderr, "Completion pool allocation failed.\n"); + return -1; + } + pool = odp_buffer_pool_create("compl_pool", pool_base, + SHM_COMPL_POOL_SIZE, + SHM_COMPL_POOL_BUF_SIZE, + ODP_CACHE_LINE_SIZE, + ODP_BUFFER_TYPE_RAW); + if (ODP_BUFFER_POOL_INVALID == pool) { + fprintf(stderr, "Completion pool creation failed.\n"); + return -1; + } + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open("eth0", pool); + if (pktio == ODP_PKTIO_INVALID) { + fprintf(stderr, "Error: pktio create failed\n"); + return -1; + } + + printf("\tODP version: %s\n", odp_version_api_str()); + + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add a suite to the registry */ + ptr_suite = CU_add_suite(__FILE__, NULL, NULL); + if (NULL == ptr_suite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + ptest = CU_ADD_TEST(ptr_suite, test_pktio_mtu); + if (NULL == ptest) { + CU_cleanup_registry(); + return CU_get_error(); + } + + ptest = CU_ADD_TEST(ptr_suite, test_pktio_promisc); + if (NULL == ptest) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + odp_term_local(); + odp_term_global(); + + return CU_get_error(); +}
Add basic check for mtu and promisc modes. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- test/validation/Makefile.am | 4 +- test/validation/odp_pktio.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 test/validation/odp_pktio.c