[6/7] test/crypto: Modify test_pdcp_proto to take parameters
diff mbox series

Message ID 20200903160652.31654-7-akhil.goyal@nxp.com
State Superseded
Delegated to: akhil goyal
Headers show
Series
  • support PDCP-SDAP for dpaa2_sec
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Akhil Goyal Sept. 3, 2020, 4:06 p.m. UTC
From: Franck LENORMAND <franck.lenormand@nxp.com>

The function test_pdcp_proto was relying to heavily on the structure
of test vectors for PDCP making it difficult to be reusable.

The function is changed to take all the test parameters as input and
does not need access to the tests vectors anymore.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
---
 app/test/test_cryptodev.c | 183 ++++++++++++++++++++++----------------
 1 file changed, 104 insertions(+), 79 deletions(-)

Patch
diff mbox series

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 70bf6fe2c..d6bc07696 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -7121,14 +7121,18 @@  security_proto_supported(enum rte_security_session_action_type action,
  * on input_vec. Checks the output of the crypto operation against
  * output_vec.
  */
-static int
-test_pdcp_proto(int i, int oop,
-	enum rte_crypto_cipher_operation opc,
-	enum rte_crypto_auth_operation opa,
-	uint8_t *input_vec,
-	unsigned int input_vec_len,
-	uint8_t *output_vec,
-	unsigned int output_vec_len)
+static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
+			   enum rte_crypto_auth_operation opa,
+			   const uint8_t *input_vec, unsigned int input_vec_len,
+			   const uint8_t *output_vec,
+			   unsigned int output_vec_len,
+			   enum rte_crypto_cipher_algorithm cipher_alg,
+			   const uint8_t *cipher_key, uint32_t cipher_key_len,
+			   enum rte_crypto_auth_algorithm auth_alg,
+			   const uint8_t *auth_key, uint32_t auth_key_len,
+			   uint8_t bearer, enum rte_security_pdcp_domain domain,
+			   uint8_t packet_direction, uint8_t sn_size,
+			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
 {
 	struct crypto_testsuite_params *ts_params = &testsuite_params;
 	struct crypto_unittest_params *ut_params = &unittest_params;
@@ -7143,7 +7147,7 @@  test_pdcp_proto(int i, int oop,
 
 	sec_cap_idx.action = ut_params->type;
 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
-	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
+	sec_cap_idx.pdcp.domain = domain;
 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
 		return -ENOTSUP;
 
@@ -7169,24 +7173,22 @@  test_pdcp_proto(int i, int oop,
 
 	/* Setup Cipher Parameters */
 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
-	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
+	ut_params->cipher_xform.cipher.algo = cipher_alg;
 	ut_params->cipher_xform.cipher.op = opc;
-	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
-	ut_params->cipher_xform.cipher.key.length =
-					pdcp_test_params[i].cipher_key_len;
+	ut_params->cipher_xform.cipher.key.data = cipher_key;
+	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
 	ut_params->cipher_xform.cipher.iv.length =
-				pdcp_test_packet_direction[i] ? 4 : 0;
+				packet_direction ? 4 : 0;
 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
 
 	/* Setup HMAC Parameters if ICV header is required */
-	if (pdcp_test_params[i].auth_alg != 0) {
+	if (auth_alg != 0) {
 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
 		ut_params->auth_xform.next = NULL;
-		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
+		ut_params->auth_xform.auth.algo = auth_alg;
 		ut_params->auth_xform.auth.op = opa;
-		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
-		ut_params->auth_xform.auth.key.length =
-					pdcp_test_params[i].auth_key_len;
+		ut_params->auth_xform.auth.key.data = auth_key;
+		ut_params->auth_xform.auth.key.length = auth_key_len;
 
 		ut_params->cipher_xform.next = &ut_params->auth_xform;
 	} else {
@@ -7197,22 +7199,22 @@  test_pdcp_proto(int i, int oop,
 		.action_type = ut_params->type,
 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
 		{.pdcp = {
-			.bearer = pdcp_test_bearer[i],
-			.domain = pdcp_test_params[i].domain,
-			.pkt_dir = pdcp_test_packet_direction[i],
-			.sn_size = pdcp_test_data_sn_size[i],
-			.hfn = pdcp_test_packet_direction[i] ?
-				0 : pdcp_test_hfn[i],
-				/**
-				 * hfn can be set as pdcp_test_hfn[i]
-				 * if hfn_ovrd is not set. Here, PDCP
-				 * packet direction is just used to
-				 * run half of the cases with session
-				 * HFN and other half with per packet
-				 * HFN.
-				 */
-			.hfn_threshold = pdcp_test_hfn_threshold[i],
-			.hfn_ovrd = pdcp_test_packet_direction[i] ? 1 : 0,
+			.bearer = bearer,
+			.domain = domain,
+			.pkt_dir = packet_direction,
+			.sn_size = sn_size,
+			.hfn = packet_direction ? 0 : hfn,
+			/**
+			 * hfn can be set as pdcp_test_hfn[i]
+			 * if hfn_ovrd is not set. Here, PDCP
+			 * packet direction is just used to
+			 * run half of the cases with session
+			 * HFN and other half with per packet
+			 * HFN.
+			 */
+			.hfn_threshold = hfn_threshold,
+			.hfn_ovrd = packet_direction ? 1 : 0,
+			.sdap_enabled = sdap,
 		} },
 		.crypto_xform = &ut_params->cipher_xform
 	};
@@ -7241,7 +7243,7 @@  test_pdcp_proto(int i, int oop,
 
 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
 					uint32_t *, IV_OFFSET);
-	*per_pkt_hfn = pdcp_test_packet_direction[i] ? pdcp_test_hfn[i] : 0;
+	*per_pkt_hfn = packet_direction ? hfn : 0;
 
 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
 
@@ -7582,74 +7584,97 @@  test_pdcp_proto_SGL(int i, int oop,
 int
 test_pdcp_proto_cplane_encap(int i)
 {
-	return test_pdcp_proto(i, 0,
-		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
-		RTE_CRYPTO_AUTH_OP_GENERATE,
-		pdcp_test_data_in[i],
-		pdcp_test_data_in_len[i],
-		pdcp_test_data_out[i],
-		pdcp_test_data_in_len[i]+4);
+	return test_pdcp_proto(
+		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
+		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
+		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
+		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
+		pdcp_test_params[i].cipher_key_len,
+		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
+		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
+		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
+		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
+		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
 }
 
 int
 test_pdcp_proto_uplane_encap(int i)
 {
-	return test_pdcp_proto(i, 0,
-		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
-		RTE_CRYPTO_AUTH_OP_GENERATE,
-		pdcp_test_data_in[i],
-		pdcp_test_data_in_len[i],
-		pdcp_test_data_out[i],
-		pdcp_test_data_in_len[i]);
-
+	return test_pdcp_proto(
+		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
+		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
+		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
+		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
+		pdcp_test_params[i].cipher_key_len,
+		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
+		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
+		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
+		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
+		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
 }
 
 int
 test_pdcp_proto_uplane_encap_with_int(int i)
 {
-	return test_pdcp_proto(i, 0,
-		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
-		RTE_CRYPTO_AUTH_OP_GENERATE,
-		pdcp_test_data_in[i],
-		pdcp_test_data_in_len[i],
-		pdcp_test_data_out[i],
-		pdcp_test_data_in_len[i] + 4);
+	return test_pdcp_proto(
+		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
+		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
+		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
+		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
+		pdcp_test_params[i].cipher_key_len,
+		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
+		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
+		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
+		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
+		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
 }
 
 int
 test_pdcp_proto_cplane_decap(int i)
 {
-	return test_pdcp_proto(i, 0,
-		RTE_CRYPTO_CIPHER_OP_DECRYPT,
-		RTE_CRYPTO_AUTH_OP_VERIFY,
-		pdcp_test_data_out[i],
-		pdcp_test_data_in_len[i] + 4,
-		pdcp_test_data_in[i],
-		pdcp_test_data_in_len[i]);
+	return test_pdcp_proto(
+		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
+		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
+		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
+		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
+		pdcp_test_params[i].cipher_key_len,
+		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
+		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
+		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
+		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
+		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
 }
 
 int
 test_pdcp_proto_uplane_decap(int i)
 {
-	return test_pdcp_proto(i, 0,
-		RTE_CRYPTO_CIPHER_OP_DECRYPT,
-		RTE_CRYPTO_AUTH_OP_VERIFY,
-		pdcp_test_data_out[i],
-		pdcp_test_data_in_len[i],
-		pdcp_test_data_in[i],
-		pdcp_test_data_in_len[i]);
+	return test_pdcp_proto(
+		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
+		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
+		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
+		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
+		pdcp_test_params[i].cipher_key_len,
+		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
+		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
+		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
+		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
+		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
 }
 
 int
 test_pdcp_proto_uplane_decap_with_int(int i)
 {
-	return test_pdcp_proto(i, 0,
-		RTE_CRYPTO_CIPHER_OP_DECRYPT,
-		RTE_CRYPTO_AUTH_OP_VERIFY,
-		pdcp_test_data_out[i],
-		pdcp_test_data_in_len[i] + 4,
-		pdcp_test_data_in[i],
-		pdcp_test_data_in_len[i]);
+	return test_pdcp_proto(
+		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
+		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
+		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
+		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
+		pdcp_test_params[i].cipher_key_len,
+		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
+		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
+		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
+		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
+		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
 }
 
 static int