From patchwork Thu Apr 21 07:59:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Elo, Matias \(Nokia - FI/Espoo\)" X-Patchwork-Id: 66322 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2900307qge; Thu, 21 Apr 2016 01:05:55 -0700 (PDT) X-Received: by 10.55.82.6 with SMTP id g6mr18055537qkb.40.1461225955722; Thu, 21 Apr 2016 01:05:55 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a75si824144qkj.208.2016.04.21.01.05.55; Thu, 21 Apr 2016 01:05:55 -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=fail (p=NONE dis=NONE) header.from=nokia.com Received: by lists.linaro.org (Postfix, from userid 109) id 5E54B68675; Thu, 21 Apr 2016 08:05:55 +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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 4703468AA3; Thu, 21 Apr 2016 08:00:49 +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 81E3668A93; Thu, 21 Apr 2016 08:00:29 +0000 (UTC) Received: from demumfd002.nsn-inter.net (demumfd002.nsn-inter.net [93.183.12.31]) by lists.linaro.org (Postfix) with ESMTPS id 0ADEF68A8D for ; Thu, 21 Apr 2016 07:59:37 +0000 (UTC) Received: from demuprx016.emea.nsn-intra.net ([10.150.129.55]) by demumfd002.nsn-inter.net (8.15.2/8.15.2) with ESMTPS id u3L7xaMU006337 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 21 Apr 2016 07:59:36 GMT Received: from 10.144.19.15 ([10.144.104.109]) by demuprx016.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id u3L7xWW4018712 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Thu, 21 Apr 2016 09:59:36 +0200 From: Matias Elo To: lng-odp@lists.linaro.org Date: Thu, 21 Apr 2016 10:59:27 +0300 Message-Id: <1461225572-18238-7-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461225572-18238-1-git-send-email-matias.elo@nokia.com> References: <1461225572-18238-1-git-send-email-matias.elo@nokia.com> X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 5975 X-purgate-ID: 151667::1461225576-00002418-F71C7098/0/0 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v5 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" Add helper function for creating test packets to reduce duplicate code. Signed-off-by: Matias Elo --- 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; ) {