DPDK patches and discussions
 help / color / mirror / Atom feed
From: Radu Nicolau <radu.nicolau@intel.com>
To: dev@dpdk.org
Cc: kai.ji@intel.com, Radu Nicolau <radu.nicolau@intel.com>,
	Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>
Subject: [PATCH 2/3] test/crypto: improve CPU mode coverage
Date: Thu, 11 Sep 2025 10:22:28 +0000	[thread overview]
Message-ID: <20250911102229.1241141-2-radu.nicolau@intel.com> (raw)
In-Reply-To: <20250911102229.1241141-1-radu.nicolau@intel.com>

Add crypto CPU mode code path for blockcipher tests.

Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
 app/test/test_cryptodev.c             |   2 +-
 app/test/test_cryptodev.h             |   1 +
 app/test/test_cryptodev_blockcipher.c | 104 +++++++++++++++++++++-----
 3 files changed, 89 insertions(+), 18 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 5229ac2bf6..0773d320d4 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -75,7 +75,7 @@
 
 static int gbl_driver_id;
 
-static enum rte_security_session_action_type gbl_action_type =
+enum rte_security_session_action_type gbl_action_type =
 	RTE_SECURITY_ACTION_TYPE_NONE;
 
 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
diff --git a/app/test/test_cryptodev.h b/app/test/test_cryptodev.h
index e243cf945a..e9bea5e793 100644
--- a/app/test/test_cryptodev.h
+++ b/app/test/test_cryptodev.h
@@ -85,6 +85,7 @@ enum cryptodev_api_test_type {
 	CRYPTODEV_RAW_API_TEST
 };
 
+extern enum rte_security_session_action_type gbl_action_type;
 extern enum cryptodev_api_test_type global_api_test_type;
 
 extern struct crypto_testsuite_params *p_testsuite_params;
diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c
index 5a124bbb5e..85756ab13c 100644
--- a/app/test/test_cryptodev_blockcipher.c
+++ b/app/test/test_cryptodev_blockcipher.c
@@ -11,6 +11,7 @@
 
 #include <rte_crypto.h>
 #include <rte_cryptodev.h>
+#include <rte_security.h>
 
 #include "test.h"
 #include "test_cryptodev.h"
@@ -567,25 +568,95 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
 			goto error_exit;
 		}
 	} else {
-		if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
-			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
-				"line %u FAILED: %s",
-				__LINE__, "Error sending packet for encryption");
-			status = TEST_FAILED;
-			goto error_exit;
-		}
+		if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
+			int32_t n_src, n_dst, st, n;
+			struct rte_crypto_sym_op *sop;
+			union rte_crypto_sym_ofs ofs;
+			struct rte_crypto_sgl sgl_src, sgl_dst;
+			struct rte_crypto_sym_vec symvec = {0};
+			struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
+			struct rte_crypto_vec vec_src[UINT8_MAX];
+			struct rte_crypto_vec vec_dst[UINT8_MAX];
+			uint32_t cipher_offset, cipher_len, auth_offset, auth_len, max_len;
+			bool is_oop = op->sym->m_dst != NULL;
+
+			if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
+				status = TEST_SKIPPED;
+				goto error_exit;
+			}
+
+			sop = op->sym;
+			cipher_offset = sop->cipher.data.offset;
+			cipher_len = sop->cipher.data.length;
+			auth_offset = sop->auth.data.offset;
+			auth_len = sop->auth.data.length;
+			max_len = RTE_MAX(cipher_offset + cipher_len, auth_offset + auth_len);
+
+			n_src = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
+				vec_src, RTE_DIM(vec_src));
+			if (n_src < 0 || n_src != sop->m_src->nb_segs) {
+				op->status = RTE_CRYPTO_OP_STATUS_ERROR;
+				status = TEST_FAILED;
+				goto error_exit;
+			}
+			sgl_src.vec = vec_src;
+			sgl_src.num = n_src;
+			symvec.src_sgl = &sgl_src;
+			if (is_oop) {
+				n_dst = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
+					vec_dst, RTE_DIM(vec_dst));
+				sgl_dst.vec = vec_dst;
+				sgl_dst.num = n_dst;
+				symvec.dest_sgl = &sgl_dst;
+			} else {
+				symvec.dest_sgl = NULL;
+			}
+
+			symvec.iv = &iv_ptr;
+			symvec.digest = &digest_ptr;
+			symvec.status = &st;
+			symvec.num = 1;
+			iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
+			digest_ptr.va = (void *)sop->auth.digest.data;
+			ofs.ofs.cipher.head = cipher_offset;
+			ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
+			ofs.ofs.auth.head = auth_offset;
+			ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
+
+			n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
+				&symvec);
+			if (st == -ENOTSUP) {
+				status = TEST_SKIPPED;
+				goto error_exit;
+			}
+			if (n != 1) {
+				status = TEST_FAILED;
+				op->status = RTE_CRYPTO_OP_STATUS_ERROR;
+				goto error_exit;
+			} else {
+				op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
+			}
+		} else {
+			if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
+				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
+					"line %u FAILED: %s",
+					__LINE__, "Error sending packet for encryption");
+				status = TEST_FAILED;
+				goto error_exit;
+			}
 
-		op = NULL;
+			op = NULL;
 
-		while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
-			rte_pause();
+			while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
+				rte_pause();
 
-		if (!op) {
-			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
-				"line %u FAILED: %s",
-				__LINE__, "Failed to process sym crypto op");
-			status = TEST_FAILED;
-			goto error_exit;
+			if (!op) {
+				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
+					"line %u FAILED: %s",
+					__LINE__, "Failed to process sym crypto op");
+				status = TEST_FAILED;
+				goto error_exit;
+			}
 		}
 	}
 
@@ -649,7 +720,6 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
 			uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
 						tdata->ciphertext.len);
-
 			if (memcmp(auth_res, tdata->digest.data, digest_len)) {
 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
 					"FAILED: %s", __LINE__, "Generated "
-- 
2.50.1


  reply	other threads:[~2025-09-11 10:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 10:22 [PATCH 1/3] crypto/ipsec_mb: improve CPU code path Radu Nicolau
2025-09-11 10:22 ` Radu Nicolau [this message]
2025-09-11 10:22 ` [PATCH 3/3] test/crypto: fix uninitialised vector fields Radu Nicolau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250911102229.1241141-2-radu.nicolau@intel.com \
    --to=radu.nicolau@intel.com \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    --cc=kai.ji@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).