From 2c85598c5377ab9b7fdc1b9a91fe5619d15a37d3 Mon Sep 17 00:00:00 2001 From: Ankur Dwivedi Date: Mon, 6 Dec 2021 16:37:55 +0530 Subject: [PATCH] test/crypto: add IPsec security stats cases Add security stats test cases in IPSEC protocol testsuite. Signed-off-by: Ankur Dwivedi Acked-by: Akhil Goyal --- 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 --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 2adec1d524..38648f4b92 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; @@ -9652,6 +9657,18 @@ test_ipsec_proto_transport_v4(const void *data __rte_unused) return test_ipsec_proto_all(&flags); } +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) { @@ -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 029fdd333a..6fa1d3d90a 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 07d2453061..3565a8c5d2 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 -- 2.39.5