From 3075d23318afdde1bc174789b933b71a9d265711 Mon Sep 17 00:00:00 2001 From: paul luse Date: Sun, 12 Apr 2020 15:01:40 -0400 Subject: [PATCH] lib/idxd: add unit test for idxd_wait_cmd() Signed-off-by: paul luse Change-Id: Ida3185431b526092a0450f2452df665ea0d19abb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1818 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- test/unit/lib/idxd/idxd.c/idxd_ut.c | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/unit/lib/idxd/idxd.c/idxd_ut.c b/test/unit/lib/idxd/idxd.c/idxd_ut.c index cb1850d7d..dfb817e7c 100644 --- a/test/unit/lib/idxd/idxd.c/idxd_ut.c +++ b/test/unit/lib/idxd/idxd.c/idxd_ut.c @@ -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();