lib/idxd: add unit test for idxd_reset_dev()

Signed-off-by: paul luse <paul.e.luse@intel.com>
Change-Id: I8a3c50c7ff5cbee1069088a3a06b83f06eb9a85f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1819
Community-CI: Mellanox Build Bot
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>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
paul luse 2020-04-12 15:48:17 -04:00 committed by Ben Walker
parent 3075d23318
commit e333c67bc0

View File

@ -37,6 +37,8 @@
#include "common/lib/test_env.c"
#include "idxd/idxd.c"
#define FAKE_REG_SIZE 1024
int
spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx)
{
@ -81,7 +83,31 @@ mock_movdir64b(void *dst, const void *src)
return;
}
#define FAKE_REG_SIZE 1024
static int
test_idxd_reset_dev(void)
{
struct spdk_idxd_device idxd = {};
union idxd_cmdsts_reg *fake_cmd_status_reg;
int rc;
idxd.reg_base = calloc(1, FAKE_REG_SIZE);
SPDK_CU_ASSERT_FATAL(idxd.reg_base != NULL);
fake_cmd_status_reg = idxd.reg_base + IDXD_CMDSTS_OFFSET;
/* Test happy path */
rc = idxd_reset_dev(&idxd);
CU_ASSERT(rc == 0);
/* Test error reported path */
fake_cmd_status_reg->err = 1;
rc = idxd_reset_dev(&idxd);
CU_ASSERT(rc == -EINVAL);
free(idxd.reg_base);
return 0;
}
static int
test_idxd_wait_cmd(void)
{
@ -162,6 +188,7 @@ int main(int argc, char **argv)
CU_ADD_TEST(suite, test_spdk_idxd_reconfigure_chan);
CU_ADD_TEST(suite, test_spdk_idxd_set_config);
CU_ADD_TEST(suite, test_idxd_wait_cmd);
CU_ADD_TEST(suite, test_idxd_reset_dev);
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();