diff mbox series

[08/13] test/crypto: add security stats cases

Message ID 1638777528-553-9-git-send-email-anoobj@marvell.com (mailing list archive)
State Superseded
Delegated to: akhil goyal
Headers show
Series Add new cases to lookaside IPsec tests | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Anoob Joseph Dec. 6, 2021, 7:58 a.m. UTC
From: Ankur Dwivedi <adwivedi@marvell.com>

Adds security stats test cases in IPSEC protocol testsuite.

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
---
 app/test/test_cryptodev.c                | 21 +++++++++++++++++++++
 app/test/test_cryptodev_security_ipsec.c | 29 +++++++++++++++++++++++++++++
 app/test/test_cryptodev_security_ipsec.h |  6 ++++++
 3 files changed, 56 insertions(+)
diff mbox series

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index f8f2660..34bc3e0 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -9332,6 +9332,11 @@  test_ipsec_proto_process(const struct ipsec_test_data td[],
 		if (ret != TEST_SUCCESS)
 			goto crypto_op_free;
 
+		ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
+					      flags, dir);
+		if (ret != TEST_SUCCESS)
+			goto crypto_op_free;
+
 		rte_crypto_op_free(ut_params->op);
 		ut_params->op = NULL;
 
@@ -9653,6 +9658,18 @@  test_ipsec_proto_transport_v4(const void *data __rte_unused)
 }
 
 static int
+test_ipsec_proto_stats(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.stats_success = true;
+
+	return test_ipsec_proto_all(&flags);
+}
+
+static int
 test_PDCP_PROTO_all(void)
 {
 	struct crypto_testsuite_params *ts_params = &testsuite_params;
@@ -14656,6 +14673,10 @@  static struct unit_test_suite ipsec_proto_testsuite  = {
 			"Transport IPv4",
 			ut_setup_security, ut_teardown,
 			test_ipsec_proto_transport_v4),
+		TEST_CASE_NAMED_ST(
+			"Statistics: success",
+			ut_setup_security, ut_teardown,
+			test_ipsec_proto_stats),
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
 };
diff --git a/app/test/test_cryptodev_security_ipsec.c b/app/test/test_cryptodev_security_ipsec.c
index 029fdd3..6fa1d3d 100644
--- a/app/test/test_cryptodev_security_ipsec.c
+++ b/app/test/test_cryptodev_security_ipsec.c
@@ -415,6 +415,8 @@  test_ipsec_td_prepare(const struct crypto_param *param1,
 						RTE_SECURITY_IPSEC_TUNNEL_IPV4;
 		}
 
+		if (flags->stats_success)
+			td->ipsec_xform.options.stats = 1;
 
 	}
 }
@@ -871,3 +873,30 @@  test_ipsec_status_check(struct rte_crypto_op *op,
 
 	return ret;
 }
+
+int
+test_ipsec_stats_verify(struct rte_security_ctx *ctx,
+			struct rte_security_session *sess,
+			const struct ipsec_test_flags *flags,
+			enum rte_security_ipsec_sa_direction dir)
+{
+	struct rte_security_stats stats = {0};
+	int ret = TEST_SUCCESS;
+
+	if (flags->stats_success) {
+		if (rte_security_session_stats_get(ctx, sess, &stats) < 0)
+			return TEST_FAILED;
+
+		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			if (stats.ipsec.opackets != 1 ||
+			    stats.ipsec.oerrors != 0)
+				ret = TEST_FAILED;
+		} else {
+			if (stats.ipsec.ipackets != 1 ||
+			    stats.ipsec.ierrors != 0)
+				ret = TEST_FAILED;
+		}
+	}
+
+	return ret;
+}
diff --git a/app/test/test_cryptodev_security_ipsec.h b/app/test/test_cryptodev_security_ipsec.h
index 07d2453..3565a8c 100644
--- a/app/test/test_cryptodev_security_ipsec.h
+++ b/app/test/test_cryptodev_security_ipsec.h
@@ -65,6 +65,7 @@  struct ipsec_test_flags {
 	bool tunnel_ipv6;
 	bool transport;
 	bool fragment;
+	bool stats_success;
 };
 
 struct crypto_param {
@@ -188,4 +189,9 @@  int test_ipsec_status_check(struct rte_crypto_op *op,
 			    enum rte_security_ipsec_sa_direction dir,
 			    int pkt_num);
 
+int test_ipsec_stats_verify(struct rte_security_ctx *ctx,
+			    struct rte_security_session *sess,
+			    const struct ipsec_test_flags *flags,
+			    enum rte_security_ipsec_sa_direction dir);
+
 #endif