Message ID | 1418050713-29694-8-git-send-email-maxim.uvarov@linaro.org |
---|---|
State | New |
Headers | show |
On 8 December 2014 at 09:58, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > Add cunit tests for new pktio api: > - MAC address get; > - Promisc mode set / test; > - MTU value set / get; > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> > --- > test/validation/.gitignore | 3 +- > test/validation/Makefile.am | 4 +- > test/validation/odp_pktio.c | 155 > ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 160 insertions(+), 2 deletions(-) > create mode 100644 test/validation/odp_pktio.c > > diff --git a/test/validation/.gitignore b/test/validation/.gitignore > index 37e2594..78e18f9 100644 > --- a/test/validation/.gitignore > +++ b/test/validation/.gitignore > @@ -1,6 +1,7 @@ > *.log > *.trs > +odp_crypto > odp_init > +odp_pktio > odp_queue > -odp_crypto > odp_shm > diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am > index f603036..0b7797e 100644 > --- a/test/validation/Makefile.am > +++ b/test/validation/Makefile.am > @@ -5,13 +5,14 @@ AM_LDFLAGS += -static > if ODP_CUNIT_ENABLED > TESTS = ${bin_PROGRAMS} > check_PROGRAMS = ${bin_PROGRAMS} > -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm > +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm 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_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common > odp_shm_LDFLAGS = $(AM_LDFLAGS) > +odp_pktio_LDFLAGS = $(AM_LDFLAGS) > endif > > dist_odp_init_SOURCES = odp_init.c > @@ -21,3 +22,4 @@ dist_odp_crypto_SOURCES = > crypto/odp_crypto_test_async_inp.c \ > crypto/odp_crypto_test_rng.c \ > odp_crypto.c > dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.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..db6aaf0 > --- /dev/null > +++ b/test/validation/odp_pktio.c > @@ -0,0 +1,155 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include <odp.h> > +#include "CUnit/Basic.h" > +#include <linux/if_ether.h> > Does this include break bare metal or other platforms ? If we take this patch now I think we need to add a TODO that links to a bug to remove this include > + > +#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_mac(void) > +{ > + unsigned char mac_addr[ETH_ALEN]; > + size_t mac_len; > + > + mac_len = odp_pktio_mac_addr(pktio, mac_addr, ETH_ALEN); > + CU_ASSERT(ETH_ALEN == mac_len); > + > + printf(" %X:%X:%X:%X:%X:%X ", > + mac_addr[0], mac_addr[1], mac_addr[2], > + mac_addr[3], mac_addr[4], mac_addr[5]); > + > + /* Fail case */ > + mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); > + CU_ASSERT(0 == mac_len); > + > + return; > +} > + > +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(i == ret); > + } > + > + ret = odp_pktio_set_mtu(pktio, def); > + CU_ASSERT(0 == ret); > + > + return; > +} > + > +static void test_pktio_promisc(void) > +{ > + int ret; > + > + ret = odp_pktio_promisc_mode_set(pktio, 1); > + CU_ASSERT(0 == ret); > + > + /* Check */ > + ret = odp_pktio_promisc_mode(pktio); > + CU_ASSERT(1 == ret); > + > + ret = odp_pktio_promisc_mode_set(pktio, 0); > + CU_ASSERT(0 == ret); > + > + /* Check */ > + ret = odp_pktio_promisc_mode(pktio); > + CU_ASSERT(0 == ret); > + > + return; > +} > + > +static CU_TestInfo test_pktio[] = { > + {"mac", test_pktio_mac }, > + {"mtu", test_pktio_mtu }, > + {"promisc", test_pktio_promisc }, > + CU_TEST_INFO_NULL, > +}; > + > +static CU_SuiteInfo suites[] = { > + { "Packet I/O" , NULL, NULL, NULL, NULL, test_pktio }, > + CU_SUITE_INFO_NULL, > +}; > + > +int main(void) > Main needs to reuse the main in validation/common, it has hooks for initialization. > +{ > + int ret; > + odp_shm_t shm; > + void *pool_base; > + odp_buffer_pool_t pool; > + > + 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; > + } > + > + /* Open a packet IO instance for this thread */ > + pktio = odp_pktio_open("loop", pool); > + if (pktio == ODP_PKTIO_INVALID) { > + fprintf(stderr, "Error: pktio create failed\n"); > + return -1; > + } > + > + printf("\tODP version: %s\n", odp_version_api_str()); > + > + /* Fail in any cunit internal errors */ > + CU_set_error_action(CUEA_ABORT); > + > + CU_initialize_registry(); > + CU_register_suites(suites); > + CU_basic_set_mode(CU_BRM_VERBOSE); > + > + CU_basic_run_tests(); > + > + ret = CU_get_number_of_failure_records(); > + > + CU_cleanup_registry(); > + > + odp_term_local(); > + odp_term_global(); > + > + return ret; > +} > -- > 1.8.5.1.163.gd7aced9 > > > _______________________________________________ > 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 37e2594..78e18f9 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -1,6 +1,7 @@ *.log *.trs +odp_crypto odp_init +odp_pktio odp_queue -odp_crypto odp_shm diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index f603036..0b7797e 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -5,13 +5,14 @@ AM_LDFLAGS += -static if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm 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_shm_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/common odp_shm_LDFLAGS = $(AM_LDFLAGS) +odp_pktio_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -21,3 +22,4 @@ dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_rng.c \ odp_crypto.c dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.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..db6aaf0 --- /dev/null +++ b/test/validation/odp_pktio.c @@ -0,0 +1,155 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <odp.h> +#include "CUnit/Basic.h" +#include <linux/if_ether.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_mac(void) +{ + unsigned char mac_addr[ETH_ALEN]; + size_t mac_len; + + mac_len = odp_pktio_mac_addr(pktio, mac_addr, ETH_ALEN); + CU_ASSERT(ETH_ALEN == mac_len); + + printf(" %X:%X:%X:%X:%X:%X ", + mac_addr[0], mac_addr[1], mac_addr[2], + mac_addr[3], mac_addr[4], mac_addr[5]); + + /* Fail case */ + mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); + CU_ASSERT(0 == mac_len); + + return; +} + +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(i == ret); + } + + ret = odp_pktio_set_mtu(pktio, def); + CU_ASSERT(0 == ret); + + return; +} + +static void test_pktio_promisc(void) +{ + int ret; + + ret = odp_pktio_promisc_mode_set(pktio, 1); + CU_ASSERT(0 == ret); + + /* Check */ + ret = odp_pktio_promisc_mode(pktio); + CU_ASSERT(1 == ret); + + ret = odp_pktio_promisc_mode_set(pktio, 0); + CU_ASSERT(0 == ret); + + /* Check */ + ret = odp_pktio_promisc_mode(pktio); + CU_ASSERT(0 == ret); + + return; +} + +static CU_TestInfo test_pktio[] = { + {"mac", test_pktio_mac }, + {"mtu", test_pktio_mtu }, + {"promisc", test_pktio_promisc }, + CU_TEST_INFO_NULL, +}; + +static CU_SuiteInfo suites[] = { + { "Packet I/O" , NULL, NULL, NULL, NULL, test_pktio }, + CU_SUITE_INFO_NULL, +}; + +int main(void) +{ + int ret; + odp_shm_t shm; + void *pool_base; + odp_buffer_pool_t pool; + + 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; + } + + /* Open a packet IO instance for this thread */ + pktio = odp_pktio_open("loop", pool); + if (pktio == ODP_PKTIO_INVALID) { + fprintf(stderr, "Error: pktio create failed\n"); + return -1; + } + + printf("\tODP version: %s\n", odp_version_api_str()); + + /* Fail in any cunit internal errors */ + CU_set_error_action(CUEA_ABORT); + + CU_initialize_registry(); + CU_register_suites(suites); + CU_basic_set_mode(CU_BRM_VERBOSE); + + CU_basic_run_tests(); + + ret = CU_get_number_of_failure_records(); + + CU_cleanup_registry(); + + odp_term_local(); + odp_term_global(); + + return ret; +}
Add cunit tests for new pktio api: - MAC address get; - Promisc mode set / test; - MTU value set / get; Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- test/validation/.gitignore | 3 +- test/validation/Makefile.am | 4 +- test/validation/odp_pktio.c | 155 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 test/validation/odp_pktio.c