]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/spdk/test/unit/lib/bdev/crypto.c/crypto_ut.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / test / unit / lib / bdev / crypto.c / crypto_ut.c
index f01aba19f420d598d23a8d63d52d555ba21a7774..792fb38d7e2dfc6c7ec0e3e6ab47f007659798e7 100644 (file)
 #include "spdk_internal/mock.h"
 #include "unit/lib/json_mock.c"
 
-/* these rte_ headers are our local copies of the DPDK headers hacked to mock some functions
- * included in them that can't be done with our mock library.
+#include <rte_crypto.h>
+#include <rte_cryptodev.h>
+
+#define MAX_TEST_BLOCKS 8192
+struct rte_crypto_op *g_test_crypto_ops[MAX_TEST_BLOCKS];
+struct rte_crypto_op *g_test_dev_full_ops[MAX_TEST_BLOCKS];
+
+uint16_t g_dequeue_mock;
+uint16_t g_enqueue_mock;
+unsigned ut_rte_crypto_op_bulk_alloc;
+int ut_rte_crypto_op_attach_sym_session = 0;
+int ut_rte_cryptodev_info_get = 0;
+bool ut_rte_cryptodev_info_get_mocked = false;
+
+/* Those functions are defined as static inline in DPDK, so we can't
+ * mock them straight away. We use defines to redirect them into
+ * our custom functions.
+ */
+#define rte_cryptodev_enqueue_burst mock_rte_cryptodev_enqueue_burst
+static inline uint16_t
+mock_rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
+                                struct rte_crypto_op **ops, uint16_t nb_ops)
+{
+       int i;
+
+       CU_ASSERT(nb_ops > 0);
+
+       for (i = 0; i < nb_ops; i++) {
+               /* Use this empty (til now) array of pointers to store
+                * enqueued operations for assertion in dev_full test.
+                */
+               g_test_dev_full_ops[i] = *ops++;
+       }
+
+       return g_enqueue_mock;
+}
+
+/* This is pretty ugly but in order to complete an IO via the
+ * poller in the submit path, we need to first call to this func
+ * to return the dequeued value and also decrement it.  On the subsequent
+ * call it needs to return 0 to indicate to the caller that there are
+ * no more IOs to drain.
+ */
+int g_test_overflow = 0;
+#define rte_cryptodev_dequeue_burst mock_rte_cryptodev_dequeue_burst
+static inline uint16_t
+mock_rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
+                                struct rte_crypto_op **ops, uint16_t nb_ops)
+{
+       CU_ASSERT(nb_ops > 0);
+
+       /* A crypto device can be full on enqueue, the driver is designed to drain
+        * the device at the time by calling the poller until it's empty, then
+        * submitting the remaining crypto ops.
+        */
+       if (g_test_overflow) {
+               if (g_dequeue_mock == 0) {
+                       return 0;
+               }
+               *ops = g_test_crypto_ops[g_enqueue_mock];
+               (*ops)->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
+               g_dequeue_mock -= 1;
+       }
+       return (g_dequeue_mock + 1);
+}
+
+/* Instead of allocating real memory, assign the allocations to our
+ * test array for assertion in tests.
  */
-#include "rte_crypto.h"
-#include "rte_cryptodev.h"
-DEFINE_STUB_V(rte_crypto_op_free, (struct rte_crypto_op *op));
+#define rte_crypto_op_bulk_alloc mock_rte_crypto_op_bulk_alloc
+static inline unsigned
+mock_rte_crypto_op_bulk_alloc(struct rte_mempool *mempool,
+                             enum rte_crypto_op_type type,
+                             struct rte_crypto_op **ops, uint16_t nb_ops)
+{
+       int i;
+
+       for (i = 0; i < nb_ops; i++) {
+               *ops++ = g_test_crypto_ops[i];
+       }
+       return ut_rte_crypto_op_bulk_alloc;
+}
+
+#define rte_mempool_put_bulk mock_rte_mempool_put_bulk
+static __rte_always_inline void
+mock_rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table,
+                         unsigned int n)
+{
+       return;
+}
+
+#define rte_crypto_op_attach_sym_session mock_rte_crypto_op_attach_sym_session
+static inline int
+mock_rte_crypto_op_attach_sym_session(struct rte_crypto_op *op,
+                                     struct rte_cryptodev_sym_session *sess)
+{
+       return ut_rte_crypto_op_attach_sym_session;
+}
+
 #include "bdev/crypto/vbdev_crypto.c"
 
 /* SPDK stubs */
