LCOV - code coverage report
Current view: top level - app/test - test_ipsec.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 18 942 1.9 %
Date: 2026-07-01 18:02:41 Functions: 3 64 4.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 592 0.8 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "test.h"
       6                 :            : 
       7                 :            : #include <time.h>
       8                 :            : 
       9                 :            : #include <rte_common.h>
      10                 :            : #include <rte_hexdump.h>
      11                 :            : #include <rte_mbuf.h>
      12                 :            : #include <rte_malloc.h>
      13                 :            : #include <rte_cycles.h>
      14                 :            : #include <rte_bus_vdev.h>
      15                 :            : #include <rte_ip.h>
      16                 :            : #include <rte_crypto.h>
      17                 :            : #include <rte_cryptodev.h>
      18                 :            : #include <rte_lcore.h>
      19                 :            : 
      20                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      21                 :            : static int
      22                 :            : test_ipsec(void)
      23                 :            : {
      24                 :            :         printf("ipsec not supported on Windows, skipping test\n");
      25                 :            :         return TEST_SKIPPED;
      26                 :            : }
      27                 :            : 
      28                 :            : #else
      29                 :            : 
      30                 :            : #include <rte_ipsec.h>
      31                 :            : #include <rte_random.h>
      32                 :            : #include <rte_esp.h>
      33                 :            : #include <rte_security_driver.h>
      34                 :            : 
      35                 :            : #include "test_cryptodev.h"
      36                 :            : 
      37                 :            : #define VDEV_ARGS_SIZE  100
      38                 :            : #define MAX_NB_SESSIONS 200
      39                 :            : #define MAX_NB_SAS              2
      40                 :            : #define REPLAY_WIN_0    0
      41                 :            : #define REPLAY_WIN_32   32
      42                 :            : #define REPLAY_WIN_64   64
      43                 :            : #define REPLAY_WIN_128  128
      44                 :            : #define REPLAY_WIN_256  256
      45                 :            : #define DATA_64_BYTES   64
      46                 :            : #define DATA_80_BYTES   80
      47                 :            : #define DATA_100_BYTES  100
      48                 :            : #define ESN_ENABLED             1
      49                 :            : #define ESN_DISABLED    0
      50                 :            : #define INBOUND_SPI             7
      51                 :            : #define OUTBOUND_SPI    17
      52                 :            : #define BURST_SIZE              32
      53                 :            : #define REORDER_PKTS    1
      54                 :            : #define DEQUEUE_COUNT   1000
      55                 :            : #define SQN_START               255
      56                 :            : 
      57                 :            : struct user_params {
      58                 :            :         enum rte_crypto_sym_xform_type auth;
      59                 :            :         enum rte_crypto_sym_xform_type cipher;
      60                 :            :         enum rte_crypto_sym_xform_type aead;
      61                 :            : 
      62                 :            :         char auth_algo[128];
      63                 :            :         char cipher_algo[128];
      64                 :            :         char aead_algo[128];
      65                 :            : };
      66                 :            : 
      67                 :            : struct ipsec_testsuite_params {
      68                 :            :         struct rte_mempool *mbuf_pool;
      69                 :            :         struct rte_mempool *cop_mpool;
      70                 :            :         struct rte_cryptodev_config conf;
      71                 :            :         struct rte_cryptodev_qp_conf qp_conf;
      72                 :            : 
      73                 :            :         uint8_t valid_dev;
      74                 :            :         uint8_t valid_dev_found;
      75                 :            : };
      76                 :            : 
      77                 :            : struct ipsec_unitest_params {
      78                 :            :         struct rte_crypto_sym_xform cipher_xform;
      79                 :            :         struct rte_crypto_sym_xform auth_xform;
      80                 :            :         struct rte_crypto_sym_xform aead_xform;
      81                 :            :         struct rte_crypto_sym_xform *crypto_xforms;
      82                 :            : 
      83                 :            :         struct rte_security_ipsec_xform ipsec_xform;
      84                 :            : 
      85                 :            :         struct rte_ipsec_state ipsec_state;
      86                 :            :         struct rte_ipsec_sa_prm sa_prm;
      87                 :            :         struct rte_ipsec_session ss[MAX_NB_SAS];
      88                 :            : 
      89                 :            :         struct rte_crypto_op *cop[BURST_SIZE];
      90                 :            : 
      91                 :            :         struct rte_mbuf *obuf[BURST_SIZE], *ibuf[BURST_SIZE],
      92                 :            :                 *testbuf[BURST_SIZE];
      93                 :            : 
      94                 :            :         uint16_t pkt_index;
      95                 :            :         bool is_stateless;
      96                 :            : };
      97                 :            : 
      98                 :            : struct ipsec_test_cfg {
      99                 :            :         uint32_t replay_win_sz;
     100                 :            :         uint32_t esn;
     101                 :            :         uint64_t flags;
     102                 :            :         size_t pkt_sz;
     103                 :            :         uint16_t num_pkts;
     104                 :            :         uint32_t reorder_pkts;
     105                 :            : };
     106                 :            : 
     107                 :            : static const struct ipsec_test_cfg test_cfg[] = {
     108                 :            :         {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, 1, 0},
     109                 :            :         {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, BURST_SIZE, 0},
     110                 :            :         {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_80_BYTES, BURST_SIZE,
     111                 :            :                 REORDER_PKTS},
     112                 :            :         {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, 1, 0},
     113                 :            :         {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, BURST_SIZE,
     114                 :            :                 REORDER_PKTS},
     115                 :            :         {REPLAY_WIN_64, ESN_ENABLED, 0, DATA_64_BYTES, 1, 0},
     116                 :            :         {REPLAY_WIN_128, ESN_ENABLED, RTE_IPSEC_SAFLAG_SQN_ATOM,
     117                 :            :                 DATA_80_BYTES, 1, 0},
     118                 :            :         {REPLAY_WIN_256, ESN_DISABLED, 0, DATA_100_BYTES, 1, 0},
     119                 :            : };
     120                 :            : 
     121                 :            : static const int num_cfg = RTE_DIM(test_cfg);
     122                 :            : static struct ipsec_testsuite_params testsuite_params = { NULL };
     123                 :            : static struct ipsec_unitest_params unittest_params;
     124                 :            : static struct user_params uparams;
     125                 :            : 
     126                 :            : struct supported_cipher_algo {
     127                 :            :         const char *keyword;
     128                 :            :         enum rte_crypto_cipher_algorithm algo;
     129                 :            :         uint16_t iv_len;
     130                 :            :         uint16_t block_size;
     131                 :            :         uint16_t key_len;
     132                 :            : };
     133                 :            : 
     134                 :            : struct supported_auth_algo {
     135                 :            :         const char *keyword;
     136                 :            :         enum rte_crypto_auth_algorithm algo;
     137                 :            :         uint16_t digest_len;
     138                 :            :         uint16_t key_len;
     139                 :            :         uint8_t key_not_req;
     140                 :            : };
     141                 :            : 
     142                 :            : const struct supported_cipher_algo cipher_algos[] = {
     143                 :            :         {
     144                 :            :                 .keyword = "null",
     145                 :            :                 .algo = RTE_CRYPTO_CIPHER_NULL,
     146                 :            :                 .iv_len = 0,
     147                 :            :                 .block_size = 4,
     148                 :            :                 .key_len = 0
     149                 :            :         },
     150                 :            : };
     151                 :            : 
     152                 :            : const struct supported_auth_algo auth_algos[] = {
     153                 :            :         {
     154                 :            :                 .keyword = "null",
     155                 :            :                 .algo = RTE_CRYPTO_AUTH_NULL,
     156                 :            :                 .digest_len = 0,
     157                 :            :                 .key_len = 0,
     158                 :            :                 .key_not_req = 1
     159                 :            :         },
     160                 :            : };
     161                 :            : 
     162                 :            : static int
     163                 :          0 : dummy_sec_create(void *device, struct rte_security_session_conf *conf,
     164                 :            :         struct rte_security_session *sess)
     165                 :            : {
     166                 :            :         RTE_SET_USED(device);
     167                 :            :         RTE_SET_USED(conf);
     168                 :            :         RTE_SET_USED(sess);
     169                 :            : 
     170                 :          0 :         return 0;
     171                 :            : }
     172                 :            : 
     173                 :            : static int
     174                 :          0 : dummy_sec_destroy(void *device, struct rte_security_session *sess)
     175                 :            : {
     176                 :            :         RTE_SET_USED(device);
     177                 :            :         RTE_SET_USED(sess);
     178                 :          0 :         return 0;
     179                 :            : }
     180                 :            : 
     181                 :            : static const struct rte_security_ops dummy_sec_ops = {
     182                 :            :         .session_create = dummy_sec_create,
     183                 :            :         .session_destroy = dummy_sec_destroy,
     184                 :            : };
     185                 :            : 
     186                 :            : static struct rte_security_ctx dummy_sec_ctx = {
     187                 :            :         .ops = &dummy_sec_ops,
     188                 :            : };
     189                 :            : 
     190                 :            : static const struct supported_cipher_algo *
     191                 :            : find_match_cipher_algo(const char *cipher_keyword)
     192                 :            : {
     193                 :            :         size_t i;
     194                 :            : 
     195                 :            :         for (i = 0; i < RTE_DIM(cipher_algos); i++) {
     196                 :            :                 const struct supported_cipher_algo *algo =
     197                 :            :                         &cipher_algos[i];
     198                 :            : 
     199   [ -  -  -  + ]:          1 :                 if (strcmp(cipher_keyword, algo->keyword) == 0)
     200                 :            :                         return algo;
     201                 :            :         }
     202                 :            : 
     203                 :            :         return NULL;
     204                 :            : }
     205                 :            : 
     206                 :            : static const struct supported_auth_algo *
     207                 :            : find_match_auth_algo(const char *auth_keyword)
     208                 :            : {
     209                 :            :         size_t i;
     210                 :            : 
     211                 :            :         for (i = 0; i < RTE_DIM(auth_algos); i++) {
     212                 :            :                 const struct supported_auth_algo *algo =
     213                 :            :                         &auth_algos[i];
     214                 :            : 
     215   [ -  -  -  + ]:          1 :                 if (strcmp(auth_keyword, algo->keyword) == 0)
     216                 :            :                         return algo;
     217                 :            :         }
     218                 :            : 
     219                 :            :         return NULL;
     220                 :            : }
     221                 :            : 
     222                 :            : static void
     223                 :            : fill_crypto_xform(struct ipsec_unitest_params *ut_params,
     224                 :            :         const struct supported_auth_algo *auth_algo,
     225                 :            :         const struct supported_cipher_algo *cipher_algo)
     226                 :            : {
     227                 :          1 :         ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
     228                 :          1 :         ut_params->cipher_xform.cipher.algo = cipher_algo->algo;
     229                 :          1 :         ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
     230                 :          1 :         ut_params->auth_xform.auth.algo = auth_algo->algo;
     231                 :            : 
     232         [ #  # ]:          0 :         if (ut_params->ipsec_xform.direction ==
     233                 :            :                         RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
     234                 :          0 :                 ut_params->cipher_xform.cipher.op =
     235                 :            :                         RTE_CRYPTO_CIPHER_OP_DECRYPT;
     236                 :          0 :                 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
     237                 :          0 :                 ut_params->cipher_xform.next = NULL;
     238                 :          0 :                 ut_params->auth_xform.next = &ut_params->cipher_xform;
     239                 :          0 :                 ut_params->crypto_xforms = &ut_params->auth_xform;
     240                 :            :         } else {
     241                 :          0 :                 ut_params->cipher_xform.cipher.op =
     242                 :            :                         RTE_CRYPTO_CIPHER_OP_ENCRYPT;
     243                 :          1 :                 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
     244                 :          0 :                 ut_params->auth_xform.next = NULL;
     245                 :          1 :                 ut_params->cipher_xform.next = &ut_params->auth_xform;
     246                 :          0 :                 ut_params->crypto_xforms = &ut_params->cipher_xform;
     247                 :            :         }
     248                 :            : }
     249                 :            : 
     250                 :            : static int
     251                 :          0 : check_cryptodev_capability(const struct ipsec_unitest_params *ut,
     252                 :            :                 uint8_t dev_id)
     253                 :            : {
     254                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
     255                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
     256                 :            :         int rc = -1;
     257                 :            : 
     258                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
     259                 :          0 :         cap_idx.algo.auth = ut->auth_xform.auth.algo;
     260                 :          0 :         cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
     261                 :            : 
     262         [ #  # ]:          0 :         if (cap != NULL) {
     263                 :          0 :                 rc = rte_cryptodev_sym_capability_check_auth(cap,
     264                 :          0 :                                 ut->auth_xform.auth.key.length,
     265                 :          0 :                                 ut->auth_xform.auth.digest_length, 0);
     266         [ #  # ]:          0 :                 if (rc == 0) {
     267                 :          0 :                         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
     268                 :          0 :                         cap_idx.algo.cipher = ut->cipher_xform.cipher.algo;
     269                 :          0 :                         cap = rte_cryptodev_sym_capability_get(
     270                 :            :                                         dev_id, &cap_idx);
     271         [ #  # ]:          0 :                         if (cap != NULL)
     272                 :          0 :                                 rc = rte_cryptodev_sym_capability_check_cipher(
     273                 :            :                                         cap,
     274                 :          0 :                                         ut->cipher_xform.cipher.key.length,
     275                 :          0 :                                         ut->cipher_xform.cipher.iv.length);
     276                 :            :                 }
     277                 :            :         }
     278                 :            : 
     279                 :          0 :         return rc;
     280                 :            : }
     281                 :            : 
     282                 :            : static int
     283         [ -  + ]:          1 : testsuite_setup(void)
     284                 :            : {
     285                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     286                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     287                 :            :         const struct supported_auth_algo *auth_algo;
     288                 :            :         const struct supported_cipher_algo *cipher_algo;
     289                 :            :         struct rte_cryptodev_info info;
     290                 :            :         uint32_t i, nb_devs, dev_id;
     291                 :            :         size_t sess_sz;
     292                 :            :         int rc;
     293                 :            : 
     294                 :            :         memset(ts_params, 0, sizeof(*ts_params));
     295                 :            :         memset(ut_params, 0, sizeof(*ut_params));
     296                 :            :         memset(&uparams, 0, sizeof(struct user_params));
     297                 :            : 
     298                 :          1 :         uparams.auth = RTE_CRYPTO_SYM_XFORM_AUTH;
     299         [ -  + ]:          1 :         uparams.cipher = RTE_CRYPTO_SYM_XFORM_CIPHER;
     300                 :            :         uparams.aead = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
     301                 :            :         strcpy(uparams.auth_algo, "null");
     302                 :            :         strcpy(uparams.cipher_algo, "null");
     303                 :            : 
     304                 :            :         auth_algo = find_match_auth_algo(uparams.auth_algo);
     305                 :            :         cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
     306                 :            :         fill_crypto_xform(ut_params, auth_algo, cipher_algo);
     307                 :            : 
     308                 :          1 :         nb_devs = rte_cryptodev_count();
     309         [ +  - ]:          1 :         if (nb_devs < 1) {
     310                 :          1 :                 RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
     311                 :          1 :                 return TEST_SKIPPED;
     312                 :            :         }
     313                 :            : 
     314                 :            :         /* Find first valid crypto device */
     315         [ #  # ]:          0 :         for (i = 0; i < nb_devs; i++) {
     316                 :          0 :                 rc = check_cryptodev_capability(ut_params, i);
     317         [ #  # ]:          0 :                 if (rc == 0) {
     318                 :          0 :                         ts_params->valid_dev = i;
     319                 :          0 :                         ts_params->valid_dev_found = 1;
     320                 :          0 :                         break;
     321                 :            :                 }
     322                 :            :         }
     323                 :            : 
     324         [ #  # ]:          0 :         if (ts_params->valid_dev_found == 0) {
     325                 :          0 :                 RTE_LOG(WARNING, USER1, "No compatible crypto device found.\n");
     326                 :          0 :                 return TEST_SKIPPED;
     327                 :            :         }
     328                 :            : 
     329                 :          0 :         ts_params->mbuf_pool = rte_pktmbuf_pool_create(
     330                 :            :                         "CRYPTO_MBUFPOOL",
     331                 :            :                         NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
     332                 :          0 :                         rte_socket_id());
     333         [ #  # ]:          0 :         if (ts_params->mbuf_pool == NULL) {
     334                 :          0 :                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
     335                 :          0 :                 return TEST_FAILED;
     336                 :            :         }
     337                 :            : 
     338                 :          0 :         ts_params->cop_mpool = rte_crypto_op_pool_create(
     339                 :            :                         "MBUF_CRYPTO_SYM_OP_POOL",
     340                 :            :                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     341                 :            :                         NUM_MBUFS, MBUF_CACHE_SIZE,
     342                 :            :                         DEFAULT_NUM_XFORMS *
     343                 :            :                         sizeof(struct rte_crypto_sym_xform) +
     344                 :            :                         MAXIMUM_IV_LENGTH,
     345                 :          0 :                         rte_socket_id());
     346         [ #  # ]:          0 :         if (ts_params->cop_mpool == NULL) {
     347                 :          0 :                 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
     348                 :          0 :                 return TEST_FAILED;
     349                 :            :         }
     350                 :            : 
     351                 :            :         /* Set up all the qps on the first of the valid devices found */
     352                 :          0 :         dev_id = ts_params->valid_dev;
     353                 :            : 
     354                 :          0 :         rte_cryptodev_info_get(dev_id, &info);
     355                 :            : 
     356                 :          0 :         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
     357                 :          0 :         ts_params->conf.socket_id = SOCKET_ID_ANY;
     358                 :          0 :         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO;
     359                 :            : 
     360                 :          0 :         sess_sz = rte_cryptodev_sym_get_private_session_size(dev_id);
     361                 :            :         sess_sz = RTE_MAX(sess_sz, sizeof(struct rte_security_session));
     362                 :            : 
     363                 :            :         /*
     364                 :            :          * Create mempools for sessions
     365                 :            :          */
     366         [ #  # ]:          0 :         if (info.sym.max_nb_sessions != 0 &&
     367                 :            :                         info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
     368                 :          0 :                 RTE_LOG(ERR, USER1, "Device does not support "
     369                 :            :                                 "at least %u sessions\n",
     370                 :            :                                 MAX_NB_SESSIONS);
     371                 :          0 :                 return TEST_FAILED;
     372                 :            :         }
     373                 :            : 
     374                 :          0 :         ts_params->qp_conf.mp_session =
     375                 :          0 :                 rte_cryptodev_sym_session_pool_create("test_sess_mp",
     376                 :            :                         MAX_NB_SESSIONS, sess_sz, 0, 0, SOCKET_ID_ANY);
     377                 :            : 
     378         [ #  # ]:          0 :         TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session,
     379                 :            :                         "session mempool allocation failed");
     380                 :            : 
     381         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
     382                 :            :                         &ts_params->conf),
     383                 :            :                         "Failed to configure cryptodev %u with %u qps",
     384                 :            :                         dev_id, ts_params->conf.nb_queue_pairs);
     385                 :            : 
     386                 :          0 :         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
     387                 :            : 
     388         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
     389                 :            :                 dev_id, 0, &ts_params->qp_conf,
     390                 :            :                 rte_cryptodev_socket_id(dev_id)),
     391                 :            :                 "Failed to setup queue pair %u on cryptodev %u",
     392                 :            :                 0, dev_id);
     393                 :            : 
     394                 :            :         return TEST_SUCCESS;
     395                 :            : }
     396                 :            : 
     397                 :            : static void
     398                 :          0 : testsuite_teardown(void)
     399                 :            : {
     400                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     401                 :            : 
     402         [ #  # ]:          0 :         if (ts_params->mbuf_pool != NULL) {
     403                 :          0 :                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
     404                 :            :                 rte_mempool_avail_count(ts_params->mbuf_pool));
     405                 :          0 :                 rte_mempool_free(ts_params->mbuf_pool);
     406                 :          0 :                 ts_params->mbuf_pool = NULL;
     407                 :            :         }
     408                 :            : 
     409         [ #  # ]:          0 :         if (ts_params->cop_mpool != NULL) {
     410                 :          0 :                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
     411                 :            :                 rte_mempool_avail_count(ts_params->cop_mpool));
     412                 :          0 :                 rte_mempool_free(ts_params->cop_mpool);
     413                 :          0 :                 ts_params->cop_mpool = NULL;
     414                 :            :         }
     415                 :            : 
     416                 :            :         /* Free session mempools */
     417         [ #  # ]:          0 :         if (ts_params->qp_conf.mp_session != NULL) {
     418                 :          0 :                 rte_mempool_free(ts_params->qp_conf.mp_session);
     419                 :          0 :                 ts_params->qp_conf.mp_session = NULL;
     420                 :            :         }
     421                 :          0 : }
     422                 :            : 
     423                 :            : static int
     424                 :          0 : ut_setup_ipsec(void)
     425                 :            : {
     426                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     427                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     428                 :            : 
     429                 :            :         /* Clear unit test parameters before running test */
     430                 :            :         memset(ut_params, 0, sizeof(*ut_params));
     431                 :            : 
     432                 :            :         /* Reconfigure device to default parameters */
     433                 :          0 :         ts_params->conf.socket_id = SOCKET_ID_ANY;
     434                 :            : 
     435                 :            :         /* Start the device */
     436         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_dev),
     437                 :            :                         "Failed to start cryptodev %u",
     438                 :            :                         ts_params->valid_dev);
     439                 :            : 
     440                 :            :         return TEST_SUCCESS;
     441                 :            : }
     442                 :            : 
     443                 :            : static void
     444                 :          0 : ut_teardown_ipsec(void)
     445                 :            : {
     446                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     447                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     448                 :            :         int i;
     449                 :            : 
     450         [ #  # ]:          0 :         for (i = 0; i < BURST_SIZE; i++) {
     451                 :            :                 /* free crypto operation structure */
     452         [ #  # ]:          0 :                 if (ut_params->cop[i]) {
     453                 :          0 :                         rte_crypto_op_free(ut_params->cop[i]);
     454                 :          0 :                         ut_params->cop[i] = NULL;
     455                 :            :                 }
     456                 :            : 
     457                 :            :                 /*
     458                 :            :                  * free mbuf - both obuf and ibuf are usually the same,
     459                 :            :                  * so check if they point at the same address is necessary,
     460                 :            :                  * to avoid freeing the mbuf twice.
     461                 :            :                  */
     462         [ #  # ]:          0 :                 if (ut_params->obuf[i]) {
     463                 :          0 :                         rte_pktmbuf_free(ut_params->obuf[i]);
     464         [ #  # ]:          0 :                         if (ut_params->ibuf[i] == ut_params->obuf[i])
     465                 :          0 :                                 ut_params->ibuf[i] = NULL;
     466                 :          0 :                         ut_params->obuf[i] = NULL;
     467                 :            :                 }
     468         [ #  # ]:          0 :                 if (ut_params->ibuf[i]) {
     469                 :          0 :                         rte_pktmbuf_free(ut_params->ibuf[i]);
     470                 :          0 :                         ut_params->ibuf[i] = NULL;
     471                 :            :                 }
     472                 :            : 
     473         [ #  # ]:          0 :                 if (ut_params->testbuf[i]) {
     474                 :          0 :                         rte_pktmbuf_free(ut_params->testbuf[i]);
     475                 :          0 :                         ut_params->testbuf[i] = NULL;
     476                 :            :                 }
     477                 :            :         }
     478                 :            : 
     479         [ #  # ]:          0 :         if (ts_params->mbuf_pool != NULL)
     480                 :          0 :                 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
     481                 :            :                         rte_mempool_avail_count(ts_params->mbuf_pool));
     482                 :            : 
     483                 :            :         /* Stop the device */
     484                 :          0 :         rte_cryptodev_stop(ts_params->valid_dev);
     485                 :          0 : }
     486                 :            : 
     487                 :            : #define IPSEC_MAX_PAD_SIZE      UINT8_MAX
     488                 :            : 
     489                 :            : static const uint8_t esp_pad_bytes[IPSEC_MAX_PAD_SIZE] = {
     490                 :            :         1, 2, 3, 4, 5, 6, 7, 8,
     491                 :            :         9, 10, 11, 12, 13, 14, 15, 16,
     492                 :            :         17, 18, 19, 20, 21, 22, 23, 24,
     493                 :            :         25, 26, 27, 28, 29, 30, 31, 32,
     494                 :            :         33, 34, 35, 36, 37, 38, 39, 40,
     495                 :            :         41, 42, 43, 44, 45, 46, 47, 48,
     496                 :            :         49, 50, 51, 52, 53, 54, 55, 56,
     497                 :            :         57, 58, 59, 60, 61, 62, 63, 64,
     498                 :            :         65, 66, 67, 68, 69, 70, 71, 72,
     499                 :            :         73, 74, 75, 76, 77, 78, 79, 80,
     500                 :            :         81, 82, 83, 84, 85, 86, 87, 88,
     501                 :            :         89, 90, 91, 92, 93, 94, 95, 96,
     502                 :            :         97, 98, 99, 100, 101, 102, 103, 104,
     503                 :            :         105, 106, 107, 108, 109, 110, 111, 112,
     504                 :            :         113, 114, 115, 116, 117, 118, 119, 120,
     505                 :            :         121, 122, 123, 124, 125, 126, 127, 128,
     506                 :            :         129, 130, 131, 132, 133, 134, 135, 136,
     507                 :            :         137, 138, 139, 140, 141, 142, 143, 144,
     508                 :            :         145, 146, 147, 148, 149, 150, 151, 152,
     509                 :            :         153, 154, 155, 156, 157, 158, 159, 160,
     510                 :            :         161, 162, 163, 164, 165, 166, 167, 168,
     511                 :            :         169, 170, 171, 172, 173, 174, 175, 176,
     512                 :            :         177, 178, 179, 180, 181, 182, 183, 184,
     513                 :            :         185, 186, 187, 188, 189, 190, 191, 192,
     514                 :            :         193, 194, 195, 196, 197, 198, 199, 200,
     515                 :            :         201, 202, 203, 204, 205, 206, 207, 208,
     516                 :            :         209, 210, 211, 212, 213, 214, 215, 216,
     517                 :            :         217, 218, 219, 220, 221, 222, 223, 224,
     518                 :            :         225, 226, 227, 228, 229, 230, 231, 232,
     519                 :            :         233, 234, 235, 236, 237, 238, 239, 240,
     520                 :            :         241, 242, 243, 244, 245, 246, 247, 248,
     521                 :            :         249, 250, 251, 252, 253, 254, 255,
     522                 :            : };
     523                 :            : 
     524                 :            : /* ***** data for tests ***** */
     525                 :            : 
     526                 :            : const char null_plain_data[] =
     527                 :            :         "Network Security People Have A Strange Sense Of Humor unlike Other "
     528                 :            :         "People who have a normal sense of humour";
     529                 :            : 
     530                 :            : const char null_encrypted_data[] =
     531                 :            :         "Network Security People Have A Strange Sense Of Humor unlike Other "
     532                 :            :         "People who have a normal sense of humour";
     533                 :            : 
     534                 :            : struct rte_ipv4_hdr ipv4_outer  = {
     535                 :            :         .version_ihl = IPVERSION << 4 |
     536                 :            :                 sizeof(ipv4_outer) / RTE_IPV4_IHL_MULTIPLIER,
     537                 :            :         .time_to_live = IPDEFTTL,
     538                 :            :         .next_proto_id = IPPROTO_ESP,
     539                 :            :         .src_addr = RTE_IPV4(192, 168, 1, 100),
     540                 :            :         .dst_addr = RTE_IPV4(192, 168, 2, 100),
     541                 :            : };
     542                 :            : 
     543                 :            : static struct rte_mbuf *
     544                 :          0 : setup_test_string(struct rte_mempool *mpool, const char *string,
     545                 :            :         size_t string_len, size_t len, uint8_t blocksize)
     546                 :            : {
     547                 :          0 :         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
     548         [ #  # ]:          0 :         size_t t_len = len - (blocksize ? (len % blocksize) : 0);
     549                 :            : 
     550         [ #  # ]:          0 :         RTE_VERIFY(len <= string_len);
     551                 :            : 
     552         [ #  # ]:          0 :         if (m) {
     553                 :          0 :                 memset(m->buf_addr, 0, m->buf_len);
     554                 :          0 :                 char *dst = rte_pktmbuf_append(m, t_len);
     555                 :            : 
     556         [ #  # ]:          0 :                 if (!dst) {
     557                 :          0 :                         rte_pktmbuf_free(m);
     558                 :          0 :                         return NULL;
     559                 :            :                 }
     560         [ #  # ]:          0 :                 if (string != NULL)
     561                 :            :                         memcpy(dst, string, t_len);
     562                 :            :                 else
     563                 :            :                         memset(dst, 0, t_len);
     564                 :            :         }
     565                 :            : 
     566                 :            :         return m;
     567                 :            : }
     568                 :            : 
     569                 :            : static struct rte_mbuf *
     570                 :          0 : setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,
     571                 :            :         size_t len, uint32_t spi, uint32_t seq)
     572                 :            : {
     573                 :          0 :         struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
     574                 :            :         uint32_t hdrlen = sizeof(struct rte_ipv4_hdr) +
     575                 :            :                 sizeof(struct rte_esp_hdr);
     576                 :            :         uint32_t taillen = sizeof(struct rte_esp_tail);
     577                 :          0 :         uint32_t t_len = len + hdrlen + taillen;
     578                 :            :         uint32_t padlen;
     579                 :            : 
     580                 :          0 :         struct rte_esp_hdr esph  = {
     581         [ #  # ]:          0 :                 .spi = rte_cpu_to_be_32(spi),
     582         [ #  # ]:          0 :                 .seq = rte_cpu_to_be_32(seq)
     583                 :            :         };
     584                 :            : 
     585                 :          0 :         padlen = RTE_ALIGN(t_len, 4) - t_len;
     586                 :            :         t_len += padlen;
     587                 :            : 
     588                 :          0 :         struct rte_esp_tail espt = {
     589                 :            :                 .pad_len = padlen,
     590                 :            :                 .next_proto = IPPROTO_IPIP,
     591                 :            :         };
     592                 :            : 
     593         [ #  # ]:          0 :         if (m == NULL)
     594                 :            :                 return NULL;
     595                 :            : 
     596                 :          0 :         memset(m->buf_addr, 0, m->buf_len);
     597                 :            :         char *dst = rte_pktmbuf_append(m, t_len);
     598                 :            : 
     599         [ #  # ]:          0 :         if (!dst) {
     600                 :          0 :                 rte_pktmbuf_free(m);
     601                 :          0 :                 return NULL;
     602                 :            :         }
     603                 :            :         /* copy outer IP and ESP header */
     604         [ #  # ]:          0 :         ipv4_outer.total_length = rte_cpu_to_be_16(t_len);
     605   [ #  #  #  # ]:          0 :         ipv4_outer.packet_id = rte_cpu_to_be_16(seq);
     606                 :            :         memcpy(dst, &ipv4_outer, sizeof(ipv4_outer));
     607                 :          0 :         dst += sizeof(ipv4_outer);
     608                 :          0 :         m->l3_len = sizeof(ipv4_outer);
     609                 :            :         memcpy(dst, &esph, sizeof(esph));
     610                 :          0 :         dst += sizeof(esph);
     611                 :            : 
     612         [ #  # ]:          0 :         if (string != NULL) {
     613                 :            :                 /* copy payload */
     614                 :            :                 memcpy(dst, string, len);
     615                 :          0 :                 dst += len;
     616                 :            :                 /* copy pad bytes */
     617                 :          0 :                 memcpy(dst, esp_pad_bytes, RTE_MIN(padlen,
     618                 :            :                         sizeof(esp_pad_bytes)));
     619                 :          0 :                 dst += padlen;
     620                 :            :                 /* copy ESP tail header */
     621                 :            :                 memcpy(dst, &espt, sizeof(espt));
     622                 :            :         } else
     623                 :          0 :                 memset(dst, 0, t_len);
     624                 :            : 
     625                 :            :         return m;
     626                 :            : }
     627                 :            : 
     628                 :            : static int
     629                 :            : create_dummy_sec_session(struct ipsec_unitest_params *ut,
     630                 :            :         struct rte_cryptodev_qp_conf *qp, uint32_t j)
     631                 :            : {
     632                 :            :         static struct rte_security_session_conf conf;
     633                 :            : 
     634                 :          0 :         ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx,
     635                 :            :                                         &conf, qp->mp_session);
     636                 :            : 
     637         [ #  # ]:          0 :         if (ut->ss[j].security.ses == NULL)
     638                 :            :                 return -ENOMEM;
     639                 :            : 
     640                 :          0 :         ut->ss[j].security.ctx = &dummy_sec_ctx;
     641                 :          0 :         ut->ss[j].security.ol_flags = 0;
     642                 :          0 :         return 0;
     643                 :            : }
     644                 :            : 
     645                 :            : static int
     646                 :            : create_crypto_session(struct ipsec_unitest_params *ut,
     647                 :            :         struct rte_cryptodev_qp_conf *qp, uint8_t dev_id, uint32_t j)
     648                 :            : {
     649                 :            :         void *s;
     650                 :            : 
     651                 :          0 :         s = rte_cryptodev_sym_session_create(dev_id, ut->crypto_xforms,
     652                 :            :                         qp->mp_session);
     653         [ #  # ]:          0 :         if (s == NULL)
     654                 :            :                 return -ENOMEM;
     655                 :            : 
     656                 :          0 :         ut->ss[j].crypto.ses = s;
     657                 :          0 :         return 0;
     658                 :            : }
     659                 :            : 
     660                 :            : static int
     661                 :          0 : create_session(struct ipsec_unitest_params *ut,
     662                 :            :         struct rte_cryptodev_qp_conf *qp, uint8_t crypto_dev, uint32_t j)
     663                 :            : {
     664         [ #  # ]:          0 :         if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
     665                 :          0 :                 return create_crypto_session(ut, qp, crypto_dev, j);
     666                 :            :         else
     667                 :          0 :                 return create_dummy_sec_session(ut, qp, j);
     668                 :            : }
     669                 :            : 
     670                 :            : static int
     671                 :          0 : fill_ipsec_param(uint32_t replay_win_sz, uint64_t flags)
     672                 :            : {
     673                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     674                 :            :         struct rte_ipsec_sa_prm *prm = &ut_params->sa_prm;
     675                 :            :         const struct supported_auth_algo *auth_algo;
     676                 :            :         const struct supported_cipher_algo *cipher_algo;
     677                 :            : 
     678                 :            :         memset(prm, 0, sizeof(*prm));
     679                 :            : 
     680                 :          0 :         prm->userdata = 1;
     681                 :          0 :         prm->flags = flags;
     682                 :            : 
     683                 :            :         /* setup ipsec xform */
     684                 :          0 :         prm->ipsec_xform = ut_params->ipsec_xform;
     685                 :          0 :         prm->ipsec_xform.salt = (uint32_t)rte_rand();
     686                 :          0 :         prm->ipsec_xform.replay_win_sz = replay_win_sz;
     687                 :            : 
     688                 :            :         /* setup tunnel related fields */
     689                 :          0 :         prm->tun.hdr_len = sizeof(ipv4_outer);
     690                 :          0 :         prm->tun.next_proto = IPPROTO_IPIP;
     691                 :          0 :         prm->tun.hdr = &ipv4_outer;
     692                 :            : 
     693                 :            :         /* setup crypto section */
     694         [ #  # ]:          0 :         if (uparams.aead != 0) {
     695                 :            :                 /* TODO: will need to fill out with other test cases */
     696                 :            :         } else {
     697   [ #  #  #  # ]:          0 :                 if (uparams.auth == 0 && uparams.cipher == 0)
     698                 :            :                         return TEST_FAILED;
     699                 :            : 
     700                 :            :                 auth_algo = find_match_auth_algo(uparams.auth_algo);
     701                 :            :                 cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
     702                 :            : 
     703                 :            :                 fill_crypto_xform(ut_params, auth_algo, cipher_algo);
     704                 :            :         }
     705                 :            : 
     706                 :          0 :         prm->crypto_xform = ut_params->crypto_xforms;
     707                 :          0 :         return TEST_SUCCESS;
     708                 :            : }
     709                 :            : 
     710                 :            : static int
     711                 :          0 : create_sa(enum rte_security_session_action_type action_type,
     712                 :            :                 uint32_t replay_win_sz, uint64_t flags, uint32_t j)
     713                 :            : {
     714                 :            :         struct ipsec_testsuite_params *ts = &testsuite_params;
     715                 :            :         struct ipsec_unitest_params *ut = &unittest_params;
     716                 :            :         size_t sz;
     717                 :            :         int rc;
     718                 :            : 
     719                 :          0 :         memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
     720                 :            : 
     721                 :          0 :         rc = fill_ipsec_param(replay_win_sz, flags);
     722         [ #  # ]:          0 :         if (rc != 0)
     723                 :            :                 return TEST_FAILED;
     724                 :            : 
     725                 :            :         /* create rte_ipsec_sa*/
     726                 :          0 :         sz = rte_ipsec_sa_size(&ut->sa_prm);
     727         [ #  # ]:          0 :         TEST_ASSERT(sz > 0, "rte_ipsec_sa_size() failed\n");
     728                 :            : 
     729                 :          0 :         ut->ss[j].sa = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
     730         [ #  # ]:          0 :         TEST_ASSERT_NOT_NULL(ut->ss[j].sa,
     731                 :            :                 "failed to allocate memory for rte_ipsec_sa\n");
     732                 :            : 
     733                 :          0 :         ut->ss[j].type = action_type;
     734                 :          0 :         rc = create_session(ut, &ts->qp_conf, ts->valid_dev, j);
     735         [ #  # ]:          0 :         if (rc != 0)
     736                 :            :                 return rc;
     737                 :            : 
     738                 :          0 :         rc = rte_ipsec_sa_init(ut->ss[j].sa, &ut->sa_prm, sz);
     739   [ #  #  #  # ]:          0 :         rc = (rc > 0 && (uint32_t)rc <= sz) ? 0 : -EINVAL;
     740                 :            :         if (rc == 0)
     741                 :          0 :                 rc = rte_ipsec_session_prepare(&ut->ss[j]);
     742                 :            : 
     743                 :            :         return rc;
     744                 :            : }
     745                 :            : 
     746                 :            : static int
     747                 :          0 : crypto_dequeue_burst(uint16_t num_pkts)
     748                 :            : {
     749                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     750                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     751                 :            :         uint32_t pkt_cnt, k;
     752                 :            :         int i;
     753                 :            : 
     754                 :          0 :         for (i = 0, pkt_cnt = 0;
     755   [ #  #  #  # ]:          0 :                 i < DEQUEUE_COUNT && pkt_cnt != num_pkts; i++) {
     756                 :          0 :                 k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
     757                 :          0 :                         &ut_params->cop[pkt_cnt], num_pkts - pkt_cnt);
     758                 :          0 :                 pkt_cnt += k;
     759                 :          0 :                 rte_delay_us(1);
     760                 :            :         }
     761                 :            : 
     762         [ #  # ]:          0 :         if (pkt_cnt != num_pkts) {
     763                 :          0 :                 RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
     764                 :          0 :                 return TEST_FAILED;
     765                 :            :         }
     766                 :            :         return TEST_SUCCESS;
     767                 :            : }
     768                 :            : 
     769                 :            : static int
     770                 :          0 : crypto_ipsec(uint16_t num_pkts)
     771                 :            : {
     772                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     773                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     774                 :            :         uint32_t k, ng;
     775                 :            :         struct rte_ipsec_group grp[1];
     776                 :            : 
     777                 :            :         /* call crypto prepare */
     778   [ #  #  #  # ]:          0 :         if (ut_params->is_stateless && (ut_params->ipsec_state.sqn != 0))
     779                 :          0 :                 k = rte_ipsec_pkt_crypto_prepare_stateless(&ut_params->ss[0],
     780                 :            :                         ut_params->ibuf, ut_params->cop, num_pkts, &ut_params->ipsec_state);
     781                 :            :         else
     782                 :          0 :                 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
     783                 :            :                         ut_params->cop, num_pkts);
     784                 :            : 
     785         [ #  # ]:          0 :         if (k != num_pkts) {
     786                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
     787                 :          0 :                 return TEST_FAILED;
     788                 :            :         }
     789                 :            : 
     790                 :          0 :         k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
     791                 :            :                 ut_params->cop, num_pkts);
     792         [ #  # ]:          0 :         if (k != num_pkts) {
     793                 :          0 :                 RTE_LOG(ERR, USER1, "rte_cryptodev_enqueue_burst fail\n");
     794                 :          0 :                 return TEST_FAILED;
     795                 :            :         }
     796                 :            : 
     797         [ #  # ]:          0 :         if (crypto_dequeue_burst(num_pkts) == TEST_FAILED)
     798                 :            :                 return TEST_FAILED;
     799                 :            : 
     800                 :          0 :         ng = rte_ipsec_pkt_crypto_group(
     801                 :            :                 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
     802                 :            :                 ut_params->obuf, grp, num_pkts);
     803         [ #  # ]:          0 :         if (ng != 1 ||
     804         [ #  # ]:          0 :                 grp[0].m[0] != ut_params->obuf[0] ||
     805         [ #  # ]:          0 :                 grp[0].cnt != num_pkts ||
     806         [ #  # ]:          0 :                 grp[0].id.ptr != &ut_params->ss[0]) {
     807                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
     808                 :          0 :                 return TEST_FAILED;
     809                 :            :         }
     810                 :            : 
     811                 :            :         /* call crypto process */
     812                 :          0 :         k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
     813         [ #  # ]:          0 :         if (k != num_pkts) {
     814                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
     815                 :          0 :                 return TEST_FAILED;
     816                 :            :         }
     817                 :            : 
     818                 :            :         return TEST_SUCCESS;
     819                 :            : }
     820                 :            : 
     821                 :            : static int
     822                 :          0 : lksd_proto_ipsec(uint16_t num_pkts)
     823                 :            : {
     824                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     825                 :            :         uint32_t i, k, ng;
     826                 :            :         struct rte_ipsec_group grp[1];
     827                 :            : 
     828                 :            :         /* call crypto prepare */
     829                 :          0 :         k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
     830                 :            :                 ut_params->cop, num_pkts);
     831         [ #  # ]:          0 :         if (k != num_pkts) {
     832                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
     833                 :          0 :                 return TEST_FAILED;
     834                 :            :         }
     835                 :            : 
     836                 :            :         /* check crypto ops */
     837         [ #  # ]:          0 :         for (i = 0; i != num_pkts; i++) {
     838         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->cop[i]->type,
     839                 :            :                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     840                 :            :                         "%s: invalid crypto op type for %u-th packet\n",
     841                 :            :                         __func__, i);
     842         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->cop[i]->status,
     843                 :            :                         RTE_CRYPTO_OP_STATUS_NOT_PROCESSED,
     844                 :            :                         "%s: invalid crypto op status for %u-th packet\n",
     845                 :            :                         __func__, i);
     846         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->cop[i]->sess_type,
     847                 :            :                         RTE_CRYPTO_OP_SECURITY_SESSION,
     848                 :            :                         "%s: invalid crypto op sess_type for %u-th packet\n",
     849                 :            :                         __func__, i);
     850         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->cop[i]->sym->m_src,
     851                 :            :                         ut_params->ibuf[i],
     852                 :            :                         "%s: invalid crypto op m_src for %u-th packet\n",
     853                 :            :                         __func__, i);
     854                 :            :         }
     855                 :            : 
     856                 :            :         /* update crypto ops, pretend all finished ok */
     857         [ #  # ]:          0 :         for (i = 0; i != num_pkts; i++)
     858                 :          0 :                 ut_params->cop[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
     859                 :            : 
     860                 :          0 :         ng = rte_ipsec_pkt_crypto_group(
     861                 :            :                 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
     862                 :            :                 ut_params->obuf, grp, num_pkts);
     863         [ #  # ]:          0 :         if (ng != 1 ||
     864         [ #  # ]:          0 :                 grp[0].m[0] != ut_params->obuf[0] ||
     865         [ #  # ]:          0 :                 grp[0].cnt != num_pkts ||
     866         [ #  # ]:          0 :                 grp[0].id.ptr != &ut_params->ss[0]) {
     867                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
     868                 :          0 :                 return TEST_FAILED;
     869                 :            :         }
     870                 :            : 
     871                 :            :         /* call crypto process */
     872                 :          0 :         k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
     873         [ #  # ]:          0 :         if (k != num_pkts) {
     874                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
     875                 :          0 :                 return TEST_FAILED;
     876                 :            :         }
     877                 :            : 
     878                 :            :         return TEST_SUCCESS;
     879                 :            : }
     880                 :            : 
     881                 :            : static void
     882                 :          0 : dump_grp_pkt(uint32_t i, struct rte_ipsec_group *grp, uint32_t k)
     883                 :            : {
     884                 :          0 :         RTE_LOG(ERR, USER1,
     885                 :            :                 "After rte_ipsec_pkt_process grp[%d].cnt=%d k=%d fail\n",
     886                 :            :                 i, grp[i].cnt, k);
     887                 :          0 :         RTE_LOG(ERR, USER1,
     888                 :            :                 "After rte_ipsec_pkt_process grp[%d].m=%p grp[%d].m[%d]=%p\n",
     889                 :            :                 i, grp[i].m, i, k, grp[i].m[k]);
     890                 :            : 
     891                 :          0 :         rte_pktmbuf_dump(stdout, grp[i].m[k], grp[i].m[k]->data_len);
     892                 :          0 : }
     893                 :            : 
     894                 :            : static int
     895                 :          0 : crypto_ipsec_2sa(void)
     896                 :            : {
     897                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
     898                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     899                 :            :         struct rte_ipsec_group grp[BURST_SIZE];
     900                 :            :         uint32_t k, ng, i, r;
     901                 :            : 
     902         [ #  # ]:          0 :         for (i = 0; i < BURST_SIZE; i++) {
     903                 :          0 :                 r = i % 2;
     904                 :            :                 /* call crypto prepare */
     905                 :          0 :                 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[r],
     906                 :          0 :                                 ut_params->ibuf + i, ut_params->cop + i, 1);
     907         [ #  # ]:          0 :                 if (k != 1) {
     908                 :          0 :                         RTE_LOG(ERR, USER1,
     909                 :            :                                 "rte_ipsec_pkt_crypto_prepare fail\n");
     910                 :          0 :                         return TEST_FAILED;
     911                 :            :                 }
     912                 :          0 :                 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
     913                 :            :                                 ut_params->cop + i, 1);
     914         [ #  # ]:          0 :                 if (k != 1) {
     915                 :          0 :                         RTE_LOG(ERR, USER1,
     916                 :            :                                 "rte_cryptodev_enqueue_burst fail\n");
     917                 :          0 :                         return TEST_FAILED;
     918                 :            :                 }
     919                 :            :         }
     920                 :            : 
     921         [ #  # ]:          0 :         if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
     922                 :            :                 return TEST_FAILED;
     923                 :            : 
     924                 :          0 :         ng = rte_ipsec_pkt_crypto_group(
     925                 :            :                 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
     926                 :            :                 ut_params->obuf, grp, BURST_SIZE);
     927         [ #  # ]:          0 :         if (ng != BURST_SIZE) {
     928                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
     929                 :            :                         ng);
     930                 :          0 :                 return TEST_FAILED;
     931                 :            :         }
     932                 :            : 
     933                 :            :         /* call crypto process */
     934         [ #  # ]:          0 :         for (i = 0; i < ng; i++) {
     935                 :          0 :                 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
     936         [ #  # ]:          0 :                 if (k != grp[i].cnt) {
     937                 :          0 :                         dump_grp_pkt(i, grp, k);
     938                 :          0 :                         return TEST_FAILED;
     939                 :            :                 }
     940                 :            :         }
     941                 :            :         return TEST_SUCCESS;
     942                 :            : }
     943                 :            : 
     944                 :            : #define PKT_4   4
     945                 :            : #define PKT_12  12
     946                 :            : #define PKT_21  21
     947                 :            : 
     948                 :            : static uint32_t
     949                 :            : crypto_ipsec_4grp(uint32_t pkt_num)
     950                 :            : {
     951                 :            :         uint32_t sa_ind;
     952                 :            : 
     953                 :            :         /* group packets in 4 different size groups, 2 per SA */
     954         [ #  # ]:          0 :         if (pkt_num < PKT_4)
     955                 :            :                 sa_ind = 0;
     956   [ #  #  #  # ]:          0 :         else if (pkt_num < PKT_12)
     957                 :            :                 sa_ind = 1;
     958   [ #  #  #  # ]:          0 :         else if (pkt_num < PKT_21)
     959                 :            :                 sa_ind = 0;
     960                 :            :         else
     961                 :            :                 sa_ind = 1;
     962                 :            : 
     963                 :            :         return sa_ind;
     964                 :            : }
     965                 :            : 
     966                 :            : static uint32_t
     967                 :          0 : crypto_ipsec_4grp_check_mbufs(uint32_t grp_ind, struct rte_ipsec_group *grp)
     968                 :            : {
     969                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
     970                 :            :         uint32_t i, j;
     971                 :            :         uint32_t rc = 0;
     972                 :            : 
     973         [ #  # ]:          0 :         if (grp_ind == 0) {
     974         [ #  # ]:          0 :                 for (i = 0, j = 0; i < PKT_4; i++, j++)
     975         [ #  # ]:          0 :                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
     976                 :            :                                 rc = TEST_FAILED;
     977                 :            :                                 break;
     978                 :            :                         }
     979         [ #  # ]:          0 :         } else if (grp_ind == 1) {
     980         [ #  # ]:          0 :                 for (i = 0, j = PKT_4; i < (PKT_12 - PKT_4); i++, j++) {
     981         [ #  # ]:          0 :                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
     982                 :            :                                 rc = TEST_FAILED;
     983                 :            :                                 break;
     984                 :            :                         }
     985                 :            :                 }
     986         [ #  # ]:          0 :         } else if (grp_ind == 2) {
     987         [ #  # ]:          0 :                 for (i = 0, j =  PKT_12; i < (PKT_21 - PKT_12); i++, j++)
     988         [ #  # ]:          0 :                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
     989                 :            :                                 rc = TEST_FAILED;
     990                 :            :                                 break;
     991                 :            :                         }
     992         [ #  # ]:          0 :         } else if (grp_ind == 3) {
     993         [ #  # ]:          0 :                 for (i = 0, j = PKT_21; i < (BURST_SIZE - PKT_21); i++, j++)
     994         [ #  # ]:          0 :                         if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
     995                 :            :                                 rc = TEST_FAILED;
     996                 :            :                                 break;
     997                 :            :                         }
     998                 :            :         } else
     999                 :            :                 rc = TEST_FAILED;
    1000                 :            : 
    1001                 :          0 :         return rc;
    1002                 :            : }
    1003                 :            : 
    1004                 :            : static uint32_t
    1005                 :          0 : crypto_ipsec_4grp_check_cnt(uint32_t grp_ind, struct rte_ipsec_group *grp)
    1006                 :            : {
    1007                 :            :         uint32_t rc = 0;
    1008                 :            : 
    1009         [ #  # ]:          0 :         if (grp_ind == 0) {
    1010         [ #  # ]:          0 :                 if (grp[grp_ind].cnt != PKT_4)
    1011                 :            :                         rc = TEST_FAILED;
    1012         [ #  # ]:          0 :         } else if (grp_ind == 1) {
    1013         [ #  # ]:          0 :                 if (grp[grp_ind].cnt != PKT_12 - PKT_4)
    1014                 :            :                         rc = TEST_FAILED;
    1015         [ #  # ]:          0 :         } else if (grp_ind == 2) {
    1016         [ #  # ]:          0 :                 if (grp[grp_ind].cnt != PKT_21 - PKT_12)
    1017                 :            :                         rc = TEST_FAILED;
    1018         [ #  # ]:          0 :         } else if (grp_ind == 3) {
    1019         [ #  # ]:          0 :                 if (grp[grp_ind].cnt != BURST_SIZE - PKT_21)
    1020                 :            :                         rc = TEST_FAILED;
    1021                 :            :         } else
    1022                 :            :                 rc = TEST_FAILED;
    1023                 :            : 
    1024                 :          0 :         return rc;
    1025                 :            : }
    1026                 :            : 
    1027                 :            : static int
    1028                 :          0 : crypto_ipsec_2sa_4grp(void)
    1029                 :            : {
    1030                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1031                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1032                 :            :         struct rte_ipsec_group grp[BURST_SIZE];
    1033                 :            :         uint32_t k, ng, i, j;
    1034                 :            :         uint32_t rc = 0;
    1035                 :            : 
    1036         [ #  # ]:          0 :         for (i = 0; i < BURST_SIZE; i++) {
    1037                 :            :                 j = crypto_ipsec_4grp(i);
    1038                 :            : 
    1039                 :            :                 /* call crypto prepare */
    1040                 :          0 :                 k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[j],
    1041                 :          0 :                                 ut_params->ibuf + i, ut_params->cop + i, 1);
    1042         [ #  # ]:          0 :                 if (k != 1) {
    1043                 :          0 :                         RTE_LOG(ERR, USER1,
    1044                 :            :                                 "rte_ipsec_pkt_crypto_prepare fail\n");
    1045                 :          0 :                         return TEST_FAILED;
    1046                 :            :                 }
    1047                 :          0 :                 k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
    1048                 :            :                                 ut_params->cop + i, 1);
    1049         [ #  # ]:          0 :                 if (k != 1) {
    1050                 :          0 :                         RTE_LOG(ERR, USER1,
    1051                 :            :                                 "rte_cryptodev_enqueue_burst fail\n");
    1052                 :          0 :                         return TEST_FAILED;
    1053                 :            :                 }
    1054                 :            :         }
    1055                 :            : 
    1056         [ #  # ]:          0 :         if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
    1057                 :            :                 return TEST_FAILED;
    1058                 :            : 
    1059                 :          0 :         ng = rte_ipsec_pkt_crypto_group(
    1060                 :            :                 (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
    1061                 :            :                 ut_params->obuf, grp, BURST_SIZE);
    1062         [ #  # ]:          0 :         if (ng != 4) {
    1063                 :          0 :                 RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
    1064                 :            :                         ng);
    1065                 :          0 :                 return TEST_FAILED;
    1066                 :            :         }
    1067                 :            : 
    1068                 :            :         /* call crypto process */
    1069         [ #  # ]:          0 :         for (i = 0; i < ng; i++) {
    1070                 :          0 :                 k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
    1071         [ #  # ]:          0 :                 if (k != grp[i].cnt) {
    1072                 :          0 :                         dump_grp_pkt(i, grp, k);
    1073                 :          0 :                         return TEST_FAILED;
    1074                 :            :                 }
    1075                 :          0 :                 rc = crypto_ipsec_4grp_check_cnt(i, grp);
    1076         [ #  # ]:          0 :                 if (rc != 0) {
    1077                 :          0 :                         RTE_LOG(ERR, USER1,
    1078                 :            :                                 "crypto_ipsec_4grp_check_cnt fail\n");
    1079                 :          0 :                         return TEST_FAILED;
    1080                 :            :                 }
    1081                 :          0 :                 rc = crypto_ipsec_4grp_check_mbufs(i, grp);
    1082         [ #  # ]:          0 :                 if (rc != 0) {
    1083                 :          0 :                         RTE_LOG(ERR, USER1,
    1084                 :            :                                 "crypto_ipsec_4grp_check_mbufs fail\n");
    1085                 :          0 :                         return TEST_FAILED;
    1086                 :            :                 }
    1087                 :            :         }
    1088                 :            :         return TEST_SUCCESS;
    1089                 :            : }
    1090                 :            : 
    1091                 :            : static void
    1092                 :          0 : test_ipsec_reorder_inb_pkt_burst(uint16_t num_pkts)
    1093                 :            : {
    1094                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1095                 :            :         struct rte_mbuf *ibuf_tmp[BURST_SIZE];
    1096                 :            :         uint16_t j;
    1097                 :            : 
    1098                 :            :         /* reorder packets and create gaps in sequence numbers */
    1099                 :            :         static const uint32_t reorder[BURST_SIZE] = {
    1100                 :            :                         24, 25, 26, 27, 28, 29, 30, 31,
    1101                 :            :                         16, 17, 18, 19, 20, 21, 22, 23,
    1102                 :            :                         8, 9, 10, 11, 12, 13, 14, 15,
    1103                 :            :                         0, 1, 2, 3, 4, 5, 6, 7,
    1104                 :            :         };
    1105                 :            : 
    1106         [ #  # ]:          0 :         if (num_pkts != BURST_SIZE)
    1107                 :          0 :                 return;
    1108                 :            : 
    1109         [ #  # ]:          0 :         for (j = 0; j != BURST_SIZE; j++)
    1110                 :          0 :                 ibuf_tmp[j] = ut_params->ibuf[reorder[j]];
    1111                 :            : 
    1112                 :            :         memcpy(ut_params->ibuf, ibuf_tmp, sizeof(ut_params->ibuf));
    1113                 :            : }
    1114                 :            : 
    1115                 :            : static int
    1116                 :          0 : test_ipsec_crypto_op_alloc(uint16_t num_pkts)
    1117                 :            : {
    1118                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1119                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1120                 :            :         int rc = 0;
    1121                 :            :         uint16_t j;
    1122                 :            : 
    1123         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1124                 :          0 :                 ut_params->cop[j] = rte_crypto_op_alloc(ts_params->cop_mpool,
    1125                 :            :                                 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
    1126         [ #  # ]:          0 :                 if (ut_params->cop[j] == NULL) {
    1127                 :          0 :                         RTE_LOG(ERR, USER1,
    1128                 :            :                                 "Failed to allocate symmetric crypto op\n");
    1129                 :            :                         rc = TEST_FAILED;
    1130                 :            :                 }
    1131                 :            :         }
    1132                 :            : 
    1133                 :          0 :         return rc;
    1134                 :            : }
    1135                 :            : 
    1136                 :            : static void
    1137                 :          0 : test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i)
    1138                 :            : {
    1139                 :          0 :         uint16_t j = ut_params->pkt_index;
    1140                 :            : 
    1141                 :            :         printf("\ntest config: num %d\n", i);
    1142                 :          0 :         printf("   replay_win_sz %u\n", test_cfg[i].replay_win_sz);
    1143                 :          0 :         printf("   esn %u\n", test_cfg[i].esn);
    1144                 :          0 :         printf("   flags 0x%" PRIx64 "\n", test_cfg[i].flags);
    1145                 :          0 :         printf("   pkt_sz %zu\n", test_cfg[i].pkt_sz);
    1146                 :          0 :         printf("   num_pkts %u\n\n", test_cfg[i].num_pkts);
    1147                 :            : 
    1148         [ #  # ]:          0 :         if (ut_params->ibuf[j]) {
    1149                 :            :                 printf("ibuf[%u] data:\n", j);
    1150                 :          0 :                 rte_pktmbuf_dump(stdout, ut_params->ibuf[j],
    1151                 :          0 :                         ut_params->ibuf[j]->data_len);
    1152                 :            :         }
    1153         [ #  # ]:          0 :         if (ut_params->obuf[j]) {
    1154                 :            :                 printf("obuf[%u] data:\n", j);
    1155                 :          0 :                 rte_pktmbuf_dump(stdout, ut_params->obuf[j],
    1156                 :          0 :                         ut_params->obuf[j]->data_len);
    1157                 :            :         }
    1158         [ #  # ]:          0 :         if (ut_params->testbuf[j]) {
    1159                 :            :                 printf("testbuf[%u] data:\n", j);
    1160                 :          0 :                 rte_pktmbuf_dump(stdout, ut_params->testbuf[j],
    1161                 :          0 :                         ut_params->testbuf[j]->data_len);
    1162                 :            :         }
    1163                 :          0 : }
    1164                 :            : 
    1165                 :            : static void
    1166                 :            : destroy_dummy_sec_session(struct ipsec_unitest_params *ut,
    1167                 :            :         uint32_t j)
    1168                 :            : {
    1169                 :          0 :         rte_security_session_destroy(&dummy_sec_ctx,
    1170                 :          0 :                                         ut->ss[j].security.ses);
    1171                 :          0 :         ut->ss[j].security.ctx = NULL;
    1172                 :            : }
    1173                 :            : 
    1174                 :            : static void
    1175                 :          0 : destroy_crypto_session(struct ipsec_unitest_params *ut,
    1176                 :            :         uint8_t crypto_dev, uint32_t j)
    1177                 :            : {
    1178                 :          0 :         rte_cryptodev_sym_session_free(crypto_dev, ut->ss[j].crypto.ses);
    1179                 :          0 :         memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
    1180                 :          0 : }
    1181                 :            : 
    1182                 :            : static void
    1183                 :          0 : destroy_session(struct ipsec_unitest_params *ut,
    1184                 :            :         uint8_t crypto_dev, uint32_t j)
    1185                 :            : {
    1186         [ #  # ]:          0 :         if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
    1187                 :          0 :                 return destroy_crypto_session(ut, crypto_dev, j);
    1188                 :            :         else
    1189                 :          0 :                 return destroy_dummy_sec_session(ut, j);
    1190                 :            : }
    1191                 :            : 
    1192                 :            : static void
    1193                 :          0 : destroy_sa(uint32_t j)
    1194                 :            : {
    1195                 :            :         struct ipsec_unitest_params *ut = &unittest_params;
    1196                 :            :         struct ipsec_testsuite_params *ts = &testsuite_params;
    1197                 :            : 
    1198                 :          0 :         rte_ipsec_sa_fini(ut->ss[j].sa);
    1199                 :          0 :         rte_free(ut->ss[j].sa);
    1200                 :            : 
    1201                 :          0 :         destroy_session(ut, ts->valid_dev, j);
    1202                 :          0 : }
    1203                 :            : 
    1204                 :            : static int
    1205                 :          0 : crypto_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
    1206                 :            :                 uint16_t num_pkts)
    1207                 :            : {
    1208                 :            :         uint16_t j;
    1209                 :            : 
    1210         [ #  # ]:          0 :         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
    1211                 :          0 :                 ut_params->pkt_index = j;
    1212                 :            : 
    1213                 :            :                 /* compare the data buffers */
    1214         [ #  # ]:          0 :                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
    1215                 :            :                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
    1216                 :            :                         test_cfg[i].pkt_sz,
    1217                 :            :                         "input and output data does not match\n");
    1218         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
    1219                 :            :                         ut_params->obuf[j]->pkt_len,
    1220                 :            :                         "data_len is not equal to pkt_len");
    1221         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
    1222                 :            :                         test_cfg[i].pkt_sz,
    1223                 :            :                         "data_len is not equal to input data");
    1224                 :            :         }
    1225                 :            : 
    1226                 :            :         return 0;
    1227                 :            : }
    1228                 :            : 
    1229                 :            : static int
    1230                 :          0 : test_ipsec_crypto_inb_burst_null_null(int i)
    1231                 :            : {
    1232                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1233                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1234                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1235                 :            :         uint16_t j;
    1236                 :            :         int rc;
    1237                 :            : 
    1238                 :            :         /* create rte_ipsec_sa */
    1239                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    1240                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1241         [ #  # ]:          0 :         if (rc != 0) {
    1242                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1243                 :          0 :                 return rc;
    1244                 :            :         }
    1245                 :            : 
    1246                 :            :         /* Generate test mbuf data */
    1247         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1248                 :            :                 /* packet with sequence number 0 is invalid */
    1249                 :          0 :                 ut_params->ibuf[j] = setup_test_string_tunneled(
    1250                 :            :                         ts_params->mbuf_pool, null_encrypted_data,
    1251                 :          0 :                         test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
    1252         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    1253                 :            :                         rc = TEST_FAILED;
    1254                 :            :         }
    1255                 :            : 
    1256         [ #  # ]:          0 :         if (rc == 0) {
    1257         [ #  # ]:          0 :                 if (test_cfg[i].reorder_pkts)
    1258                 :          0 :                         test_ipsec_reorder_inb_pkt_burst(num_pkts);
    1259                 :          0 :                 rc = test_ipsec_crypto_op_alloc(num_pkts);
    1260                 :            :         }
    1261                 :            : 
    1262         [ #  # ]:          0 :         if (rc == 0) {
    1263                 :            :                 /* call ipsec library api */
    1264                 :          0 :                 rc = crypto_ipsec(num_pkts);
    1265         [ #  # ]:          0 :                 if (rc == 0)
    1266                 :          0 :                         rc = crypto_inb_burst_null_null_check(
    1267                 :            :                                         ut_params, i, num_pkts);
    1268                 :            :                 else {
    1269                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    1270                 :            :                                 i);
    1271                 :            :                         rc = TEST_FAILED;
    1272                 :            :                 }
    1273                 :            :         }
    1274                 :            : 
    1275         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1276                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1277                 :            : 
    1278                 :          0 :         destroy_sa(0);
    1279                 :          0 :         return rc;
    1280                 :            : }
    1281                 :            : 
    1282                 :            : static int
    1283                 :          0 : test_ipsec_crypto_inb_burst_null_null_wrapper(void)
    1284                 :            : {
    1285                 :            :         int i;
    1286                 :            :         int rc = 0;
    1287                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1288                 :            : 
    1289                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    1290                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    1291                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1292                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1293                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1294                 :            : 
    1295         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1296                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1297                 :          0 :                 rc = test_ipsec_crypto_inb_burst_null_null(i);
    1298                 :            :         }
    1299                 :            : 
    1300                 :          0 :         return rc;
    1301                 :            : }
    1302                 :            : 
    1303                 :            : static int
    1304                 :          0 : crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
    1305                 :            :         uint16_t num_pkts)
    1306                 :            : {
    1307                 :            :         void *obuf_data;
    1308                 :            :         void *testbuf_data;
    1309                 :            :         uint16_t j;
    1310                 :            : 
    1311         [ #  # ]:          0 :         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
    1312                 :          0 :                 ut_params->pkt_index = j;
    1313                 :            : 
    1314                 :          0 :                 testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
    1315                 :          0 :                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
    1316                 :            :                 /* compare the buffer data */
    1317         [ #  # ]:          0 :                 TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
    1318                 :            :                         ut_params->obuf[j]->pkt_len,
    1319                 :            :                         "test and output data does not match\n");
    1320         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
    1321                 :            :                         ut_params->testbuf[j]->data_len,
    1322                 :            :                         "obuf data_len is not equal to testbuf data_len");
    1323         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
    1324                 :            :                         ut_params->testbuf[j]->pkt_len,
    1325                 :            :                         "obuf pkt_len is not equal to testbuf pkt_len");
    1326                 :            :         }
    1327                 :            : 
    1328                 :            :         return 0;
    1329                 :            : }
    1330                 :            : 
    1331                 :            : static int
    1332                 :          0 : test_ipsec_verify_sqn(struct ipsec_unitest_params *ut_params,
    1333                 :            :                 uint16_t num_pkts, uint32_t sqn_start)
    1334                 :            : {
    1335                 :            :         struct rte_esp_hdr esph;
    1336                 :            :         uint8_t *obuf_data;
    1337                 :            :         uint32_t sqn;
    1338                 :            :         uint16_t j;
    1339                 :            : 
    1340         [ #  # ]:          0 :         for (j = 0; j < num_pkts; j++) {
    1341                 :          0 :                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
    1342                 :            : 
    1343                 :            :                 memcpy(&esph, obuf_data + sizeof(ipv4_outer), sizeof(esph));
    1344         [ #  # ]:          0 :                 sqn = rte_be_to_cpu_32(esph.seq);
    1345         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(sqn, sqn_start + j,
    1346                 :            :                         "Invalid sequence number in packet %u\n", j);
    1347                 :            :         }
    1348                 :            : 
    1349                 :            :         return 0;
    1350                 :            : }
    1351                 :            : 
    1352                 :            : static int
    1353                 :          0 : test_ipsec_crypto_outb_single_burst_null_null(int i, uint32_t sqn_start)
    1354                 :            : {
    1355                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1356                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1357                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1358                 :            :         uint16_t j;
    1359                 :            :         int rc = 0;
    1360                 :            : 
    1361         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1362                 :          0 :                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
    1363                 :            :                         null_plain_data, sizeof(null_plain_data),
    1364                 :          0 :                         test_cfg[i].pkt_sz, 0);
    1365         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    1366                 :            :                         rc = TEST_FAILED;
    1367                 :            :                 else {
    1368                 :            :                         /* Generate test mbuf data */
    1369                 :            :                         /* packet with sequence number 0 is invalid */
    1370                 :          0 :                         ut_params->testbuf[j] = setup_test_string_tunneled(
    1371                 :            :                                         ts_params->mbuf_pool,
    1372                 :            :                                         null_plain_data, test_cfg[i].pkt_sz,
    1373                 :            :                                         OUTBOUND_SPI, j + sqn_start);
    1374         [ #  # ]:          0 :                         if (ut_params->testbuf[j] == NULL)
    1375                 :            :                                 rc = TEST_FAILED;
    1376                 :            :                 }
    1377                 :            :         }
    1378                 :            : 
    1379         [ #  # ]:          0 :         if (rc == 0)
    1380                 :          0 :                 rc = test_ipsec_crypto_op_alloc(num_pkts);
    1381                 :            : 
    1382         [ #  # ]:          0 :         if (rc == 0) {
    1383                 :            :                 /* call ipsec library api */
    1384                 :          0 :                 rc = crypto_ipsec(num_pkts);
    1385         [ #  # ]:          0 :                 if (rc == 0)
    1386                 :          0 :                         rc = crypto_outb_burst_null_null_check(ut_params,
    1387                 :            :                                         num_pkts);
    1388                 :            :                 else
    1389                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    1390                 :            :                                 i);
    1391                 :            :         }
    1392                 :            : 
    1393         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1394                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1395                 :            : 
    1396                 :          0 :         test_ipsec_verify_sqn(ut_params, num_pkts, sqn_start);
    1397                 :            : 
    1398                 :          0 :         return rc;
    1399                 :            : }
    1400                 :            : 
    1401                 :            : static int
    1402                 :          0 : test_ipsec_crypto_outb_burst_null_null(int i)
    1403                 :            : {
    1404                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1405                 :            :         uint32_t sqn_start;
    1406                 :            :         int32_t rc;
    1407                 :            : 
    1408                 :            :         /* create rte_ipsec_sa*/
    1409                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    1410                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1411         [ #  # ]:          0 :         if (rc != 0) {
    1412                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1413                 :          0 :                 return rc;
    1414                 :            :         }
    1415                 :            : 
    1416                 :            :         /* Generate input mbuf data and test normal IPsec processing */
    1417                 :            :         sqn_start = 1;
    1418                 :          0 :         rc = test_ipsec_crypto_outb_single_burst_null_null(i, sqn_start);
    1419         [ #  # ]:          0 :         if (rc != 0) {
    1420                 :          0 :                 RTE_LOG(ERR, USER1, "burst failed, cfg %d\n", i);
    1421                 :          0 :                 return rc;
    1422                 :            :         }
    1423                 :            : 
    1424         [ #  # ]:          0 :         if (ut_params->is_stateless) {
    1425                 :            : 
    1426                 :            :                 /* Generate input mbuf data for stateless IPsec processing. */
    1427                 :          0 :                 sqn_start = ut_params->ipsec_state.sqn = SQN_START;
    1428                 :          0 :                 rc = test_ipsec_crypto_outb_single_burst_null_null(i, sqn_start);
    1429         [ #  # ]:          0 :                 if (rc != 0) {
    1430                 :          0 :                         RTE_LOG(ERR, USER1, "stateless burst failed, cfg %d\n", i);
    1431                 :          0 :                         return rc;
    1432                 :            :                 }
    1433                 :            :         }
    1434                 :            : 
    1435                 :          0 :         destroy_sa(0);
    1436                 :          0 :         return rc;
    1437                 :            : }
    1438                 :            : 
    1439                 :            : static int
    1440                 :          0 : test_ipsec_crypto_outb_burst_stateless_null_null_wrapper(void)
    1441                 :            : {
    1442                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1443                 :            :         int rc = 0;
    1444                 :            :         int i;
    1445                 :            : 
    1446                 :          0 :         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
    1447                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
    1448                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1449                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1450                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1451                 :          0 :         ut_params->is_stateless = true;
    1452                 :            : 
    1453         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1454                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1455                 :          0 :                 ut_params->ipsec_state.sqn = 0;
    1456                 :          0 :                 rc = test_ipsec_crypto_outb_burst_null_null(i);
    1457                 :            : 
    1458                 :            :         }
    1459                 :            : 
    1460                 :          0 :         return rc;
    1461                 :            : }
    1462                 :            : 
    1463                 :            : static int
    1464                 :          0 : test_ipsec_crypto_outb_burst_null_null_wrapper(void)
    1465                 :            : {
    1466                 :            :         int i;
    1467                 :            :         int rc = 0;
    1468                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1469                 :            : 
    1470                 :          0 :         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
    1471                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
    1472                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1473                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1474                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1475                 :            : 
    1476         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1477                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1478                 :          0 :                 rc = test_ipsec_crypto_outb_burst_null_null(i);
    1479                 :            :         }
    1480                 :            : 
    1481                 :          0 :         return rc;
    1482                 :            : }
    1483                 :            : 
    1484                 :            : static int
    1485                 :          0 : inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
    1486                 :            :         uint16_t num_pkts)
    1487                 :            : {
    1488                 :            :         void *ibuf_data;
    1489                 :            :         void *obuf_data;
    1490                 :            :         uint16_t j;
    1491                 :            : 
    1492         [ #  # ]:          0 :         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
    1493                 :          0 :                 ut_params->pkt_index = j;
    1494                 :            : 
    1495                 :            :                 /* compare the buffer data */
    1496                 :          0 :                 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
    1497                 :          0 :                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
    1498                 :            : 
    1499         [ #  # ]:          0 :                 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
    1500                 :            :                         ut_params->ibuf[j]->data_len,
    1501                 :            :                         "input and output data does not match\n");
    1502         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
    1503                 :            :                         ut_params->obuf[j]->data_len,
    1504                 :            :                         "ibuf data_len is not equal to obuf data_len");
    1505         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
    1506                 :            :                         ut_params->obuf[j]->pkt_len,
    1507                 :            :                         "ibuf pkt_len is not equal to obuf pkt_len");
    1508         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
    1509                 :            :                         test_cfg[i].pkt_sz,
    1510                 :            :                         "data_len is not equal input data");
    1511                 :            :         }
    1512                 :            :         return 0;
    1513                 :            : }
    1514                 :            : 
    1515                 :            : static int
    1516                 :          0 : test_ipsec_inline_crypto_inb_burst_null_null(int i)
    1517                 :            : {
    1518                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1519                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1520                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1521                 :            :         uint16_t j;
    1522                 :            :         int32_t rc;
    1523                 :            :         uint32_t n;
    1524                 :            : 
    1525                 :            :         /* create rte_ipsec_sa*/
    1526                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
    1527                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1528         [ #  # ]:          0 :         if (rc != 0) {
    1529                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1530                 :          0 :                 return rc;
    1531                 :            :         }
    1532                 :            : 
    1533                 :            :         /* Generate inbound mbuf data */
    1534         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1535                 :          0 :                 ut_params->ibuf[j] = setup_test_string_tunneled(
    1536                 :            :                         ts_params->mbuf_pool,
    1537                 :          0 :                         null_plain_data, test_cfg[i].pkt_sz,
    1538                 :          0 :                         INBOUND_SPI, j + 1);
    1539         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    1540                 :            :                         rc = TEST_FAILED;
    1541                 :            :                 else {
    1542                 :            :                         /* Generate test mbuf data */
    1543                 :          0 :                         ut_params->obuf[j] = setup_test_string(
    1544                 :            :                                 ts_params->mbuf_pool,
    1545                 :            :                                 null_plain_data, sizeof(null_plain_data),
    1546                 :            :                                 test_cfg[i].pkt_sz, 0);
    1547         [ #  # ]:          0 :                         if (ut_params->obuf[j] == NULL)
    1548                 :            :                                 rc = TEST_FAILED;
    1549                 :            :                 }
    1550                 :            :         }
    1551                 :            : 
    1552         [ #  # ]:          0 :         if (rc == 0) {
    1553                 :          0 :                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
    1554                 :            :                                 num_pkts);
    1555         [ #  # ]:          0 :                 if (n == num_pkts)
    1556                 :          0 :                         rc = inline_inb_burst_null_null_check(ut_params, i,
    1557                 :            :                                         num_pkts);
    1558                 :            :                 else {
    1559                 :          0 :                         RTE_LOG(ERR, USER1,
    1560                 :            :                                 "rte_ipsec_pkt_process failed, cfg %d\n",
    1561                 :            :                                 i);
    1562                 :            :                         rc = TEST_FAILED;
    1563                 :            :                 }
    1564                 :            :         }
    1565                 :            : 
    1566         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1567                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1568                 :            : 
    1569                 :          0 :         destroy_sa(0);
    1570                 :          0 :         return rc;
    1571                 :            : }
    1572                 :            : 
    1573                 :            : static int
    1574                 :          0 : test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
    1575                 :            : {
    1576                 :            :         int i;
    1577                 :            :         int rc = 0;
    1578                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1579                 :            : 
    1580                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    1581                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    1582                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1583                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1584                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1585                 :            : 
    1586         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1587                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1588                 :          0 :                 rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
    1589                 :            :         }
    1590                 :            : 
    1591                 :          0 :         return rc;
    1592                 :            : }
    1593                 :            : 
    1594                 :            : static int
    1595                 :          0 : test_ipsec_inline_proto_inb_burst_null_null(int i)
    1596                 :            : {
    1597                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1598                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1599                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1600                 :            :         uint16_t j;
    1601                 :            :         int32_t rc;
    1602                 :            :         uint32_t n;
    1603                 :            : 
    1604                 :            :         /* create rte_ipsec_sa*/
    1605                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
    1606                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1607         [ #  # ]:          0 :         if (rc != 0) {
    1608                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1609                 :          0 :                 return rc;
    1610                 :            :         }
    1611                 :            : 
    1612                 :            :         /* Generate inbound mbuf data */
    1613         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1614                 :          0 :                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
    1615                 :            :                         null_plain_data, sizeof(null_plain_data),
    1616                 :          0 :                         test_cfg[i].pkt_sz, 0);
    1617         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    1618                 :            :                         rc = TEST_FAILED;
    1619                 :            :                 else {
    1620                 :            :                         /* Generate test mbuf data */
    1621                 :          0 :                         ut_params->obuf[j] = setup_test_string(
    1622                 :            :                                 ts_params->mbuf_pool,
    1623                 :            :                                 null_plain_data, sizeof(null_plain_data),
    1624                 :            :                                 test_cfg[i].pkt_sz, 0);
    1625         [ #  # ]:          0 :                         if (ut_params->obuf[j] == NULL)
    1626                 :            :                                 rc = TEST_FAILED;
    1627                 :            :                 }
    1628                 :            :         }
    1629                 :            : 
    1630         [ #  # ]:          0 :         if (rc == 0) {
    1631                 :          0 :                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
    1632                 :            :                                 num_pkts);
    1633         [ #  # ]:          0 :                 if (n == num_pkts)
    1634                 :          0 :                         rc = inline_inb_burst_null_null_check(ut_params, i,
    1635                 :            :                                         num_pkts);
    1636                 :            :                 else {
    1637                 :          0 :                         RTE_LOG(ERR, USER1,
    1638                 :            :                                 "rte_ipsec_pkt_process failed, cfg %d\n",
    1639                 :            :                                 i);
    1640                 :            :                         rc = TEST_FAILED;
    1641                 :            :                 }
    1642                 :            :         }
    1643                 :            : 
    1644         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1645                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1646                 :            : 
    1647                 :          0 :         destroy_sa(0);
    1648                 :          0 :         return rc;
    1649                 :            : }
    1650                 :            : 
    1651                 :            : static int
    1652                 :          0 : test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
    1653                 :            : {
    1654                 :            :         int i;
    1655                 :            :         int rc = 0;
    1656                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1657                 :            : 
    1658                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    1659                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    1660                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1661                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1662                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1663                 :            : 
    1664         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1665                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1666                 :          0 :                 rc = test_ipsec_inline_proto_inb_burst_null_null(i);
    1667                 :            :         }
    1668                 :            : 
    1669                 :          0 :         return rc;
    1670                 :            : }
    1671                 :            : 
    1672                 :            : static int
    1673                 :          0 : inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
    1674                 :            :         uint16_t num_pkts)
    1675                 :            : {
    1676                 :            :         void *obuf_data;
    1677                 :            :         void *ibuf_data;
    1678                 :            :         uint16_t j;
    1679                 :            : 
    1680         [ #  # ]:          0 :         for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
    1681                 :          0 :                 ut_params->pkt_index = j;
    1682                 :            : 
    1683                 :            :                 /* compare the buffer data */
    1684                 :          0 :                 ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
    1685                 :          0 :                 obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
    1686         [ #  # ]:          0 :                 TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
    1687                 :            :                         ut_params->ibuf[j]->data_len,
    1688                 :            :                         "input and output data does not match\n");
    1689         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
    1690                 :            :                         ut_params->obuf[j]->data_len,
    1691                 :            :                         "ibuf data_len is not equal to obuf data_len");
    1692         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
    1693                 :            :                         ut_params->obuf[j]->pkt_len,
    1694                 :            :                         "ibuf pkt_len is not equal to obuf pkt_len");
    1695                 :            : 
    1696                 :            :                 /* check mbuf ol_flags */
    1697         [ #  # ]:          0 :                 TEST_ASSERT(ut_params->ibuf[j]->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD,
    1698                 :            :                             "ibuf RTE_MBUF_F_TX_SEC_OFFLOAD is not set");
    1699                 :            :         }
    1700                 :            :         return 0;
    1701                 :            : }
    1702                 :            : 
    1703                 :            : static int
    1704                 :          0 : test_ipsec_inline_crypto_outb_burst_null_null(int i)
    1705                 :            : {
    1706                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1707                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1708                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1709                 :            :         uint16_t j;
    1710                 :            :         int32_t rc;
    1711                 :            :         uint32_t n;
    1712                 :            : 
    1713                 :            :         /* create rte_ipsec_sa */
    1714                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
    1715                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1716         [ #  # ]:          0 :         if (rc != 0) {
    1717                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1718                 :          0 :                 return rc;
    1719                 :            :         }
    1720                 :            : 
    1721                 :            :         /* Generate test mbuf data */
    1722         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1723                 :          0 :                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
    1724                 :            :                         null_plain_data, sizeof(null_plain_data),
    1725                 :          0 :                         test_cfg[i].pkt_sz, 0);
    1726         [ #  # ]:          0 :                 if (ut_params->ibuf[0] == NULL)
    1727                 :            :                         rc = TEST_FAILED;
    1728                 :            : 
    1729                 :            :                 if (rc == 0) {
    1730                 :            :                         /* Generate test tunneled mbuf data for comparison */
    1731                 :          0 :                         ut_params->obuf[j] = setup_test_string_tunneled(
    1732                 :            :                                         ts_params->mbuf_pool,
    1733                 :            :                                         null_plain_data, test_cfg[i].pkt_sz,
    1734                 :          0 :                                         OUTBOUND_SPI, j + 1);
    1735         [ #  # ]:          0 :                         if (ut_params->obuf[j] == NULL)
    1736                 :            :                                 rc = TEST_FAILED;
    1737                 :            :                 }
    1738                 :            :         }
    1739                 :            : 
    1740         [ #  # ]:          0 :         if (rc == 0) {
    1741                 :          0 :                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
    1742                 :            :                                 num_pkts);
    1743         [ #  # ]:          0 :                 if (n == num_pkts)
    1744                 :          0 :                         rc = inline_outb_burst_null_null_check(ut_params,
    1745                 :            :                                         num_pkts);
    1746                 :            :                 else {
    1747                 :          0 :                         RTE_LOG(ERR, USER1,
    1748                 :            :                                 "rte_ipsec_pkt_process failed, cfg %d\n",
    1749                 :            :                                 i);
    1750                 :            :                         rc = TEST_FAILED;
    1751                 :            :                 }
    1752                 :            :         }
    1753                 :            : 
    1754         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1755                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1756                 :            : 
    1757                 :          0 :         destroy_sa(0);
    1758                 :          0 :         return rc;
    1759                 :            : }
    1760                 :            : 
    1761                 :            : static int
    1762                 :          0 : test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
    1763                 :            : {
    1764                 :            :         int i;
    1765                 :            :         int rc = 0;
    1766                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1767                 :            : 
    1768                 :          0 :         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
    1769                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
    1770                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1771                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1772                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1773                 :            : 
    1774         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1775                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1776                 :          0 :                 rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
    1777                 :            :         }
    1778                 :            : 
    1779                 :          0 :         return rc;
    1780                 :            : }
    1781                 :            : 
    1782                 :            : static int
    1783                 :          0 : test_ipsec_inline_proto_outb_burst_null_null(int i)
    1784                 :            : {
    1785                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1786                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1787                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1788                 :            :         uint16_t j;
    1789                 :            :         int32_t rc;
    1790                 :            :         uint32_t n;
    1791                 :            : 
    1792                 :            :         /* create rte_ipsec_sa */
    1793                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
    1794                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1795         [ #  # ]:          0 :         if (rc != 0) {
    1796                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1797                 :          0 :                 return rc;
    1798                 :            :         }
    1799                 :            : 
    1800                 :            :         /* Generate test mbuf data */
    1801         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1802                 :          0 :                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
    1803                 :            :                         null_plain_data, sizeof(null_plain_data),
    1804                 :          0 :                         test_cfg[i].pkt_sz, 0);
    1805         [ #  # ]:          0 :                 if (ut_params->ibuf[0] == NULL)
    1806                 :            :                         rc = TEST_FAILED;
    1807                 :            : 
    1808                 :            :                 if (rc == 0) {
    1809                 :            :                         /* Generate test tunneled mbuf data for comparison */
    1810                 :          0 :                         ut_params->obuf[j] = setup_test_string(
    1811                 :            :                                 ts_params->mbuf_pool, null_plain_data,
    1812                 :            :                                 sizeof(null_plain_data), test_cfg[i].pkt_sz,
    1813                 :            :                                 0);
    1814         [ #  # ]:          0 :                         if (ut_params->obuf[j] == NULL)
    1815                 :            :                                 rc = TEST_FAILED;
    1816                 :            :                 }
    1817                 :            :         }
    1818                 :            : 
    1819         [ #  # ]:          0 :         if (rc == 0) {
    1820                 :          0 :                 n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
    1821                 :            :                                 num_pkts);
    1822         [ #  # ]:          0 :                 if (n == num_pkts)
    1823                 :          0 :                         rc = inline_outb_burst_null_null_check(ut_params,
    1824                 :            :                                         num_pkts);
    1825                 :            :                 else {
    1826                 :          0 :                         RTE_LOG(ERR, USER1,
    1827                 :            :                                 "rte_ipsec_pkt_process failed, cfg %d\n",
    1828                 :            :                                 i);
    1829                 :            :                         rc = TEST_FAILED;
    1830                 :            :                 }
    1831                 :            :         }
    1832                 :            : 
    1833         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1834                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1835                 :            : 
    1836                 :          0 :         destroy_sa(0);
    1837                 :          0 :         return rc;
    1838                 :            : }
    1839                 :            : 
    1840                 :            : static int
    1841                 :          0 : test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
    1842                 :            : {
    1843                 :            :         int i;
    1844                 :            :         int rc = 0;
    1845                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1846                 :            : 
    1847                 :          0 :         ut_params->ipsec_xform.spi = OUTBOUND_SPI;
    1848                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
    1849                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1850                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1851                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1852                 :            : 
    1853         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1854                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1855                 :          0 :                 rc = test_ipsec_inline_proto_outb_burst_null_null(i);
    1856                 :            :         }
    1857                 :            : 
    1858                 :          0 :         return rc;
    1859                 :            : }
    1860                 :            : 
    1861                 :            : static int
    1862                 :          0 : test_ipsec_lksd_proto_inb_burst_null_null(int i)
    1863                 :            : {
    1864                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1865                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1866                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    1867                 :            :         uint16_t j;
    1868                 :            :         int rc;
    1869                 :            : 
    1870                 :            :         /* create rte_ipsec_sa */
    1871                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
    1872                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1873         [ #  # ]:          0 :         if (rc != 0) {
    1874                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1875                 :          0 :                 return rc;
    1876                 :            :         }
    1877                 :            : 
    1878                 :            :         /* Generate test mbuf data */
    1879         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    1880                 :            :                 /* packet with sequence number 0 is invalid */
    1881                 :          0 :                 ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
    1882                 :            :                         null_encrypted_data, sizeof(null_encrypted_data),
    1883                 :          0 :                         test_cfg[i].pkt_sz, 0);
    1884         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    1885                 :            :                         rc = TEST_FAILED;
    1886                 :            :         }
    1887                 :            : 
    1888         [ #  # ]:          0 :         if (rc == 0) {
    1889         [ #  # ]:          0 :                 if (test_cfg[i].reorder_pkts)
    1890                 :          0 :                         test_ipsec_reorder_inb_pkt_burst(num_pkts);
    1891                 :          0 :                 rc = test_ipsec_crypto_op_alloc(num_pkts);
    1892                 :            :         }
    1893                 :            : 
    1894         [ #  # ]:          0 :         if (rc == 0) {
    1895                 :            :                 /* call ipsec library api */
    1896                 :          0 :                 rc = lksd_proto_ipsec(num_pkts);
    1897         [ #  # ]:          0 :                 if (rc == 0)
    1898                 :          0 :                         rc = crypto_inb_burst_null_null_check(ut_params, i,
    1899                 :            :                                         num_pkts);
    1900                 :            :                 else {
    1901                 :          0 :                         RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
    1902                 :            :                                 __func__, i);
    1903                 :            :                         rc = TEST_FAILED;
    1904                 :            :                 }
    1905                 :            :         }
    1906                 :            : 
    1907         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    1908                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    1909                 :            : 
    1910                 :          0 :         destroy_sa(0);
    1911                 :          0 :         return rc;
    1912                 :            : }
    1913                 :            : 
    1914                 :            : static int
    1915                 :          0 : test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
    1916                 :            : {
    1917                 :            :         int i;
    1918                 :            :         int rc = 0;
    1919                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1920                 :            : 
    1921                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    1922                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    1923                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1924                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1925                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1926                 :            : 
    1927         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1928                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1929                 :          0 :                 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
    1930                 :            :         }
    1931                 :            : 
    1932                 :          0 :         return rc;
    1933                 :            : }
    1934                 :            : 
    1935                 :            : static int
    1936                 :          0 : test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
    1937                 :            : {
    1938                 :            :         int i;
    1939                 :            :         int rc = 0;
    1940                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1941                 :            : 
    1942                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    1943                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
    1944                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    1945                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    1946                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    1947                 :            : 
    1948         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    1949                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    1950                 :          0 :                 rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
    1951                 :            :         }
    1952                 :            : 
    1953                 :          0 :         return rc;
    1954                 :            : }
    1955                 :            : 
    1956                 :            : static int
    1957                 :          0 : replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
    1958                 :            :         int num_pkts)
    1959                 :            : {
    1960                 :            :         uint16_t j;
    1961                 :            : 
    1962         [ #  # ]:          0 :         for (j = 0; j < num_pkts; j++) {
    1963                 :            :                 /* compare the buffer data */
    1964         [ #  # ]:          0 :                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
    1965                 :            :                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
    1966                 :            :                         test_cfg[i].pkt_sz,
    1967                 :            :                         "input and output data does not match\n");
    1968                 :            : 
    1969         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
    1970                 :            :                         ut_params->obuf[j]->pkt_len,
    1971                 :            :                         "data_len is not equal to pkt_len");
    1972                 :            :         }
    1973                 :            : 
    1974                 :            :         return 0;
    1975                 :            : }
    1976                 :            : 
    1977                 :            : static int
    1978                 :          0 : test_ipsec_replay_inb_inside_null_null(int i)
    1979                 :            : {
    1980                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    1981                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    1982                 :            :         int rc;
    1983                 :            : 
    1984                 :            :         /* create rte_ipsec_sa*/
    1985                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    1986                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    1987         [ #  # ]:          0 :         if (rc != 0) {
    1988                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    1989                 :          0 :                 return rc;
    1990                 :            :         }
    1991                 :            : 
    1992                 :            :         /* Generate inbound mbuf data */
    1993                 :          0 :         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
    1994                 :          0 :                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
    1995         [ #  # ]:          0 :         if (ut_params->ibuf[0] == NULL)
    1996                 :            :                 rc = TEST_FAILED;
    1997                 :            :         else
    1998                 :          0 :                 rc = test_ipsec_crypto_op_alloc(1);
    1999                 :            : 
    2000         [ #  # ]:          0 :         if (rc == 0) {
    2001                 :            :                 /* call ipsec library api */
    2002                 :          0 :                 rc = crypto_ipsec(1);
    2003         [ #  # ]:          0 :                 if (rc == 0)
    2004                 :          0 :                         rc = replay_inb_null_null_check(ut_params, i, 1);
    2005                 :            :                 else {
    2006                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    2007                 :            :                                         i);
    2008                 :            :                         rc = TEST_FAILED;
    2009                 :            :                 }
    2010                 :            :         }
    2011                 :            : 
    2012   [ #  #  #  # ]:          0 :         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
    2013                 :            :                 /* generate packet with seq number inside the replay window */
    2014         [ #  # ]:          0 :                 if (ut_params->ibuf[0]) {
    2015                 :          0 :                         rte_pktmbuf_free(ut_params->ibuf[0]);
    2016                 :          0 :                         ut_params->ibuf[0] = 0;
    2017                 :            :                 }
    2018                 :            : 
    2019                 :          0 :                 ut_params->ibuf[0] = setup_test_string_tunneled(
    2020                 :            :                         ts_params->mbuf_pool, null_encrypted_data,
    2021                 :            :                         test_cfg[i].pkt_sz, INBOUND_SPI,
    2022                 :            :                         test_cfg[i].replay_win_sz);
    2023         [ #  # ]:          0 :                 if (ut_params->ibuf[0] == NULL)
    2024                 :            :                         rc = TEST_FAILED;
    2025                 :            :                 else
    2026                 :          0 :                         rc = test_ipsec_crypto_op_alloc(1);
    2027                 :            : 
    2028         [ #  # ]:          0 :                 if (rc == 0) {
    2029                 :            :                         /* call ipsec library api */
    2030                 :          0 :                         rc = crypto_ipsec(1);
    2031         [ #  # ]:          0 :                         if (rc == 0)
    2032                 :          0 :                                 rc = replay_inb_null_null_check(
    2033                 :            :                                                 ut_params, i, 1);
    2034                 :            :                         else {
    2035                 :          0 :                                 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
    2036                 :            :                                 rc = TEST_FAILED;
    2037                 :            :                         }
    2038                 :            :                 }
    2039                 :            :         }
    2040                 :            : 
    2041         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    2042                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    2043                 :            : 
    2044                 :          0 :         destroy_sa(0);
    2045                 :            : 
    2046                 :          0 :         return rc;
    2047                 :            : }
    2048                 :            : 
    2049                 :            : static int
    2050                 :          0 : test_ipsec_replay_inb_inside_null_null_wrapper(void)
    2051                 :            : {
    2052                 :            :         int i;
    2053                 :            :         int rc = 0;
    2054                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2055                 :            : 
    2056                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    2057                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    2058                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    2059                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    2060                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    2061                 :            : 
    2062         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    2063                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    2064                 :          0 :                 rc = test_ipsec_replay_inb_inside_null_null(i);
    2065                 :            :         }
    2066                 :            : 
    2067                 :          0 :         return rc;
    2068                 :            : }
    2069                 :            : 
    2070                 :            : static int
    2071                 :          0 : test_ipsec_replay_inb_outside_null_null(int i)
    2072                 :            : {
    2073                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    2074                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2075                 :            :         int rc;
    2076                 :            : 
    2077                 :            :         /* create rte_ipsec_sa */
    2078                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2079                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    2080         [ #  # ]:          0 :         if (rc != 0) {
    2081                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    2082                 :          0 :                 return rc;
    2083                 :            :         }
    2084                 :            : 
    2085                 :            :         /* Generate test mbuf data */
    2086                 :          0 :         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
    2087                 :          0 :                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
    2088                 :            :                 test_cfg[i].replay_win_sz + 2);
    2089         [ #  # ]:          0 :         if (ut_params->ibuf[0] == NULL)
    2090                 :            :                 rc = TEST_FAILED;
    2091                 :            :         else
    2092                 :          0 :                 rc = test_ipsec_crypto_op_alloc(1);
    2093                 :            : 
    2094         [ #  # ]:          0 :         if (rc == 0) {
    2095                 :            :                 /* call ipsec library api */
    2096                 :          0 :                 rc = crypto_ipsec(1);
    2097         [ #  # ]:          0 :                 if (rc == 0)
    2098                 :          0 :                         rc = replay_inb_null_null_check(ut_params, i, 1);
    2099                 :            :                 else {
    2100                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    2101                 :            :                                         i);
    2102                 :            :                         rc = TEST_FAILED;
    2103                 :            :                 }
    2104                 :            :         }
    2105                 :            : 
    2106   [ #  #  #  # ]:          0 :         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
    2107                 :            :                 /* generate packet with seq number outside the replay window */
    2108         [ #  # ]:          0 :                 if (ut_params->ibuf[0]) {
    2109                 :          0 :                         rte_pktmbuf_free(ut_params->ibuf[0]);
    2110                 :          0 :                         ut_params->ibuf[0] = 0;
    2111                 :            :                 }
    2112                 :          0 :                 ut_params->ibuf[0] = setup_test_string_tunneled(
    2113                 :            :                         ts_params->mbuf_pool, null_encrypted_data,
    2114                 :            :                         test_cfg[i].pkt_sz, INBOUND_SPI, 1);
    2115         [ #  # ]:          0 :                 if (ut_params->ibuf[0] == NULL)
    2116                 :            :                         rc = TEST_FAILED;
    2117                 :            :                 else
    2118                 :          0 :                         rc = test_ipsec_crypto_op_alloc(1);
    2119                 :            : 
    2120         [ #  # ]:          0 :                 if (rc == 0) {
    2121                 :            :                         /* call ipsec library api */
    2122                 :          0 :                         rc = crypto_ipsec(1);
    2123         [ #  # ]:          0 :                         if (rc == 0) {
    2124         [ #  # ]:          0 :                                 if (test_cfg[i].esn == 0) {
    2125                 :          0 :                                         RTE_LOG(ERR, USER1,
    2126                 :            :                                                 "packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
    2127                 :            :                                                 i,
    2128                 :            :                                                 test_cfg[i].replay_win_sz + 2,
    2129                 :            :                                                 1);
    2130                 :            :                                         rc = TEST_FAILED;
    2131                 :            :                                 }
    2132                 :            :                         } else {
    2133                 :          0 :                                 RTE_LOG(ERR, USER1,
    2134                 :            :                                         "packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
    2135                 :            :                                         i, test_cfg[i].replay_win_sz + 2, 1);
    2136                 :            :                                 rc = 0;
    2137                 :            :                         }
    2138                 :            :                 }
    2139                 :            :         }
    2140                 :            : 
    2141         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    2142                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    2143                 :            : 
    2144                 :          0 :         destroy_sa(0);
    2145                 :            : 
    2146                 :          0 :         return rc;
    2147                 :            : }
    2148                 :            : 
    2149                 :            : static int
    2150                 :          0 : test_ipsec_replay_inb_outside_null_null_wrapper(void)
    2151                 :            : {
    2152                 :            :         int i;
    2153                 :            :         int rc = 0;
    2154                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2155                 :            : 
    2156                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    2157                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    2158                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    2159                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    2160                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    2161                 :            : 
    2162         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    2163                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    2164                 :          0 :                 rc = test_ipsec_replay_inb_outside_null_null(i);
    2165                 :            :         }
    2166                 :            : 
    2167                 :          0 :         return rc;
    2168                 :            : }
    2169                 :            : 
    2170                 :            : static int
    2171                 :          0 : test_ipsec_replay_inb_repeat_null_null(int i)
    2172                 :            : {
    2173                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    2174                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2175                 :            :         int rc;
    2176                 :            : 
    2177                 :            :         /* create rte_ipsec_sa */
    2178                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2179                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    2180         [ #  # ]:          0 :         if (rc != 0) {
    2181                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    2182                 :          0 :                 return rc;
    2183                 :            :         }
    2184                 :            : 
    2185                 :            :         /* Generate test mbuf data */
    2186                 :          0 :         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
    2187                 :          0 :                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
    2188         [ #  # ]:          0 :         if (ut_params->ibuf[0] == NULL)
    2189                 :            :                 rc = TEST_FAILED;
    2190                 :            :         else
    2191                 :          0 :                 rc = test_ipsec_crypto_op_alloc(1);
    2192                 :            : 
    2193         [ #  # ]:          0 :         if (rc == 0) {
    2194                 :            :                 /* call ipsec library api */
    2195                 :          0 :                 rc = crypto_ipsec(1);
    2196         [ #  # ]:          0 :                 if (rc == 0)
    2197                 :          0 :                         rc = replay_inb_null_null_check(ut_params, i, 1);
    2198                 :            :                 else {
    2199                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    2200                 :            :                                         i);
    2201                 :            :                         rc = TEST_FAILED;
    2202                 :            :                 }
    2203                 :            :         }
    2204                 :            : 
    2205   [ #  #  #  # ]:          0 :         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
    2206                 :            :                 /*
    2207                 :            :                  * generate packet with repeat seq number in the replay
    2208                 :            :                  * window
    2209                 :            :                  */
    2210         [ #  # ]:          0 :                 if (ut_params->ibuf[0]) {
    2211                 :          0 :                         rte_pktmbuf_free(ut_params->ibuf[0]);
    2212                 :          0 :                         ut_params->ibuf[0] = 0;
    2213                 :            :                 }
    2214                 :            : 
    2215                 :          0 :                 ut_params->ibuf[0] = setup_test_string_tunneled(
    2216                 :            :                         ts_params->mbuf_pool, null_encrypted_data,
    2217                 :            :                         test_cfg[i].pkt_sz, INBOUND_SPI, 1);
    2218         [ #  # ]:          0 :                 if (ut_params->ibuf[0] == NULL)
    2219                 :            :                         rc = TEST_FAILED;
    2220                 :            :                 else
    2221                 :          0 :                         rc = test_ipsec_crypto_op_alloc(1);
    2222                 :            : 
    2223         [ #  # ]:          0 :                 if (rc == 0) {
    2224                 :            :                         /* call ipsec library api */
    2225                 :          0 :                         rc = crypto_ipsec(1);
    2226         [ #  # ]:          0 :                         if (rc == 0) {
    2227                 :          0 :                                 RTE_LOG(ERR, USER1,
    2228                 :            :                                         "packet is not repeated in the replay window, cfg %d seq %u\n",
    2229                 :            :                                         i, 1);
    2230                 :            :                                 rc = TEST_FAILED;
    2231                 :            :                         } else {
    2232                 :          0 :                                 RTE_LOG(ERR, USER1,
    2233                 :            :                                         "packet is repeated in the replay window, cfg %d seq %u\n",
    2234                 :            :                                         i, 1);
    2235                 :            :                                 rc = 0;
    2236                 :            :                         }
    2237                 :            :                 }
    2238                 :            :         }
    2239                 :            : 
    2240         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    2241                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    2242                 :            : 
    2243                 :          0 :         destroy_sa(0);
    2244                 :            : 
    2245                 :          0 :         return rc;
    2246                 :            : }
    2247                 :            : 
    2248                 :            : static int
    2249                 :          0 : test_ipsec_replay_inb_repeat_null_null_wrapper(void)
    2250                 :            : {
    2251                 :            :         int i;
    2252                 :            :         int rc = 0;
    2253                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2254                 :            : 
    2255                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    2256                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    2257                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    2258                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    2259                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    2260                 :            : 
    2261         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    2262                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    2263                 :          0 :                 rc = test_ipsec_replay_inb_repeat_null_null(i);
    2264                 :            :         }
    2265                 :            : 
    2266                 :          0 :         return rc;
    2267                 :            : }
    2268                 :            : 
    2269                 :            : static int
    2270                 :          0 : test_ipsec_replay_inb_inside_burst_null_null(int i)
    2271                 :            : {
    2272                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    2273                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2274                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    2275                 :            :         int rc;
    2276                 :            :         int j;
    2277                 :            : 
    2278                 :            :         /* create rte_ipsec_sa*/
    2279                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2280                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    2281         [ #  # ]:          0 :         if (rc != 0) {
    2282                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
    2283                 :          0 :                 return rc;
    2284                 :            :         }
    2285                 :            : 
    2286                 :            :         /* Generate inbound mbuf data */
    2287                 :          0 :         ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
    2288                 :          0 :                 null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
    2289         [ #  # ]:          0 :         if (ut_params->ibuf[0] == NULL)
    2290                 :            :                 rc = TEST_FAILED;
    2291                 :            :         else
    2292                 :          0 :                 rc = test_ipsec_crypto_op_alloc(1);
    2293                 :            : 
    2294         [ #  # ]:          0 :         if (rc == 0) {
    2295                 :            :                 /* call ipsec library api */
    2296                 :          0 :                 rc = crypto_ipsec(1);
    2297         [ #  # ]:          0 :                 if (rc == 0)
    2298                 :          0 :                         rc = replay_inb_null_null_check(ut_params, i, 1);
    2299                 :            :                 else {
    2300                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    2301                 :            :                                         i);
    2302                 :            :                         rc = TEST_FAILED;
    2303                 :            :                 }
    2304                 :            :         }
    2305                 :            : 
    2306   [ #  #  #  # ]:          0 :         if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
    2307                 :            :                 /*
    2308                 :            :                  *  generate packet(s) with seq number(s) inside the
    2309                 :            :                  *  replay window
    2310                 :            :                  */
    2311         [ #  # ]:          0 :                 if (ut_params->ibuf[0]) {
    2312                 :          0 :                         rte_pktmbuf_free(ut_params->ibuf[0]);
    2313                 :          0 :                         ut_params->ibuf[0] = 0;
    2314                 :            :                 }
    2315                 :            : 
    2316   [ #  #  #  # ]:          0 :                 for (j = 0; j < num_pkts && rc == 0; j++) {
    2317                 :            :                         /* packet with sequence number 1 already processed */
    2318                 :          0 :                         ut_params->ibuf[j] = setup_test_string_tunneled(
    2319                 :            :                                 ts_params->mbuf_pool, null_encrypted_data,
    2320                 :          0 :                                 test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
    2321         [ #  # ]:          0 :                         if (ut_params->ibuf[j] == NULL)
    2322                 :            :                                 rc = TEST_FAILED;
    2323                 :            :                 }
    2324                 :            : 
    2325         [ #  # ]:          0 :                 if (rc == 0) {
    2326         [ #  # ]:          0 :                         if (test_cfg[i].reorder_pkts)
    2327                 :          0 :                                 test_ipsec_reorder_inb_pkt_burst(num_pkts);
    2328                 :          0 :                         rc = test_ipsec_crypto_op_alloc(num_pkts);
    2329                 :            :                 }
    2330                 :            : 
    2331         [ #  # ]:          0 :                 if (rc == 0) {
    2332                 :            :                         /* call ipsec library api */
    2333                 :          0 :                         rc = crypto_ipsec(num_pkts);
    2334         [ #  # ]:          0 :                         if (rc == 0)
    2335                 :          0 :                                 rc = replay_inb_null_null_check(
    2336                 :            :                                                 ut_params, i, num_pkts);
    2337                 :            :                         else {
    2338                 :          0 :                                 RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
    2339                 :            :                                 rc = TEST_FAILED;
    2340                 :            :                         }
    2341                 :            :                 }
    2342                 :            :         }
    2343                 :            : 
    2344         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    2345                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    2346                 :            : 
    2347                 :          0 :         destroy_sa(0);
    2348                 :            : 
    2349                 :          0 :         return rc;
    2350                 :            : }
    2351                 :            : 
    2352                 :            : static int
    2353                 :          0 : test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
    2354                 :            : {
    2355                 :            :         int i;
    2356                 :            :         int rc = 0;
    2357                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2358                 :            : 
    2359                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    2360                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    2361                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    2362                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    2363                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    2364                 :            : 
    2365         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    2366                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    2367                 :          0 :                 rc = test_ipsec_replay_inb_inside_burst_null_null(i);
    2368                 :            :         }
    2369                 :            : 
    2370                 :          0 :         return rc;
    2371                 :            : }
    2372                 :            : 
    2373                 :            : 
    2374                 :            : static int
    2375                 :          0 : crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
    2376                 :            :                 int i)
    2377                 :            : {
    2378                 :            :         uint16_t j;
    2379                 :            : 
    2380         [ #  # ]:          0 :         for (j = 0; j < BURST_SIZE; j++) {
    2381                 :          0 :                 ut_params->pkt_index = j;
    2382                 :            : 
    2383                 :            :                 /* compare the data buffers */
    2384         [ #  # ]:          0 :                 TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
    2385                 :            :                         rte_pktmbuf_mtod(ut_params->obuf[j], void *),
    2386                 :            :                         test_cfg[i].pkt_sz,
    2387                 :            :                         "input and output data does not match\n");
    2388         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
    2389                 :            :                         ut_params->obuf[j]->pkt_len,
    2390                 :            :                         "data_len is not equal to pkt_len");
    2391         [ #  # ]:          0 :                 TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
    2392                 :            :                         test_cfg[i].pkt_sz,
    2393                 :            :                         "data_len is not equal to input data");
    2394                 :            :         }
    2395                 :            : 
    2396                 :            :         return 0;
    2397                 :            : }
    2398                 :            : 
    2399                 :            : static int
    2400                 :          0 : test_ipsec_crypto_inb_burst_2sa_null_null(int i)
    2401                 :            : {
    2402                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    2403                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2404                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    2405                 :            :         uint16_t j, r;
    2406                 :            :         int rc = 0;
    2407                 :            : 
    2408         [ #  # ]:          0 :         if (num_pkts != BURST_SIZE)
    2409                 :            :                 return rc;
    2410                 :            : 
    2411                 :            :         /* create rte_ipsec_sa */
    2412                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2413                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    2414         [ #  # ]:          0 :         if (rc != 0) {
    2415                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
    2416                 :          0 :                 return rc;
    2417                 :            :         }
    2418                 :            : 
    2419                 :            :         /* create second rte_ipsec_sa */
    2420                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
    2421                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2422                 :            :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
    2423         [ #  # ]:          0 :         if (rc != 0) {
    2424                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
    2425                 :          0 :                 destroy_sa(0);
    2426                 :          0 :                 return rc;
    2427                 :            :         }
    2428                 :            : 
    2429                 :            :         /* Generate test mbuf data */
    2430         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    2431                 :          0 :                 r = j % 2;
    2432                 :            :                 /* packet with sequence number 0 is invalid */
    2433                 :          0 :                 ut_params->ibuf[j] = setup_test_string_tunneled(
    2434                 :            :                         ts_params->mbuf_pool, null_encrypted_data,
    2435                 :          0 :                         test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
    2436         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    2437                 :            :                         rc = TEST_FAILED;
    2438                 :            :         }
    2439                 :            : 
    2440         [ #  # ]:          0 :         if (rc == 0)
    2441                 :          0 :                 rc = test_ipsec_crypto_op_alloc(num_pkts);
    2442                 :            : 
    2443         [ #  # ]:          0 :         if (rc == 0) {
    2444                 :            :                 /* call ipsec library api */
    2445                 :          0 :                 rc = crypto_ipsec_2sa();
    2446         [ #  # ]:          0 :                 if (rc == 0)
    2447                 :          0 :                         rc = crypto_inb_burst_2sa_null_null_check(
    2448                 :            :                                         ut_params, i);
    2449                 :            :                 else {
    2450                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    2451                 :            :                                 i);
    2452                 :            :                         rc = TEST_FAILED;
    2453                 :            :                 }
    2454                 :            :         }
    2455                 :            : 
    2456         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    2457                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    2458                 :            : 
    2459                 :          0 :         destroy_sa(0);
    2460                 :          0 :         destroy_sa(1);
    2461                 :          0 :         return rc;
    2462                 :            : }
    2463                 :            : 
    2464                 :            : static int
    2465                 :          0 : test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
    2466                 :            : {
    2467                 :            :         int i;
    2468                 :            :         int rc = 0;
    2469                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2470                 :            : 
    2471                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    2472                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    2473                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    2474                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    2475                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    2476                 :            : 
    2477         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    2478                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    2479                 :          0 :                 rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
    2480                 :            :         }
    2481                 :            : 
    2482                 :          0 :         return rc;
    2483                 :            : }
    2484                 :            : 
    2485                 :            : static int
    2486                 :          0 : test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
    2487                 :            : {
    2488                 :            :         struct ipsec_testsuite_params *ts_params = &testsuite_params;
    2489                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2490                 :          0 :         uint16_t num_pkts = test_cfg[i].num_pkts;
    2491                 :            :         uint16_t j, k;
    2492                 :            :         int rc = 0;
    2493                 :            : 
    2494         [ #  # ]:          0 :         if (num_pkts != BURST_SIZE)
    2495                 :            :                 return rc;
    2496                 :            : 
    2497                 :            :         /* create rte_ipsec_sa */
    2498                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2499                 :          0 :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
    2500         [ #  # ]:          0 :         if (rc != 0) {
    2501                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
    2502                 :          0 :                 return rc;
    2503                 :            :         }
    2504                 :            : 
    2505                 :            :         /* create second rte_ipsec_sa */
    2506                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
    2507                 :          0 :         rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
    2508                 :            :                         test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
    2509         [ #  # ]:          0 :         if (rc != 0) {
    2510                 :          0 :                 RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
    2511                 :          0 :                 destroy_sa(0);
    2512                 :          0 :                 return rc;
    2513                 :            :         }
    2514                 :            : 
    2515                 :            :         /* Generate test mbuf data */
    2516         [ #  # ]:          0 :         for (j = 0; j < num_pkts && rc == 0; j++) {
    2517         [ #  # ]:          0 :                 k = crypto_ipsec_4grp(j);
    2518                 :            : 
    2519                 :            :                 /* packet with sequence number 0 is invalid */
    2520                 :          0 :                 ut_params->ibuf[j] = setup_test_string_tunneled(
    2521                 :            :                         ts_params->mbuf_pool, null_encrypted_data,
    2522                 :          0 :                         test_cfg[i].pkt_sz, INBOUND_SPI + k, j + 1);
    2523         [ #  # ]:          0 :                 if (ut_params->ibuf[j] == NULL)
    2524                 :            :                         rc = TEST_FAILED;
    2525                 :            :         }
    2526                 :            : 
    2527         [ #  # ]:          0 :         if (rc == 0)
    2528                 :          0 :                 rc = test_ipsec_crypto_op_alloc(num_pkts);
    2529                 :            : 
    2530         [ #  # ]:          0 :         if (rc == 0) {
    2531                 :            :                 /* call ipsec library api */
    2532                 :          0 :                 rc = crypto_ipsec_2sa_4grp();
    2533         [ #  # ]:          0 :                 if (rc == 0)
    2534                 :          0 :                         rc = crypto_inb_burst_2sa_null_null_check(
    2535                 :            :                                         ut_params, i);
    2536                 :            :                 else {
    2537                 :          0 :                         RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
    2538                 :            :                                 i);
    2539                 :            :                         rc = TEST_FAILED;
    2540                 :            :                 }
    2541                 :            :         }
    2542                 :            : 
    2543         [ #  # ]:          0 :         if (rc == TEST_FAILED)
    2544                 :          0 :                 test_ipsec_dump_buffers(ut_params, i);
    2545                 :            : 
    2546                 :          0 :         destroy_sa(0);
    2547                 :          0 :         destroy_sa(1);
    2548                 :          0 :         return rc;
    2549                 :            : }
    2550                 :            : 
    2551                 :            : static int
    2552                 :          0 : test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper(void)
    2553                 :            : {
    2554                 :            :         int i;
    2555                 :            :         int rc = 0;
    2556                 :            :         struct ipsec_unitest_params *ut_params = &unittest_params;
    2557                 :            : 
    2558                 :          0 :         ut_params->ipsec_xform.spi = INBOUND_SPI;
    2559                 :          0 :         ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
    2560                 :          0 :         ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
    2561                 :          0 :         ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
    2562                 :          0 :         ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
    2563                 :            : 
    2564         [ #  # ]:          0 :         for (i = 0; i < num_cfg && rc == 0; i++) {
    2565                 :          0 :                 ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
    2566                 :          0 :                 rc = test_ipsec_crypto_inb_burst_2sa_4grp_null_null(i);
    2567                 :            :         }
    2568                 :            : 
    2569                 :          0 :         return rc;
    2570                 :            : }
    2571                 :            : 
    2572                 :            : static struct unit_test_suite ipsec_testsuite  = {
    2573                 :            :         .suite_name = "IPsec NULL Unit Test Suite",
    2574                 :            :         .setup = testsuite_setup,
    2575                 :            :         .teardown = testsuite_teardown,
    2576                 :            :         .unit_test_cases = {
    2577                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2578                 :            :                         test_ipsec_crypto_inb_burst_null_null_wrapper),
    2579                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2580                 :            :                         test_ipsec_crypto_outb_burst_null_null_wrapper),
    2581                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2582                 :            :                         test_ipsec_crypto_outb_burst_stateless_null_null_wrapper),
    2583                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2584                 :            :                         test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
    2585                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2586                 :            :                         test_ipsec_inline_crypto_outb_burst_null_null_wrapper),
    2587                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2588                 :            :                         test_ipsec_inline_proto_inb_burst_null_null_wrapper),
    2589                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2590                 :            :                         test_ipsec_inline_proto_outb_burst_null_null_wrapper),
    2591                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2592                 :            :                         test_ipsec_lksd_proto_inb_burst_null_null_wrapper),
    2593                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2594                 :            :                         test_ipsec_lksd_proto_outb_burst_null_null_wrapper),
    2595                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2596                 :            :                         test_ipsec_replay_inb_inside_null_null_wrapper),
    2597                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2598                 :            :                         test_ipsec_replay_inb_outside_null_null_wrapper),
    2599                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2600                 :            :                         test_ipsec_replay_inb_repeat_null_null_wrapper),
    2601                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2602                 :            :                         test_ipsec_replay_inb_inside_burst_null_null_wrapper),
    2603                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2604                 :            :                         test_ipsec_crypto_inb_burst_2sa_null_null_wrapper),
    2605                 :            :                 TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
    2606                 :            :                         test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper),
    2607                 :            :                 TEST_CASES_END() /**< NULL terminate unit test array */
    2608                 :            :         }
    2609                 :            : };
    2610                 :            : 
    2611                 :            : static int
    2612                 :          1 : test_ipsec(void)
    2613                 :            : {
    2614                 :          1 :         return unit_test_suite_runner(&ipsec_testsuite);
    2615                 :            : }
    2616                 :            : 
    2617                 :            : #endif /* !RTE_EXEC_ENV_WINDOWS */
    2618                 :            : 
    2619                 :        301 : REGISTER_FAST_TEST(ipsec_autotest, NOHUGE_OK, ASAN_OK, test_ipsec);

Generated by: LCOV version 1.14