LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/accel/dpdk_compressdev.c - accel_dpdk_compressdev_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 532 568 93.7 %
Date: 2024-07-10 23:02:33 Functions: 33 42 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 78 106 73.6 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2018 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  *   Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "spdk_internal/cunit.h"
       8                 :            : /* We have our own mock for this */
       9                 :            : #define UNIT_TEST_NO_VTOPHYS
      10                 :            : #include "common/lib/test_env.c"
      11                 :            : #include "spdk_internal/mock.h"
      12                 :            : #include "thread/thread_internal.h"
      13                 :            : #include "unit/lib/json_mock.c"
      14                 :            : 
      15                 :            : #include <rte_compressdev.h>
      16                 :            : 
      17                 :            : /* There will be one if the data perfectly matches the chunk size,
      18                 :            :  * or there could be an offset into the data and a remainder after
      19                 :            :  * the data or both for a max of 3.
      20                 :            :  */
      21                 :            : #define UT_MBUFS_PER_OP 3
      22                 :            : /* For testing the crossing of a huge page boundary on address translation,
      23                 :            :  * we'll have an extra one but we only test on the source side.
      24                 :            :  */
      25                 :            : #define UT_MBUFS_PER_OP_BOUND_TEST 4
      26                 :            : 
      27                 :            : struct spdk_io_channel *g_io_ch;
      28                 :            : struct rte_comp_op g_comp_op[2];
      29                 :            : struct comp_device_qp g_device_qp;
      30                 :            : struct compress_dev g_device;
      31                 :            : struct rte_compressdev_capabilities g_cdev_cap;
      32                 :            : static struct rte_mbuf *g_src_mbufs[UT_MBUFS_PER_OP_BOUND_TEST];
      33                 :            : static struct rte_mbuf *g_dst_mbufs[UT_MBUFS_PER_OP];
      34                 :            : static struct rte_mbuf g_expected_src_mbufs[UT_MBUFS_PER_OP_BOUND_TEST];
      35                 :            : static struct rte_mbuf g_expected_dst_mbufs[UT_MBUFS_PER_OP];
      36                 :            : struct compress_io_channel *g_comp_ch;
      37                 :            : 
      38                 :            : /* Those functions are defined as static inline in DPDK, so we can't
      39                 :            :  * mock them straight away. We use defines to redirect them into
      40                 :            :  * our custom functions.
      41                 :            :  */
      42                 :            : 
      43                 :            : static int ut_total_rte_pktmbuf_attach_extbuf = 0;
      44                 :            : static void mock_rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr, rte_iova_t buf_iova,
      45                 :            :                 uint16_t buf_len, struct rte_mbuf_ext_shared_info *shinfo);
      46                 :            : #define rte_pktmbuf_attach_extbuf mock_rte_pktmbuf_attach_extbuf
      47                 :            : static void
      48                 :        142 : mock_rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr, rte_iova_t buf_iova,
      49                 :            :                                uint16_t buf_len, struct rte_mbuf_ext_shared_info *shinfo)
      50                 :            : {
      51         [ -  + ]:        142 :         assert(m != NULL);
      52                 :        142 :         m->buf_addr = buf_addr;
      53                 :        142 :         m->buf_iova = buf_iova;
      54                 :        142 :         m->buf_len = buf_len;
      55                 :        142 :         m->data_len = m->pkt_len = 0;
      56                 :        142 :         ut_total_rte_pktmbuf_attach_extbuf++;
      57                 :        142 : }
      58                 :            : 
      59                 :            : static char *mock_rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len);
      60                 :            : #define rte_pktmbuf_append mock_rte_pktmbuf_append
      61                 :            : static char *
      62                 :        142 : mock_rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
      63                 :            : {
      64                 :        142 :         m->pkt_len = m->pkt_len + len;
      65                 :        142 :         return NULL;
      66                 :            : }
      67                 :            : 
      68                 :            : static inline int mock_rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail);
      69                 :            : #define rte_pktmbuf_chain mock_rte_pktmbuf_chain
      70                 :            : static inline int
      71                 :         96 : mock_rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail)
      72                 :            : {
      73                 :            :         struct rte_mbuf *cur_tail;
      74                 :            : 
      75                 :         96 :         cur_tail = rte_pktmbuf_lastseg(head);
      76                 :         96 :         cur_tail->next = tail;
      77                 :            : 
      78                 :         96 :         return 0;
      79                 :            : }
      80                 :            : 
      81                 :            : uint16_t ut_max_nb_queue_pairs = 0;
      82                 :            : void __rte_experimental mock_rte_compressdev_info_get(uint8_t dev_id,
      83                 :            :                 struct rte_compressdev_info *dev_info);
      84                 :            : #define rte_compressdev_info_get mock_rte_compressdev_info_get
      85                 :            : void __rte_experimental
      86                 :         12 : mock_rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info)
      87                 :            : {
      88                 :         12 :         dev_info->max_nb_queue_pairs = ut_max_nb_queue_pairs;
      89                 :         12 :         dev_info->capabilities = &g_cdev_cap;
      90                 :         12 :         dev_info->driver_name = "compressdev";
      91                 :         12 : }
      92                 :            : 
      93                 :            : int ut_rte_compressdev_configure = 0;
      94                 :            : int __rte_experimental mock_rte_compressdev_configure(uint8_t dev_id,
      95                 :            :                 struct rte_compressdev_config *config);
      96                 :            : #define rte_compressdev_configure mock_rte_compressdev_configure
      97                 :            : int __rte_experimental
      98                 :         12 : mock_rte_compressdev_configure(uint8_t dev_id, struct rte_compressdev_config *config)
      99                 :            : {
     100                 :         12 :         return ut_rte_compressdev_configure;
     101                 :            : }
     102                 :            : 
     103                 :            : int ut_rte_compressdev_queue_pair_setup = 0;
     104                 :            : int __rte_experimental mock_rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
     105                 :            :                 uint32_t max_inflight_ops, int socket_id);
     106                 :            : #define rte_compressdev_queue_pair_setup mock_rte_compressdev_queue_pair_setup
     107                 :            : int __rte_experimental
     108                 :        290 : mock_rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
     109                 :            :                                       uint32_t max_inflight_ops, int socket_id)
     110                 :            : {
     111                 :        290 :         return ut_rte_compressdev_queue_pair_setup;
     112                 :            : }
     113                 :            : 
     114                 :            : int ut_rte_compressdev_start = 0;
     115                 :            : int __rte_experimental mock_rte_compressdev_start(uint8_t dev_id);
     116                 :            : #define rte_compressdev_start mock_rte_compressdev_start
     117                 :            : int __rte_experimental
     118                 :          6 : mock_rte_compressdev_start(uint8_t dev_id)
     119                 :            : {
     120                 :          6 :         return ut_rte_compressdev_start;
     121                 :            : }
     122                 :            : 
     123                 :            : int ut_rte_compressdev_private_xform_create = 0;
     124                 :            : int __rte_experimental mock_rte_compressdev_private_xform_create(uint8_t dev_id,
     125                 :            :                 const struct rte_comp_xform *xform, void **private_xform);
     126                 :            : #define rte_compressdev_private_xform_create mock_rte_compressdev_private_xform_create
     127                 :            : int __rte_experimental
     128                 :          6 : mock_rte_compressdev_private_xform_create(uint8_t dev_id,
     129                 :            :                 const struct rte_comp_xform *xform, void **private_xform)
     130                 :            : {
     131                 :          6 :         return ut_rte_compressdev_private_xform_create;
     132                 :            : }
     133                 :            : 
     134                 :            : uint8_t ut_rte_compressdev_count = 0;
     135                 :            : uint8_t __rte_experimental mock_rte_compressdev_count(void);
     136                 :            : #define rte_compressdev_count mock_rte_compressdev_count
     137                 :            : uint8_t __rte_experimental
     138                 :         18 : mock_rte_compressdev_count(void)
     139                 :            : {
     140                 :         18 :         return ut_rte_compressdev_count;
     141                 :            : }
     142                 :            : 
     143                 :            : struct rte_mempool *ut_rte_comp_op_pool_create = NULL;
     144                 :            : struct rte_mempool *__rte_experimental mock_rte_comp_op_pool_create(const char *name,
     145                 :            :                 unsigned int nb_elts, unsigned int cache_size, uint16_t user_size,
     146                 :            :                 int socket_id);
     147                 :            : #define rte_comp_op_pool_create mock_rte_comp_op_pool_create
     148                 :            : struct rte_mempool *__rte_experimental
     149                 :         12 : mock_rte_comp_op_pool_create(const char *name, unsigned int nb_elts,
     150                 :            :                              unsigned int cache_size, uint16_t user_size, int socket_id)
     151                 :            : {
     152                 :         12 :         return ut_rte_comp_op_pool_create;
     153                 :            : }
     154                 :            : 
     155                 :            : void mock_rte_pktmbuf_free(struct rte_mbuf *m);
     156                 :            : #define rte_pktmbuf_free mock_rte_pktmbuf_free
     157                 :            : void
     158                 :         16 : mock_rte_pktmbuf_free(struct rte_mbuf *m)
     159                 :            : {
     160                 :         16 : }
     161                 :            : 
     162                 :            : void mock_rte_pktmbuf_free_bulk(struct rte_mbuf **m, unsigned int cnt);
     163                 :            : #define rte_pktmbuf_free_bulk mock_rte_pktmbuf_free_bulk
     164                 :            : void
     165                 :         24 : mock_rte_pktmbuf_free_bulk(struct rte_mbuf **m, unsigned int cnt)
     166                 :            : {
     167                 :         24 : }
     168                 :            : 
     169                 :            : static bool ut_boundary_alloc = false;
     170                 :            : static int ut_rte_pktmbuf_alloc_bulk = 0;
     171                 :            : int mock_rte_pktmbuf_alloc_bulk(struct rte_mempool *pool, struct rte_mbuf **mbufs,
     172                 :            :                                 unsigned count);
     173                 :            : #define rte_pktmbuf_alloc_bulk mock_rte_pktmbuf_alloc_bulk
     174                 :            : int
     175                 :         56 : mock_rte_pktmbuf_alloc_bulk(struct rte_mempool *pool, struct rte_mbuf **mbufs,
     176                 :            :                             unsigned count)
     177                 :            : {
     178                 :            :         int i;
     179                 :            : 
     180                 :            :         /* This mocked function only supports the alloc of up to 3 src and 3 dst. */
     181                 :         56 :         ut_rte_pktmbuf_alloc_bulk += count;
     182                 :            : 
     183         [ +  + ]:         56 :         if (ut_rte_pktmbuf_alloc_bulk == 1) {
     184                 :            :                 /* allocation of an extra mbuf for boundary cross test */
     185                 :         10 :                 ut_boundary_alloc = true;
     186                 :         10 :                 g_src_mbufs[UT_MBUFS_PER_OP_BOUND_TEST - 1]->next = NULL;
     187                 :         10 :                 *mbufs = g_src_mbufs[UT_MBUFS_PER_OP_BOUND_TEST - 1];
     188                 :         10 :                 ut_rte_pktmbuf_alloc_bulk = 0;
     189         [ +  + ]:         46 :         } else if (ut_rte_pktmbuf_alloc_bulk == UT_MBUFS_PER_OP) {
     190                 :            :                 /* first test allocation, src mbufs */
     191         [ +  + ]:         88 :                 for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     192                 :         66 :                         g_src_mbufs[i]->next = NULL;
     193                 :         66 :                         *mbufs++ = g_src_mbufs[i];
     194                 :            :                 }
     195         [ +  + ]:         24 :         } else if (ut_rte_pktmbuf_alloc_bulk == UT_MBUFS_PER_OP * 2) {
     196                 :            :                 /* second test allocation, dst mbufs */
     197         [ +  + ]:         88 :                 for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     198                 :         66 :                         g_dst_mbufs[i]->next = NULL;
     199                 :         66 :                         *mbufs++ = g_dst_mbufs[i];
     200                 :            :                 }
     201                 :         22 :                 ut_rte_pktmbuf_alloc_bulk = 0;
     202                 :            :         } else {
     203                 :          2 :                 return -1;
     204                 :            :         }
     205                 :         54 :         return 0;
     206                 :            : }
     207                 :            : 
     208                 :            : struct rte_mempool *
     209                 :         12 : rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size,
     210                 :            :                         uint16_t priv_size, uint16_t data_room_size, int socket_id)
     211                 :            : {
     212                 :            :         struct spdk_mempool *tmp;
     213                 :            : 
     214                 :         12 :         tmp = spdk_mempool_create("mbuf_mp", 1024, sizeof(struct rte_mbuf),
     215                 :            :                                   SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
     216                 :            :                                   SPDK_ENV_SOCKET_ID_ANY);
     217                 :            : 
     218                 :         12 :         return (struct rte_mempool *)tmp;
     219                 :            : }
     220                 :            : 
     221                 :            : void
     222                 :         10 : rte_mempool_free(struct rte_mempool *mp)
     223                 :            : {
     224         [ +  - ]:         10 :         if (mp) {
     225                 :         10 :                 spdk_mempool_free((struct spdk_mempool *)mp);
     226                 :            :         }
     227                 :         10 : }
     228                 :            : 
     229                 :            : #include "accel/dpdk_compressdev/accel_dpdk_compressdev.c"
     230                 :            : 
     231                 :            : static void _compress_done(void *arg, int status);
     232                 :            : static int ut_expected_task_status = 0;
     233                 :            : void
     234                 :          8 : spdk_accel_task_complete(struct spdk_accel_task *accel_task, int status)
     235                 :            : {
     236                 :          8 :         CU_ASSERT(status == ut_expected_task_status);
     237                 :          8 :         accel_task->cb_fn(accel_task, status);
     238                 :          8 : }
     239                 :            : 
     240                 :            : /* SPDK stubs */
     241                 :          0 : DEFINE_STUB_V(spdk_accel_module_finish, (void));
     242                 :          0 : DEFINE_STUB_V(spdk_accel_module_list_add, (struct spdk_accel_module_if *accel_module));
     243                 :            : 
     244                 :            : /* DPDK stubs */
     245         [ #  # ]:          0 : DEFINE_STUB(rte_compressdev_capability_get, const struct rte_compressdev_capabilities *,
     246                 :            :             (uint8_t dev_id,
     247                 :            :              enum rte_comp_algorithm algo), NULL);
     248                 :            : #define DPDK_DYNFIELD_OFFSET offsetof(struct rte_mbuf, dynfield1[1])
     249         [ -  + ]:         14 : DEFINE_STUB(rte_mbuf_dynfield_register, int, (const struct rte_mbuf_dynfield *params),
     250                 :            :             DPDK_DYNFIELD_OFFSET);
     251         [ -  + ]:        326 : DEFINE_STUB(rte_socket_id, unsigned, (void), 0);
     252         [ #  # ]:          0 : DEFINE_STUB(rte_vdev_init, int, (const char *name, const char *args), 0);
     253                 :         22 : DEFINE_STUB_V(rte_comp_op_free, (struct rte_comp_op *op));
     254         [ -  + ]:         26 : DEFINE_STUB(rte_comp_op_alloc, struct rte_comp_op *, (struct rte_mempool *mempool), NULL);
     255                 :            : 
     256                 :            : int g_small_size_counter = 0;
     257                 :            : int g_small_size_modify = 0;
     258                 :            : uint64_t g_small_size = 0;
     259                 :            : uint64_t
     260                 :        178 : spdk_vtophys(const void *buf, uint64_t *size)
     261                 :            : {
     262                 :        178 :         g_small_size_counter++;
     263         [ +  + ]:        178 :         if (g_small_size_counter == g_small_size_modify) {
     264                 :         10 :                 *size = g_small_size;
     265                 :         10 :                 g_small_size_counter = 0;
     266                 :         10 :                 g_small_size_modify = 0;
     267                 :            :         }
     268                 :        178 :         return (uint64_t)buf;
     269                 :            : }
     270                 :            : 
     271                 :            : static uint16_t ut_rte_compressdev_dequeue_burst = 0;
     272                 :            : uint16_t
     273                 :          6 : rte_compressdev_dequeue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_comp_op **ops,
     274                 :            :                               uint16_t nb_op)
     275                 :            : {
     276         [ -  + ]:          6 :         if (ut_rte_compressdev_dequeue_burst == 0) {
     277                 :          0 :                 return 0;
     278                 :            :         }
     279                 :            : 
     280                 :          6 :         ops[0] = &g_comp_op[0];
     281                 :          6 :         ops[1] = &g_comp_op[1];
     282                 :            : 
     283                 :          6 :         return ut_rte_compressdev_dequeue_burst;
     284                 :            : }
     285                 :            : 
     286                 :            : static uint16_t g_done_count = 1;
     287                 :            : static void
     288                 :          8 : _compress_done(void *arg, int status)
     289                 :            : {
     290                 :          8 :         struct spdk_accel_task *task  = arg;
     291                 :            : 
     292         [ +  + ]:          8 :         if (status == 0) {
     293                 :          6 :                 CU_ASSERT(*task->output_size == g_comp_op[g_done_count++].produced);
     294                 :            :         }
     295                 :          8 : }
     296                 :            : 
     297                 :            : static void
     298                 :         14 : _get_mbuf_array(struct rte_mbuf **mbuf_array, struct rte_mbuf *mbuf_head,
     299                 :            :                 int mbuf_count, bool null_final)
     300                 :            : {
     301                 :            :         int i;
     302                 :            : 
     303         [ +  + ]:         62 :         for (i = 0; i < mbuf_count; i++) {
     304                 :         48 :                 mbuf_array[i] = mbuf_head;
     305         [ +  + ]:         48 :                 if (mbuf_head) {
     306                 :         46 :                         mbuf_head = mbuf_head->next;
     307                 :            :                 }
     308                 :            :         }
     309         [ -  + ]:         14 :         if (null_final) {
     310                 :          0 :                 mbuf_array[i - 1] = NULL;
     311                 :            :         }
     312                 :         14 : }
     313                 :            : 
     314                 :            : #define FAKE_ENQUEUE_SUCCESS 255
     315                 :            : #define FAKE_ENQUEUE_ERROR 128
     316                 :            : #define FAKE_ENQUEUE_BUSY 64
     317                 :            : static uint16_t ut_enqueue_value = FAKE_ENQUEUE_SUCCESS;
     318                 :            : static struct rte_comp_op ut_expected_op;
     319                 :            : uint16_t
     320                 :         14 : rte_compressdev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_comp_op **ops,
     321                 :            :                               uint16_t nb_ops)
     322                 :            : {
     323                 :         14 :         struct rte_comp_op *op = *ops;
     324                 :          7 :         struct rte_mbuf *op_mbuf[UT_MBUFS_PER_OP_BOUND_TEST];
     325                 :          7 :         struct rte_mbuf *exp_mbuf[UT_MBUFS_PER_OP_BOUND_TEST];
     326                 :         14 :         int i, num_src_mbufs = UT_MBUFS_PER_OP;
     327                 :            : 
     328   [ +  +  +  - ]:         14 :         switch (ut_enqueue_value) {
     329                 :          2 :         case FAKE_ENQUEUE_BUSY:
     330                 :          2 :                 op->status = RTE_COMP_OP_STATUS_NOT_PROCESSED;
     331                 :          2 :                 return 0;
     332                 :         10 :         case FAKE_ENQUEUE_SUCCESS:
     333                 :         10 :                 op->status = RTE_COMP_OP_STATUS_SUCCESS;
     334                 :         10 :                 return 1;
     335                 :          2 :         case FAKE_ENQUEUE_ERROR:
     336                 :          2 :                 op->status = RTE_COMP_OP_STATUS_ERROR;
     337                 :          2 :                 return 0;
     338                 :          0 :         default:
     339                 :          0 :                 break;
     340                 :            :         }
     341                 :            : 
     342                 :            :         /* by design the compress module will never send more than 1 op at a time */
     343                 :          0 :         CU_ASSERT(op->private_xform == ut_expected_op.private_xform);
     344                 :            : 
     345                 :            :         /* setup our local pointers to the chained mbufs, those pointed to in the
     346                 :            :          * operation struct and the expected values.
     347                 :            :          */
     348                 :          0 :         _get_mbuf_array(op_mbuf, op->m_src, SPDK_COUNTOF(op_mbuf), true);
     349                 :          0 :         _get_mbuf_array(exp_mbuf, ut_expected_op.m_src, SPDK_COUNTOF(exp_mbuf), true);
     350                 :            : 
     351   [ #  #  #  # ]:          0 :         if (ut_boundary_alloc == true) {
     352                 :            :                 /* if we crossed a boundary, we need to check the 4th src mbuf and
     353                 :            :                  * reset the global that is used to identify whether we crossed
     354                 :            :                  * or not
     355                 :            :                  */
     356                 :          0 :                 num_src_mbufs = UT_MBUFS_PER_OP_BOUND_TEST;
     357                 :          0 :                 exp_mbuf[UT_MBUFS_PER_OP_BOUND_TEST - 1] = ut_expected_op.m_src->next->next->next;
     358                 :          0 :                 op_mbuf[UT_MBUFS_PER_OP_BOUND_TEST - 1] = op->m_src->next->next->next;
     359                 :          0 :                 ut_boundary_alloc = false;
     360                 :            :         }
     361                 :            : 
     362         [ #  # ]:          0 :         for (i = 0; i < num_src_mbufs; i++) {
     363                 :          0 :                 CU_ASSERT(op_mbuf[i]->buf_addr == exp_mbuf[i]->buf_addr);
     364                 :          0 :                 CU_ASSERT(op_mbuf[i]->buf_iova == exp_mbuf[i]->buf_iova);
     365                 :          0 :                 CU_ASSERT(op_mbuf[i]->buf_len == exp_mbuf[i]->buf_len);
     366                 :          0 :                 CU_ASSERT(op_mbuf[i]->pkt_len == exp_mbuf[i]->pkt_len);
     367                 :            :         }
     368                 :            : 
     369                 :            :         /* if only 3 mbufs were used in the test, the 4th should be zeroed */
     370         [ #  # ]:          0 :         if (num_src_mbufs == UT_MBUFS_PER_OP) {
     371                 :          0 :                 CU_ASSERT(op_mbuf[UT_MBUFS_PER_OP_BOUND_TEST - 1] == NULL);
     372                 :          0 :                 CU_ASSERT(exp_mbuf[UT_MBUFS_PER_OP_BOUND_TEST - 1] == NULL);
     373                 :            :         }
     374                 :          0 :         CU_ASSERT(*RTE_MBUF_DYNFIELD(op->m_src, g_mbuf_offset, uint64_t *) ==
     375                 :            :                   *RTE_MBUF_DYNFIELD(ut_expected_op.m_src, g_mbuf_offset, uint64_t *));
     376                 :          0 :         CU_ASSERT(op->src.offset == ut_expected_op.src.offset);
     377                 :          0 :         CU_ASSERT(op->src.length == ut_expected_op.src.length);
     378                 :            : 
     379                 :            :         /* check dst mbuf values */
     380                 :          0 :         _get_mbuf_array(op_mbuf, op->m_dst, SPDK_COUNTOF(op_mbuf), true);
     381                 :          0 :         _get_mbuf_array(exp_mbuf, ut_expected_op.m_dst, SPDK_COUNTOF(exp_mbuf), true);
     382                 :            : 
     383         [ #  # ]:          0 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     384                 :          0 :                 CU_ASSERT(op_mbuf[i]->buf_addr == exp_mbuf[i]->buf_addr);
     385                 :          0 :                 CU_ASSERT(op_mbuf[i]->buf_iova == exp_mbuf[i]->buf_iova);
     386                 :          0 :                 CU_ASSERT(op_mbuf[i]->buf_len == exp_mbuf[i]->buf_len);
     387                 :          0 :                 CU_ASSERT(op_mbuf[i]->pkt_len == exp_mbuf[i]->pkt_len);
     388                 :            :         }
     389                 :          0 :         CU_ASSERT(op->dst.offset == ut_expected_op.dst.offset);
     390                 :            : 
     391                 :          0 :         return ut_enqueue_value;
     392                 :            : }
     393                 :            : 
     394                 :            : /* Global setup for all tests that share a bunch of preparation... */
     395                 :            : static int
     396                 :          2 : test_setup(void)
     397                 :            : {
     398                 :            :         struct spdk_thread *thread;
     399                 :            :         int i;
     400                 :            : 
     401                 :          2 :         spdk_thread_lib_init(NULL, 0);
     402                 :            : 
     403                 :          2 :         thread = spdk_thread_create(NULL, NULL);
     404                 :          2 :         spdk_set_thread(thread);
     405                 :            : 
     406                 :          2 :         g_comp_xform = (struct rte_comp_xform) {
     407                 :            :                 .type = RTE_COMP_COMPRESS,
     408                 :            :                 .compress = {
     409                 :            :                         .algo = RTE_COMP_ALGO_DEFLATE,
     410                 :            :                         .deflate.huffman = RTE_COMP_HUFFMAN_DEFAULT,
     411                 :            :                         .level = RTE_COMP_LEVEL_MAX,
     412                 :            :                         .window_size = DEFAULT_WINDOW_SIZE,
     413                 :            :                         .chksum = RTE_COMP_CHECKSUM_NONE,
     414                 :            :                         .hash_algo = RTE_COMP_HASH_ALGO_NONE
     415                 :            :                 }
     416                 :            :         };
     417                 :            : 
     418                 :          2 :         g_decomp_xform = (struct rte_comp_xform) {
     419                 :            :                 .type = RTE_COMP_DECOMPRESS,
     420                 :            :                 .decompress = {
     421                 :            :                         .algo = RTE_COMP_ALGO_DEFLATE,
     422                 :            :                         .chksum = RTE_COMP_CHECKSUM_NONE,
     423                 :            :                         .window_size = DEFAULT_WINDOW_SIZE,
     424                 :            :                         .hash_algo = RTE_COMP_HASH_ALGO_NONE
     425                 :            :                 }
     426                 :            :         };
     427                 :          2 :         g_device.comp_xform = &g_comp_xform;
     428                 :          2 :         g_device.decomp_xform = &g_decomp_xform;
     429                 :          2 :         g_cdev_cap.comp_feature_flags = RTE_COMP_FF_SHAREABLE_PRIV_XFORM;
     430                 :          2 :         g_device.cdev_info.driver_name = "compressdev";
     431                 :          2 :         g_device.cdev_info.capabilities = &g_cdev_cap;
     432         [ +  + ]:         10 :         for (i = 0; i < UT_MBUFS_PER_OP_BOUND_TEST; i++) {
     433                 :          8 :                 g_src_mbufs[i] = spdk_zmalloc(sizeof(struct rte_mbuf), 0x40, NULL,
     434                 :            :                                               SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
     435                 :            :         }
     436         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     437                 :          6 :                 g_dst_mbufs[i] = spdk_zmalloc(sizeof(struct rte_mbuf), 0x40, NULL,
     438                 :            :                                               SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
     439                 :            :         }
     440                 :            : 
     441                 :          2 :         g_io_ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct compress_io_channel));
     442                 :          2 :         g_io_ch->thread = thread;
     443                 :          2 :         g_comp_ch = (struct compress_io_channel *)spdk_io_channel_get_ctx(g_io_ch);
     444                 :          2 :         g_comp_ch->device_qp = &g_device_qp;
     445                 :          2 :         g_comp_ch->device_qp->device = &g_device;
     446                 :          2 :         g_device_qp.device->sgl_in = true;
     447                 :          2 :         g_device_qp.device->sgl_out = true;
     448                 :          2 :         g_comp_ch->src_mbufs = calloc(UT_MBUFS_PER_OP_BOUND_TEST, sizeof(void *));
     449                 :          2 :         g_comp_ch->dst_mbufs = calloc(UT_MBUFS_PER_OP, sizeof(void *));
     450                 :          2 :         STAILQ_INIT(&g_comp_ch->queued_tasks);
     451                 :            : 
     452         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP_BOUND_TEST - 1; i++) {
     453                 :          6 :                 g_expected_src_mbufs[i].next = &g_expected_src_mbufs[i + 1];
     454                 :            :         }
     455                 :          2 :         g_expected_src_mbufs[UT_MBUFS_PER_OP_BOUND_TEST - 1].next = NULL;
     456                 :            : 
     457                 :            :         /* we only test w/4 mbufs on src side */
     458         [ +  + ]:          6 :         for (i = 0; i < UT_MBUFS_PER_OP - 1; i++) {
     459                 :          4 :                 g_expected_dst_mbufs[i].next = &g_expected_dst_mbufs[i + 1];
     460                 :            :         }
     461                 :          2 :         g_expected_dst_mbufs[UT_MBUFS_PER_OP - 1].next = NULL;
     462                 :          2 :         g_mbuf_offset = DPDK_DYNFIELD_OFFSET;
     463                 :            : 
     464                 :          2 :         return 0;
     465                 :            : }
     466                 :            : 
     467                 :            : /* Global teardown for all tests */
     468                 :            : static int
     469                 :          2 : test_cleanup(void)
     470                 :            : {
     471                 :            :         struct spdk_thread *thread;
     472                 :            :         int i;
     473                 :            : 
     474         [ +  + ]:         10 :         for (i = 0; i < UT_MBUFS_PER_OP_BOUND_TEST; i++) {
     475                 :          8 :                 spdk_free(g_src_mbufs[i]);
     476                 :            :         }
     477         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     478                 :          6 :                 spdk_free(g_dst_mbufs[i]);
     479                 :            :         }
     480                 :          2 :         free(g_comp_ch->src_mbufs);
     481                 :          2 :         free(g_comp_ch->dst_mbufs);
     482                 :          2 :         free(g_io_ch);
     483                 :            : 
     484                 :          2 :         thread = spdk_get_thread();
     485                 :          2 :         spdk_thread_exit(thread);
     486         [ +  + ]:          4 :         while (!spdk_thread_is_exited(thread)) {
     487                 :          2 :                 spdk_thread_poll(thread, 0, 0);
     488                 :            :         }
     489                 :          2 :         spdk_thread_destroy(thread);
     490                 :            : 
     491                 :          2 :         spdk_thread_lib_fini();
     492                 :            : 
     493                 :          2 :         return 0;
     494                 :            : }
     495                 :            : 
     496                 :            : static void
     497                 :          2 : test_compress_operation(void)
     498                 :            : {
     499                 :          2 :         struct iovec src_iovs[3] = {};
     500                 :            :         int src_iovcnt;
     501                 :          2 :         struct iovec dst_iovs[3] = {};
     502                 :            :         int dst_iovcnt;
     503                 :          2 :         struct spdk_accel_task task = {};
     504                 :            :         int rc, i;
     505                 :          1 :         struct rte_mbuf *exp_src_mbuf[UT_MBUFS_PER_OP];
     506                 :          1 :         struct rte_mbuf *exp_dst_mbuf[UT_MBUFS_PER_OP];
     507                 :          1 :         uint32_t output_size;
     508                 :            : 
     509                 :          2 :         src_iovcnt = dst_iovcnt = 3;
     510         [ +  + ]:          8 :         for (i = 0; i < dst_iovcnt; i++) {
     511                 :          6 :                 src_iovs[i].iov_len = 0x1000;
     512                 :          6 :                 dst_iovs[i].iov_len = 0x1000;
     513                 :          6 :                 src_iovs[i].iov_base = (void *)0x10000000 + 0x1000 * i;
     514                 :          6 :                 dst_iovs[i].iov_base = (void *)0x20000000 + 0x1000 * i;
     515                 :            :         }
     516                 :            : 
     517                 :          2 :         task.cb_fn = _compress_done;
     518                 :          2 :         task.op_code = SPDK_ACCEL_OPC_COMPRESS;
     519                 :          2 :         task.output_size = &output_size;
     520                 :          2 :         task.d.iovs = dst_iovs;
     521                 :          2 :         task.d.iovcnt = dst_iovcnt;
     522                 :          2 :         task.s.iovs = src_iovs;
     523                 :          2 :         task.s.iovcnt = src_iovcnt;
     524                 :            : 
     525                 :            :         /* test rte_comp_op_alloc failure */
     526                 :          2 :         MOCK_SET(rte_comp_op_alloc, NULL);
     527                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     528                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     529                 :          2 :         CU_ASSERT(rc == 0);
     530                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == false);
     531         [ +  + ]:          6 :         while (!STAILQ_EMPTY(&g_comp_ch->queued_tasks)) {
     532         [ -  + ]:          2 :                 STAILQ_REMOVE_HEAD(&g_comp_ch->queued_tasks, link);
     533                 :            :         }
     534                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     535                 :            : 
     536                 :            :         /* test mempool get failure */
     537                 :          2 :         MOCK_SET(rte_comp_op_alloc, &g_comp_op[0]);
     538                 :          2 :         ut_rte_pktmbuf_alloc_bulk = -1;
     539                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     540                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     541                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == false);
     542         [ +  + ]:          6 :         while (!STAILQ_EMPTY(&g_comp_ch->queued_tasks)) {
     543         [ -  + ]:          2 :                 STAILQ_REMOVE_HEAD(&g_comp_ch->queued_tasks, link);
     544                 :            :         }
     545                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     546                 :          2 :         CU_ASSERT(rc == 0);
     547                 :          2 :         ut_rte_pktmbuf_alloc_bulk = 0;
     548                 :            : 
     549                 :            :         /* test enqueue failure busy */
     550                 :          2 :         ut_enqueue_value = FAKE_ENQUEUE_BUSY;
     551                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     552                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     553                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == false);
     554         [ +  + ]:          6 :         while (!STAILQ_EMPTY(&g_comp_ch->queued_tasks)) {
     555         [ -  + ]:          2 :                 STAILQ_REMOVE_HEAD(&g_comp_ch->queued_tasks, link);
     556                 :            :         }
     557                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     558                 :          2 :         CU_ASSERT(rc == 0);
     559                 :          2 :         ut_enqueue_value = 1;
     560                 :            : 
     561                 :            :         /* test enqueue failure error */
     562                 :          2 :         ut_enqueue_value = FAKE_ENQUEUE_ERROR;
     563                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     564                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     565                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     566                 :          2 :         CU_ASSERT(rc == -EINVAL);
     567                 :          2 :         ut_enqueue_value = FAKE_ENQUEUE_SUCCESS;
     568                 :            : 
     569                 :            :         /* test success with 3 vector iovec */
     570                 :          2 :         ut_expected_op.private_xform = &g_decomp_xform;
     571                 :          2 :         ut_expected_op.src.offset = 0;
     572                 :          2 :         ut_expected_op.src.length = src_iovs[0].iov_len + src_iovs[1].iov_len + src_iovs[2].iov_len;
     573                 :            : 
     574                 :            :         /* setup the src expected values */
     575                 :          2 :         _get_mbuf_array(exp_src_mbuf, &g_expected_src_mbufs[0], SPDK_COUNTOF(exp_src_mbuf), false);
     576                 :          2 :         ut_expected_op.m_src = exp_src_mbuf[0];
     577                 :            : 
     578         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     579                 :          6 :                 *RTE_MBUF_DYNFIELD(exp_src_mbuf[i], g_mbuf_offset, uint64_t *) = (uint64_t)&task;
     580                 :          6 :                 exp_src_mbuf[i]->buf_addr = src_iovs[i].iov_base;
     581                 :          6 :                 exp_src_mbuf[i]->buf_iova = spdk_vtophys(src_iovs[i].iov_base, &src_iovs[i].iov_len);
     582                 :          6 :                 exp_src_mbuf[i]->buf_len = src_iovs[i].iov_len;
     583                 :          6 :                 exp_src_mbuf[i]->pkt_len = src_iovs[i].iov_len;
     584                 :            :         }
     585                 :            : 
     586                 :            :         /* setup the dst expected values */
     587                 :          2 :         _get_mbuf_array(exp_dst_mbuf, &g_expected_dst_mbufs[0], SPDK_COUNTOF(exp_dst_mbuf), false);
     588                 :          2 :         ut_expected_op.dst.offset = 0;
     589                 :          2 :         ut_expected_op.m_dst = exp_dst_mbuf[0];
     590                 :            : 
     591         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     592                 :          6 :                 exp_dst_mbuf[i]->buf_addr = dst_iovs[i].iov_base;
     593                 :          6 :                 exp_dst_mbuf[i]->buf_iova = spdk_vtophys(dst_iovs[i].iov_base, &dst_iovs[i].iov_len);
     594                 :          6 :                 exp_dst_mbuf[i]->buf_len = dst_iovs[i].iov_len;
     595                 :          6 :                 exp_dst_mbuf[i]->pkt_len = dst_iovs[i].iov_len;
     596                 :            :         }
     597                 :            : 
     598                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     599                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     600                 :          2 :         CU_ASSERT(rc == 0);
     601                 :            : 
     602                 :            :         /* test sgl out failure */
     603                 :          2 :         g_device.sgl_out = false;
     604                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     605                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     606                 :          2 :         CU_ASSERT(rc == -EINVAL);
     607                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     608                 :          2 :         g_device.sgl_out = true;
     609                 :            : 
     610                 :            :         /* test sgl in failure */
     611                 :          2 :         g_device.sgl_in = false;
     612                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     613                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     614                 :          2 :         CU_ASSERT(rc == -EINVAL);
     615                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     616                 :          2 :         g_device.sgl_in = true;
     617                 :          2 : }
     618                 :            : 
     619                 :            : static void
     620                 :          2 : test_compress_operation_cross_boundary(void)
     621                 :            : {
     622                 :          2 :         struct iovec src_iovs[3] = {};
     623                 :            :         int src_iovcnt;
     624                 :          2 :         struct iovec dst_iovs[3] = {};
     625                 :            :         int dst_iovcnt;
     626                 :            :         int rc, i;
     627                 :          1 :         struct rte_mbuf *exp_src_mbuf[UT_MBUFS_PER_OP_BOUND_TEST];
     628                 :          1 :         struct rte_mbuf *exp_dst_mbuf[UT_MBUFS_PER_OP_BOUND_TEST];
     629                 :          2 :         struct spdk_accel_task task = {};
     630                 :          1 :         uint32_t output_size;
     631                 :            : 
     632                 :            :         /* Setup the same basic 3 IOV test as used in the simple success case
     633                 :            :          * but then we'll start testing a vtophy boundary crossing at each
     634                 :            :          * position.
     635                 :            :          */
     636                 :          2 :         src_iovcnt = dst_iovcnt = 3;
     637         [ +  + ]:          8 :         for (i = 0; i < dst_iovcnt; i++) {
     638                 :          6 :                 src_iovs[i].iov_len = 0x1000;
     639                 :          6 :                 dst_iovs[i].iov_len = 0x1000;
     640                 :          6 :                 src_iovs[i].iov_base = (void *)0x10000000 + 0x1000 * i;
     641                 :          6 :                 dst_iovs[i].iov_base = (void *)0x20000000 + 0x1000 * i;
     642                 :            :         }
     643                 :            : 
     644                 :          2 :         ut_expected_op.private_xform = &g_decomp_xform;
     645                 :          2 :         ut_expected_op.src.offset = 0;
     646                 :          2 :         ut_expected_op.src.length = src_iovs[0].iov_len + src_iovs[1].iov_len + src_iovs[2].iov_len;
     647                 :            : 
     648                 :            :         /* setup the src expected values */
     649                 :          2 :         _get_mbuf_array(exp_src_mbuf, &g_expected_src_mbufs[0], SPDK_COUNTOF(exp_src_mbuf), false);
     650                 :          2 :         ut_expected_op.m_src = exp_src_mbuf[0];
     651                 :            : 
     652         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     653                 :          6 :                 *RTE_MBUF_DYNFIELD(exp_src_mbuf[i], g_mbuf_offset, uint64_t *) = (uint64_t)&task;
     654                 :          6 :                 exp_src_mbuf[i]->buf_addr = src_iovs[i].iov_base;
     655                 :          6 :                 exp_src_mbuf[i]->buf_iova = spdk_vtophys(src_iovs[i].iov_base, &src_iovs[i].iov_len);
     656                 :          6 :                 exp_src_mbuf[i]->buf_len = src_iovs[i].iov_len;
     657                 :          6 :                 exp_src_mbuf[i]->pkt_len = src_iovs[i].iov_len;
     658                 :            :         }
     659                 :            : 
     660                 :            :         /* setup the dst expected values, we don't test needing a 4th dst mbuf */
     661                 :          2 :         _get_mbuf_array(exp_dst_mbuf, &g_expected_dst_mbufs[0], SPDK_COUNTOF(exp_dst_mbuf), false);
     662                 :          2 :         ut_expected_op.dst.offset = 0;
     663                 :          2 :         ut_expected_op.m_dst = exp_dst_mbuf[0];
     664                 :            : 
     665         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     666                 :          6 :                 exp_dst_mbuf[i]->buf_addr = dst_iovs[i].iov_base;
     667                 :          6 :                 exp_dst_mbuf[i]->buf_iova = spdk_vtophys(dst_iovs[i].iov_base, &dst_iovs[i].iov_len);
     668                 :          6 :                 exp_dst_mbuf[i]->buf_len = dst_iovs[i].iov_len;
     669                 :          6 :                 exp_dst_mbuf[i]->pkt_len = dst_iovs[i].iov_len;
     670                 :            :         }
     671                 :            : 
     672                 :            :         /* force the 1st IOV to get partial length from spdk_vtophys */
     673                 :          2 :         g_small_size_counter = 0;
     674                 :          2 :         g_small_size_modify = 1;
     675                 :          2 :         g_small_size = 0x800;
     676                 :          2 :         *RTE_MBUF_DYNFIELD(exp_src_mbuf[3], g_mbuf_offset, uint64_t *) = (uint64_t)&task;
     677                 :            : 
     678                 :            :         /* first only has shorter length */
     679                 :          2 :         exp_src_mbuf[0]->pkt_len = exp_src_mbuf[0]->buf_len = 0x800;
     680                 :            : 
     681                 :            :         /* 2nd was inserted by the boundary crossing condition and finishes off
     682                 :            :          * the length from the first */
     683                 :          2 :         exp_src_mbuf[1]->buf_addr = (void *)0x10000800;
     684                 :          2 :         exp_src_mbuf[1]->buf_iova = 0x10000800;
     685                 :          2 :         exp_src_mbuf[1]->pkt_len = exp_src_mbuf[1]->buf_len = 0x800;
     686                 :            : 
     687                 :            :         /* 3rd looks like that the 2nd would have */
     688                 :          2 :         exp_src_mbuf[2]->buf_addr = (void *)0x10001000;
     689                 :          2 :         exp_src_mbuf[2]->buf_iova = 0x10001000;
     690                 :          2 :         exp_src_mbuf[2]->pkt_len = exp_src_mbuf[2]->buf_len = 0x1000;
     691                 :            : 
     692                 :            :         /* a new 4th looks like what the 3rd would have */
     693                 :          2 :         exp_src_mbuf[3]->buf_addr = (void *)0x10002000;
     694                 :          2 :         exp_src_mbuf[3]->buf_iova = 0x10002000;
     695                 :          2 :         exp_src_mbuf[3]->pkt_len = exp_src_mbuf[3]->buf_len = 0x1000;
     696                 :            : 
     697                 :          2 :         task.cb_fn = _compress_done;
     698                 :          2 :         task.op_code = SPDK_ACCEL_OPC_COMPRESS;
     699                 :          2 :         task.output_size = &output_size;
     700                 :          2 :         task.d.iovs = dst_iovs;
     701                 :          2 :         task.d.iovcnt = dst_iovcnt;
     702                 :          2 :         task.s.iovs = src_iovs;
     703                 :          2 :         task.s.iovcnt = src_iovcnt;
     704                 :            : 
     705                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     706                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     707                 :          2 :         CU_ASSERT(rc == 0);
     708                 :            : 
     709                 :            :         /* Now force the 2nd IOV to get partial length from spdk_vtophys */
     710                 :          2 :         g_small_size_counter = 0;
     711                 :          2 :         g_small_size_modify = 2;
     712                 :          2 :         g_small_size = 0x800;
     713                 :            : 
     714                 :            :         /* first is normal */
     715                 :          2 :         exp_src_mbuf[0]->buf_addr = (void *)0x10000000;
     716                 :          2 :         exp_src_mbuf[0]->buf_iova = 0x10000000;
     717                 :          2 :         exp_src_mbuf[0]->pkt_len = exp_src_mbuf[0]->buf_len = 0x1000;
     718                 :            : 
     719                 :            :         /* second only has shorter length */
     720                 :          2 :         exp_src_mbuf[1]->buf_addr = (void *)0x10001000;
     721                 :          2 :         exp_src_mbuf[1]->buf_iova = 0x10001000;
     722                 :          2 :         exp_src_mbuf[1]->pkt_len = exp_src_mbuf[1]->buf_len = 0x800;
     723                 :            : 
     724                 :            :         /* 3rd was inserted by the boundary crossing condition and finishes off
     725                 :            :          * the length from the first */
     726                 :          2 :         exp_src_mbuf[2]->buf_addr = (void *)0x10001800;
     727                 :          2 :         exp_src_mbuf[2]->buf_iova = 0x10001800;
     728                 :          2 :         exp_src_mbuf[2]->pkt_len = exp_src_mbuf[2]->buf_len = 0x800;
     729                 :            : 
     730                 :            :         /* a new 4th looks like what the 3rd would have */
     731                 :          2 :         exp_src_mbuf[3]->buf_addr = (void *)0x10002000;
     732                 :          2 :         exp_src_mbuf[3]->buf_iova = 0x10002000;
     733                 :          2 :         exp_src_mbuf[3]->pkt_len = exp_src_mbuf[3]->buf_len = 0x1000;
     734                 :            : 
     735                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     736                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     737                 :          2 :         CU_ASSERT(rc == 0);
     738                 :            : 
     739                 :            :         /* Finally force the 3rd IOV to get partial length from spdk_vtophys */
     740                 :          2 :         g_small_size_counter = 0;
     741                 :          2 :         g_small_size_modify = 3;
     742                 :          2 :         g_small_size = 0x800;
     743                 :            : 
     744                 :            :         /* first is normal */
     745                 :          2 :         exp_src_mbuf[0]->buf_addr = (void *)0x10000000;
     746                 :          2 :         exp_src_mbuf[0]->buf_iova = 0x10000000;
     747                 :          2 :         exp_src_mbuf[0]->pkt_len = exp_src_mbuf[0]->buf_len = 0x1000;
     748                 :            : 
     749                 :            :         /* second is normal */
     750                 :          2 :         exp_src_mbuf[1]->buf_addr = (void *)0x10001000;
     751                 :          2 :         exp_src_mbuf[1]->buf_iova = 0x10001000;
     752                 :          2 :         exp_src_mbuf[1]->pkt_len = exp_src_mbuf[1]->buf_len = 0x1000;
     753                 :            : 
     754                 :            :         /* 3rd has shorter length */
     755                 :          2 :         exp_src_mbuf[2]->buf_addr = (void *)0x10002000;
     756                 :          2 :         exp_src_mbuf[2]->buf_iova = 0x10002000;
     757                 :          2 :         exp_src_mbuf[2]->pkt_len = exp_src_mbuf[2]->buf_len = 0x800;
     758                 :            : 
     759                 :            :         /* a new 4th handles the remainder from the 3rd */
     760                 :          2 :         exp_src_mbuf[3]->buf_addr = (void *)0x10002800;
     761                 :          2 :         exp_src_mbuf[3]->buf_iova = 0x10002800;
     762                 :          2 :         exp_src_mbuf[3]->pkt_len = exp_src_mbuf[3]->buf_len = 0x800;
     763                 :            : 
     764                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     765                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     766                 :          2 :         CU_ASSERT(rc == 0);
     767                 :            : 
     768                 :            :         /* Single input iov is split on page boundary, sgl_in is not supported */
     769                 :          2 :         g_device.sgl_in = false;
     770                 :          2 :         g_small_size_counter = 0;
     771                 :          2 :         g_small_size_modify = 1;
     772                 :          2 :         g_small_size = 0x800;
     773                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     774                 :          2 :         CU_ASSERT(rc == -EINVAL);
     775                 :          2 :         g_device.sgl_in = true;
     776                 :            : 
     777                 :            :         /* Single output iov is split on page boundary, sgl_out is not supported */
     778                 :          2 :         g_device.sgl_out = false;
     779                 :          2 :         g_small_size_counter = 0;
     780                 :          2 :         g_small_size_modify = 2;
     781                 :          2 :         g_small_size = 0x800;
     782                 :          2 :         rc = _compress_operation(g_comp_ch, &task);
     783                 :          2 :         CU_ASSERT(rc == -EINVAL);
     784                 :          2 :         g_device.sgl_out = true;
     785                 :          2 : }
     786                 :            : 
     787                 :            : static void
     788                 :          2 : test_setup_compress_mbuf(void)
     789                 :            : {
     790                 :          2 :         struct iovec src_iovs = {};
     791                 :          2 :         int src_iovcnt = 1;
     792                 :          2 :         struct spdk_accel_task task = {};
     793                 :          2 :         int src_mbuf_added = 0;
     794                 :          1 :         uint64_t total_length;
     795                 :          1 :         struct rte_mbuf *exp_src_mbuf[UT_MBUFS_PER_OP_BOUND_TEST];
     796                 :            :         int rc, i;
     797                 :            : 
     798                 :            :         /* setup the src expected values */
     799                 :          2 :         _get_mbuf_array(exp_src_mbuf, &g_expected_src_mbufs[0], SPDK_COUNTOF(exp_src_mbuf), false);
     800                 :            : 
     801                 :            :         /* no splitting */
     802                 :          2 :         total_length = 0;
     803                 :          2 :         ut_total_rte_pktmbuf_attach_extbuf = 0;
     804                 :          2 :         src_iovs.iov_len = 0x1000;
     805                 :          2 :         src_iovs.iov_base = (void *)0x10000000 + 0x1000;
     806                 :          2 :         rc = _setup_compress_mbuf(exp_src_mbuf, &src_mbuf_added, &total_length,
     807                 :            :                                   &src_iovs, src_iovcnt, &task);
     808                 :          2 :         CU_ASSERT(rc == 0);
     809                 :          2 :         CU_ASSERT(total_length = src_iovs.iov_len);
     810                 :          2 :         CU_ASSERT(src_mbuf_added == 0);
     811                 :          2 :         CU_ASSERT(ut_total_rte_pktmbuf_attach_extbuf == 1);
     812                 :            : 
     813                 :            :         /* one split, for splitting tests we need the global mbuf array unlinked,
     814                 :            :          * otherwise the functional code will attempt to link them but if they are
     815                 :            :          * already linked, it will just create a chain that links to itself */
     816         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP_BOUND_TEST - 1; i++) {
     817                 :          6 :                 g_expected_src_mbufs[i].next = NULL;
     818                 :            :         }
     819                 :          2 :         total_length = 0;
     820                 :          2 :         ut_total_rte_pktmbuf_attach_extbuf = 0;
     821                 :          2 :         src_iovs.iov_len = 0x1000 + MBUF_SPLIT;
     822                 :          2 :         exp_src_mbuf[0]->buf_len = src_iovs.iov_len;
     823                 :          2 :         exp_src_mbuf[0]->pkt_len = src_iovs.iov_len;
     824                 :          2 :         rc = _setup_compress_mbuf(exp_src_mbuf, &src_mbuf_added, &total_length,
     825                 :            :                                   &src_iovs, src_iovcnt, &task);
     826                 :          2 :         CU_ASSERT(rc == 0);
     827                 :          2 :         CU_ASSERT(total_length = src_iovs.iov_len);
     828                 :          2 :         CU_ASSERT(src_mbuf_added == 0);
     829                 :          2 :         CU_ASSERT(ut_total_rte_pktmbuf_attach_extbuf == 2);
     830                 :            : 
     831                 :            :         /* two splits */
     832         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP_BOUND_TEST - 1; i++) {
     833                 :          6 :                 g_expected_src_mbufs[i].next = NULL;
     834                 :            :         }
     835                 :          2 :         total_length = 0;
     836                 :          2 :         ut_total_rte_pktmbuf_attach_extbuf = 0;
     837                 :          2 :         src_iovs.iov_len = 0x1000 + 2 * MBUF_SPLIT;
     838                 :          2 :         exp_src_mbuf[0]->buf_len = src_iovs.iov_len;
     839                 :          2 :         exp_src_mbuf[0]->pkt_len = src_iovs.iov_len;
     840                 :            : 
     841                 :          2 :         rc = _setup_compress_mbuf(exp_src_mbuf, &src_mbuf_added, &total_length,
     842                 :            :                                   &src_iovs, src_iovcnt, &task);
     843                 :          2 :         CU_ASSERT(rc == 0);
     844                 :          2 :         CU_ASSERT(total_length = src_iovs.iov_len);
     845                 :          2 :         CU_ASSERT(src_mbuf_added == 0);
     846                 :          2 :         CU_ASSERT(ut_total_rte_pktmbuf_attach_extbuf == 3);
     847                 :            : 
     848                 :            :         /* relink the global mbuf array */
     849         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP_BOUND_TEST - 1; i++) {
     850                 :          6 :                 g_expected_src_mbufs[i].next = &g_expected_src_mbufs[i + 1];
     851                 :            :         }
     852                 :          2 : }
     853                 :            : 
     854                 :            : static void
     855                 :          2 : test_poller(void)
     856                 :            : {
     857                 :            :         int rc;
     858                 :            :         struct compress_io_channel *args;
     859                 :          1 :         struct rte_mbuf mbuf[4]; /* one src, one dst, 2 ops */
     860                 :          2 :         struct iovec src_iovs[3] = {};
     861                 :          2 :         struct iovec dst_iovs[3] = {};
     862                 :          1 :         uint32_t output_size[2];
     863                 :          2 :         struct spdk_accel_task task[2] = {};
     864                 :            :         struct spdk_accel_task *task_to_resubmit;
     865                 :          1 :         struct rte_mbuf *exp_src_mbuf[UT_MBUFS_PER_OP];
     866                 :          1 :         struct rte_mbuf *exp_dst_mbuf[UT_MBUFS_PER_OP];
     867                 :            :         int i;
     868                 :            : 
     869                 :          2 :         args = calloc(1, sizeof(*args));
     870         [ -  + ]:          2 :         SPDK_CU_ASSERT_FATAL(args != NULL);
     871         [ -  + ]:          2 :         memset(&g_comp_op[0], 0, sizeof(struct rte_comp_op));
     872                 :          2 :         g_comp_op[0].m_src = &mbuf[0];
     873                 :          2 :         g_comp_op[1].m_src = &mbuf[1];
     874                 :          2 :         g_comp_op[0].m_dst = &mbuf[2];
     875                 :          2 :         g_comp_op[1].m_dst = &mbuf[3];
     876         [ +  + ]:          8 :         for (i = 0; i < 3; i++) {
     877                 :          6 :                 src_iovs[i].iov_len = 0x1000;
     878                 :          6 :                 dst_iovs[i].iov_len = 0x1000;
     879                 :          6 :                 src_iovs[i].iov_base = (void *)0x10000000 + 0x1000 * i;
     880                 :          6 :                 dst_iovs[i].iov_base = (void *)0x20000000 + 0x1000 * i;
     881                 :            :         }
     882                 :          2 :         task[0].cb_fn = task[1].cb_fn = _compress_done;
     883                 :          2 :         task[0].output_size = &output_size[0];
     884                 :          2 :         task[1].output_size = &output_size[1];
     885                 :            : 
     886                 :            :         /* Error from dequeue, nothing needing to be resubmitted.
     887                 :            :          */
     888                 :          2 :         ut_rte_compressdev_dequeue_burst = 1;
     889                 :          2 :         ut_expected_task_status = RTE_COMP_OP_STATUS_NOT_PROCESSED;
     890                 :            :         /* setup what we want dequeue to return for the op */
     891                 :          2 :         *RTE_MBUF_DYNFIELD(g_comp_op[0].m_src, g_mbuf_offset, uint64_t *) = (uint64_t)&task[0];
     892                 :          2 :         g_comp_op[0].produced = 1;
     893                 :          2 :         g_done_count = 0;
     894                 :          2 :         g_comp_op[0].status = RTE_COMP_OP_STATUS_NOT_PROCESSED;
     895                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     896                 :          2 :         rc = comp_dev_poller((void *)g_comp_ch);
     897                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     898                 :          2 :         CU_ASSERT(rc == SPDK_POLLER_BUSY);
     899                 :          2 :         ut_expected_task_status = RTE_COMP_OP_STATUS_SUCCESS;
     900                 :            : 
     901                 :            :         /* Success from dequeue, 2 ops. nothing needing to be resubmitted.
     902                 :            :          */
     903                 :          2 :         ut_rte_compressdev_dequeue_burst = 2;
     904                 :            :         /* setup what we want dequeue to return for the op */
     905                 :          2 :         *RTE_MBUF_DYNFIELD(g_comp_op[0].m_src, g_mbuf_offset, uint64_t *) = (uint64_t)&task[0];
     906                 :          2 :         g_comp_op[0].produced = 16;
     907                 :          2 :         g_comp_op[0].status = RTE_COMP_OP_STATUS_SUCCESS;
     908                 :          2 :         *RTE_MBUF_DYNFIELD(g_comp_op[1].m_src, g_mbuf_offset, uint64_t *) = (uint64_t)&task[1];
     909                 :          2 :         g_comp_op[1].produced = 32;
     910                 :          2 :         g_comp_op[1].status = RTE_COMP_OP_STATUS_SUCCESS;
     911                 :          2 :         g_done_count = 0;
     912                 :          2 :         ut_enqueue_value = FAKE_ENQUEUE_SUCCESS;
     913                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     914                 :          2 :         rc = comp_dev_poller((void *)g_comp_ch);
     915                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     916                 :          2 :         CU_ASSERT(rc == SPDK_POLLER_BUSY);
     917                 :            : 
     918                 :            :         /* One to dequeue, one op to be resubmitted. */
     919                 :          2 :         ut_rte_compressdev_dequeue_burst = 1;
     920                 :            :         /* setup what we want dequeue to return for the op */
     921                 :          2 :         *RTE_MBUF_DYNFIELD(g_comp_op[0].m_src, g_mbuf_offset, uint64_t *) = (uint64_t)&task[0];
     922                 :          2 :         g_comp_op[0].produced = 16;
     923                 :          2 :         g_comp_op[0].status = 0;
     924                 :          2 :         g_done_count = 0;
     925                 :          2 :         task_to_resubmit = calloc(1, sizeof(struct spdk_accel_task));
     926         [ -  + ]:          2 :         SPDK_CU_ASSERT_FATAL(task_to_resubmit != NULL);
     927                 :          2 :         task_to_resubmit->s.iovs = &src_iovs[0];
     928                 :          2 :         task_to_resubmit->s.iovcnt = 3;
     929                 :          2 :         task_to_resubmit->d.iovs = &dst_iovs[0];
     930                 :          2 :         task_to_resubmit->d.iovcnt = 3;
     931                 :          2 :         task_to_resubmit->op_code = SPDK_ACCEL_OPC_COMPRESS;
     932                 :          2 :         task_to_resubmit->cb_arg = args;
     933                 :          2 :         ut_enqueue_value = FAKE_ENQUEUE_SUCCESS;
     934                 :          2 :         ut_expected_op.private_xform = &g_decomp_xform;
     935                 :          2 :         ut_expected_op.src.offset = 0;
     936                 :          2 :         ut_expected_op.src.length = src_iovs[0].iov_len + src_iovs[1].iov_len + src_iovs[2].iov_len;
     937                 :            : 
     938                 :            :         /* setup the src expected values */
     939                 :          2 :         _get_mbuf_array(exp_src_mbuf, &g_expected_src_mbufs[0], SPDK_COUNTOF(exp_src_mbuf), false);
     940                 :          2 :         ut_expected_op.m_src = exp_src_mbuf[0];
     941                 :            : 
     942         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     943                 :          6 :                 *RTE_MBUF_DYNFIELD(exp_src_mbuf[i], g_mbuf_offset, uint64_t *) = (uint64_t)&task[0];
     944                 :          6 :                 exp_src_mbuf[i]->buf_addr = src_iovs[i].iov_base;
     945                 :          6 :                 exp_src_mbuf[i]->buf_iova = spdk_vtophys(src_iovs[i].iov_base, &src_iovs[i].iov_len);
     946                 :          6 :                 exp_src_mbuf[i]->buf_len = src_iovs[i].iov_len;
     947                 :          6 :                 exp_src_mbuf[i]->pkt_len = src_iovs[i].iov_len;
     948                 :            :         }
     949                 :            : 
     950                 :            :         /* setup the dst expected values */
     951                 :          2 :         _get_mbuf_array(exp_dst_mbuf, &g_expected_dst_mbufs[0], SPDK_COUNTOF(exp_dst_mbuf), false);
     952                 :          2 :         ut_expected_op.dst.offset = 0;
     953                 :          2 :         ut_expected_op.m_dst = exp_dst_mbuf[0];
     954                 :            : 
     955         [ +  + ]:          8 :         for (i = 0; i < UT_MBUFS_PER_OP; i++) {
     956                 :          6 :                 exp_dst_mbuf[i]->buf_addr = dst_iovs[i].iov_base;
     957                 :          6 :                 exp_dst_mbuf[i]->buf_iova = spdk_vtophys(dst_iovs[i].iov_base, &dst_iovs[i].iov_len);
     958                 :          6 :                 exp_dst_mbuf[i]->buf_len = dst_iovs[i].iov_len;
     959                 :          6 :                 exp_dst_mbuf[i]->pkt_len = dst_iovs[i].iov_len;
     960                 :            :         }
     961                 :          2 :         MOCK_SET(rte_comp_op_alloc, &g_comp_op[0]);
     962                 :          2 :         STAILQ_INSERT_TAIL(&g_comp_ch->queued_tasks,
     963                 :            :                            task_to_resubmit,
     964                 :            :                            link);
     965                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == false);
     966                 :          2 :         rc = comp_dev_poller((void *)g_comp_ch);
     967                 :          2 :         CU_ASSERT(STAILQ_EMPTY(&g_comp_ch->queued_tasks) == true);
     968                 :          2 :         CU_ASSERT(rc == SPDK_POLLER_BUSY);
     969                 :            : 
     970                 :          2 :         free(task_to_resubmit);
     971                 :          2 :         free(args);
     972                 :          2 : }
     973                 :            : 
     974                 :            : static void
     975                 :          2 : test_initdrivers(void)
     976                 :            : {
     977                 :            :         int rc;
     978                 :            : 
     979                 :            :         /* compressdev count 0 */
     980                 :          2 :         rc = accel_init_compress_drivers();
     981                 :          2 :         CU_ASSERT(rc == -ENODEV);
     982                 :            : 
     983                 :            :         /* bogus count */
     984                 :          2 :         ut_rte_compressdev_count = RTE_COMPRESS_MAX_DEVS + 1;
     985                 :          2 :         rc = accel_init_compress_drivers();
     986                 :          2 :         CU_ASSERT(rc == -EINVAL);
     987                 :            : 
     988                 :            :         /* failure with rte_mbuf_dynfield_register */
     989                 :          2 :         ut_rte_compressdev_count = 1;
     990                 :          2 :         MOCK_SET(rte_mbuf_dynfield_register, -1);
     991                 :          2 :         rc = accel_init_compress_drivers();
     992                 :          2 :         CU_ASSERT(rc == -EINVAL);
     993                 :          2 :         MOCK_SET(rte_mbuf_dynfield_register, DPDK_DYNFIELD_OFFSET);
     994                 :            : 
     995                 :            :         /* error on create_compress_dev() */
     996                 :          2 :         ut_rte_comp_op_pool_create = (struct rte_mempool *)0xDEADBEEF;
     997                 :          2 :         ut_rte_compressdev_count = 1;
     998                 :          2 :         ut_rte_compressdev_configure = -1;
     999                 :          2 :         rc = accel_init_compress_drivers();
    1000                 :          2 :         CU_ASSERT(rc == -1);
    1001                 :            : 
    1002                 :            :         /* error on create_compress_dev() but coverage for large num queues */
    1003                 :          2 :         ut_max_nb_queue_pairs = 99;
    1004                 :          2 :         rc = accel_init_compress_drivers();
    1005                 :          2 :         CU_ASSERT(rc == -1);
    1006                 :            : 
    1007                 :            :         /* qpair setup fails */
    1008                 :          2 :         ut_rte_compressdev_configure = 0;
    1009                 :          2 :         ut_max_nb_queue_pairs = 0;
    1010                 :          2 :         ut_rte_compressdev_queue_pair_setup = -1;
    1011                 :          2 :         rc = accel_init_compress_drivers();
    1012                 :          2 :         CU_ASSERT(rc == -EINVAL);
    1013                 :            : 
    1014                 :            :         /* rte_compressdev_start fails */
    1015                 :          2 :         ut_rte_compressdev_queue_pair_setup = 0;
    1016                 :          2 :         ut_rte_compressdev_start = -1;
    1017                 :          2 :         rc = accel_init_compress_drivers();
    1018                 :          2 :         CU_ASSERT(rc == -1);
    1019                 :            : 
    1020                 :            :         /* rte_compressdev_private_xform_create() fails */
    1021                 :          2 :         ut_rte_compressdev_start = 0;
    1022                 :          2 :         ut_rte_compressdev_private_xform_create = -2;
    1023                 :          2 :         rc = accel_init_compress_drivers();
    1024                 :          2 :         CU_ASSERT(rc == -2);
    1025                 :            : 
    1026                 :            :         /* success */
    1027                 :          2 :         ut_rte_compressdev_private_xform_create = 0;
    1028                 :          2 :         rc = accel_init_compress_drivers();
    1029                 :          2 :         CU_ASSERT(rc == 0);
    1030                 :          2 : }
    1031                 :            : 
    1032                 :            : int
    1033                 :          2 : main(int argc, char **argv)
    1034                 :            : {
    1035                 :          2 :         CU_pSuite       suite = NULL;
    1036                 :            :         unsigned int    num_failures;
    1037                 :            : 
    1038                 :          2 :         CU_initialize_registry();
    1039                 :            : 
    1040                 :          2 :         suite = CU_add_suite("compress", test_setup, test_cleanup);
    1041                 :          2 :         CU_ADD_TEST(suite, test_compress_operation);
    1042                 :          2 :         CU_ADD_TEST(suite, test_compress_operation_cross_boundary);
    1043                 :          2 :         CU_ADD_TEST(suite, test_setup_compress_mbuf);
    1044                 :          2 :         CU_ADD_TEST(suite, test_initdrivers);
    1045                 :          2 :         CU_ADD_TEST(suite, test_poller);
    1046                 :            : 
    1047                 :          2 :         num_failures = spdk_ut_run_tests(argc, argv, NULL);
    1048                 :          2 :         CU_cleanup_registry();
    1049                 :          2 :         return num_failures;
    1050                 :            : }

Generated by: LCOV version 1.14