@@ -52,7 +145,6 @@ DEFINE_STUB(spdk_conf_section_get_nval, char *,
            (struct spdk_conf_section *sp, const char *key, int idx), NULL);
 DEFINE_STUB(spdk_conf_section_get_nmval, char *,
            (struct spdk_conf_section *sp, const char *key, int idx1, int idx2), NULL);
-
 DEFINE_STUB_V(spdk_bdev_module_list_add, (struct spdk_bdev_module *bdev_module));
 DEFINE_STUB_V(spdk_bdev_free_io, (struct spdk_bdev_io *g_bdev_io));
 DEFINE_STUB(spdk_bdev_io_type_supported, bool, (struct spdk_bdev *bdev,
@@ -60,7 +152,7 @@ DEFINE_STUB(spdk_bdev_io_type_supported, bool, (struct spdk_bdev *bdev,
 DEFINE_STUB_V(spdk_bdev_module_release_bdev, (struct spdk_bdev *bdev));
 DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc));
 DEFINE_STUB(spdk_bdev_get_name, const char *, (const struct spdk_bdev *bdev), 0);
-DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), 0);
+DEFINE_STUB(spdk_bdev_get_buf_align, size_t, (const struct spdk_bdev *bdev), 0);
 DEFINE_STUB(spdk_bdev_get_io_channel, struct spdk_io_channel *, (struct spdk_bdev_desc *desc), 0);
 DEFINE_STUB_V(spdk_bdev_unregister, (struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn,
                                     void *cb_arg));
