On Thu, Dec 18, 2014 at 03:18:38AM +0000, Bill Fischofer wrote: > > > On Wed, Dec 17, 2014 at 6:17 PM, Stuart Haslam > <[email protected]<mailto:[email protected]>> wrote: > This is primarily sunny day basic functional testing, all tests are > single threaded. > > On platforms other than linux-generic testing will be performed using > the "loop" interface by default. > > For linux-generic, since we don't have a working "loop" device, a > wrapper script is run that attempts to create a pair of virtual > Ethernet interfaces for testing. If creating the interfaces fails > the test is skipped and "make check" reports it as such. > > Signed-off-by: Stuart Haslam > <[email protected]<mailto:[email protected]>> > --- > > Changes in v3; > > - mostly changes addressing review comments from Anders. > > - removed test for odp_pktio_inq_remdef() > > - added check for empty ODP_PLATFORM in odp_pktio_run > > test/validation/.gitignore | 1 + > test/validation/Makefile.am | 7 +- > test/validation/odp_pktio.c | 501 > ++++++++++++++++++++++++++++++++++++++++++ > test/validation/odp_pktio_run | 132 +++++++++++ > 4 files changed, 639 insertions(+), 2 deletions(-) > create mode 100644 test/validation/odp_pktio.c > create mode 100755 test/validation/odp_pktio_run > > diff --git a/test/validation/.gitignore b/test/validation/.gitignore > index 32834ae..c727223 100644 > --- a/test/validation/.gitignore > +++ b/test/validation/.gitignore > @@ -5,3 +5,4 @@ odp_queue > odp_crypto > odp_schedule > odp_shm > +odp_pktio > diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am > index d0b5426..cbeef5d 100644 > --- a/test/validation/Makefile.am > +++ b/test/validation/Makefile.am > @@ -3,10 +3,12 @@ include $(top_srcdir)/test/Makefile.inc > AM_CFLAGS += -I$(srcdir)/common > AM_LDFLAGS += -static > > +AM_TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} > + > if ODP_CUNIT_ENABLED > -TESTS = ${bin_PROGRAMS} > +TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio_run > 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_pktio > odp_init_LDFLAGS = $(AM_LDFLAGS) > odp_queue_LDFLAGS = $(AM_LDFLAGS) > odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto > @@ -18,6 +20,7 @@ odp_schedule_LDFLAGS = $(AM_LDFLAGS) > endif > > dist_odp_init_SOURCES = odp_init.c > +dist_odp_pktio_SOURCES = odp_pktio.c common/odp_cunit_common.c > dist_odp_queue_SOURCES = odp_queue.c common/odp_cunit_common.c > dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ > crypto/odp_crypto_test_sync_inp.c \ > diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c > new file mode 100644 > index 0000000..75a9859 > --- /dev/null > +++ b/test/validation/odp_pktio.c > @@ -0,0 +1,501 @@ > +/* Copyright (c) 2014, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > +#include <odp.h> > +#include <odp_cunit_common.h> > +#include <odp_packet.h> > + > +#include <odph_eth.h> > +#include <odph_ip.h> > +#include <odph_udp.h> > + > +#include <stdlib.h> > + > +#define SHM_PKT_POOL_SIZE (32*2048) > +#define SHM_PKT_POOL_BUF_SIZE 1856 > +#define MAX_NUM_IFACES 2 > +#define TEST_SEQ_INVALID ((uint32_t)~0) > +#define TEST_SEQ_MAGIC 0x92749451 > + > +/** interface names used for testing */ > +static const char *iface_name[MAX_NUM_IFACES]; > + > +/** number of interfaces being used (1=loopback, 2=pair) */ > +static int num_ifaces; > + > +/** local container for pktio attributes */ > +typedef struct { > + const char *name; > + odp_pktio_t id; > + odp_queue_t outq; > + odp_queue_t inq; > +} pktio_info_t; > + > +/** structure of test packet UDP payload */ > +typedef struct { > + uint32be_t magic; > + uint32be_t seq; > +} pkt_test_data_t; > + > +/** default packet pool */ > +odp_buffer_pool_t default_pkt_pool = ODP_BUFFER_POOL_INVALID; > + > +/** sequence number of IP packets */ > +odp_atomic_u32_t ip_seq; > + > +static void pktio_pkt_set_macs(odp_packet_t pkt, > + pktio_info_t *src, pktio_info_t *dst) > +{ > + uint32_t len; > + odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, &len); > + int ret; > + > + ret = odp_pktio_mac_addr(src->id, ð->src, sizeof(eth->src)); > + CU_ASSERT(ret == ODPH_ETHADDR_LEN); > + > + ret = odp_pktio_mac_addr(dst->id, ð->dst, sizeof(eth->dst)); > + CU_ASSERT(ret == ODPH_ETHADDR_LEN); > +} > + > +static int pktio_pkt_set_seq(odp_packet_t pkt) > +{ > + static uint32_t tstseq; > + size_t l4_off; > + pkt_test_data_t data; > + > + data.magic = TEST_SEQ_MAGIC; > + data.seq = tstseq; > + > + l4_off = odp_packet_l4_offset(pkt); > + if (!l4_off) { > + CU_FAIL("packet L4 offset not set"); > + return -1; > + } > + > + odp_packet_copydata_in(pkt, l4_off+ODPH_UDPHDR_LEN, > + sizeof(data), &data); > + > + tstseq++; > + > + return 0; > +} > + > +static uint32_t pktio_pkt_seq(odp_packet_t pkt) > +{ > + size_t l4_off; > + pkt_test_data_t data; > + > + l4_off = odp_packet_l4_offset(pkt); > + if (l4_off) { > + odp_packet_copydata_out(pkt, l4_off+ODPH_UDPHDR_LEN, > + sizeof(data), &data); > + > + if (data.magic == TEST_SEQ_MAGIC) > + return data.seq; > + } > + > + return TEST_SEQ_INVALID; > +} > + > +static odp_packet_t pktio_create_packet(void) > +{ > + odp_packet_t pkt; > + odph_ethhdr_t *eth; > + odph_ipv4hdr_t *ip; > + odph_udphdr_t *udp; > + char *buf; > + uint16_t seq; > + size_t payload_len = sizeof(pkt_test_data_t); > + uint8_t mac[ODPH_ETHADDR_LEN] = {0}; > + > + pkt = odp_packet_alloc(default_pkt_pool, payload_len + > ODPH_UDPHDR_LEN + > + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN); > + if (pkt == ODP_PACKET_INVALID) { > + CU_FAIL("failed to allocate packet buffer"); > + return ODP_PACKET_INVALID; > + } > + buf = odp_packet_data(pkt); > + > + /* Ethernet */ > + odp_packet_l2_offset_set(pkt, 0); > + eth = (odph_ethhdr_t *)buf; > + memcpy(eth->src.addr, mac, ODPH_ETHADDR_LEN); > + memcpy(eth->dst.addr, mac, ODPH_ETHADDR_LEN); > + eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4); > + > + /* IP */ > + odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN); > + ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN); > + ip->dst_addr = odp_cpu_to_be_32(0); > + ip->src_addr = odp_cpu_to_be_32(0); > + ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN; > + ip->tot_len = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN + > + ODPH_IPV4HDR_LEN); > + ip->ttl = 128; > + ip->proto = ODPH_IPPROTO_UDP; > + seq = odp_atomic_fetch_inc_u32(&ip_seq); > + ip->id = odp_cpu_to_be_16(seq); > + ip->chksum = 0; > + odph_ipv4_csum_update(pkt); > + > + /* UDP */ > + odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); > + udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN); > + udp->src_port = odp_cpu_to_be_16(0); > + udp->dst_port = odp_cpu_to_be_16(0); > + udp->length = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN); > + udp->chksum = 0; > + > + if (pktio_pkt_set_seq(pkt) != 0) { > + odp_packet_free(pkt); > + return ODP_PACKET_INVALID; > + } > + > + return pkt; > +} > + > +static int pktio_fixup_checksums(odp_packet_t pkt) > +{ > + odph_ipv4hdr_t *ip; > + odph_udphdr_t *udp; > + uint32_t len; > + > + ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, &len); > + > + if (ip->proto != ODPH_IPPROTO_UDP) { > + CU_FAIL("unexpected L4 protocol"); > + return -1; > + } > + > + udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, &len); > + > + ip->chksum = 0; > + odph_ipv4_csum_update(pkt); > + udp->chksum = 0; > + udp->chksum = odph_ipv4_udp_chksum(pkt); > + > + return 0; > +} > + > +static int default_pool_create(void) > +{ > + odp_buffer_pool_param_t params; > + > + if (default_pkt_pool != ODP_BUFFER_POOL_INVALID) > + return -1; > + > + params.buf_size = SHM_PKT_POOL_BUF_SIZE; > + params.buf_align = 0; > + params.num_bufs = SHM_PKT_POOL_SIZE/SHM_PKT_POOL_BUF_SIZE; > > This convention for specifying a buffer count is vestigial from the prior > odp_buffer_pool_create() API which > didn't support a num_bufs specification. Since you're letting ODP calculate > the pool size rather than passing a SHM object yourself (which is the > preferred form of this API), it's better to just state directly how many > buffers you want the pool to contain rather than doing math to derive it. > Similar comments apply to all other instances of pool creation here since > they're just copying this model. >
That makes sense. I basically just copied this from the one of the buffer pool patches, which does still do this in places (commit id 0d934707). > Also, note that SHM_PKT_POOL_SIZE is not an integral multiple of > SHM_PKT_POOL_BUF_SIZE here, so you're requesting 35.3 buffers, which > certainly looks odd (it will be truncated to 35 by integer math). > OK I'll fix it. -- Stuart. _______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
