Commit e333c67b authored by paul luse's avatar paul luse Committed by Ben Walker
Browse files

lib/idxd: add unit test for idxd_reset_dev()



Signed-off-by: default avatarpaul 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 3075d233
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -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();