From patchwork Thu Aug 20 16:44:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 52601 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id A5D3E22E4F for ; Thu, 20 Aug 2015 16:45:48 +0000 (UTC) Received: by lagz9 with SMTP id z9sf13291593lag.3 for ; Thu, 20 Aug 2015 09:45:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=feOnrYUB2rRZzaDG3aGCiJgg+raExrhojI3A9LuV+Zc=; b=c3X2OdMFqQryWSpbgcLCHBt7gELJ8cjZbLKCkOV+X8Z2c7etxjJkCElPHSPKn3UaWX j3XS2PPMXKc2wPprpIlbCX+jzuGNQWzgu74Q1GtSbFYFweoHdjcXCbmw9sVJ8vhR32F4 uLhKtG3YtD+HmAzv1KmBdmmoAPTQeX49raBWxuBFUZ6mmvSzl7j7XZhTyul45iGamFkE J+QPFsUYpKEg7HzKeJtATVPQdP+eUzx5uJCBpUcBMa/mSMvY5+6W9DEQPYwGvKWpRaDu 2Cj2+NJh4eq1vM7Wxf6srPdHfZatLzWM1ivnGGTu7k2VLWQLiZM5wKLqNNs/TFw6ATMw J+iw== X-Gm-Message-State: ALoCoQk5aSRNYOIsFw8iJ4syWfwyLIRPbLyMn/JfUpWe7ecu6YDpkIHWHxbezBiz/wjVz6DMNLBy X-Received: by 10.180.35.162 with SMTP id i2mr9425877wij.6.1440089147555; Thu, 20 Aug 2015 09:45:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.169 with SMTP id f9ls212562lam.93.gmail; Thu, 20 Aug 2015 09:45:47 -0700 (PDT) X-Received: by 10.112.148.130 with SMTP id ts2mr3709136lbb.17.1440089147385; Thu, 20 Aug 2015 09:45:47 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id ef5si4058338lbd.79.2015.08.20.09.45.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2015 09:45:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by laba3 with SMTP id a3so26243992lab.1 for ; Thu, 20 Aug 2015 09:45:47 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr3793964lbc.32.1440089147268; Thu, 20 Aug 2015 09:45:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp111504lbb; Thu, 20 Aug 2015 09:45:45 -0700 (PDT) X-Received: by 10.140.237.140 with SMTP id i134mr7670728qhc.81.1440089145777; Thu, 20 Aug 2015 09:45:45 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 4si7165777qku.12.2015.08.20.09.45.44; Thu, 20 Aug 2015 09:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id C476862084; Thu, 20 Aug 2015 16:45:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 0A5986208B; Thu, 20 Aug 2015 16:44:39 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C03FB62084; Thu, 20 Aug 2015 16:44:30 +0000 (UTC) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by lists.linaro.org (Postfix) with ESMTPS id 18AD26205E for ; Thu, 20 Aug 2015 16:44:27 +0000 (UTC) Received: by widdq5 with SMTP id dq5so11429295wid.0 for ; Thu, 20 Aug 2015 09:44:26 -0700 (PDT) X-Received: by 10.180.74.229 with SMTP id x5mr14438274wiv.90.1440089066390; Thu, 20 Aug 2015 09:44:26 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id pu6sm6281514wjc.34.2015.08.20.09.44.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Aug 2015 09:44:25 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Thu, 20 Aug 2015 17:44:18 +0100 Message-Id: <1440089058-12833-3-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1440089058-12833-1-git-send-email-stuart.haslam@linaro.org> References: <1440089058-12833-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 3/3] validation: pktio: test for transmit error handling X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stuart.haslam@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Test that transmit errors are handled correctly by attempting to send a packet larger than the MTU of the interface. Signed-off-by: Stuart Haslam --- test/validation/pktio/pktio.c | 168 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 148 insertions(+), 20 deletions(-) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index be4f940..340d691 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -21,6 +21,7 @@ #define MAX_NUM_IFACES 2 #define TEST_SEQ_INVALID ((uint32_t)~0) #define TEST_SEQ_MAGIC 0x92749451 +#define TX_BATCH_LEN 4 /** interface names used for testing */ static const char *iface_name[MAX_NUM_IFACES]; @@ -34,6 +35,7 @@ typedef struct { odp_pktio_t id; odp_queue_t outq; odp_queue_t inq; + enum { PKTIN_MODE_RECV, PKTIN_MODE_POLL, PKTIN_MODE_SCHED } mode; } pktio_info_t; /** magic number and sequence at start of UDP payload */ @@ -336,31 +338,40 @@ static odp_event_t queue_deq_wait_time(odp_queue_t queue, uint64_t ns) return ODP_EVENT_INVALID; } -static odp_packet_t wait_for_packet(odp_queue_t queue, +static odp_packet_t wait_for_packet(pktio_info_t *pktio_rx, uint32_t seq, uint64_t ns) { uint64_t start, now, diff; odp_event_t ev; - odp_packet_t pkt = ODP_PACKET_INVALID; + odp_packet_t pkt; start = odp_time_cycles(); do { - if (queue != ODP_QUEUE_INVALID && - odp_queue_type(queue) == ODP_QUEUE_TYPE_POLL) - ev = queue_deq_wait_time(queue, ns); - else - ev = odp_schedule(NULL, ns); - - if (ev != ODP_EVENT_INVALID) { - if (odp_event_type(ev) == ODP_EVENT_PACKET) { - pkt = odp_packet_from_event(ev); - if (pktio_pkt_seq(pkt) == seq) - return pkt; + pkt = ODP_PACKET_INVALID; + + if (pktio_rx->mode == PKTIN_MODE_RECV) { + odp_pktio_recv(pktio_rx->id, &pkt, 1); + } else { + if (pktio_rx->mode == PKTIN_MODE_POLL) + ev = queue_deq_wait_time(pktio_rx->inq, ns); + else + ev = odp_schedule(NULL, + odp_schedule_wait_time(ns)); + + if (ev != ODP_EVENT_INVALID) { + if (odp_event_type(ev) == ODP_EVENT_PACKET) + pkt = odp_packet_from_event(ev); + else + odp_event_free(ev); } + } - /* not interested in this event */ - odp_buffer_free(odp_buffer_from_event(ev)); + if (pkt != ODP_PACKET_INVALID) { + if (pktio_pkt_seq(pkt) == seq) + return pkt; + + odp_packet_free(pkt); } now = odp_time_cycles(); @@ -424,7 +435,7 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b, /* and wait for them to arrive back */ for (i = 0; i < num_pkts; ++i) { - rx_pkt = wait_for_packet(pktio_b->inq, tx_seq[i], ODP_TIME_SEC); + rx_pkt = wait_for_packet(pktio_b, tx_seq[i], ODP_TIME_SEC); if (rx_pkt == ODP_PACKET_INVALID) break; @@ -454,10 +465,13 @@ static void test_txrx(odp_queue_type_t q_type, int num_pkts) } create_inq(io->id, q_type); io->outq = odp_pktio_outq_getdef(io->id); - if (q_type == ODP_QUEUE_TYPE_POLL) + if (q_type == ODP_QUEUE_TYPE_POLL) { + io->mode = PKTIN_MODE_POLL; io->inq = odp_pktio_inq_getdef(io->id); - else + } else { + io->mode = PKTIN_MODE_SCHED; io->inq = ODP_QUEUE_INVALID; + } } /* if we have two interfaces then send through one and receive on @@ -479,7 +493,7 @@ void pktio_test_poll_queue(void) void pktio_test_poll_multi(void) { - test_txrx(ODP_QUEUE_TYPE_POLL, 4); + test_txrx(ODP_QUEUE_TYPE_POLL, TX_BATCH_LEN); } void pktio_test_sched_queue(void) @@ -489,7 +503,7 @@ void pktio_test_sched_queue(void) void pktio_test_sched_multi(void) { - test_txrx(ODP_QUEUE_TYPE_SCHED, 4); + test_txrx(ODP_QUEUE_TYPE_SCHED, TX_BATCH_LEN); } void pktio_test_jumbo(void) @@ -632,6 +646,118 @@ void pktio_test_inq(void) CU_ASSERT(odp_pktio_close(pktio) == 0); } +static void pktio_test_send_failure(void) +{ + odp_pktio_t pktio_tx, pktio_rx; + odp_packet_t pkt_tbl[TX_BATCH_LEN]; + uint32_t pkt_seq[TX_BATCH_LEN]; + int ret, mtu, i = 0; + odp_pool_param_t pool_params; + odp_pool_t pkt_pool; + int long_pkt_idx = TX_BATCH_LEN / 2; + pktio_info_t info_rx; + int pkt_len_toobig; + + pktio_tx = create_pktio(iface_name[0], 0); + if (pktio_tx == ODP_PKTIO_INVALID) { + CU_FAIL("failed to open pktio"); + return; + } + + /* read the MTU from the transmit interface */ + mtu = odp_pktio_mtu(pktio_tx); + + /* if the interface MTU is larger that the biggest packet we can + * allocate then we can't use this method to test transmit failures */ + pkt_len_toobig = mtu + 32; + if (pkt_len_toobig > ODP_CONFIG_PACKET_BUF_LEN_MAX) { + CU_ASSERT(odp_pktio_close(pktio_tx) == 0); + return; + } + + /* configure the pool so that we can generate test packets larger + * than the interface MTU */ + memset(&pool_params, 0, sizeof(pool_params)); + pool_params.pkt.len = pkt_len_toobig; + pool_params.pkt.seg_len = pool_params.pkt.len; + pool_params.pkt.num = TX_BATCH_LEN + 1; + pool_params.type = ODP_POOL_PACKET; + pkt_pool = odp_pool_create("pkt_pool_oversize", &pool_params); + CU_ASSERT_FATAL(pkt_pool != ODP_POOL_INVALID); + + if (num_ifaces > 1) + pktio_rx = create_pktio(iface_name[1], 1); + else + pktio_rx = pktio_tx; + + /* generate a batch of packets with a single overly long packet + * in the middle */ + for (i = 0; i < TX_BATCH_LEN; ++i) { + uint32_t pkt_len; + + if (i == long_pkt_idx) + pkt_len = pool_params.pkt.len; + else + pkt_len = PKT_LEN_NORMAL; + + pkt_tbl[i] = odp_packet_alloc(pkt_pool, pkt_len); + if (pkt_tbl[i] == ODP_PACKET_INVALID) + break; + + pkt_seq[i] = pktio_init_packet(pkt_tbl[i]); + if (pkt_seq[i] == TEST_SEQ_INVALID) + break; + } + + if (i != TX_BATCH_LEN) { + CU_FAIL("failed to generate test packets\n"); + return; + } + + /* try to send the batch with the long packet in the middle, the + * initial short packets should be sent */ + odp_errno_zero(); + ret = odp_pktio_send(pktio_tx, pkt_tbl, TX_BATCH_LEN); + CU_ASSERT(ret == long_pkt_idx); + CU_ASSERT(odp_errno() == 0); + + info_rx.id = pktio_rx; + info_rx.outq = ODP_QUEUE_INVALID; + info_rx.inq = ODP_QUEUE_INVALID; + info_rx.mode = PKTIN_MODE_RECV; + + for (i = 0; i < ret; ++i) { + pkt_tbl[i] = wait_for_packet(&info_rx, + pkt_seq[i], ODP_TIME_SEC); + if (pkt_tbl[i] == ODP_PACKET_INVALID) + break; + } + + if (i != ret) { + CU_FAIL("failed to receive transmitted packets\n"); + return; + } + + /* now try to send starting with the too-long packet and verify + * it fails */ + odp_errno_zero(); + ret = odp_pktio_send(pktio_tx, + &pkt_tbl[long_pkt_idx], + TX_BATCH_LEN - long_pkt_idx); + CU_ASSERT(ret == -1); + CU_ASSERT(odp_errno() != 0); + + for (i = 0; i < TX_BATCH_LEN; ++i) { + if (pkt_tbl[i] != ODP_PACKET_INVALID) + odp_packet_free(pkt_tbl[i]); + } + + if (pktio_rx != pktio_tx) + CU_ASSERT(odp_pktio_close(pktio_rx) == 0); + CU_ASSERT(odp_pktio_close(pktio_tx) == 0); + CU_ASSERT(odp_pool_destroy(pkt_pool) == 0); +} + static int create_pool(const char *iface, int num) { char pool_name[ODP_POOL_NAME_LEN]; @@ -737,6 +863,7 @@ CU_TestInfo pktio_suite_unsegmented[] = { {"pktio sched queues", pktio_test_sched_queue}, {"pktio sched multi", pktio_test_sched_multi}, {"pktio jumbo frames", pktio_test_jumbo}, + {"pktio send failure", pktio_test_send_failure}, {"pktio mtu", pktio_test_mtu}, {"pktio promisc mode", pktio_test_promisc}, {"pktio mac", pktio_test_mac}, @@ -750,6 +877,7 @@ CU_TestInfo pktio_suite_segmented[] = { {"pktio sched queues", pktio_test_sched_queue}, {"pktio sched multi", pktio_test_sched_multi}, {"pktio jumbo frames", pktio_test_jumbo}, + {"pktio send failure", pktio_test_send_failure}, CU_TEST_INFO_NULL };