@@ -70,43 +162,49 @@ DEFINE_STUB(spdk_bdev_open, int, (struct spdk_bdev *bdev, bool write,
 DEFINE_STUB(spdk_bdev_module_claim_bdev, int, (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
                struct spdk_bdev_module *module), 0);
 DEFINE_STUB_V(spdk_bdev_module_examine_done, (struct spdk_bdev_module *module));
-DEFINE_STUB(spdk_vbdev_register, int, (struct spdk_bdev *vbdev, struct spdk_bdev **base_bdevs,
-                                      int base_bdev_count), 0);
-DEFINE_STUB(spdk_bdev_get_by_name, struct spdk_bdev *, (const char *bdev_name), NULL);
+DEFINE_STUB(spdk_bdev_register, int, (struct spdk_bdev *vbdev), 0);
 DEFINE_STUB(spdk_env_get_socket_id, uint32_t, (uint32_t core), 0);
 
 /* DPDK stubs */
 DEFINE_STUB(rte_cryptodev_count, uint8_t, (void), 0);
 DEFINE_STUB(rte_eal_get_configuration, struct rte_config *, (void), NULL);
 DEFINE_STUB_V(rte_mempool_free, (struct rte_mempool *mp));
+DEFINE_STUB(rte_mempool_create, struct rte_mempool *, (const char *name, unsigned n,
+               unsigned elt_size,
+               unsigned cache_size, unsigned private_data_size,
+               rte_mempool_ctor_t *mp_init, void *mp_init_arg,
+               rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
+               int socket_id, unsigned flags), (struct rte_mempool *)1);
 DEFINE_STUB(rte_socket_id, unsigned, (void), 0);
 DEFINE_STUB(rte_crypto_op_pool_create, struct rte_mempool *,
            (const char *name, enum rte_crypto_op_type type, unsigned nb_elts,
             unsigned cache_size, uint16_t priv_size, int socket_id), (struct rte_mempool *)1);
 DEFINE_STUB(rte_cryptodev_device_count_by_driver, uint8_t, (uint8_t driver_id), 0);
-DEFINE_STUB(rte_cryptodev_socket_id, int, (uint8_t dev_id), 0);
 DEFINE_STUB(rte_cryptodev_configure, int, (uint8_t dev_id, struct rte_cryptodev_config *config), 0);
+#if RTE_VERSION >= RTE_VERSION_NUM(19, 02, 0, 0)
+DEFINE_STUB(rte_cryptodev_queue_pair_setup, int, (uint8_t dev_id, uint16_t queue_pair_id,
+               const struct rte_cryptodev_qp_conf *qp_conf, int socket_id), 0);
+DEFINE_STUB(rte_cryptodev_sym_session_pool_create, struct rte_mempool *, (const char *name,
+               uint32_t nb_elts,
+               uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
+               int socket_id), (struct rte_mempool *)1);
+#else
 DEFINE_STUB(rte_cryptodev_queue_pair_setup, int, (uint8_t dev_id, uint16_t queue_pair_id,
                const struct rte_cryptodev_qp_conf *qp_conf,
                int socket_id, struct rte_mempool *session_pool), 0);
-DEFINE_STUB(rte_cryptodev_start, int, (uint8_t dev_id), 0)
+#endif
+DEFINE_STUB(rte_cryptodev_start, int, (uint8_t dev_id), 0);
 DEFINE_STUB_V(rte_cryptodev_stop, (uint8_t dev_id));
 DEFINE_STUB(rte_cryptodev_sym_session_create, struct rte_cryptodev_sym_session *,
            (struct rte_mempool *mempool), (struct rte_cryptodev_sym_session *)1);
-DEFINE_STUB(rte_cryptodev_sym_session_clear, int, (uint8_t dev_id,
-               struct rte_cryptodev_sym_session *sess), 0);
-DEFINE_STUB(rte_cryptodev_sym_session_free, int, (struct rte_cryptodev_sym_session *sess), 0);
 DEFINE_STUB(rte_cryptodev_sym_session_init, int, (uint8_t dev_id,
                struct rte_cryptodev_sym_session *sess,
                struct rte_crypto_sym_xform *xforms, struct rte_mempool *mempool), 0);
 DEFINE_STUB(rte_vdev_init, int, (const char *name, const char *args), 0);
-void __attribute__((noreturn)) __rte_panic(const char *funcname, const char *format, ...)
-{
-       abort();
-}
-struct rte_mempool_ops_table rte_mempool_ops_table;
+DEFINE_STUB(rte_cryptodev_sym_session_free, int, (struct rte_cryptodev_sym_session *sess), 0);
+DEFINE_STUB(rte_vdev_uninit, int, (const char *name), 0);
+
 struct rte_cryptodev *rte_cryptodevs;
-__thread unsigned per_lcore__lcore_id = 0;
 
 /* global vars and setup/cleanup functions used for all test functions */
 struct spdk_bdev_io *g_bdev_io;
@@ -118,21 +216,6 @@ struct vbdev_crypto g_crypto_bdev;
 struct rte_config *g_test_config;
 struct device_qp g_dev_qp;
 
-#define MAX_TEST_BLOCKS 8192
-struct rte_crypto_op *g_test_crypto_ops[MAX_TEST_BLOCKS];
-struct rte_crypto_op *g_test_dequeued_ops[MAX_TEST_BLOCKS];
-struct rte_crypto_op *g_test_dev_full_ops[MAX_TEST_BLOCKS];
-
-/* These globals are externs in our local rte_ header files so we can control
- * specific functions for mocking.
- */
-uint16_t g_dequeue_mock;
-uint16_t g_enqueue_mock;
-unsigned ut_rte_crypto_op_bulk_alloc;
-int ut_rte_crypto_op_attach_sym_session = 0;
-
-int ut_rte_cryptodev_info_get = 0;
-bool ut_rte_cryptodev_info_get_mocked = false;
 void
 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
 {
@@ -148,7 +231,7 @@ rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
 void
 spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, uint64_t len)
 {
-       cb(g_io_ch, g_bdev_io);
+       cb(g_io_ch, g_bdev_io, true);
 }
 
 /* Mock these functions to call the callback and then return the value we require */
@@ -216,94 +299,11 @@ spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status sta
        g_completion_called = true;
 }
 
-/* Used in testing device full condition */
-static inline uint16_t
-rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
-                           struct rte_crypto_op **ops, uint16_t nb_ops)
-{
-       int i;
-
-       CU_ASSERT(nb_ops > 0);
-
-       for (i = 0; i < nb_ops; i++) {
-               /* Use this empty (til now) array of pointers to store
-                * enqueued operations for assertion in dev_full test.
-                */
-               g_test_dev_full_ops[i] = *ops++;
-       }
-
-       return g_enqueue_mock;
-}
-
-/* This is pretty ugly but in order to complete an IO via the
- * poller in the submit path, we need to first call to this func
- * to return the dequeued value and also decrement it.  On the subsequent
- * call it needs to return 0 to indicate to the caller that there are
- * no more IOs to drain.
- */
-int g_test_overflow = 0;
-static inline uint16_t
-rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
-                           struct rte_crypto_op **ops, uint16_t nb_ops)
-{
-       CU_ASSERT(nb_ops > 0);
-
-       /* A crypto device can be full on enqueue, the driver is designed to drain
-        * the device at the time by calling the poller until it's empty, then
-        * submitting the remaining crypto ops.
-        */
-       if (g_test_overflow) {
-               if (g_dequeue_mock == 0) {
-                       return 0;
-               }
-               *ops = g_test_crypto_ops[g_enqueue_mock];
-               (*ops)->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
-               g_dequeue_mock -= 1;
-       }
-       return (g_dequeue_mock + 1);
-}
-
-/* Instead of allocating real memory, assign the allocations to our
- * test array for assertion in tests.
- */
-static inline unsigned
-rte_crypto_op_bulk_alloc(struct rte_mempool *mempool,
-                        enum rte_crypto_op_type type,
-                        struct rte_crypto_op **ops, uint16_t nb_ops)
-{
-       int i;
-
-       for (i = 0; i < nb_ops; i++) {
-               *ops++ = g_test_crypto_ops[i];
-       }
-       return ut_rte_crypto_op_bulk_alloc;
-}
-
-static __rte_always_inline void
-rte_mempool_put_bulk(struct rte_mempool *mp, void *const *obj_table,
-                    unsigned int n)
-{
-       return;
-}
-
-static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
-{
-       return NULL;
-}
-
-
-static inline int
-rte_crypto_op_attach_sym_session(struct rte_crypto_op *op,
-                                struct rte_cryptodev_sym_session *sess)
-{
-       return ut_rte_crypto_op_attach_sym_session;
-}
-
 /* Global setup for all tests that share a bunch of preparation... */
 static int
 test_setup(void)
 {
-       int i;
+       int i, rc;
 
        /* Prepare essential variables for test routines */
        g_bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct crypto_bdev_io));
