From patchwork Wed Apr 20 06:20:45 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: 66172 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2271439qge; Tue, 19 Apr 2016 23:24:15 -0700 (PDT) X-Received: by 10.140.198.135 with SMTP id t129mr9181011qha.36.1461133455134; Tue, 19 Apr 2016 23:24:15 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e5si26129717qkb.92.2016.04.19.23.24.14; Tue, 19 Apr 2016 23:24:15 -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 BC30667442; Wed, 20 Apr 2016 06:24:14 +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 A30AE6742B; Wed, 20 Apr 2016 06:21:17 +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 3EE32673D2; Wed, 20 Apr 2016 06:20:58 +0000 (UTC) Received: from demumfd002.nsn-inter.net (demumfd002.nsn-inter.net [93.183.12.31]) by lists.linaro.org (Postfix) with ESMTPS id AF282673E4 for ; Wed, 20 Apr 2016 06:20:54 +0000 (UTC) Received: from demuprx017.emea.nsn-intra.net ([10.150.129.56]) by demumfd002.nsn-inter.net (8.15.2/8.15.2) with ESMTPS id u3K6Kr8M028830 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Apr 2016 06:20:53 GMT Received: from 10.144.19.15 ([10.144.104.109]) by demuprx017.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id u3K6Ko42012445 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Wed, 20 Apr 2016 08:20:53 +0200 From: Matias Elo To: lng-odp@lists.linaro.org Date: Wed, 20 Apr 2016 09:20:45 +0300 Message-Id: <1461133250-2403-7-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461133250-2403-1-git-send-email-matias.elo@nokia.com> References: <1461133250-2403-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::1461133253-00002418-5A0B69B4/0/0 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v3 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 d52a520..768b32f 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]); @@ -1172,6 +1169,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; @@ -1203,19 +1201,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); @@ -1292,6 +1278,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; @@ -1321,20 +1308,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], @@ -1376,31 +1352,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; ) {