From patchwork Tue Oct 27 16:42:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 55647 Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1906797lbq; Tue, 27 Oct 2015 09:50:10 -0700 (PDT) X-Received: by 10.107.6.225 with SMTP id f94mr48467871ioi.194.1445964610714; Tue, 27 Oct 2015 09:50:10 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g190si4641213ioe.134.2015.10.27.09.50.10; Tue, 27 Oct 2015 09:50:10 -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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id F274461E50; Tue, 27 Oct 2015 16:50:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A677F61E12; Tue, 27 Oct 2015 16:45:28 +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 5194C61D8F; Tue, 27 Oct 2015 16:44:45 +0000 (UTC) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by lists.linaro.org (Postfix) with ESMTPS id 4276661E53 for ; Tue, 27 Oct 2015 16:42:39 +0000 (UTC) Received: by wicll6 with SMTP id ll6so168174297wic.0 for ; Tue, 27 Oct 2015 09:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=REZ2izsMY/dBRoYiviHoJ41/hhyiQ19XmGQyUb4Yr8U=; b=poVbG5k3J2tydS4tptiHypkMsYHjxM3oiAcbe4lGGPFhAIBgAYZm5odnNCHhTt3v03 COlEQjJNjHx28T562qh6FwV3XQ4n1de9v+utouJGnO8LUogWQyInITGWrtNkdSfwEL3P +Bh25ISKDouryOq/4TnZlHlyw8baX6oox94aTzNGC9goLuMfurrwZWRupEgBQ9jlTmfh xhE3MYPOewRLvcvyDP6LBRa9RXlbA4xieeV6+SAsTXO6aezXJsyEJli8mgg1iRU2IWpJ ahl4Jl55zu/8uVt9aJmUdjHTC1KhkUfeWeyWdyBHUktRJWqXExJF8AJ/NJkrzRz1RFA5 vX3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=REZ2izsMY/dBRoYiviHoJ41/hhyiQ19XmGQyUb4Yr8U=; b=Slmtz9FzK+SPmOwvH27QD0Ae3ic1lMCFEwpvm/PS6to7GG2z9WF8gbJpzIuck23V1i 6tx1tv0HMFSXSrr82aLjLmcKF8zhwdDSmPR1wI8zfbRNa5th+nU6roDDIFgyhIYAvwhI PVPpRYWdYcGoZIbzlU5ApARLhQDWDOQN0d20SzXrAhb7MGZUBOm8bvJBzNxhHnSLktZw M3eFNU1Ig9Z6TGLVrcv+O121F6NhWwoK1LVk6IcbaqmRa88BUp69MtmHtCV8dH5jHrhK FUUO4Ghf7q7wv1oC5HFkf5etvke376NoXZ9+buPjwInFUP+nKE0bHYOL03ftBBnRQlNI Il7A== X-Gm-Message-State: ALoCoQmUEa7uR9GzPXiKVPleJf1/TdS6P2mPoQetnyH3CGU+E1KMj/Qw0Qdzj1gOAQckq3mSCaF6 X-Received: by 10.180.96.202 with SMTP id du10mr20075845wib.22.1445964158475; Tue, 27 Oct 2015 09:42:38 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id q8sm18359749wiz.23.2015.10.27.09.42.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Oct 2015 09:42:37 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Tue, 27 Oct 2015 16:42:05 +0000 Message-Id: <1445964125-21658-6-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1445964125-21658-1-git-send-email-stuart.haslam@linaro.org> References: <1445964125-21658-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 5/5] validation: pktio: test for transmit error handling X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" 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 | 151 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 3 deletions(-) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 5fe8293..6320b77 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]; @@ -507,7 +508,7 @@ void pktio_test_poll_queue(void) void pktio_test_poll_multi(void) { - test_txrx(ODP_PKTIN_MODE_POLL, 4); + test_txrx(ODP_PKTIN_MODE_POLL, TX_BATCH_LEN); } void pktio_test_sched_queue(void) @@ -517,7 +518,7 @@ void pktio_test_sched_queue(void) void pktio_test_sched_multi(void) { - test_txrx(ODP_PKTIN_MODE_SCHED, 4); + test_txrx(ODP_PKTIN_MODE_SCHED, TX_BATCH_LEN); } void pktio_test_recv(void) @@ -527,7 +528,7 @@ void pktio_test_recv(void) void pktio_test_recv_multi(void) { - test_txrx(ODP_PKTIN_MODE_RECV, 4); + test_txrx(ODP_PKTIN_MODE_RECV, TX_BATCH_LEN); } void pktio_test_jumbo(void) @@ -801,6 +802,146 @@ static void pktio_test_start_stop(void) } } +/* + * This is a pre-condition check that the pktio_test_send_failure() + * test case can be run. If the TX interface MTU is larger that the + * biggest packet we can allocate then the test won't be able to + * attempt to send packets larger than the MTU, so skip the test. + */ +static int pktio_check_send_failure(void) +{ + odp_pktio_t pktio_tx; + int mtu; + odp_pktio_param_t pktio_param; + int iface_idx = 0; + const char *iface = iface_name[iface_idx]; + + memset(&pktio_param, 0, sizeof(pktio_param)); + + pktio_param.in_mode = ODP_PKTIN_MODE_RECV; + + pktio_tx = odp_pktio_open(iface, pool[iface_idx], &pktio_param); + if (pktio_tx == ODP_PKTIO_INVALID) { + fprintf(stderr, "%s: failed to open pktio\n", __func__); + return 0; + } + + /* read the MTU from the transmit interface */ + mtu = odp_pktio_mtu(pktio_tx); + + odp_pktio_close(pktio_tx); + + return (mtu <= ODP_CONFIG_PACKET_BUF_LEN_MAX - 32); +} + +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, alloc_pkts; + odp_pool_param_t pool_params; + odp_pool_t pkt_pool; + int long_pkt_idx = TX_BATCH_LEN / 2; + pktio_info_t info_rx; + + pktio_tx = create_pktio(0, ODP_PKTIN_MODE_RECV); + 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); + + ret = odp_pktio_start(pktio_tx); + CU_ASSERT_FATAL(ret == 0); + + /* 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 = mtu + 32; + 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(1, ODP_PKTIN_MODE_RECV); + ret = odp_pktio_start(pktio_rx); + CU_ASSERT_FATAL(ret == 0); + } 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; + } + alloc_pkts = i; + + if (alloc_pkts == TX_BATCH_LEN) { + /* try to send the batch with the long packet in the middle, + * the initial short packets should be sent successfully */ + 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.in_mode = ODP_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) { + /* 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); + } else { + CU_FAIL("failed to receive transmitted packets\n"); + } + } else { + CU_FAIL("failed to generate test packets\n"); + } + + for (i = 0; i < alloc_pkts; ++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]; @@ -909,6 +1050,8 @@ odp_testinfo_t pktio_suite_unsegmented[] = { ODP_TEST_INFO(pktio_test_recv), ODP_TEST_INFO(pktio_test_recv_multi), ODP_TEST_INFO(pktio_test_jumbo), + ODP_TEST_INFO_CONDITIONAL(pktio_test_send_failure, + pktio_check_send_failure), ODP_TEST_INFO(pktio_test_mtu), ODP_TEST_INFO(pktio_test_promisc), ODP_TEST_INFO(pktio_test_mac), @@ -925,6 +1068,8 @@ odp_testinfo_t pktio_suite_segmented[] = { ODP_TEST_INFO(pktio_test_recv), ODP_TEST_INFO(pktio_test_recv_multi), ODP_TEST_INFO(pktio_test_jumbo), + ODP_TEST_INFO_CONDITIONAL(pktio_test_send_failure, + pktio_check_send_failure), ODP_TEST_INFO_NULL };