@@ -320,6 +320,7 @@ test_setup(void)
        g_crypto_ch->device_qp = &g_dev_qp;
        g_test_config = calloc(1, sizeof(struct rte_config));
        g_test_config->lcore_count = 1;
+       TAILQ_INIT(&g_crypto_ch->pending_cry_ios);
 
        /* Allocate a real mbuf pool so we can test error paths */
        g_mbuf_mp = spdk_mempool_create("mbuf_mp", NUM_MBUFS, sizeof(struct rte_mbuf),
@@ -330,10 +331,14 @@ test_setup(void)
         * same coverage just calloc them here.
         */
        for (i = 0; i < MAX_TEST_BLOCKS; i++) {
-               g_test_crypto_ops[i] = calloc(1, sizeof(struct rte_crypto_op) +
-                                             sizeof(struct rte_crypto_sym_op));
-               g_test_dequeued_ops[i] = calloc(1, sizeof(struct rte_crypto_op) +
-                                               sizeof(struct rte_crypto_sym_op));
+               rc = posix_memalign((void **)&g_test_crypto_ops[i], 64,
+                                   sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op) +
+                                   AES_CBC_IV_LENGTH);
+               if (rc != 0) {
+                       assert(false);
+               }
+               memset(g_test_crypto_ops[i], 0, sizeof(struct rte_crypto_op) +
+                      sizeof(struct rte_crypto_sym_op));
        }
        return 0;
 }
@@ -348,7 +353,6 @@ test_cleanup(void)
        spdk_mempool_free(g_mbuf_mp);
        for (i = 0; i < MAX_TEST_BLOCKS; i++) {
                free(g_test_crypto_ops[i]);
-               free(g_test_dequeued_ops[i]);
        }
        free(g_bdev_io->u.bdev.iovs);
        free(g_bdev_io);
@@ -379,6 +383,7 @@ test_error_paths(void)
        /* same thing but switch to reads to test error path in _crypto_complete_io() */
        g_bdev_io->type = SPDK_BDEV_IO_TYPE_READ;
        g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
+       TAILQ_INSERT_TAIL(&g_crypto_ch->pending_cry_ios, g_bdev_io, module_link);
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
        /* Now with the read_blocks failing */
@@ -397,20 +402,6 @@ test_error_paths(void)
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
        ut_rte_crypto_op_bulk_alloc = 1;
 
