From patchwork Thu Apr 21 00:14:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 66266 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2742938qge; Wed, 20 Apr 2016 17:19:24 -0700 (PDT) X-Received: by 10.141.43.193 with SMTP id u184mr15458935qhe.59.1461197964950; Wed, 20 Apr 2016 17:19:24 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w126si6810679qhw.107.2016.04.20.17.19.24; Wed, 20 Apr 2016 17:19:24 -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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9DA7F68602; Thu, 21 Apr 2016 00:19:24 +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_H2, 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 BB84B68A48; Thu, 21 Apr 2016 00:15:16 +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 8532E68625; Thu, 21 Apr 2016 00:14:57 +0000 (UTC) Received: from mail-oi0-f43.google.com (mail-oi0-f43.google.com [209.85.218.43]) by lists.linaro.org (Postfix) with ESMTPS id 5689768602 for ; Thu, 21 Apr 2016 00:14:24 +0000 (UTC) Received: by mail-oi0-f43.google.com with SMTP id p188so69162641oih.2 for ; Wed, 20 Apr 2016 17:14:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=15BmLI+AfJy4gsKpod0038CG/EkOP823K/sbDmzPsVM=; b=jHfCYNKrxBlZ1AHJTdprnuthUq2MqaDztwI0RtSlpNSCKygnplaFv9Ub8AD3T0LbFu 9Xy3zypTToUzc1jWPVokewH6XvRzypuCsXTVBJMk6LTge1N65XqUB2hBnsI2Avau/TrH D3vki5Ho/9g2o8AwXitYMge9RDQgppwAbI6ySSetuBNz5RW4sFpAzzt/bb/pfS3Fs+fH pE1onW6I0dVJCrqeOhtUjGm2K9oIz0uSaD2RvkhVMX6TzxmVTFZ5y48v4z880KtL3DsM TGEVSHei+BXAZ39tR20yyKRi2EYPmum2vOM7w3syAXka/rhuZddQNjwTnwPTfNX+PLpE VbBA== X-Gm-Message-State: AOPr4FV1hoDS8oZ2zr9MPxm0K9q+qJcBv/JzlRXQAFsE9NdsIE0hf6zD3k2nWA7ztn6Cy59CWKA= X-Received: by 10.202.69.134 with SMTP id s128mr4795964oia.97.1461197663875; Wed, 20 Apr 2016 17:14:23 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id a34sm335otb.1.2016.04.20.17.14.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Apr 2016 17:14:23 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 20 Apr 2016 19:14:10 -0500 Message-Id: <1461197655-23743-7-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1461197655-23743-1-git-send-email-bill.fischofer@linaro.org> References: <1461197655-23743-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv4 06/11] validation: pktio: add helper function for creating test packets 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" From: Matias Elo Add helper function for creating test packets to reduce duplicate code. Signed-off-by: Matias Elo Reviewed-and-tested-by: Bill Fischofer --- test/validation/pktio/pktio.c | 134 +++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 88 deletions(-) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index b141cd6..6dc6505 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -372,6 +372,33 @@ static int flush_input_queue(odp_pktio_t pktio, odp_pktin_mode_t imode) return 0; } +static int create_packets(odp_packet_t pkt_tbl[], uint32_t pkt_seq[], int num, + odp_pktio_t pktio_src, odp_pktio_t pktio_dst) +{ + int i; + + for (i = 0; i < num; i++) { + pkt_tbl[i] = odp_packet_alloc(default_pkt_pool, packet_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) { + odp_packet_free(pkt_tbl[i]); + break; + } + + pktio_pkt_set_macs(pkt_tbl[i], pktio_src, pktio_dst); + + if (pktio_fixup_checksums(pkt_tbl[i]) != 0) { + odp_packet_free(pkt_tbl[i]); + break; + } + } + + return i; +} + static int get_packets(pktio_info_t *pktio_rx, odp_packet_t pkt_tbl[], int num, txrx_mode_e mode) { @@ -512,25 +539,9 @@ static void pktio_txrx_multi(pktio_info_t *pktio_a, pktio_info_t *pktio_b, } /* generate test packets to send */ - for (i = 0; i < num_pkts; ++i) { - tx_pkt[i] = odp_packet_alloc(default_pkt_pool, packet_len); - if (tx_pkt[i] == ODP_PACKET_INVALID) - break; - - tx_seq[i] = pktio_init_packet(tx_pkt[i]); - if (tx_seq[i] == TEST_SEQ_INVALID) { - odp_packet_free(tx_pkt[i]); - break; - } - - pktio_pkt_set_macs(tx_pkt[i], pktio_a->id, pktio_b->id); - if (pktio_fixup_checksums(tx_pkt[i]) != 0) { - odp_packet_free(tx_pkt[i]); - break; - } - } - - if (i != num_pkts) { + ret = create_packets(tx_pkt, tx_seq, num_pkts, pktio_a->id, + pktio_b->id); + if (ret != num_pkts) { CU_FAIL("failed to generate test packets"); return; } @@ -738,25 +749,9 @@ void pktio_test_recv_queue(void) pktio_rx = pktio_tx; /* Allocate and initialize test packets */ - for (i = 0; i < TX_BATCH_LEN; i++) { - pkt_tbl[i] = odp_packet_alloc(default_pkt_pool, packet_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) { - odp_packet_free(pkt_tbl[i]); - break; - } - - pktio_pkt_set_macs(pkt_tbl[i], pktio_tx, pktio_rx); - - if (pktio_fixup_checksums(pkt_tbl[i]) != 0) { - odp_packet_free(pkt_tbl[i]); - break; - } - } - if (i != TX_BATCH_LEN) { + ret = create_packets(pkt_tbl, pkt_seq, TX_BATCH_LEN, pktio_tx, + pktio_rx); + if (ret != TX_BATCH_LEN) { CU_FAIL("Failed to generate test packets"); return; } @@ -799,6 +794,8 @@ void pktio_test_recv_queue(void) } while (num_rx < TX_BATCH_LEN && odp_time_cmp(end, odp_time_local()) > 0); + CU_ASSERT(num_rx == TX_BATCH_LEN); + for (i = 0; i < num_rx; i++) odp_packet_free(pkt_tbl[i]); @@ -1192,6 +1189,7 @@ void pktio_test_statistics_counters(void) odp_pktio_t pktio[MAX_NUM_IFACES]; odp_packet_t pkt; odp_packet_t tx_pkt[1000]; + uint32_t pkt_seq[1000]; odp_event_t ev; int i, pkts, tx_pkts, ret, alloc = 0; odp_pktout_queue_t pktout; @@ -1223,19 +1221,7 @@ void pktio_test_statistics_counters(void) odp_event_free(ev); } - /* alloc */ - for (alloc = 0; alloc < 1000; alloc++) { - pkt = odp_packet_alloc(default_pkt_pool, packet_len); - if (pkt == ODP_PACKET_INVALID) - break; - pktio_init_packet(pkt); - pktio_pkt_set_macs(pkt, pktio_tx, pktio_rx); - if (pktio_fixup_checksums(pkt) != 0) { - odp_packet_free(pkt); - break; - } - tx_pkt[alloc] = pkt; - } + alloc = create_packets(tx_pkt, pkt_seq, 1000, pktio_tx, pktio_rx); ret = odp_pktio_stats_reset(pktio_tx); CU_ASSERT(ret == 0); @@ -1312,6 +1298,7 @@ void pktio_test_start_stop(void) odp_pktio_t pktio[MAX_NUM_IFACES]; odp_packet_t pkt; odp_packet_t tx_pkt[1000]; + uint32_t pkt_seq[1000]; odp_event_t ev; int i, pkts, ret, alloc = 0; odp_pktout_queue_t pktout; @@ -1341,20 +1328,9 @@ void pktio_test_start_stop(void) /* Test Rx on a stopped interface. Only works if there are 2 */ if (num_ifaces > 1) { - for (alloc = 0; alloc < 1000; alloc++) { - pkt = odp_packet_alloc(default_pkt_pool, packet_len); - if (pkt == ODP_PACKET_INVALID) - break; - pktio_init_packet(pkt); - pktio_pkt_set_macs(pkt, pktio[0], pktio[1]); - if (pktio_fixup_checksums(pkt) != 0) { - odp_packet_free(pkt); - break; - } - - tx_pkt[alloc] = pkt; - } + alloc = create_packets(tx_pkt, pkt_seq, 1000, pktio[0], + pktio[1]); for (pkts = 0; pkts != alloc; ) { ret = odp_pktout_send(pktout, &tx_pkt[pkts], @@ -1396,31 +1372,13 @@ void pktio_test_start_stop(void) } } - /* alloc */ - for (alloc = 0; alloc < 1000; alloc++) { - pkt = odp_packet_alloc(default_pkt_pool, packet_len); - if (pkt == ODP_PACKET_INVALID) - break; - pktio_init_packet(pkt); - if (num_ifaces > 1) { - pktio_pkt_set_macs(pkt, pktio[0], pktio[1]); - } else { - uint32_t len; - odph_ethhdr_t *eth; - eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, &len); - ret = odp_pktio_mac_addr(pktio[0], - ð->dst, sizeof(eth->dst)); - CU_ASSERT(ret == ODPH_ETHADDR_LEN); - } - - if (pktio_fixup_checksums(pkt) != 0) { - odp_packet_free(pkt); - break; - } - - tx_pkt[alloc] = pkt; - } + if (num_ifaces > 1) + alloc = create_packets(tx_pkt, pkt_seq, 1000, pktio[0], + pktio[1]); + else + alloc = create_packets(tx_pkt, pkt_seq, 1000, pktio[0], + pktio[0]); /* send */ for (pkts = 0; pkts != alloc; ) {