From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 19CD1A046B for ; Mon, 22 Jul 2019 15:45:14 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AF3F81BE99; Mon, 22 Jul 2019 15:45:05 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 792AB231E for ; Mon, 22 Jul 2019 15:45:02 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jul 2019 06:44:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,295,1559545200"; d="scan'208";a="368026936" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga005.fm.intel.com with ESMTP; 22 Jul 2019 06:44:49 -0700 Received: from wgcvswdev001.ir.intel.com (wgcvswdev001.ir.intel.com [10.102.246.100]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x6MDinib025721; Mon, 22 Jul 2019 14:44:49 +0100 Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id x6MDiInf032247; Mon, 22 Jul 2019 14:44:18 +0100 Received: (from lgovin3x@localhost) by wgcvswdev001.ir.intel.com with œ id x6MDiIrx032243; Mon, 22 Jul 2019 14:44:18 +0100 From: Lavanya Govindarajan To: dev@dpdk.org Cc: reshma.pattan@intel.com, olivier.matz@6wind.com, bruce.richardson@intel.com, pallantlax.poornima@intel.com Date: Mon, 22 Jul 2019 14:42:48 +0100 Message-Id: <1563802968-32033-3-git-send-email-lavanyax.govindarajan@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1555332015-31506-1-git-send-email-lavanyax.govindarajan@intel.com> References: <1555332015-31506-1-git-send-email-lavanyax.govindarajan@intel.com> Subject: [dpdk-dev] [PATCH v2 2/2] app/test: add unit test cases to mbuf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Pallantla Poornima Added UT for the below four functions in test_mbuf.c rte_get_rx_ol_flag_list rte_get_tx_ol_flag_list rte_get_rx_ol_flag_name rte_get_tx_ol_flag_name Signed-off-by: Pallantla Poornima --- app/test/test_mbuf.c | 260 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 623453d57..1b3879c96 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -42,6 +42,7 @@ #define MBUF_TEST_DATA_LEN3 256 #define MBUF_TEST_HDR1_LEN 20 #define MBUF_TEST_HDR2_LEN 30 +#define MBUF_TEST_LEN 250 #define MBUF_TEST_ALL_HDRS_LEN (MBUF_TEST_HDR1_LEN+MBUF_TEST_HDR2_LEN) #define MBUF_TEST_SEG_SIZE 64 #define MBUF_TEST_BURST 8 @@ -1132,6 +1133,245 @@ test_tx_offload(void) return (v1 == v2) ? 0 : -EINVAL; } + +static int +test_get_rx_ol_flag_list(void) +{ + int ret = 0; + char buf[256] = ""; + int buflen = 0; + + /* Test case to check with null buffer */ + ret = rte_get_rx_ol_flag_list(0, NULL, 0); + if (ret != -1) + GOTO_FAIL("%s expected: -1, received =%d\n", __func__, ret); + + /* Test case to check with zero buffer len */ + ret = rte_get_rx_ol_flag_list(PKT_RX_L4_CKSUM_MASK, buf, 0); + if (ret != -1) + GOTO_FAIL("%s expected: -1, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen != 0) + GOTO_FAIL("%s buffer should be empty, expected: 0, received =%d\n", + __func__, buflen); + + /* Test case to check with reduced buffer len */ + int32_t len = sizeof(buf) - MBUF_TEST_LEN; + ret = rte_get_rx_ol_flag_list(0, buf, len); + if (ret != -1) + GOTO_FAIL("%s expected: -1, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen != (len - 1)) + GOTO_FAIL("%s invalid buffer length retrieved, expected: %d," + "received =%d\n", __func__, + (len - 1), buflen); + + /* Test case to check with zero mask value */ + ret = rte_get_rx_ol_flag_list(0, buf, sizeof(buf)); + if (ret != 0) + GOTO_FAIL("%s expected: 0, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen == 0) + GOTO_FAIL("%s expected: %s, received =%d\n", __func__, + "non-zero, buffer should not be empty", buflen); + + /* Test case to check with valid mask value */ + ret = rte_get_rx_ol_flag_list(PKT_RX_SEC_OFFLOAD, buf, sizeof(buf)); + if (ret != 0) + GOTO_FAIL("%s expected: 0, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen == 0) + GOTO_FAIL("%s expected: %s, received =%d\n", __func__, + "non-zero, buffer should not be empty", buflen); + + + return 0; +fail: + return -1; +} + +static int +test_get_tx_ol_flag_list(void) +{ + int ret = 0; + char buf[256] = ""; + int buflen = 0; + + /* Test case to check with null buffer */ + ret = rte_get_tx_ol_flag_list(0, NULL, 0); + if (ret != -1) + GOTO_FAIL("%s expected: -1, received =%d\n", __func__, ret); + + /* Test case to check with zero buffer len */ + ret = rte_get_tx_ol_flag_list(PKT_TX_IP_CKSUM, buf, 0); + if (ret != -1) + GOTO_FAIL("%s expected: -1, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen != 0) { + GOTO_FAIL("%s buffer should be empty, expected: 0, received =%d\n", + __func__, buflen); + } + + /* Test case to check with reduced buffer len */ + int32_t len = sizeof(buf) - MBUF_TEST_LEN; + ret = rte_get_tx_ol_flag_list(0, buf, len); + if (ret != -1) + GOTO_FAIL("%s expected: -1, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen != (len - 1)) + GOTO_FAIL("%s invalid buffer length retrieved, expected: %d," + "received =%d\n", __func__, + (len - 1), buflen); + + /* Test case to check with zero mask value */ + ret = rte_get_tx_ol_flag_list(0, buf, sizeof(buf)); + if (ret != 0) + GOTO_FAIL("%s expected: 0, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen == 0) + GOTO_FAIL("%s expected: %s, received =%d\n", __func__, + "non-zero, buffer should not be empty", buflen); + + /* Test case to check with valid mask value */ + ret = rte_get_tx_ol_flag_list(PKT_TX_UDP_CKSUM, buf, sizeof(buf)); + if (ret != 0) + GOTO_FAIL("%s expected: 0, received =%d\n", __func__, ret); + + buflen = strlen(buf); + if (buflen == 0) + GOTO_FAIL("%s expected: %s, received =%d\n", __func__, + "non-zero, buffer should not be empty", buflen); + + return 0; +fail: + return -1; + +} + +struct flag_name { + uint64_t flag; + const char *name; +}; + +static int +test_get_rx_ol_flag_name(void) +{ + uint16_t i; + const char *flag_str = NULL; + const struct flag_name rx_flags[] = { + { PKT_RX_VLAN, "PKT_RX_VLAN" }, + { PKT_RX_RSS_HASH, "PKT_RX_RSS_HASH" }, + { PKT_RX_FDIR, "PKT_RX_FDIR"}, + { PKT_RX_L4_CKSUM_BAD, "PKT_RX_L4_CKSUM_BAD"}, + { PKT_RX_L4_CKSUM_GOOD, "PKT_RX_L4_CKSUM_GOOD"}, + { PKT_RX_L4_CKSUM_NONE, "PKT_RX_L4_CKSUM_NONE"}, + { PKT_RX_IP_CKSUM_BAD, "PKT_RX_IP_CKSUM_BAD"}, + { PKT_RX_IP_CKSUM_GOOD, "PKT_RX_IP_CKSUM_GOOD"}, + { PKT_RX_IP_CKSUM_NONE, "PKT_RX_IP_CKSUM_NONE"}, + { PKT_RX_EIP_CKSUM_BAD, "PKT_RX_EIP_CKSUM_BAD" }, + { PKT_RX_VLAN_STRIPPED, "PKT_RX_VLAN_STRIPPED" }, + { PKT_RX_IEEE1588_PTP, "PKT_RX_IEEE1588_PTP"}, + { PKT_RX_IEEE1588_TMST, "PKT_RX_IEEE1588_TMST"}, + { PKT_RX_FDIR_ID, "PKT_RX_FDIR_ID"}, + { PKT_RX_FDIR_FLX, "PKT_RX_FDIR_FLX"}, + { PKT_RX_QINQ_STRIPPED, "PKT_RX_QINQ_STRIPPED" }, + { PKT_RX_LRO, "PKT_RX_LRO" }, + { PKT_RX_TIMESTAMP, "PKT_RX_TIMESTAMP"}, + { PKT_RX_SEC_OFFLOAD, "PKT_RX_SEC_OFFLOAD" }, + { PKT_RX_SEC_OFFLOAD_FAILED, "PKT_RX_SEC_OFFLOAD_FAILED" }, + { PKT_RX_OUTER_L4_CKSUM_BAD, "PKT_RX_OUTER_L4_CKSUM_BAD" }, + { PKT_RX_OUTER_L4_CKSUM_GOOD, "PKT_RX_OUTER_L4_CKSUM_GOOD"}, + { PKT_RX_OUTER_L4_CKSUM_INVALID, + "PKT_RX_OUTER_L4_CKSUM_INVALID" }, + }; + + /* Test case to check with valid flag */ + for (i = 0; i < RTE_DIM(rx_flags); i++) { + flag_str = rte_get_rx_ol_flag_name(rx_flags[i].flag); + if (flag_str == NULL) + GOTO_FAIL("%s: Expected flag name= %s; received = %s\n", + __func__, rx_flags[i].name, flag_str); + if (strcmp(flag_str, rx_flags[i].name) != 0) + GOTO_FAIL("%s Expected flag name = %s; received = %s\n", + __func__, rx_flags[i].name, flag_str); + } + /* Test case to check with invalid flag */ + flag_str = rte_get_rx_ol_flag_name(0); + if (flag_str != NULL) { + GOTO_FAIL("%s Expected : NULL; received = %s\n", + __func__, flag_str); + } + + return 0; +fail: + return -1; +} + +static int +test_get_tx_ol_flag_name(void) +{ + uint16_t i; + const char *flag_str = NULL; + const struct flag_name tx_flags[] = { + + { PKT_TX_VLAN, "PKT_TX_VLAN" }, + { PKT_TX_IP_CKSUM, "PKT_TX_IP_CKSUM" }, + { PKT_TX_TCP_CKSUM, "PKT_TX_TCP_CKSUM" }, + { PKT_TX_SCTP_CKSUM, "PKT_TX_SCTP_CKSUM" }, + { PKT_TX_UDP_CKSUM, "PKT_TX_UDP_CKSUM" }, + { PKT_TX_IEEE1588_TMST, "PKT_TX_IEEE1588_TMST" }, + { PKT_TX_TCP_SEG, "PKT_TX_TCP_SEG" }, + { PKT_TX_IPV4, "PKT_TX_IPV4" }, + { PKT_TX_IPV6, "PKT_TX_IPV6" }, + { PKT_TX_OUTER_IP_CKSUM, "PKT_TX_OUTER_IP_CKSUM" }, + { PKT_TX_OUTER_IPV4, "PKT_TX_OUTER_IPV4" }, + { PKT_TX_OUTER_IPV6, "PKT_TX_OUTER_IPV6" }, + { PKT_TX_TUNNEL_VXLAN, "PKT_TX_TUNNEL_VXLAN" }, + { PKT_TX_TUNNEL_GRE, "PKT_TX_TUNNEL_GRE" }, + { PKT_TX_TUNNEL_IPIP, "PKT_TX_TUNNEL_IPIP" }, + { PKT_TX_TUNNEL_GENEVE, "PKT_TX_TUNNEL_GENEVE" }, + { PKT_TX_TUNNEL_MPLSINUDP, "PKT_TX_TUNNEL_MPLSINUDP" }, + { PKT_TX_TUNNEL_VXLAN_GPE, "PKT_TX_TUNNEL_VXLAN_GPE" }, + { PKT_TX_TUNNEL_IP, "PKT_TX_TUNNEL_IP" }, + { PKT_TX_TUNNEL_UDP, "PKT_TX_TUNNEL_UDP" }, + { PKT_TX_QINQ, "PKT_TX_QINQ" }, + { PKT_TX_MACSEC, "PKT_TX_MACSEC" }, + { PKT_TX_SEC_OFFLOAD, "PKT_TX_SEC_OFFLOAD" }, + { PKT_TX_UDP_SEG, "PKT_TX_UDP_SEG" }, + { PKT_TX_OUTER_UDP_CKSUM, "PKT_TX_OUTER_UDP_CKSUM" }, + { PKT_TX_METADATA, "PKT_TX_METADATA" }, + }; + + /* Test case to check with valid flag */ + for (i = 0; i < RTE_DIM(tx_flags); i++) { + flag_str = rte_get_tx_ol_flag_name(tx_flags[i].flag); + if (flag_str == NULL) + GOTO_FAIL("%s: Expected flag name= %s; received = %s\n", + __func__, tx_flags[i].name, flag_str); + if (strcmp(flag_str, tx_flags[i].name) != 0) + GOTO_FAIL("%s Expected flag name = %s; received = %s\n", + __func__, tx_flags[i].name, flag_str); + } + /* Test case to check with invalid flag */ + flag_str = rte_get_tx_ol_flag_name(0); + if (flag_str != NULL) { + GOTO_FAIL("%s Expected : NULL; received = %s\n", + __func__, flag_str); + } + + return 0; +fail: + return -1; + +} + static int test_mbuf_validate_tx_offload(const char *test_name, struct rte_mempool *pktmbuf_pool, @@ -1833,6 +2073,26 @@ test_mbuf(void) goto err; } + if (test_get_rx_ol_flag_list() < 0) { + printf("test_rte_get_rx_ol_flag_list() failed\n"); + goto err; + } + + if (test_get_tx_ol_flag_list() < 0) { + printf("test_rte_get_tx_ol_flag_list() failed\n"); + goto err; + } + + if (test_get_rx_ol_flag_name() < 0) { + printf("test_rte_get_rx_ol_flag_name() failed\n"); + goto err; + } + + if (test_get_tx_ol_flag_name() < 0) { + printf("test_rte_get_tx_ol_flag_name() failed\n"); + goto err; + } + /* test to validate tx offload flags */ uint64_t ol_flags = 0; /* test to validate if IP checksum is counted only for IPV4 packet */ -- 2.17.2