From patchwork Mon Nov 9 11:21:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 56213 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp122192lbb; Mon, 9 Nov 2015 03:25:40 -0800 (PST) X-Received: by 10.140.221.198 with SMTP id r189mr30425218qhb.94.1447068340891; Mon, 09 Nov 2015 03:25:40 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u47si10667251qge.94.2015.11.09.03.25.40; Mon, 09 Nov 2015 03:25:40 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 72A6961809; Mon, 9 Nov 2015 11:25:40 +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 E635761846; Mon, 9 Nov 2015 11:23:58 +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 5B75961809; Mon, 9 Nov 2015 11:23:46 +0000 (UTC) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com [209.85.217.180]) by lists.linaro.org (Postfix) with ESMTPS id 2951C6198B for ; Mon, 9 Nov 2015 11:22:05 +0000 (UTC) Received: by lbblt2 with SMTP id lt2so77252723lbb.3 for ; Mon, 09 Nov 2015 03:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zQWym2K/mM+bKPHYxfupKChJP31rp7J5A0MdDxxrWMg=; b=ZlSzqoJfoKWDRNYnk3sPTlGqT+R5og6BcCpQ8xaZt2tspf2lYYETnbydFGDEqijSAr i4pCHOSl9Z6KxHye4oSFelU3Dbhjz8Vw63e7qXL9xf2rLwoZjeyLF39Ks0l+K/wwBV+O PCjRX/m9aUF2NmjcSIolhBCGuo/EtE9hAbUq0DgSTj8wO8+cpppVHbHQRtceTMQJHwFe 39RSnu5BmANvMS1NqLHL4CUVUTQdZJo7bwxztIrygeqXqWQS+ds+LsjsBNCmhCGG58Cf Azv4Wz1hYyCSNDpiOrh0DiIl/d2r8E1D/T7F6ZNyBpadvBzeC7HM9hE2WON+EjbXf0m9 olyg== 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=zQWym2K/mM+bKPHYxfupKChJP31rp7J5A0MdDxxrWMg=; b=IBz9mJbGR5lVoYq+1Ko2aQPAhJQlHTiXQ9voG/mnjrPHir4AhLsmb1CEdBdXPvk8Pi QtwBelwtmj/+BItQOcigW7MW5v2ZUkJYVB8X3ec/glSR4Y/MsOHIoz96b7yJYRv0U4Fs TaUjk0sLW5hXVqhwJdTPKlPDl1xncTZ9JeY9hHgFV7SjsDUcZO8pDPl/ztdpBgRC6quK nhhDaE3jz8sBIfxuVCL0+v8c6TlYRy/rcyvAu9bUeLFsjeWKWtlacPR7d7Hm3DjcKLuD cyreLZspNpjbAlFr2qmCGcCg+bc7A45jVQh9+wssZrUTkcRVNktXLNzxD4PtIZgXHWvX HzfQ== X-Gm-Message-State: ALoCoQkHl1l+OLGJeukfG0DaQnss9pphjudZ7lyc4xEBjnvfpPMl8GVGlro1cGv4tTTLbX51AF+b X-Received: by 10.112.135.136 with SMTP id ps8mr13168055lbb.38.1447068124018; Mon, 09 Nov 2015 03:22:04 -0800 (PST) Received: from localhost.localdomain (ppp91-76-161-180.pppoe.mtu-net.ru. [91.76.161.180]) by smtp.gmail.com with ESMTPSA id 200sm2299784lfz.48.2015.11.09.03.22.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Nov 2015 03:22:03 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 9 Nov 2015 14:21:53 +0300 Message-Id: <1447068113-3733-6-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447068113-3733-1-git-send-email-maxim.uvarov@linaro.org> References: <1447068113-3733-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 5/5] validation: implement pktio statistics counters 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" Signed-off-by: Maxim Uvarov --- test/validation/pktio/pktio.c | 130 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 6320b77..c591c94 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -690,6 +690,135 @@ void pktio_test_inq(void) CU_ASSERT(odp_pktio_close(pktio) == 0); } +static void _print_pktio_stats(odp_pktio_stats_t *s, const char *name) +{ + printf("\n%s:\n" + " in_octets %"PRIu64"\n" + " in_ucast_pkts %"PRIu64"\n" + " in_discards %"PRIu64"\n" + " in_errors %"PRIu64"\n" + " in_unknown_protos %"PRIu64"\n" + " out_octets %"PRIu64"\n" + " out_ucast_pkts %"PRIu64"\n" + " out_discards %"PRIu64"\n" + " out_errors %"PRIu64"\n", + name, + s->in_octets, + s->in_ucast_pkts, + s->in_discards, + s->in_errors, + s->in_unknown_protos, + s->out_octets, + s->out_ucast_pkts, + s->out_discards, + s->out_errors); +} + +static void pktio_test_statistics_counters(void) +{ + odp_pktio_t pktio[MAX_NUM_IFACES]; + odp_packet_t pkt; + odp_event_t tx_ev[1000]; + odp_event_t ev; + int i, pkts, ret, alloc = 0; + odp_queue_t outq; + uint64_t wait = odp_schedule_wait_time(ODP_TIME_MSEC); + odp_pktio_stats_t stats[2]; + + for (i = 0; i < num_ifaces; i++) { + pktio[i] = create_pktio(i, ODP_PKTIN_MODE_SCHED); + CU_ASSERT_FATAL(pktio[i] != ODP_PKTIO_INVALID); + create_inq(pktio[i], ODP_QUEUE_TYPE_SCHED); + } + + outq = odp_pktio_outq_getdef(pktio[0]); + + ret = odp_pktio_start(pktio[0]); + CU_ASSERT(ret == 0); + if (num_ifaces > 1) { + ret = odp_pktio_start(pktio[1]); + CU_ASSERT(ret == 0); + } + + /* flush packets with magic number in pipes */ + for (i = 0; i < 1000; i++) { + ev = odp_schedule(NULL, wait); + if (ev != ODP_EVENT_INVALID) + 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); + tx_ev[alloc] = odp_packet_to_event(pkt); + } + + ret = odp_pktio_stats_reset(pktio[0]); + CU_ASSERT(ret == 0); + if (num_ifaces > 1) { + ret = odp_pktio_stats_reset(pktio[1]); + CU_ASSERT(ret == 0); + } + + /* send */ + for (pkts = 0; pkts != alloc; ) { + ret = odp_queue_enq_multi(outq, &tx_ev[pkts], alloc - pkts); + if (ret < 0) { + CU_FAIL("unable to enqueue packet\n"); + break; + } + pkts += ret; + } + + /* get */ + for (i = 0, pkts = 0; i < 1000; i++) { + ev = odp_schedule(NULL, wait); + if (ev != ODP_EVENT_INVALID) { + if (odp_event_type(ev) == ODP_EVENT_PACKET) { + pkt = odp_packet_from_event(ev); + if (pktio_pkt_seq(pkt) != TEST_SEQ_INVALID) + pkts++; + } + odp_event_free(ev); + } + } + + ret = odp_pktio_stats(pktio[0], &stats[0]); + CU_ASSERT(ret == 0); + _print_pktio_stats(&stats[0], iface_name[0]); + + if (num_ifaces > 1) { + ret = odp_pktio_stats(pktio[1], &stats[1]); + CU_ASSERT(ret == 0); + _print_pktio_stats(&stats[1], iface_name[1]); + + CU_ASSERT(stats[1].in_ucast_pkts >= (uint64_t)pkts); + CU_ASSERT(stats[0].out_ucast_pkts == stats[1].in_ucast_pkts); + CU_ASSERT(stats[0].out_octets == stats[1].in_octets); + CU_ASSERT(stats[0].out_octets >= + (stats[0].out_ucast_pkts * (uint64_t)pkts)); + } else { + CU_ASSERT(stats[0].in_ucast_pkts == (uint64_t)pkts); + CU_ASSERT(stats[0].in_octets == + (PKT_LEN_NORMAL * (uint64_t)pkts)); + } + + CU_ASSERT(pkts == alloc); + CU_ASSERT((stats[0].in_discards | + stats[0].in_errors | + stats[0].in_unknown_protos | + stats[0].out_discards | + stats[0].out_errors) == 0); + + for (i = 0; i < num_ifaces; i++) { + destroy_inq(pktio[i]); + CU_ASSERT(odp_pktio_close(pktio[i]) == 0); + } +} + static void pktio_test_start_stop(void) { odp_pktio_t pktio[MAX_NUM_IFACES]; @@ -1057,6 +1186,7 @@ odp_testinfo_t pktio_suite_unsegmented[] = { ODP_TEST_INFO(pktio_test_mac), ODP_TEST_INFO(pktio_test_inq_remdef), ODP_TEST_INFO(pktio_test_start_stop), + ODP_TEST_INFO(pktio_test_statistics_counters), ODP_TEST_INFO_NULL };