From ea8e4c4115c10a86ef7969ecbaed0dbe5eb1a54f Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 21 Feb 2016 12:10:34 -0800 Subject: [PATCH] Tests: add helper for TESTUNITREADY Signed-off-by: Ronnie Sahlberg --- test-tool/iscsi-support.h | 14 +++++++ test-tool/test_iscsi_cmdsn_toohigh.c | 6 +-- test-tool/test_iscsi_cmdsn_toolow.c | 6 +-- test-tool/test_preventallow_2_itnexuses.c | 5 +-- test-tool/test_preventallow_cold_reset.c | 17 ++++----- test-tool/test_preventallow_eject.c | 13 ++----- test-tool/test_preventallow_itnexus_loss.c | 13 ++----- test-tool/test_preventallow_logout.c | 12 ++---- test-tool/test_preventallow_lun_reset.c | 11 ++---- test-tool/test_preventallow_warm_reset.c | 11 ++---- test-tool/test_sanitize_reset.c | 10 ++--- test-tool/test_startstopunit_noloej.c | 43 ++++++++-------------- test-tool/test_startstopunit_pwrcnd.c | 7 ++-- test-tool/test_startstopunit_simple.c | 22 ++++------- test-tool/test_testunitready_simple.c | 7 +--- 15 files changed, 80 insertions(+), 117 deletions(-) diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 031527f..41d1a9b 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -434,6 +434,20 @@ do { \ CU_ASSERT_EQUAL(_r, 0); \ } while (0); +#define TESTUNITREADY(...) \ + do { \ + int _r; \ + _r = testunitready(__VA_ARGS__); \ + if (_r == -2) { \ + logging(LOG_NORMAL, "[SKIPPED] TESTUNITREADY " \ + "is not implemented."); \ + CU_PASS("[SKIPPED] Target does not support " \ + "TESTUNITREADY. Skipping test"); \ + return; \ + } \ + CU_ASSERT_EQUAL(_r, 0); \ + } while (0); + #define VERIFY10(...) \ do { \ int _r; \ diff --git a/test-tool/test_iscsi_cmdsn_toohigh.c b/test-tool/test_iscsi_cmdsn_toohigh.c index 51683b8..8c5f72e 100644 --- a/test-tool/test_iscsi_cmdsn_toohigh.c +++ b/test-tool/test_iscsi_cmdsn_toohigh.c @@ -85,8 +85,6 @@ void test_iscsi_cmdsn_toohigh(void) iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN. should work again"); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); } diff --git a/test-tool/test_iscsi_cmdsn_toolow.c b/test-tool/test_iscsi_cmdsn_toolow.c index 9652813..e5eef78 100644 --- a/test-tool/test_iscsi_cmdsn_toolow.c +++ b/test-tool/test_iscsi_cmdsn_toolow.c @@ -86,8 +86,6 @@ void test_iscsi_cmdsn_toolow(void) iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN. should work again"); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); } diff --git a/test-tool/test_preventallow_2_itnexuses.c b/test-tool/test_preventallow_2_itnexuses.c index c87d0f6..c4e6a41 100644 --- a/test-tool/test_preventallow_2_itnexuses.c +++ b/test-tool/test_preventallow_2_itnexuses.c @@ -54,9 +54,8 @@ test_preventallow_2_itnexuses(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Create a second connection to the target"); ret = mpath_sd2_get_or_clone(sd, &sd2); diff --git a/test-tool/test_preventallow_cold_reset.c b/test-tool/test_preventallow_cold_reset.c index fd703de..2543ceb 100644 --- a/test-tool/test_preventallow_cold_reset.c +++ b/test-tool/test_preventallow_cold_reset.c @@ -28,7 +28,7 @@ void test_preventallow_cold_reset(void) { - int ret; + int ret; CHECK_FOR_SBC; CHECK_FOR_REMOVABLE; @@ -52,27 +52,24 @@ test_preventallow_cold_reset(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Perform cold reset on target"); ret = iscsi_task_mgmt_target_cold_reset_sync(sd->iscsi_ctx); + CU_ASSERT_EQUAL(ret, 0); + logging(LOG_VERBOSE, "Wait until all unit attentions clear"); while (testunitready(sd, EXPECT_STATUS_GOOD) != 0) ; - CU_ASSERT_EQUAL(ret, 0); - logging(LOG_VERBOSE, "Try to eject the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Load the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, diff --git a/test-tool/test_preventallow_eject.c b/test-tool/test_preventallow_eject.c index 1a4e061..a2bc997 100644 --- a/test-tool/test_preventallow_eject.c +++ b/test-tool/test_preventallow_eject.c @@ -28,8 +28,6 @@ void test_preventallow_eject(void) { - int ret; - CHECK_FOR_SBC; CHECK_FOR_REMOVABLE; @@ -44,9 +42,8 @@ test_preventallow_eject(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); PREVENTALLOW(sd, 0); @@ -54,12 +51,10 @@ test_preventallow_eject(void) logging(LOG_VERBOSE, "Try to eject the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Set the PREVENT flag"); PREVENTALLOW(sd, 1); diff --git a/test-tool/test_preventallow_itnexus_loss.c b/test-tool/test_preventallow_itnexus_loss.c index d604f19..2e99cae 100644 --- a/test-tool/test_preventallow_itnexus_loss.c +++ b/test-tool/test_preventallow_itnexus_loss.c @@ -28,8 +28,6 @@ void test_preventallow_itnexus_loss(void) { - int ret; - CHECK_FOR_SBC; CHECK_FOR_REMOVABLE; @@ -52,10 +50,8 @@ test_preventallow_itnexus_loss(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Disconnect from the target."); iscsi_destroy_context(sd->iscsi_ctx); @@ -72,9 +68,8 @@ test_preventallow_itnexus_loss(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Load the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, diff --git a/test-tool/test_preventallow_logout.c b/test-tool/test_preventallow_logout.c index 2133a62..ed24955 100644 --- a/test-tool/test_preventallow_logout.c +++ b/test-tool/test_preventallow_logout.c @@ -28,8 +28,6 @@ void test_preventallow_logout(void) { - int ret; - CHECK_FOR_SBC; CHECK_FOR_REMOVABLE; @@ -52,9 +50,8 @@ test_preventallow_logout(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Logout from target"); iscsi_logout_sync(sd->iscsi_ctx); @@ -72,9 +69,8 @@ test_preventallow_logout(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Load the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, diff --git a/test-tool/test_preventallow_lun_reset.c b/test-tool/test_preventallow_lun_reset.c index 0d96a45..c37f7ae 100644 --- a/test-tool/test_preventallow_lun_reset.c +++ b/test-tool/test_preventallow_lun_reset.c @@ -52,10 +52,8 @@ test_preventallow_lun_reset(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Perform LUN reset on target"); ret = iscsi_task_mgmt_lun_reset_sync(sd->iscsi_ctx, sd->iscsi_lun); @@ -70,9 +68,8 @@ test_preventallow_lun_reset(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Load the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, diff --git a/test-tool/test_preventallow_warm_reset.c b/test-tool/test_preventallow_warm_reset.c index 8be600e..da5781a 100644 --- a/test-tool/test_preventallow_warm_reset.c +++ b/test-tool/test_preventallow_warm_reset.c @@ -52,10 +52,8 @@ test_preventallow_warm_reset(void) EXPECT_REMOVAL_PREVENTED); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Perform warm reset on target"); ret = iscsi_task_mgmt_target_warm_reset_sync(sd->iscsi_ctx); @@ -70,9 +68,8 @@ test_preventallow_warm_reset(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Load the medium"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, diff --git a/test-tool/test_sanitize_reset.c b/test-tool/test_sanitize_reset.c index c9f2caa..0f79bcc 100644 --- a/test-tool/test_sanitize_reset.c +++ b/test-tool/test_sanitize_reset.c @@ -95,9 +95,8 @@ test_sanitize_reset(void) logging(LOG_VERBOSE, "Verify that the SANITIZE has started and that " "TESTUNITREADY fails with SANITIZE_IN_PROGRESS"); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Verify that STARTSTOPUNIT fails with " "SANITIZE_IN_PROGRESS"); @@ -164,9 +163,8 @@ test_sanitize_reset(void) } logging(LOG_VERBOSE, "Verify that the SANITIZE is still going."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Wait until the SANITIZE operation has finished"); while (testunitready_clear_ua(sd)) { diff --git a/test-tool/test_startstopunit_noloej.c b/test-tool/test_startstopunit_noloej.c index 77ba875..b128ed2 100644 --- a/test-tool/test_startstopunit_noloej.c +++ b/test-tool/test_startstopunit_noloej.c @@ -29,8 +29,6 @@ void test_startstopunit_noloej(void) { - int ret; - logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test STARTSTOPUNIT LOEJ==0"); if (!inq->rmb) { @@ -44,73 +42,64 @@ test_startstopunit_noloej(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==0 START==1"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 0, 1, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==0"); STARTSTOPUNIT(sd, 1, 0, 0, 0, 0, 0, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==1"); STARTSTOPUNIT(sd, 1, 0, 0, 0, 0, 1, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==0"); STARTSTOPUNIT(sd, 0, 0, 0, 1, 0, 0, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==1"); STARTSTOPUNIT(sd, 0, 0, 0, 1, 0, 1, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==0"); STARTSTOPUNIT(sd, 1, 0, 0, 1, 0, 0, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==1"); STARTSTOPUNIT(sd, 1, 0, 0, 1, 0, 1, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "In case the target did eject the medium, load it again."); STARTSTOPUNIT(sd, 1, 0, 0, 0, 1, 1, diff --git a/test-tool/test_startstopunit_pwrcnd.c b/test-tool/test_startstopunit_pwrcnd.c index 6d9157d..0fac705 100644 --- a/test-tool/test_startstopunit_pwrcnd.c +++ b/test-tool/test_startstopunit_pwrcnd.c @@ -29,7 +29,7 @@ void test_startstopunit_pwrcnd(void) { - int i, ret; + int i; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test STARTSTOPUNIT PowerCondition"); @@ -45,9 +45,8 @@ test_startstopunit_pwrcnd(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); } logging(LOG_VERBOSE, "In case the target did eject the medium, load it again."); diff --git a/test-tool/test_startstopunit_simple.c b/test-tool/test_startstopunit_simple.c index 82cffee..f97d047 100644 --- a/test-tool/test_startstopunit_simple.c +++ b/test-tool/test_startstopunit_simple.c @@ -52,29 +52,24 @@ test_startstopunit_simple(void) logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is ejected."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Test we can load the removable the media with IMMED==1"); STARTSTOPUNIT(sd, 1, 0, 0, 0, 1, 1, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can read from the media."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); - + TESTUNITREADY(sd, + EXPECT_SANITIZE); logging(LOG_VERBOSE, "Test we can eject removable the media with IMMED==1"); STARTSTOPUNIT(sd, 0, 0, 0, 0, 1, 0, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is ejected."); - ret = testunitready(sd, - EXPECT_NO_MEDIUM); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_NO_MEDIUM); logging(LOG_VERBOSE, "Test we can load the removable the media with IMMED==1"); @@ -82,7 +77,6 @@ test_startstopunit_simple(void) EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Verify we can access the media again."); - ret = testunitready(sd, - EXPECT_SANITIZE); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_SANITIZE); } diff --git a/test-tool/test_testunitready_simple.c b/test-tool/test_testunitready_simple.c index f2e8eca..9b46fb4 100644 --- a/test-tool/test_testunitready_simple.c +++ b/test-tool/test_testunitready_simple.c @@ -27,11 +27,8 @@ void test_testunitready_simple(void) { - int ret; - logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test TESTUNITREADY"); - ret = testunitready(sd, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + TESTUNITREADY(sd, + EXPECT_STATUS_GOOD); }