From patchwork Fri Oct 23 09:16:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 55471 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 8433520581 for ; Fri, 23 Oct 2015 09:21:08 +0000 (UTC) Received: by wiyb4 with SMTP id b4sf8312990wiy.2 for ; Fri, 23 Oct 2015 02:21:07 -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=W6iraTBxB50aF9Sf+gNfEoIzjaCiV4qqVe77mi17pUE=; b=IrgwsBcsa+HxkibXmcyYlFjB7gzxn+4bHzzrtKk2Uhb6pGliivrjtZrnZo7BIvsbPt wIjOPvJoYYI9CINouBmKOngpv+dwgcO0ZBlaWngwLRdohs77+3sTHN/qSMO1Vj7m+Ml5 l23L9d6yNOBQOmRoFw8iSC6zvfvnUW46uha3675BSSUIM6XLq12VoBCWxkP6J/p/zx8k vTgOjAE6P1Ru5KQGXcRgrXHxWqm5UmknTSUUJIzJ9GIgrpd5FSwC4fL1H6H6PGbCHjud w7hF76MwJGuDhEJ2hgiXfC9wbVRg70k1Y3wdL2ZfKc+Sh5DP3NROXAcCUdZaiPElkO9b tHiA== X-Gm-Message-State: ALoCoQl0JJN54EhionRebpVfPLmZ4hg7oYqnp4NJ9fFhBghZQ51SWHixpc3387EOMcASUMsm1CpK X-Received: by 10.112.151.9 with SMTP id um9mr4666180lbb.19.1445592067858; Fri, 23 Oct 2015 02:21:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.21.152 with SMTP id 24ls366280lfv.97.gmail; Fri, 23 Oct 2015 02:21:07 -0700 (PDT) X-Received: by 10.25.145.209 with SMTP id t200mr6905536lfd.88.1445592067707; Fri, 23 Oct 2015 02:21:07 -0700 (PDT) Received: from mail-lf0-x235.google.com (mail-lf0-x235.google.com. [2a00:1450:4010:c07::235]) by mx.google.com with ESMTPS id o18si12145527lfo.58.2015.10.23.02.21.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Oct 2015 02:21:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c07::235 as permitted sender) client-ip=2a00:1450:4010:c07::235; Received: by lffz202 with SMTP id z202so76738047lff.3 for ; Fri, 23 Oct 2015 02:21:07 -0700 (PDT) X-Received: by 10.112.163.131 with SMTP id yi3mr10619100lbb.36.1445592067201; Fri, 23 Oct 2015 02:21:07 -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.59.35 with SMTP id w3csp1094507lbq; Fri, 23 Oct 2015 02:21:06 -0700 (PDT) X-Received: by 10.140.39.180 with SMTP id v49mr23786182qgv.98.1445592066082; Fri, 23 Oct 2015 02:21:06 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e140si17692275qhc.20.2015.10.23.02.21.05; Fri, 23 Oct 2015 02:21:06 -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 9088E62C91; Fri, 23 Oct 2015 09:21:05 +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 3F16462CA5; Fri, 23 Oct 2015 09:17:51 +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 81BB762CA8; Fri, 23 Oct 2015 09:17:45 +0000 (UTC) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by lists.linaro.org (Postfix) with ESMTPS id 7CCFA62C8F for ; Fri, 23 Oct 2015 09:17:17 +0000 (UTC) Received: by wicll6 with SMTP id ll6so22657193wic.1 for ; Fri, 23 Oct 2015 02:17:16 -0700 (PDT) X-Received: by 10.194.93.194 with SMTP id cw2mr3162459wjb.35.1445591836782; Fri, 23 Oct 2015 02:17:16 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id jt9sm6422177wjc.24.2015.10.23.02.17.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Oct 2015 02:17:16 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Fri, 23 Oct 2015 10:16:52 +0100 Message-Id: <1445591812-10857-6-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1445591812-10857-1-git-send-email-stuart.haslam@linaro.org> References: <1445591812-10857-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 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: 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-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 2a00:1450:4010:c07::235 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com 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 | 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 };