From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9E1F644107; Thu, 30 May 2024 00:58:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73A5A40DCA; Thu, 30 May 2024 00:57:48 +0200 (CEST) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mails.dpdk.org (Postfix) with ESMTP id D8CF140A6F for ; Thu, 30 May 2024 00:57:41 +0200 (CEST) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2bf62b121ccso185167a91.0 for ; Wed, 29 May 2024 15:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717023461; x=1717628261; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IIkhU8oLFDEE/9mXOvOY6Hvh+Pj2IOf4e5YXH8jGfhY=; b=rkMnsv+OuoMUNt6NUjcZkYgsWRVwU66pAQpS5rUegeSTjFK7CcBOtyWcpr5t9WIvWk aAVmdYMCCDxH7kaidgtJuF3FCLMAWA7OE8Sz0ovAIBmp4Tp9xN023RFpNFXDj7xP46Wk 7xQ6tUy0RHkr6jKrEXfRJ/HlznzPif9Obt9XYJOXmgIXC7gpttFykO/qXCAfBpaW1yF+ fhY3gnX26zuGkOOik68ZwTMOs21uxCFYGtFuXB6Qdgtpe4DjFBqwJN5Riy+znKL8iPWL 4G1VJxewuD2b9QYN3+byAbuQl+RR+GixTRoeRNzsWEk/FWcq6uHf3I8ODxchuOvsoUvN 2ggg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717023461; x=1717628261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IIkhU8oLFDEE/9mXOvOY6Hvh+Pj2IOf4e5YXH8jGfhY=; b=HDDFc9qhx2yqdntSmE1wGTVZHpm/iFGlxJ1+efEL6SxidrwGh3KZWXIar5uxKCA6Ae gU0u5DNA6J6m4M1SgM+ra7LRxHJPdgotTt7dReoHK1+tfRHkXW+ti3gxHC4qhI+j7EE/ j/dM5h0vCGedtnTlNq9poPsuct4vv6eXjWansXLPCp5Z1JMER1cMqJI44j7jOEE1PJ/T JywSAhIg5BYOUHMT8NocnKohtyFjYOzzy1QNfkJjkSa0t4AHLivrJgQMQ85MQOVmXNWL 1ULIXxvw+4TteOiHS8UiuOWZd1n6R23+SkEjx+hzhYROc2DU9K0Y43FCD8NssewTIFa0 qXvw== X-Gm-Message-State: AOJu0YyKyWl+F7zjGfFCSIAGQFQKmjI3xSmdhjfQmLNW+p7We9TOvvtO 8a5XTxotimnG6lBpkQE7SR2OYY/JFRaLWrM/slM/J4zD7OdC93jdZSXmvTm7c8sFS1Px9wXTkjM q X-Google-Smtp-Source: AGHT+IH3FGOxcTawTlj2kwc3MNDxU/CIA2U8Cg5BLSIqiQxZT/sIe4rLxbos/RTnZ2vz/NRJJZxgSA== X-Received: by 2002:a17:90a:ff0d:b0:2b5:91d1:3ae8 with SMTP id 98e67ed59e1d1-2c1acc59484mr257569a91.14.1717023460940; Wed, 29 May 2024 15:57:40 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c1a77baebcsm351762a91.53.2024.05.29.15.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 15:57:40 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v6 8/8] test: update to latencystats tests Date: Wed, 29 May 2024 15:54:45 -0700 Message-ID: <20240529225732.442539-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529225732.442539-1-stephen@networkplumber.org> References: <20240408195036.182545-1-stephen@networkplumber.org> <20240529225732.442539-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org No need for loop and memset() here. Just use structure initialization. Remove unnecessary initializations. Look at the number of samples, min, max and average numbers to make sure they look correct. Forward for longer to make sure multiple samples are taken. Signed-off-by: Stephen Hemminger --- app/test/test_latencystats.c | 84 ++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/app/test/test_latencystats.c b/app/test/test_latencystats.c index c309ab194f..676a99d385 100644 --- a/app/test/test_latencystats.c +++ b/app/test/test_latencystats.c @@ -14,18 +14,19 @@ #include "sample_packet_forward.h" #include "test.h" -#define NUM_STATS 4 +#define NUM_STATS 5 #define LATENCY_NUM_PACKETS 10 #define QUEUE_ID 0 static uint16_t portid; static struct rte_ring *ring; -static struct rte_metric_name lat_stats_strings[] = { +static struct rte_metric_name lat_stats_strings[NUM_STATS] = { {"min_latency_ns"}, {"avg_latency_ns"}, {"max_latency_ns"}, {"jitter_ns"}, + {"samples"}, }; /* Test case for latency init with metrics init */ @@ -70,13 +71,9 @@ static int test_latency_uninit(void) /* Test case to get names of latency stats */ static int test_latencystats_get_names(void) { - int ret = 0, i = 0; - int size = 0; - struct rte_metric_name names[NUM_STATS]; - - size_t m_size = sizeof(struct rte_metric_name); - for (i = 0; i < NUM_STATS; i++) - memset(&names[i], 0, m_size); + int ret, i; + uint16_t size; + struct rte_metric_name names[NUM_STATS] = { }; /* Success Test: Valid names and size */ size = NUM_STATS; @@ -106,13 +103,9 @@ static int test_latencystats_get_names(void) /* Test case to get latency stats values */ static int test_latencystats_get(void) { - int ret = 0, i = 0; - int size = 0; - struct rte_metric_value values[NUM_STATS]; - - size_t v_size = sizeof(struct rte_metric_value); - for (i = 0; i < NUM_STATS; i++) - memset(&values[i], 0, v_size); + int ret; + uint16_t size; + struct rte_metric_value values[NUM_STATS] = { }; /* Success Test: Valid values and valid size */ size = NUM_STATS; @@ -149,10 +142,14 @@ static void test_latency_ring_free(void) static int test_latency_packet_forward(void) { + unsigned int i; int ret; struct rte_mbuf *pbuf[LATENCY_NUM_PACKETS] = { }; struct rte_mempool *mp; char poolname[] = "mbuf_pool"; + uint64_t end_cycles; + struct rte_metric_value values[NUM_STATS] = { }; + struct rte_metric_name names[NUM_STATS] = { }; ret = test_get_mbuf_from_pool(&mp, pbuf, poolname); if (ret < 0) { @@ -166,9 +163,41 @@ static int test_latency_packet_forward(void) return TEST_FAILED; } - ret = test_packet_forward(pbuf, portid, QUEUE_ID); - if (ret < 0) - printf("send pkts Failed\n"); + ret = rte_latencystats_get_names(names, NUM_STATS); + TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); + + ret = rte_latencystats_get(values, NUM_STATS); + TEST_ASSERT(ret == NUM_STATS, "Test failed to get results before forwarding"); + TEST_ASSERT(values[4].value == 0, "Samples not zero at start of test"); + + /* + * Want test to run long enough to collect sufficient samples + * but not so long that scheduler decides to reschedule it (1000 hz). + */ + end_cycles = rte_rdtsc() + rte_get_tsc_hz() / 2000; + do { + ret = test_packet_forward(pbuf, portid, QUEUE_ID); + if (ret < 0) + printf("send pkts Failed\n"); + } while (rte_rdtsc() < end_cycles); + + ret = rte_latencystats_get(values, NUM_STATS); + TEST_ASSERT(ret == NUM_STATS, "Test failed to get results after forwarding"); + + for (i = 0; i < NUM_STATS; i++) { + uint16_t k = values[i].key; + + printf("%s = %"PRIu64"\n", + names[k].name, values[i].value); + } + + TEST_ASSERT(values[4].value > 0, "No samples taken"); + TEST_ASSERT(values[0].value > 0, "Min latency should not be zero"); + TEST_ASSERT(values[1].value > 0, "Avg latency should not be zero"); + TEST_ASSERT(values[2].value > 0, "Max latency should not be zero"); + TEST_ASSERT(values[0].value < values[1].value, "Min latency > Avg latency"); + TEST_ASSERT(values[0].value < values[2].value, "Min latency > Max latency"); + TEST_ASSERT(values[1].value < values[2].value, "Avg latency > Max latency"); rte_eth_dev_stop(portid); test_put_mbuf_to_pool(mp, pbuf); @@ -188,22 +217,23 @@ unit_test_suite latencystats_testsuite = { */ TEST_CASE_ST(NULL, NULL, test_latency_init), - /* Test Case 2: Do packet forwarding for metrics - * calculation and check the latency metrics values - * are updated - */ - TEST_CASE_ST(test_latency_packet_forward, NULL, - test_latency_update), - /* Test Case 3: To check whether latency stats names + /* Test Case 2: To check whether latency stats names * are retrieved */ TEST_CASE_ST(NULL, NULL, test_latencystats_get_names), - /* Test Case 4: To check whether latency stats + /* Test Case 3: To check whether latency stats * values are retrieved */ TEST_CASE_ST(NULL, NULL, test_latencystats_get), + /* Test Case 4: Do packet forwarding for metrics + * calculation and check the latency metrics values + * are updated + */ + TEST_CASE_ST(test_latency_packet_forward, NULL, + test_latency_update), + /* Test Case 5: To check uninit of latency test */ TEST_CASE_ST(NULL, NULL, test_latency_uninit), -- 2.43.0