-       /* test failure of rte_cryptodev_sym_session_create() */
-       g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
-       MOCK_SET(rte_cryptodev_sym_session_create, NULL);
-       vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
-       CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
-       MOCK_SET(rte_cryptodev_sym_session_create, (struct rte_cryptodev_sym_session *)1);
-
-       /* test failure of rte_cryptodev_sym_session_init() */
-       g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
-       MOCK_SET(rte_cryptodev_sym_session_init, -1);
-       vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
-       CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
-       MOCK_SET(rte_cryptodev_sym_session_init, 0);
-
        /* test failure of rte_crypto_op_attach_sym_session() */
        g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS;
        ut_rte_crypto_op_attach_sym_session = -1;
@@ -436,7 +427,6 @@ test_simple_write(void)
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == 1);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT);
        CU_ASSERT(g_io_ctx->cry_iov.iov_len == 512);
        CU_ASSERT(g_io_ctx->cry_iov.iov_base != NULL);
        CU_ASSERT(g_io_ctx->cry_offset_blocks == 0);
@@ -450,7 +440,7 @@ test_simple_write(void)
        CU_ASSERT(g_test_crypto_ops[0]->sym->m_dst->buf_addr != NULL);
        CU_ASSERT(g_test_crypto_ops[0]->sym->m_dst->data_len == 512);
 
-       spdk_dma_free(g_io_ctx->cry_iov.iov_base);
+       spdk_free(g_io_ctx->cry_iov.iov_base);
        spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[0]->sym->m_src);
        spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[0]->sym->m_dst);
 }
@@ -471,7 +461,6 @@ test_simple_read(void)
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == 1);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
        CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->buf_addr == &test_simple_read);
        CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->data_len == 512);
        CU_ASSERT(g_test_crypto_ops[0]->sym->m_src->next == NULL);
@@ -504,7 +493,6 @@ test_large_rw(void)
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == (int)num_blocks);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
 
        for (i = 0; i < num_blocks; i++) {
                CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_large_rw + (i * block_len));
@@ -530,7 +518,6 @@ test_large_rw(void)
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == (int)num_blocks);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT);
 
        for (i = 0; i < num_blocks; i++) {
                CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_large_rw + (i * block_len));
@@ -548,7 +535,7 @@ test_large_rw(void)
                spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_src);
                spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_dst);
        }
-       spdk_dma_free(g_io_ctx->cry_iov.iov_base);
+       spdk_free(g_io_ctx->cry_iov.iov_base);
 }
 
 static void
