LCOV - code coverage report
Current view: top level - app/test - test_cryptodev.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 42 63 66.7 %
Date: 2025-06-01 17:49:23 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 33 54 61.1 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2015-2017 Intel Corporation
       3                 :            :  */
       4                 :            : #ifndef TEST_CRYPTODEV_H_
       5                 :            : #define TEST_CRYPTODEV_H_
       6                 :            : 
       7                 :            : #include <rte_cryptodev.h>
       8                 :            : 
       9                 :            : #define MAX_NUM_OPS_INFLIGHT            (4096)
      10                 :            : #define MIN_NUM_OPS_INFLIGHT            (128)
      11                 :            : #define DEFAULT_NUM_OPS_INFLIGHT        (128)
      12                 :            : #define TEST_STATS_RETRIES              (100)
      13                 :            : 
      14                 :            : #define DEFAULT_NUM_XFORMS              (2)
      15                 :            : #define NUM_MBUFS                       (8191)
      16                 :            : #define MBUF_CACHE_SIZE                 (256)
      17                 :            : #define MBUF_DATAPAYLOAD_SIZE           (4096 + DIGEST_BYTE_LENGTH_SHA512)
      18                 :            : #define MBUF_SIZE                       (sizeof(struct rte_mbuf) + \
      19                 :            :                 RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE)
      20                 :            : #define LARGE_MBUF_DATAPAYLOAD_SIZE     (UINT16_MAX - RTE_PKTMBUF_HEADROOM)
      21                 :            : #define LARGE_MBUF_SIZE                 (RTE_PKTMBUF_HEADROOM + LARGE_MBUF_DATAPAYLOAD_SIZE)
      22                 :            : 
      23                 :            : #define BYTE_LENGTH(x)                          (x/8)
      24                 :            : /* HASH DIGEST LENGTHS */
      25                 :            : #define DIGEST_BYTE_LENGTH_MD5                  (BYTE_LENGTH(128))
      26                 :            : #define DIGEST_BYTE_LENGTH_SHA1                 (BYTE_LENGTH(160))
      27                 :            : #define DIGEST_BYTE_LENGTH_SHA224               (BYTE_LENGTH(224))
      28                 :            : #define DIGEST_BYTE_LENGTH_SHA256               (BYTE_LENGTH(256))
      29                 :            : #define DIGEST_BYTE_LENGTH_SHA384               (BYTE_LENGTH(384))
      30                 :            : #define DIGEST_BYTE_LENGTH_SHA512               (BYTE_LENGTH(512))
      31                 :            : #define DIGEST_BYTE_LENGTH_AES_XCBC             (BYTE_LENGTH(96))
      32                 :            : #define DIGEST_BYTE_LENGTH_SNOW3G_UIA2          (BYTE_LENGTH(32))
      33                 :            : #define DIGEST_BYTE_LENGTH_KASUMI_F9            (BYTE_LENGTH(32))
      34                 :            : #define AES_XCBC_MAC_KEY_SZ                     (16)
      35                 :            : #define DIGEST_BYTE_LENGTH_AES_GCM              (BYTE_LENGTH(128))
      36                 :            : 
      37                 :            : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1               (12)
      38                 :            : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA224             (16)
      39                 :            : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA256             (16)
      40                 :            : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA384             (24)
      41                 :            : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA512             (32)
      42                 :            : 
      43                 :            : #define MAXIMUM_IV_LENGTH                               (16)
      44                 :            : #define AES_GCM_J0_LENGTH                               (16)
      45                 :            : 
      46                 :            : #define IV_OFFSET                       (sizeof(struct rte_crypto_op) + \
      47                 :            :                 sizeof(struct rte_crypto_sym_op) + DEFAULT_NUM_XFORMS * \
      48                 :            :                 sizeof(struct rte_crypto_sym_xform))
      49                 :            : 
      50                 :            : #define CRYPTODEV_NAME_NULL_PMD         crypto_null
      51                 :            : #define CRYPTODEV_NAME_AESNI_MB_PMD     crypto_aesni_mb
      52                 :            : #define CRYPTODEV_NAME_AESNI_GCM_PMD    crypto_aesni_gcm
      53                 :            : #define CRYPTODEV_NAME_OPENSSL_PMD      crypto_openssl
      54                 :            : #define CRYPTODEV_NAME_QAT_SYM_PMD      crypto_qat
      55                 :            : #define CRYPTODEV_NAME_QAT_ASYM_PMD     crypto_qat_asym
      56                 :            : #define CRYPTODEV_NAME_SNOW3G_PMD       crypto_snow3g
      57                 :            : #define CRYPTODEV_NAME_KASUMI_PMD       crypto_kasumi
      58                 :            : #define CRYPTODEV_NAME_ZUC_PMD          crypto_zuc
      59                 :            : #define CRYPTODEV_NAME_CHACHA20_POLY1305_PMD    crypto_chacha20_poly1305
      60                 :            : #define CRYPTODEV_NAME_ARMV8_PMD        crypto_armv8
      61                 :            : #define CRYPTODEV_NAME_DPAA_SEC_PMD     crypto_dpaa_sec
      62                 :            : #define CRYPTODEV_NAME_DPAA2_SEC_PMD    crypto_dpaa2_sec
      63                 :            : #define CRYPTODEV_NAME_SCHEDULER_PMD    crypto_scheduler
      64                 :            : #define CRYPTODEV_NAME_MVSAM_PMD                crypto_mvsam
      65                 :            : #define CRYPTODEV_NAME_CCP_PMD          crypto_ccp
      66                 :            : #define CRYPTODEV_NAME_VIRTIO_PMD       crypto_virtio
      67                 :            : #define CRYPTODEV_NAME_VIRTIO_USER_PMD  crypto_virtio_user
      68                 :            : #define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx
      69                 :            : #define CRYPTODEV_NAME_CAAM_JR_PMD      crypto_caam_jr
      70                 :            : #define CRYPTODEV_NAME_NITROX_PMD       crypto_nitrox_sym
      71                 :            : #define CRYPTODEV_NAME_BCMFS_PMD        crypto_bcmfs
      72                 :            : #define CRYPTODEV_NAME_CN9K_PMD         crypto_cn9k
      73                 :            : #define CRYPTODEV_NAME_CN10K_PMD        crypto_cn10k
      74                 :            : #define CRYPTODEV_NAME_MLX5_PMD         crypto_mlx5
      75                 :            : #define CRYPTODEV_NAME_UADK_PMD         crypto_uadk
      76                 :            : #define CRYPTODEV_NAME_ZSDA_SYM_PMD     crypto_zsda
      77                 :            : 
      78                 :            : 
      79                 :            : enum cryptodev_api_test_type {
      80                 :            :         CRYPTODEV_API_TEST = 0,
      81                 :            :         CRYPTODEV_RAW_API_TEST
      82                 :            : };
      83                 :            : 
      84                 :            : extern enum cryptodev_api_test_type global_api_test_type;
      85                 :            : 
      86                 :            : extern struct crypto_testsuite_params *p_testsuite_params;
      87                 :            : struct crypto_testsuite_params {
      88                 :            :         struct rte_mempool *mbuf_pool;
      89                 :            :         struct rte_mempool *large_mbuf_pool;
      90                 :            :         struct rte_mempool *op_mpool;
      91                 :            :         struct rte_mempool *session_mpool;
      92                 :            :         struct rte_cryptodev_config conf;
      93                 :            :         struct rte_cryptodev_qp_conf qp_conf;
      94                 :            : 
      95                 :            :         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
      96                 :            :         uint8_t valid_dev_count;
      97                 :            : };
      98                 :            : 
      99                 :            : /**
     100                 :            :  * Write (spread) data from buffer to mbuf data
     101                 :            :  *
     102                 :            :  * @param mbuf
     103                 :            :  *   Destination mbuf
     104                 :            :  * @param offset
     105                 :            :  *   Start offset in mbuf
     106                 :            :  * @param len
     107                 :            :  *   Number of bytes to copy
     108                 :            :  * @param buffer
     109                 :            :  *   Continuous source buffer
     110                 :            :  */
     111                 :            : static inline void
     112                 :        150 : pktmbuf_write(struct rte_mbuf *mbuf, int offset, int len, const uint8_t *buffer)
     113                 :            : {
     114                 :            :         int n = len;
     115                 :            :         int l;
     116                 :            :         struct rte_mbuf *m;
     117                 :            :         char *dst;
     118                 :            : 
     119   [ +  -  -  + ]:        150 :         for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
     120                 :          0 :                 offset -= m->data_len;
     121                 :            : 
     122                 :        150 :         l = m->data_len - offset;
     123                 :            : 
     124                 :            :         /* copy data from first segment */
     125                 :        150 :         dst = rte_pktmbuf_mtod_offset(m, char *, offset);
     126         [ +  + ]:        150 :         if (len <= l) {
     127         [ +  + ]:        132 :                 rte_memcpy(dst, buffer, len);
     128                 :        132 :                 return;
     129                 :            :         }
     130                 :            : 
     131         [ +  + ]:         18 :         rte_memcpy(dst, buffer, l);
     132                 :         18 :         buffer += l;
     133                 :         18 :         n -= l;
     134                 :            : 
     135         [ +  + ]:         93 :         for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
     136                 :         76 :                 dst = rte_pktmbuf_mtod(m, char *);
     137                 :         76 :                 l = m->data_len;
     138         [ +  + ]:         76 :                 if (n < l) {
     139         [ -  + ]:          1 :                         rte_memcpy(dst, buffer, n);
     140                 :          1 :                         return;
     141                 :            :                 }
     142         [ +  + ]:         75 :                 rte_memcpy(dst, buffer, l);
     143                 :         75 :                 buffer += l;
     144                 :         75 :                 n -= l;
     145                 :            :         }
     146                 :            : }
     147                 :            : 
     148                 :            : static inline uint8_t *
     149                 :        140 : pktmbuf_mtod_offset(struct rte_mbuf *mbuf, int offset)
     150                 :            : {
     151                 :            :         struct rte_mbuf *m;
     152                 :            : 
     153   [ +  -  +  + ]:        171 :         for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
     154                 :         31 :                 offset -= m->data_len;
     155                 :            : 
     156         [ -  + ]:        140 :         if (m == NULL) {
     157                 :            :                 printf("pktmbuf_mtod_offset: offset out of buffer\n");
     158                 :          0 :                 return NULL;
     159                 :            :         }
     160                 :        140 :         return rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
     161                 :            : }
     162                 :            : 
     163                 :            : static inline rte_iova_t
     164                 :         93 : pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset)
     165                 :            : {
     166                 :            :         struct rte_mbuf *m;
     167                 :            : 
     168   [ +  -  +  + ]:        115 :         for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
     169                 :         22 :                 offset -= m->data_len;
     170                 :            : 
     171         [ -  + ]:         93 :         if (m == NULL) {
     172                 :            :                 printf("pktmbuf_iova_offset: offset out of buffer\n");
     173                 :          0 :                 return 0;
     174                 :            :         }
     175                 :         93 :         return rte_pktmbuf_iova_offset(m, offset);
     176                 :            : }
     177                 :            : 
     178                 :            : static inline struct rte_mbuf *
     179                 :        150 : create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
     180                 :            :                 int nb_segs, uint8_t pattern)
     181                 :            : {
     182                 :            :         struct rte_mbuf *m = NULL, *mbuf = NULL;
     183                 :            :         int size, t_len, data_len = 0;
     184                 :            :         uint8_t *dst;
     185                 :            : 
     186         [ -  + ]:        150 :         if (nb_segs < 1) {
     187                 :            :                 printf("Number of segments must be 1 or more (is %d)\n",
     188                 :            :                                 nb_segs);
     189                 :          0 :                 return NULL;
     190                 :            :         }
     191                 :            : 
     192         [ +  - ]:        150 :         t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
     193                 :            :         size = pkt_len;
     194                 :            : 
     195                 :            :         /* Create chained mbuf_src and fill it generated data */
     196                 :            :         do {
     197                 :            : 
     198                 :        226 :                 m = rte_pktmbuf_alloc(mbuf_pool);
     199         [ -  + ]:        226 :                 if (m == NULL) {
     200                 :            :                         printf("Cannot create segment for source mbuf");
     201                 :          0 :                         goto fail;
     202                 :            :                 }
     203                 :            : 
     204         [ +  + ]:        226 :                 if (mbuf == NULL)
     205                 :            :                         mbuf = m;
     206                 :            : 
     207                 :            :                 /* Make sure if tailroom is zeroed */
     208                 :        226 :                 memset(m->buf_addr, pattern, m->buf_len);
     209                 :            : 
     210                 :        226 :                 data_len = size > t_len ? t_len : size;
     211                 :        226 :                 dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
     212         [ -  + ]:        226 :                 if (dst == NULL) {
     213                 :            :                         printf("Cannot append %d bytes to the mbuf\n",
     214                 :            :                                         data_len);
     215                 :          0 :                         goto fail;
     216                 :            :                 }
     217                 :            : 
     218         [ +  + ]:        226 :                 if (mbuf != m)
     219                 :            :                         rte_pktmbuf_chain(mbuf, m);
     220                 :            : 
     221                 :        226 :                 size -= data_len;
     222                 :            : 
     223         [ +  + ]:        226 :         } while (size > 0);
     224                 :            : 
     225                 :            :         return mbuf;
     226                 :            : 
     227                 :          0 : fail:
     228                 :          0 :         rte_pktmbuf_free(mbuf);
     229                 :          0 :         return NULL;
     230                 :            : }
     231                 :            : 
     232                 :            : static inline struct rte_mbuf *
     233                 :          0 : create_segmented_mbuf_multi_pool(struct rte_mempool *mbuf_pool_small,
     234                 :            :                 struct rte_mempool *mbuf_pool_large, int pkt_len, int nb_segs, uint8_t pattern)
     235                 :            : {
     236                 :            :         struct rte_mempool *mbuf_pool;
     237                 :            :         int max_seg_len, seg_len;
     238                 :            : 
     239         [ #  # ]:          0 :         if (nb_segs < 1) {
     240                 :            :                 printf("Number of segments must be 1 or more (is %d)\n", nb_segs);
     241                 :          0 :                 return NULL;
     242                 :            :         }
     243                 :            : 
     244         [ #  # ]:          0 :         if (pkt_len >= nb_segs)
     245                 :          0 :                 seg_len = pkt_len / nb_segs;
     246                 :            :         else
     247                 :            :                 seg_len = 1;
     248                 :            : 
     249                 :            :         /* Determine max segment length */
     250                 :          0 :         max_seg_len = seg_len + pkt_len % nb_segs;
     251                 :            : 
     252         [ #  # ]:          0 :         if (max_seg_len > LARGE_MBUF_DATAPAYLOAD_SIZE) {
     253                 :            :                 printf("Segment size %d is too big\n", max_seg_len);
     254                 :          0 :                 return NULL;
     255                 :            :         }
     256                 :            : 
     257         [ #  # ]:          0 :         if (max_seg_len > MBUF_DATAPAYLOAD_SIZE)
     258                 :            :                 mbuf_pool = mbuf_pool_large;
     259                 :            :         else
     260                 :            :                 mbuf_pool = mbuf_pool_small;
     261                 :            : 
     262         [ #  # ]:          0 :         if (mbuf_pool == NULL) {
     263                 :            :                 printf("Invalid mbuf pool\n");
     264                 :          0 :                 return NULL;
     265                 :            :         }
     266                 :            : 
     267                 :          0 :         return create_segmented_mbuf(mbuf_pool, pkt_len, nb_segs, pattern);
     268                 :            : }
     269                 :            : 
     270                 :            : int
     271                 :            : process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
     272                 :            :                 struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
     273                 :            :                 uint8_t len_in_bits, uint8_t cipher_iv_len);
     274                 :            : 
     275                 :            : int
     276                 :            : check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
     277                 :            :                 uint16_t num_ciphers);
     278                 :            : 
     279                 :            : int
     280                 :            : check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
     281                 :            :                 uint16_t num_auths);
     282                 :            : 
     283                 :            : int
     284                 :            : check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
     285                 :            :                 uint16_t num_aeads);
     286                 :            : 
     287                 :            : int
     288                 :            : ut_setup(void);
     289                 :            : 
     290                 :            : void
     291                 :            : ut_teardown(void);
     292                 :            : 
     293                 :            : #endif /* TEST_CRYPTODEV_H_ */

Generated by: LCOV version 1.14