bdev/compress: add UT for vbdev_init_compress_drivers()
Change-Id: I714aad7f82050b5ca480d2c51cffaaee8f059495 Signed-off-by: paul luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452739 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
eb71364bce
commit
9790bba16d
@ -54,6 +54,7 @@ static struct rte_mbuf g_expected_src_mbufs[2];
|
||||
static struct rte_mbuf g_expected_dst_mbufs[2];
|
||||
struct comp_bdev_io *g_io_ctx;
|
||||
struct comp_io_channel *g_comp_ch;
|
||||
struct rte_config *g_test_config;
|
||||
|
||||
/* Those functions are defined as static inline in DPDK, so we can't
|
||||
* mock them straight away. We use defines to redirect them into
|
||||
@ -88,24 +89,27 @@ static inline int mock_rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t ut_max_nb_queue_pairs = 0;
|
||||
void __rte_experimental mock_rte_compressdev_info_get(uint8_t dev_id,
|
||||
struct rte_compressdev_info *dev_info);
|
||||
#define rte_compressdev_info_get mock_rte_compressdev_info_get
|
||||
void __rte_experimental
|
||||
mock_rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info)
|
||||
{
|
||||
/* TODO return global struct */
|
||||
dev_info->max_nb_queue_pairs = ut_max_nb_queue_pairs;
|
||||
}
|
||||
|
||||
int ut_rte_compressdev_configure = 0;
|
||||
int __rte_experimental mock_rte_compressdev_configure(uint8_t dev_id,
|
||||
struct rte_compressdev_config *config);
|
||||
#define rte_compressdev_configure mock_rte_compressdev_configure
|
||||
int __rte_experimental
|
||||
mock_rte_compressdev_configure(uint8_t dev_id, struct rte_compressdev_config *config)
|
||||
{
|
||||
return 0;
|
||||
return ut_rte_compressdev_configure;
|
||||
}
|
||||
|
||||
int ut_rte_compressdev_queue_pair_setup = 0;
|
||||
int __rte_experimental mock_rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
|
||||
uint32_t max_inflight_ops, int socket_id);
|
||||
#define rte_compressdev_queue_pair_setup mock_rte_compressdev_queue_pair_setup
|
||||
@ -113,17 +117,19 @@ int __rte_experimental
|
||||
mock_rte_compressdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
|
||||
uint32_t max_inflight_ops, int socket_id)
|
||||
{
|
||||
return 0;
|
||||
return ut_rte_compressdev_queue_pair_setup;
|
||||
}
|
||||
|
||||
int ut_rte_compressdev_start = 0;
|
||||
int __rte_experimental mock_rte_compressdev_start(uint8_t dev_id);
|
||||
#define rte_compressdev_start mock_rte_compressdev_start
|
||||
int __rte_experimental
|
||||
mock_rte_compressdev_start(uint8_t dev_id)
|
||||
{
|
||||
return 0;
|
||||
return ut_rte_compressdev_start;
|
||||
}
|
||||
|
||||
int ut_rte_compressdev_private_xform_create = 0;
|
||||
int __rte_experimental mock_rte_compressdev_private_xform_create(uint8_t dev_id,
|
||||
const struct rte_comp_xform *xform, void **private_xform);
|
||||
#define rte_compressdev_private_xform_create mock_rte_compressdev_private_xform_create
|
||||
@ -131,17 +137,19 @@ int __rte_experimental
|
||||
mock_rte_compressdev_private_xform_create(uint8_t dev_id,
|
||||
const struct rte_comp_xform *xform, void **private_xform)
|
||||
{
|
||||
return 0;
|
||||
return ut_rte_compressdev_private_xform_create;
|
||||
}
|
||||
|
||||
uint8_t ut_rte_compressdev_count = 0;
|
||||
uint8_t __rte_experimental mock_rte_compressdev_count(void);
|
||||
#define rte_compressdev_count mock_rte_compressdev_count
|
||||
uint8_t __rte_experimental
|
||||
mock_rte_compressdev_count(void)
|
||||
{
|
||||
return 0;
|
||||
return ut_rte_compressdev_count;
|
||||
}
|
||||
|
||||
struct rte_mempool *ut_rte_comp_op_pool_create = NULL;
|
||||
struct rte_mempool *__rte_experimental mock_rte_comp_op_pool_create(const char *name,
|
||||
unsigned int nb_elts, unsigned int cache_size, uint16_t user_size,
|
||||
int socket_id);
|
||||
@ -150,7 +158,7 @@ struct rte_mempool *__rte_experimental
|
||||
mock_rte_comp_op_pool_create(const char *name, unsigned int nb_elts,
|
||||
unsigned int cache_size, uint16_t user_size, int socket_id)
|
||||
{
|
||||
return NULL;
|
||||
return ut_rte_comp_op_pool_create;
|
||||
}
|
||||
|
||||
void mock_rte_pktmbuf_free(struct rte_mbuf *m);
|
||||
@ -195,6 +203,14 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size,
|
||||
return (struct rte_mempool *)tmp;
|
||||
}
|
||||
|
||||
void
|
||||
rte_mempool_free(struct rte_mempool *mp)
|
||||
{
|
||||
if (mp) {
|
||||
spdk_mempool_free((struct spdk_mempool *)mp);
|
||||
}
|
||||
}
|
||||
|
||||
static int ut_spdk_reduce_vol_op_complete_err = 0;
|
||||
void
|
||||
spdk_reduce_vol_writev(struct spdk_reduce_vol *vol, struct iovec *iov, int iovcnt,
|
||||
@ -250,7 +266,6 @@ DEFINE_STUB(spdk_reduce_vol_get_params, const struct spdk_reduce_vol_params *,
|
||||
DEFINE_STUB(rte_socket_id, unsigned, (void), 0);
|
||||
DEFINE_STUB(rte_eal_get_configuration, struct rte_config *, (void), NULL);
|
||||
DEFINE_STUB(rte_vdev_init, int, (const char *name, const char *args), 0);
|
||||
DEFINE_STUB_V(rte_mempool_free, (struct rte_mempool *mp));
|
||||
DEFINE_STUB(rte_compressdev_dequeue_burst, uint16_t,
|
||||
(uint8_t dev_id, uint16_t qp_id, struct rte_comp_op **ops, uint16_t nb_ops), 0);
|
||||
DEFINE_STUB_V(rte_comp_op_free, (struct rte_comp_op *op));
|
||||
@ -423,6 +438,9 @@ test_setup(void)
|
||||
g_io_ctx->comp_bdev = &g_comp_bdev;
|
||||
g_comp_bdev.device_qp = &g_device_qp;
|
||||
|
||||
g_test_config = calloc(1, sizeof(struct rte_config));
|
||||
g_test_config->lcore_count = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -438,6 +456,7 @@ test_cleanup(void)
|
||||
free(g_bdev_io->u.bdev.iovs);
|
||||
free(g_bdev_io);
|
||||
free(g_io_ch);
|
||||
free(g_test_config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -595,6 +614,100 @@ test_reset(void)
|
||||
static void
|
||||
test_initdrivers(void)
|
||||
{
|
||||
int rc;
|
||||
static struct rte_mempool *orig_mbuf_mp;
|
||||
struct comp_device_qp *dev_qp;
|
||||
struct comp_device_qp *tmp_qp;
|
||||
|
||||
orig_mbuf_mp = g_mbuf_mp;
|
||||
g_mbuf_mp = NULL;
|
||||
|
||||
/* test return values from rte_vdev_init() */
|
||||
MOCK_SET(rte_eal_get_configuration, g_test_config);
|
||||
MOCK_SET(rte_vdev_init, -EEXIST);
|
||||
rc = vbdev_init_compress_drivers();
|
||||
/* This is not an error condition, we already have one */
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* success */
|
||||
MOCK_SET(rte_vdev_init, 0);
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* error */
|
||||
MOCK_SET(rte_vdev_init, -2);
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
CU_ASSERT(g_mbuf_mp == NULL);
|
||||
CU_ASSERT(g_comp_op_mp == NULL);
|
||||
|
||||
/* compressdev count 0 */
|
||||
ut_rte_compressdev_count = 0;
|
||||
MOCK_SET(rte_vdev_init, 0);
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* bogus count */
|
||||
ut_rte_compressdev_count = RTE_COMPRESS_MAX_DEVS + 1;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
|
||||
/* can't get mbuf pool */
|
||||
ut_rte_compressdev_count = 1;
|
||||
MOCK_SET(spdk_mempool_create, NULL);
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -ENOMEM);
|
||||
MOCK_CLEAR(spdk_mempool_create);
|
||||
|
||||
/* can't get comp op pool */
|
||||
ut_rte_comp_op_pool_create = NULL;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -ENOMEM);
|
||||
|
||||
/* error on create_compress_dev() */
|
||||
ut_rte_comp_op_pool_create = (struct rte_mempool *)&test_initdrivers;
|
||||
ut_rte_compressdev_configure = -1;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -1);
|
||||
|
||||
/* error on create_compress_dev() but coverage for large num queues */
|
||||
ut_max_nb_queue_pairs = 99;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -1);
|
||||
|
||||
/* qpair setup fails */
|
||||
ut_rte_compressdev_configure = 0;
|
||||
ut_max_nb_queue_pairs = 0;
|
||||
ut_rte_compressdev_queue_pair_setup = -1;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -EINVAL);
|
||||
|
||||
/* rte_compressdev_start fails */
|
||||
ut_rte_compressdev_queue_pair_setup = 0;
|
||||
ut_rte_compressdev_start = -1;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -1);
|
||||
|
||||
/* rte_compressdev_private_xform_create() fails */
|
||||
ut_rte_compressdev_start = 0;
|
||||
ut_rte_compressdev_private_xform_create = -2;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == -2);
|
||||
|
||||
/* rte_compressdev_private_xform_create()succeeds */
|
||||
ut_rte_compressdev_start = 0;
|
||||
ut_rte_compressdev_private_xform_create = 0;
|
||||
rc = vbdev_init_compress_drivers();
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
TAILQ_FOREACH_SAFE(dev_qp, &g_comp_device_qp, link, tmp_qp) {
|
||||
TAILQ_REMOVE(&g_comp_device_qp, dev_qp, link);
|
||||
free(dev_qp->device);
|
||||
free(dev_qp);
|
||||
}
|
||||
|
||||
free(g_mbuf_mp);
|
||||
g_mbuf_mp = orig_mbuf_mp;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user