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

lib/idxd: add unit test for idxd_wait_cmd()



Signed-off-by: default avatarpaul luse <paul.e.luse@intel.com>
Change-Id: Ida3185431b526092a0450f2452df665ea0d19abb
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1818


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 8e496c51
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -81,6 +81,39 @@ mock_movdir64b(void *dst, const void *src)
	return;
}

#define FAKE_REG_SIZE 1024
static int
test_idxd_wait_cmd(void)
{
	struct spdk_idxd_device idxd = {};
	int timeout = 1;
	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_wait_cmd(&idxd, timeout);
	CU_ASSERT(rc == 0);

	/* Setup up our fake register to set the error bit. */
	fake_cmd_status_reg->err = 1;
	rc = idxd_wait_cmd(&idxd, timeout);
	CU_ASSERT(rc == -EINVAL);
	fake_cmd_status_reg->err = 0;

	/* Setup up our fake register to set the active bit. */
	fake_cmd_status_reg->active = 1;
	rc = idxd_wait_cmd(&idxd, timeout);
	CU_ASSERT(rc == -EBUSY);

	free(idxd.reg_base);

	return 0;
}

static int
test_spdk_idxd_set_config(void)
{
@@ -128,6 +161,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_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();