Fixes and improvements in crypto unit tests
cover Fixes and improvements in crypto unit tests
Enable larger packet sizes in TLS tests and add minor improvements in crypto unit tests.
Anoob Joseph (6):
test/crypto: add asserts to validate test lengths test/crypto: enable larger packet sizes with TLS test/crypto: remove redefinition test/crypto: remove unused macros test/crypto: start opening brace in new line test/crypto: free pools in teardown
app/test/test_cryptodev.c | 35 ++++++----- app/test/test_cryptodev.h | 58 +++++++++++++++---- app/test/test_cryptodev_aead_test_vectors.h | 14 ++++- app/test/test_cryptodev_security_tls_record.h | 12 ++-- app/test/test_security_proto.h | 7 ++- 5 files changed, 92 insertions(+), 34 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/6 test/crypto: add asserts to validate test lengths
Add asserts to validate the max lengths set.
--- app/test/test_cryptodev.c | 2 +- app/test/test_cryptodev.h | 2 ++ app/test/test_cryptodev_aead_test_vectors.h | 14 +++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-)
app/test/test_cryptodev.c +1 -1
@@ -665,7 +665,7 @@ testsuite_setup(void)/* Not already created so create */ ts_params->large_mbuf_pool =rte_pktmbuf_pool_create ("CRYPTO_LARGE_MBUFPOOL" , -1 ,0 ,0 ,UINT16_MAX , +1 ,0 ,0 ,LARGE_MBUF_SIZE ,rte_socket_id ());if (ts_params->large_mbuf_pool ==NULL ) { RTE_LOG(ERR, USER1,
app/test/test_cryptodev.h +2 -0
@@ -24,6 +24,8 @@#define MBUF_DATAPAYLOAD_SIZE (4096 + DIGEST_BYTE_LENGTH_SHA512)#define MBUF_SIZE (sizeof(struct rte_mbuf) + \ RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE) +#define LARGE_MBUF_DATAPAYLOAD_SIZE (UINT16_MAX - RTE_PKTMBUF_HEADROOM) +#define LARGE_MBUF_SIZE (RTE_PKTMBUF_HEADROOM + LARGE_MBUF_DATAPAYLOAD_SIZE)#define BYTE_LENGTH (x) (x/8)/* HASH DIGEST LENGTHS */
app/test/test_cryptodev_aead_test_vectors.h +13 -1
@@ -5,11 +5,23 @@#ifndef TEST_CRYPTODEV_AEAD_TEST_VECTORS_H_ #define TEST_CRYPTODEV_AEAD_TEST_VECTORS_H_ +#include "test_cryptodev.h" +#define GMAC_LARGE_PLAINTEXT_LENGTH 65344 -#define MAX_AAD_LENGTH 65536 +#define MAX_AAD_LENGTH (65535 - RTE_PKTMBUF_HEADROOM)#define GCM_LARGE_AAD_LENGTH 65296#define AEAD_TEXT_MAX_LENGTH 8096 +static_assert (GMAC_LARGE_PLAINTEXT_LENGTH <=LARGE_MBUF_DATAPAYLOAD_SIZE , +"GMAC_LARGE_PLAINTEXT_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE" ); +static_assert (MAX_AAD_LENGTH <=LARGE_MBUF_DATAPAYLOAD_SIZE , +"MAX_AAD_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE" ); +static_assert (GCM_LARGE_AAD_LENGTH <=LARGE_MBUF_DATAPAYLOAD_SIZE , +"GCM_LARGE_AAD_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE" ); +static_assert (AEAD_TEXT_MAX_LENGTH <=LARGE_MBUF_DATAPAYLOAD_SIZE , +"AEAD_TEXT_MAX_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE" ); + +static uint8_t gcm_aad_zero_text[MAX_AAD_LENGTH ] = {0 }; static uint8_t gcm_aad_text[MAX_AAD_LENGTH] = {
Signature · 1 line
2.45.2
PATCH 2/6 test/crypto: enable larger packet sizes with TLS
In reply to Anoob JosephEnable larger packet sizes with TLS. Add wrapper for existing create_segmented_mbuf() function to get allocations from both pools.
--- app/test/test_cryptodev.c | 13 +++++-- app/test/test_cryptodev.h | 38 +++++++++++++++++++ app/test/test_cryptodev_security_tls_record.h | 12 +++--- app/test/test_security_proto.h | 7 +++- 4 files changed, 58 insertions(+), 12 deletions(-)
app/test/test_cryptodev.c +9 -4
@@ -12139,12 +12139,13 @@ test_tls_record_proto_process(const struct tls_record_test_data td[], }/* Setup source mbuf payload */ - ut_params->ibuf =create_segmented_mbuf (ts_params->mbuf_pool, td[i].input_text.len, - nb_segs,0 ); + ut_params->ibuf =create_segmented_mbuf_multi_pool (ts_params->mbuf_pool, + ts_params->large_mbuf_pool, td[i].input_text.len, nb_segs,0 );pktmbuf_write (ut_params->ibuf,0 , td[i].input_text.len, td[i].input_text.data);if (flags->out_of_place) - ut_params->obuf =create_segmented_mbuf (ts_params->mbuf_pool, - td[i].output_text.len, nb_segs,0 ); + ut_params->obuf =create_segmented_mbuf_multi_pool (ts_params->mbuf_pool, + ts_params->large_mbuf_pool, td[i].output_text.len, nb_segs, +0 );else ut_params->obuf =NULL ;
@@ -12375,6 +12376,10 @@ test_tls_record_proto_all(const struct tls_record_test_flags *flags) pass_cnt++; } +if (flags->data_walkthrough) +printf ("\t Min payload size: %d, Max payload size: %d\n" , +TLS_RECORD_PLAINTEXT_MIN_LEN , max_payload_len); +if (pass_cnt >0 )return TEST_SUCCESS ;else
app/test/test_cryptodev.h +38 -0
@@ -233,6 +233,44 @@ create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,return NULL ; } +static inline struct rte_mbuf * +create_segmented_mbuf_multi_pool (struct rte_mempool *mbuf_pool_small, +struct rte_mempool *mbuf_pool_large,int pkt_len,int nb_segs,uint8_t pattern) +{ +struct rte_mempool *mbuf_pool; +int max_seg_len, seg_len; + +if (nb_segs <1 ) { +printf ("Number of segments must be 1 or more (is %d)\n" , nb_segs); +return NULL ; + } + +if (pkt_len >= nb_segs) + seg_len = pkt_len / nb_segs; +else + seg_len =1 ; + +/* Determine max segment length */ + max_seg_len = seg_len + pkt_len % nb_segs; + +if (max_seg_len >LARGE_MBUF_DATAPAYLOAD_SIZE ) { +printf ("Segment size %d is too big\n" , max_seg_len); +return NULL ; + } + +if (max_seg_len >MBUF_DATAPAYLOAD_SIZE ) + mbuf_pool = mbuf_pool_large; +else + mbuf_pool = mbuf_pool_small; + +if (mbuf_pool ==NULL ) { +printf ("Invalid mbuf pool\n" ); +return NULL ; + } + +return create_segmented_mbuf (mbuf_pool, pkt_len, nb_segs, pattern); +} + int process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id, struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
app/test/test_cryptodev_security_tls_record.h +6 -6
@@ -11,32 +11,32 @@#include "test_security_proto.h" /* TLS 1.2 Ciphertext length can be up to (2^14 + 2048 + 5 (TLS Header)) Bytes */ -#define TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (4096u) +#define TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (18437u)static_assert (TLS_1_2_RECORD_CIPHERTEXT_MAX_LEN <=TEST_SEC_CIPHERTEXT_MAX_LEN ,"TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!" );/* TLS 1.2 Plaintext length can be up to (2^14 + 1024) Bytes */ -#define TLS_1_2_RECORD_PLAINTEXT_MAX_LEN (3072u) +#define TLS_1_2_RECORD_PLAINTEXT_MAX_LEN (17408u)static_assert (TLS_1_2_RECORD_PLAINTEXT_MAX_LEN <=TEST_SEC_CLEARTEXT_MAX_LEN ,"TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!" );/* DTLS 1.2 Ciphertext length is similar to TLS 1.2 */ -#define DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (4096u) +#define DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN (18437u)static_assert (DTLS_1_2_RECORD_CIPHERTEXT_MAX_LEN <=TEST_SEC_CIPHERTEXT_MAX_LEN ,"TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!" );/* DTLS 1.2 Plaintext length is similar to TLS 1.2 */ -#define DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN (3072u) +#define DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN (17408u)static_assert (DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN <=TEST_SEC_CLEARTEXT_MAX_LEN ,"TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!" );/* TLS 1.3 Ciphertext length can be up to (2^14 + 256 + 5 (TLS Header)) Bytes */ -#define TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN (4096u) +#define TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN (16645u)static_assert (TLS_1_3_RECORD_CIPHERTEXT_MAX_LEN <=TEST_SEC_CIPHERTEXT_MAX_LEN ,"TEST_SEC_CIPHERTEXT_MAX_LEN should be at least RECORD MAX LEN!" );/* TLS 1.3 Plaintext length can be up to 2^14 Bytes */ -#define TLS_1_3_RECORD_PLAINTEXT_MAX_LEN (3072u) +#define TLS_1_3_RECORD_PLAINTEXT_MAX_LEN (16384u)static_assert (TLS_1_3_RECORD_PLAINTEXT_MAX_LEN <=TEST_SEC_CLEARTEXT_MAX_LEN ,"TEST_SEC_CLEARTEXT_MAX_LEN should be at least RECORD MAX LEN!" );
app/test/test_security_proto.h +5 -2
@@ -10,10 +10,13 @@#include "test_cryptodev.h" -#define TEST_SEC_CLEARTEXT_MAX_LEN (MBUF_DATAPAYLOAD_SIZE - 1024) -#define TEST_SEC_CIPHERTEXT_MAX_LEN (MBUF_DATAPAYLOAD_SIZE) +#define TEST_SEC_CLEARTEXT_MAX_LEN 17408u +#define TEST_SEC_CIPHERTEXT_MAX_LEN 18437u#define TEST_SEC_PKTS_MAX 32 +static_assert (TEST_SEC_CIPHERTEXT_MAX_LEN <=LARGE_MBUF_DATAPAYLOAD_SIZE , +"TEST_SEC_CIPHERTEXT_MAX_LEN should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE" ); +struct crypto_param {enum rte_crypto_sym_xform_type type;union {
Signature · 1 line
2.45.2
PATCH 3/6 test/crypto: remove redefinition
In reply to Anoob JosephRemove redefinition of TRUE & FALSE. These are defined by stdbool. Can use the same.
--- app/test/test_cryptodev.c | 5 +++-- app/test/test_cryptodev.h | 3 --- 2 files changed, 3 insertions(+), 5 deletions(-)
app/test/test_cryptodev.c +3 -2
@@ -3,6 +3,7 @@* Copyright 2020 NXP */ +#include <stdbool.h> #include <time.h> #include <rte_common.h>
@@ -796,7 +797,7 @@ check_capabilities_supported(enum rte_crypto_sym_xform_type type, const int *algs, uint16_t num_algs) { uint8_t dev_id = testsuite_params.valid_devs[0]; -bool some_alg_supported = FALSE; +bool some_alg_supported = false;uint16_t i;for (i =0 ; i < num_algs && !some_alg_supported; i++) {
@@ -805,7 +806,7 @@ check_capabilities_supported(enum rte_crypto_sym_xform_type type, };if (rte_cryptodev_sym_capability_get (dev_id, &alg) !=NULL ) - some_alg_supported = TRUE; + some_alg_supported = true; }if (!some_alg_supported)return TEST_SKIPPED ;
app/test/test_cryptodev.h +0 -3
@@ -8,9 +8,6 @@#define HEX_DUMP 0 -#define FALSE 0 -#define TRUE 1 -#define MAX_NUM_OPS_INFLIGHT (4096)#define MIN_NUM_OPS_INFLIGHT (128)#define DEFAULT_NUM_OPS_INFLIGHT (128)
Signature · 1 line
2.45.2
PATCH 4/6 test/crypto: remove unused macros
In reply to Anoob JosephThe macros are not used. Remove the same.
--- app/test/test_cryptodev.c | 2 -- app/test/test_cryptodev.h | 5 ----- 2 files changed, 7 deletions(-)
app/test/test_cryptodev.c +0 -2
@@ -65,8 +65,6 @@#define VDEV_ARGS_SIZE 100#define MAX_NB_SESSIONS 4 -#define MAX_DRV_SERVICE_CTX_SIZE 256 -#define MAX_RAW_DEQUEUE_COUNT 65535#define IN_PLACE 0
app/test/test_cryptodev.h +0 -5
@@ -6,15 +6,10 @@#include <rte_cryptodev.h> -#define HEX_DUMP 0 -#define MAX_NUM_OPS_INFLIGHT (4096)#define MIN_NUM_OPS_INFLIGHT (128)#define DEFAULT_NUM_OPS_INFLIGHT (128) -#define MAX_NUM_QPS_PER_QAT_DEVICE (2) -#define DEFAULT_NUM_QPS_PER_QAT_DEVICE (2) -#define DEFAULT_BURST_SIZE (64)#define DEFAULT_NUM_XFORMS (2)#define NUM_MBUFS (8191)#define MBUF_CACHE_SIZE (256)
Signature · 1 line
2.45.2
PATCH 5/6 test/crypto: start opening brace in new line
In reply to Anoob JosephStart opening brace of the function body in new line as suggested in coding guideline.
--- app/test/test_cryptodev.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
app/test/test_cryptodev.h +6 -4
@@ -144,7 +144,8 @@ pktmbuf_write(struct rte_mbuf *mbuf, int offset, int len, const uint8_t *buffer) }static inline uint8_t * -pktmbuf_mtod_offset (struct rte_mbuf *mbuf,int offset) { +pktmbuf_mtod_offset (struct rte_mbuf *mbuf,int offset) +{struct rte_mbuf *m;for (m = mbuf; (m !=NULL ) && (offset > m->data_len); m = m->next)
@@ -158,7 +159,8 @@ pktmbuf_mtod_offset(struct rte_mbuf *mbuf, int offset) { }static inline rte_iova_t -pktmbuf_iova_offset (struct rte_mbuf *mbuf,int offset) { +pktmbuf_iova_offset (struct rte_mbuf *mbuf,int offset) +{struct rte_mbuf *m;for (m = mbuf; (m !=NULL ) && (offset > m->data_len); m = m->next)
@@ -173,8 +175,8 @@ pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset) {static inline struct rte_mbuf *create_segmented_mbuf (struct rte_mempool *mbuf_pool,int pkt_len, -int nb_segs,uint8_t pattern) { - +int nb_segs,uint8_t pattern) +{struct rte_mbuf *m =NULL , *mbuf =NULL ;int size, t_len, data_len =0 ;uint8_t *dst;
Signature · 1 line
2.45.2
PATCH 6/6 test/crypto: free pools in teardown
In reply to Anoob JosephFree the pools allocated in testsuite_setup.
--- app/test/test_cryptodev.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
app/test/test_cryptodev.c +9 -4
@@ -770,14 +770,19 @@ testsuite_teardown(void)struct crypto_testsuite_params *ts_params = &testsuite_params;int res; +if (ts_params->large_mbuf_pool !=NULL ) { +rte_mempool_free (ts_params->large_mbuf_pool); + ts_params->large_mbuf_pool =NULL ; + } +if (ts_params->mbuf_pool !=NULL ) { -RTE_LOG (DEBUG ,USER1 ,"CRYPTO_MBUFPOOL count %u\n" , -rte_mempool_avail_count (ts_params->mbuf_pool)); +rte_mempool_free (ts_params->mbuf_pool); + ts_params->mbuf_pool =NULL ; }if (ts_params->op_mpool !=NULL ) { -RTE_LOG (DEBUG ,USER1 ,"CRYPTO_OP_POOL count %u\n" , -rte_mempool_avail_count (ts_params->op_mpool)); +rte_mempool_free (ts_params->op_mpool); + ts_params->op_mpool =NULL ; }if (ts_params->session_mpool !=NULL ) {
Signature · 1 line
2.45.2
Akhil Goyal
AppliedQuoted 13 lines
Subject: [PATCH 0/6] Fixes and improvements in crypto unit tests
Enable larger packet sizes in TLS tests and add minor improvements in crypto unit tests.
Anoob Joseph (6):
test/crypto: add asserts to validate test lengths test/crypto: enable larger packet sizes with TLS test/crypto: remove redefinition test/crypto: remove unused macros test/crypto: start opening brace in new line test/crypto: free pools in teardown
Quoted 7 lines
app/test/test_cryptodev.c | 35 ++++++----- app/test/test_cryptodev.h | 58 +++++++++++++++---- app/test/test_cryptodev_aead_test_vectors.h | 14 ++++- app/test/test_cryptodev_security_tls_record.h | 12 ++-- app/test/test_security_proto.h | 7 ++- 5 files changed, 92 insertions(+), 34 deletions(-)
Series Acked-by: Akhil Goyal <[email protected]>
Applied to dpdk-next-crypto
Thanks.