@@ -577,7 +564,6 @@ test_dev_full(void)
 
        /* this test only completes one of the 2 IOs (in the drain path) */
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == 1);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
 
        for (i = 0; i < num_blocks; i++) {
                /* One of the src_mbufs was freed because of the device full condition so
@@ -621,7 +607,6 @@ test_crazy_rw(void)
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == num_blocks);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_DECRYPT);
 
        for (i = 0; i < num_blocks; i++) {
                CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_crazy_rw + (i * block_len));
@@ -656,7 +641,6 @@ test_crazy_rw(void)
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_io_ctx->cryop_cnt_remaining == num_blocks);
-       CU_ASSERT(g_io_ctx->crypto_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT);
 
        for (i = 0; i < num_blocks; i++) {
                CU_ASSERT(g_test_crypto_ops[i]->sym->m_src->buf_addr == &test_crazy_rw + (i * block_len));
@@ -670,7 +654,7 @@ test_crazy_rw(void)
                spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_src);
                spdk_mempool_put(g_mbuf_mp, g_test_crypto_ops[i]->sym->m_dst);
        }
-       spdk_dma_free(g_io_ctx->cry_iov.iov_base);
+       spdk_free(g_io_ctx->cry_iov.iov_base);
 }
 
 static void
@@ -695,111 +679,143 @@ test_passthru(void)
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
        MOCK_CLEAR(spdk_bdev_flush_blocks);
 
-       g_bdev_io->type = SPDK_BDEV_IO_TYPE_RESET;
-       MOCK_SET(spdk_bdev_reset, 0);
-       vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
-       CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
-       MOCK_SET(spdk_bdev_reset, -1);
-       vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
-       CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
-       MOCK_CLEAR(spdk_bdev_reset);
-
        /* We should never get a WZ command, we report that we don't support it. */
        g_bdev_io->type = SPDK_BDEV_IO_TYPE_WRITE_ZEROES;
        vbdev_crypto_submit_request(g_io_ch, g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
 }
 
+static void
+test_reset(void)
+{
+       /* TODO: There are a few different ways to do this given that
+        * the code uses spdk_for_each_channel() to implement reset
+        * handling. SUbmitting w/o UT for this function for now and
+        * will follow up with something shortly.
+        */
+}
+
 static void
 test_initdrivers(void)
 {
        int rc;
        static struct spdk_mempool *orig_mbuf_mp;
-       static struct spdk_mempool *orig_session_mp;
+       static struct rte_mempool *orig_session_mp;
+       static struct rte_mempool *orig_session_mp_priv;
+
+
+       /* These tests will alloc and free our g_mbuf_mp
+        * so save that off here and restore it after each test is over.
+        */
+       orig_mbuf_mp = g_mbuf_mp;
+       orig_session_mp = g_session_mp;
+       orig_session_mp_priv = g_session_mp_priv;
+
+       g_session_mp_priv = NULL;
+       g_session_mp = NULL;
+       g_mbuf_mp = NULL;
 
        /* No drivers available, not an error though */
        MOCK_SET(rte_eal_get_configuration, g_test_config);
        MOCK_SET(rte_cryptodev_count, 0);
        rc = vbdev_crypto_init_crypto_drivers();
        CU_ASSERT(rc == 0);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
 
        /* Test failure of DPDK dev init. */
        MOCK_SET(rte_cryptodev_count, 2);
        MOCK_SET(rte_vdev_init, -1);
        rc = vbdev_crypto_init_crypto_drivers();
        CU_ASSERT(rc == -EINVAL);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
        MOCK_SET(rte_vdev_init, 0);
 
        /* Can't create session pool. */
        MOCK_SET(spdk_mempool_create, NULL);
-       orig_mbuf_mp = g_mbuf_mp;
-       orig_session_mp = g_session_mp;
        rc = vbdev_crypto_init_crypto_drivers();
-       g_mbuf_mp = orig_mbuf_mp;
-       g_session_mp = orig_session_mp;
        CU_ASSERT(rc == -ENOMEM);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
        MOCK_CLEAR(spdk_mempool_create);
 
-       /* Can't create op pool. These tests will alloc and free our g_mbuf_mp
-        * so save that off here and restore it after each test is over.
-        */
-       orig_mbuf_mp = g_mbuf_mp;
-       orig_session_mp = g_session_mp;
+       /* Can't create op pool. */
        MOCK_SET(rte_crypto_op_pool_create, NULL);
        rc = vbdev_crypto_init_crypto_drivers();
-       g_mbuf_mp = orig_mbuf_mp;
-       g_session_mp = orig_session_mp;
        CU_ASSERT(rc == -ENOMEM);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
        MOCK_SET(rte_crypto_op_pool_create, (struct rte_mempool *)1);
 
-       /* Check resources are sufficient failure. */
-       orig_mbuf_mp = g_mbuf_mp;
-       orig_session_mp = g_session_mp;
+       /* Check resources are not sufficient */
+       MOCK_CLEARED_ASSERT(spdk_mempool_create);
        rc = vbdev_crypto_init_crypto_drivers();
-       g_mbuf_mp = orig_mbuf_mp;
-       g_session_mp = orig_session_mp;
        CU_ASSERT(rc == -EINVAL);
 
        /* Test crypto dev configure failure. */
        MOCK_SET(rte_cryptodev_device_count_by_driver, 2);
        MOCK_SET(rte_cryptodev_info_get, 1);
        MOCK_SET(rte_cryptodev_configure, -1);
-       orig_mbuf_mp = g_mbuf_mp;
-       orig_session_mp = g_session_mp;
+       MOCK_CLEARED_ASSERT(spdk_mempool_create);
        rc = vbdev_crypto_init_crypto_drivers();
-       g_mbuf_mp = orig_mbuf_mp;
-       g_session_mp = orig_session_mp;
        MOCK_SET(rte_cryptodev_configure, 0);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
        CU_ASSERT(rc == -EINVAL);
 
        /* Test failure of qp setup. */
        MOCK_SET(rte_cryptodev_queue_pair_setup, -1);
-       orig_mbuf_mp = g_mbuf_mp;
-       orig_session_mp = g_session_mp;
+       MOCK_CLEARED_ASSERT(spdk_mempool_create);
        rc = vbdev_crypto_init_crypto_drivers();
-       g_mbuf_mp = orig_mbuf_mp;
-       g_session_mp = orig_session_mp;
        CU_ASSERT(rc == -EINVAL);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
        MOCK_SET(rte_cryptodev_queue_pair_setup, 0);
 
        /* Test failure of dev start. */
        MOCK_SET(rte_cryptodev_start, -1);
-       orig_mbuf_mp = g_mbuf_mp;
-       orig_session_mp = g_session_mp;
+       MOCK_CLEARED_ASSERT(spdk_mempool_create);
        rc = vbdev_crypto_init_crypto_drivers();
-       g_mbuf_mp = orig_mbuf_mp;
-       g_session_mp = orig_session_mp;
        CU_ASSERT(rc == -EINVAL);
+       CU_ASSERT(g_mbuf_mp == NULL);
+       CU_ASSERT(g_session_mp == NULL);
+       CU_ASSERT(g_session_mp_priv == NULL);
        MOCK_SET(rte_cryptodev_start, 0);
 
        /* Test happy path. */
+       MOCK_CLEARED_ASSERT(spdk_mempool_create);
        rc = vbdev_crypto_init_crypto_drivers();
+       /* We don't have spdk_mempool_create mocked right now, so make sure to free the mempools. */
+       CU_ASSERT(g_mbuf_mp != NULL);
+       CU_ASSERT(g_session_mp != NULL);
+       spdk_mempool_free(g_mbuf_mp);
+       rte_mempool_free(g_session_mp);
+       if (g_session_mp_priv != NULL) {
+               /* g_session_mp_priv may or may not be set depending on the DPDK version */
+               rte_mempool_free(g_session_mp_priv);
+       }
        CU_ASSERT(rc == 0);
+
+       /* restore our initial values. */
+       g_mbuf_mp = orig_mbuf_mp;
+       g_session_mp = orig_session_mp;
+       g_session_mp_priv = orig_session_mp_priv;
 }
 
 static void
 test_crypto_op_complete(void)
 {
+       /* Need to prove to scan-build that we are setting iov_bases properly. */
+       void *old_iov_base;
+       struct crypto_bdev_io *orig_ctx;
+
        /* Make sure completion code respects failure. */
        g_bdev_io->internal.status = SPDK_BDEV_IO_STATUS_FAILED;
        g_completion_called = false;
@@ -821,7 +837,10 @@ test_crypto_op_complete(void)
        g_completion_called = false;
        MOCK_SET(spdk_bdev_writev_blocks, 0);
        /* Code under test will free this, if not ASAN will complain. */
-       g_io_ctx->cry_iov.iov_base = spdk_dma_malloc(16, 0x10, NULL);
+       g_io_ctx->cry_iov.iov_base = spdk_malloc(16, 0x10, NULL, SPDK_ENV_LCORE_ID_ANY,
+                                    SPDK_MALLOC_DMA);
+       orig_ctx = (struct crypto_bdev_io *)g_bdev_io->driver_ctx;
+       old_iov_base = orig_ctx->cry_iov.iov_base;
        _crypto_operation_complete(g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS);
        CU_ASSERT(g_completion_called == true);
@@ -832,7 +851,12 @@ test_crypto_op_complete(void)
        g_completion_called = false;
        MOCK_SET(spdk_bdev_writev_blocks, -1);
        /* Code under test will free this, if not ASAN will complain. */
-       g_io_ctx->cry_iov.iov_base = spdk_dma_malloc(16, 0x10, NULL);
+       g_io_ctx->cry_iov.iov_base = spdk_malloc(16, 0x40, NULL, SPDK_ENV_LCORE_ID_ANY,
+                                    SPDK_MALLOC_DMA);
+       /* To Do: remove this garbage assert as soon as scan-build stops throwing a
+        * heap use after free error.
+        */
+       SPDK_CU_ASSERT_FATAL(old_iov_base != orig_ctx->cry_iov.iov_base);
        _crypto_operation_complete(g_bdev_io);
        CU_ASSERT(g_bdev_io->internal.status == SPDK_BDEV_IO_STATUS_FAILED);
        CU_ASSERT(g_completion_called == true);
@@ -894,7 +918,9 @@ main(int argc, char **argv)
            CU_add_test(suite, "test_crypto_op_complete",
                        test_crypto_op_complete) == NULL ||
            CU_add_test(suite, "test_supported_io",
-                       test_supported_io) == NULL
+                       test_supported_io) == NULL ||
+           CU_add_test(suite, "test_reset",
+                       test_reset) == NULL
           ) {
                CU_cleanup_registry();
                return CU_get_error();