From patchwork Wed Oct 14 12:31:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 54916 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 0DFE023012 for ; Wed, 14 Oct 2015 12:33:33 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf25205909lbb.3 for ; Wed, 14 Oct 2015 05:33:32 -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=4+YHqVK4oUZFQuUFRNnKjA5VLaMx6FL76vNPKHMnd8Q=; b=LynqIIfXiXN0D9ZSmAPUbAYc6x2s66EGWNM/yWhxrxeBg9jsPvzsgZfcsmNii0nRuR appG5gjVCtenE6pS4BExQ7z+qNvR0axs/hgxmBM2J0tvfBMvza0OiDiD5dSQH+CuB+I8 pKepL6XmeAIGPI2StHFdXePDzmwLIeskqiHHrFyhhDBWwwE5PIpbmuPFoEJTA+BFYObv GJZb7VTH3b59iqNt04L/ULJKIDV5gXFC7vr+f07OEVygyAUgo0qsmM70y30Pqcy7v7cJ /O4XDrzS42cXiP9vqxKibD63SBIi3sQstf8cR80gA/Z2Epx7K65kFXuTUpWjTW6p0wo9 R+VQ== X-Gm-Message-State: ALoCoQmy0fCZlMnHSKD0Vf3jjctKW+O5hTim5LkvDqdcikHxDDK02gCaBCTFEFB1LkKKvhuONLAI X-Received: by 10.112.151.9 with SMTP id um9mr705080lbb.19.1444826011966; Wed, 14 Oct 2015 05:33:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.165.199 with SMTP id o190ls34256lfe.60.gmail; Wed, 14 Oct 2015 05:33:31 -0700 (PDT) X-Received: by 10.25.142.203 with SMTP id q194mr958334lfd.83.1444826011823; Wed, 14 Oct 2015 05:33:31 -0700 (PDT) Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id z140si1337384lfd.172.2015.10.14.05.33.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:33:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by lfaz124 with SMTP id z124so10477262lfa.1 for ; Wed, 14 Oct 2015 05:33:30 -0700 (PDT) X-Received: by 10.25.211.201 with SMTP id k192mr995352lfg.32.1444826010174; Wed, 14 Oct 2015 05:33:30 -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 w3csp2705032lbq; Wed, 14 Oct 2015 05:33:29 -0700 (PDT) X-Received: by 10.140.22.48 with SMTP id 45mr3579371qgm.23.1444826008987; Wed, 14 Oct 2015 05:33:28 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n10si7580563qki.73.2015.10.14.05.33.28; Wed, 14 Oct 2015 05:33:28 -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 94261619DD; Wed, 14 Oct 2015 12:33:28 +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.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 [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id EF60661A1E; Wed, 14 Oct 2015 12:32:04 +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 D919A61B7D; Wed, 14 Oct 2015 12:31:44 +0000 (UTC) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by lists.linaro.org (Postfix) with ESMTPS id 399BA61A10 for ; Wed, 14 Oct 2015 12:31:43 +0000 (UTC) Received: by wicge5 with SMTP id ge5so234274656wic.0 for ; Wed, 14 Oct 2015 05:31:42 -0700 (PDT) X-Received: by 10.194.117.39 with SMTP id kb7mr3661723wjb.129.1444825902467; Wed, 14 Oct 2015 05:31:42 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id ly4sm9789462wjb.4.2015.10.14.05.31.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Oct 2015 05:31:41 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Wed, 14 Oct 2015 13:31:28 +0100 Message-Id: <1444825888-29381-6-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1444825888-29381-1-git-send-email-stuart.haslam@linaro.org> References: <1444825888-29381-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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-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.45 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 | 151 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 3 deletions(-) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 69d016e..0d7facb 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) @@ -796,6 +797,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 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]; @@ -904,6 +1045,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), @@ -920,6 +1063,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 };