TESTS: change testunitready to new api

Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
This commit is contained in:
Ronnie Sahlberg
2014-09-17 14:13:14 -07:00
committed by Ronnie Sahlberg
parent fe11a6178b
commit 3ee3964332
18 changed files with 87 additions and 150 deletions

View File

@@ -1377,34 +1377,24 @@ int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int
}
int
testunitready(struct iscsi_context *iscsi, int lun)
testunitready(struct iscsi_context *iscsi, int lun, int status, enum scsi_sense_key key, int *ascq, int num_ascq)
{
struct scsi_task *task;
int ret;
logging(LOG_VERBOSE, "Send TESTUNITREADY");
task = iscsi_testunitready_sync(iscsi, lun);
if (task == NULL) {
logging(LOG_NORMAL,
"[FAILED] Failed to send TESTUNITREADY command: %s",
iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_TIMEOUT) {
logging(LOG_NORMAL,
"TESTUNITREADY timed out");
logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting %s)",
scsi_status_str(status));
task = scsi_cdb_testunitready();
assert(task != NULL);
task = iscsi_scsi_command_sync(iscsi, lun, task, NULL);
ret = check_result("TESTUNITREADY", iscsi, task, status, key, ascq, num_ascq);
if (task) {
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_GOOD) {
logging(LOG_NORMAL,
"[FAILED] TESTUNITREADY command: failed with sense. %s",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned SUCCESS.");
return 0;
return ret;
}
int
@@ -1439,91 +1429,6 @@ out:
return ret;
}
int
testunitready_nomedium(struct iscsi_context *iscsi, int lun)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting MEDIUM_NOT_PRESENT)");
task = iscsi_testunitready_sync(iscsi, lun);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY "
"command: %s", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY command successful. But should have failed with NOT_READY/MEDIUM_NOT_PRESENT*");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_NOT_READY
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY Should have failed "
"with NOT_READY/MEDIUM_NOT_PRESENT* But failed "
"with %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned MEDIUM_NOT_PRESENT.");
return 0;
}
int
testunitready_sanitize(struct iscsi_context *iscsi, int lun)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting SANITIZE_IN_PROGRESS)");
task = iscsi_testunitready_sync(iscsi, lun);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY "
"command: %s", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY command successful. But should have failed with NOT_READY/SANITIZE_IN_PROGRESS");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_NOT_READY
|| task->sense.ascq != SCSI_SENSE_ASCQ_SANITIZE_IN_PROGRESS) {
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY Should have failed "
"with NOT_READY/SANITIZE_IN_PROGRESS But failed "
"with %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned SANITIZE_IN_PROGRESS.");
return 0;
}
int
testunitready_conflict(struct iscsi_context *iscsi, int lun)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting RESERVATION_CONFLICT)");
task = iscsi_testunitready_sync(iscsi, lun);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY "
"command: %s", iscsi_get_error(iscsi));
return -1;
}
if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) {
logging(LOG_NORMAL, "[FAILED] Expected RESERVATION CONFLICT");
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned RESERVATION_CONFLICT.");
return 0;
}
/*
* Returns -1 if allocating a SCSI task failed or if a communication error
* occurred and a SCSI status if a SCSI response has been received.

View File

@@ -289,10 +289,7 @@ int synchronizecache10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t l
int synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed);
int synchronizecache16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed);
int testunitready_clear_ua(struct iscsi_context *iscsi, int lun);
int testunitready(struct iscsi_context *iscsi, int lun);
int testunitready_nomedium(struct iscsi_context *iscsi, int lun);
int testunitready_conflict(struct iscsi_context *iscsi, int lun);
int testunitready_sanitize(struct iscsi_context *iscsi, int lun);
int testunitready(struct iscsi_context *iscsi, int lun, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int mode_sense(struct iscsi_context *iscsi, int lun);
int unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);
int unmap_writeprotected(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);

View File

@@ -64,7 +64,8 @@ void test_iscsi_cmdsn_toohigh(void)
iscsi_set_noautoreconnect(iscsic, 1);
iscsi_set_timeout(iscsic, 3);
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, -1);
if (ret == -1) {
logging(LOG_VERBOSE, "[SUCCESS] We did not receive a reply");
@@ -75,7 +76,8 @@ void test_iscsi_cmdsn_toohigh(void)
iscsi_set_noautoreconnect(iscsic, 0);
logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN. should work again");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -64,7 +64,8 @@ void test_iscsi_cmdsn_toolow(void)
iscsi_set_noautoreconnect(iscsic, 1);
iscsi_set_timeout(iscsic, 3);
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, -1);
if (ret == -1) {
logging(LOG_VERBOSE, "[SUCCESS] We did not receive a reply");
@@ -76,7 +77,8 @@ void test_iscsi_cmdsn_toolow(void)
iscsi_set_noautoreconnect(iscsic, 0);
logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN. should work again");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -65,6 +65,7 @@ test_mandatory_sbc(void)
}
logging(LOG_VERBOSE, "Test TESTUNITREADY.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -48,7 +48,8 @@ test_nomedia_sbc(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY when medium is ejected.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test SYNCHRONIZECACHE10 when medium is ejected.");

View File

@@ -45,7 +45,8 @@ test_preventallow_2_itnexuses(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Create a second connection to the target");

View File

@@ -45,14 +45,15 @@ test_preventallow_cold_reset(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Perform cold reset on target");
ret = iscsi_task_mgmt_target_cold_reset_sync(iscsic);
logging(LOG_VERBOSE, "Wait until all unit attentions clear");
while (testunitready(iscsic, tgt_lun) != 0);
while (testunitready(iscsic, tgt_lun, EXPECT_STATUS_GOOD) != 0);
CU_ASSERT_EQUAL(ret, 0);
@@ -62,7 +63,8 @@ test_preventallow_cold_reset(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can not access the media.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Load the medium");

View File

@@ -45,7 +45,8 @@ test_preventallow_eject(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test we can clear PREVENT flag");
@@ -58,7 +59,8 @@ test_preventallow_eject(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can not access the media.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Set the PREVENT flag");

View File

@@ -45,7 +45,8 @@ test_preventallow_itnexus_loss(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
@@ -65,7 +66,8 @@ test_preventallow_itnexus_loss(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can not access the media.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Load the medium");

View File

@@ -45,7 +45,8 @@ test_preventallow_logout(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
@@ -66,7 +67,8 @@ test_preventallow_logout(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can not access the media.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Load the medium");

View File

@@ -45,7 +45,8 @@ test_preventallow_lun_reset(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
@@ -53,7 +54,7 @@ test_preventallow_lun_reset(void)
ret = iscsi_task_mgmt_lun_reset_sync(iscsic, tgt_lun);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Wait until all unit attentions clear");
while (testunitready(iscsic, tgt_lun) != 0);
while (testunitready(iscsic, tgt_lun, EXPECT_STATUS_GOOD) != 0);
logging(LOG_VERBOSE, "Try to eject the medium");
@@ -62,7 +63,8 @@ test_preventallow_lun_reset(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can not access the media.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Load the medium");

View File

@@ -45,7 +45,8 @@ test_preventallow_warm_reset(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can still access the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
@@ -53,7 +54,7 @@ test_preventallow_warm_reset(void)
ret = iscsi_task_mgmt_target_warm_reset_sync(iscsic);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Wait until all unit attentions clear");
while (testunitready(iscsic, tgt_lun) != 0);
while (testunitready(iscsic, tgt_lun, EXPECT_STATUS_GOOD) != 0);
logging(LOG_VERBOSE, "Try to eject the medium");
@@ -62,7 +63,8 @@ test_preventallow_warm_reset(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can not access the media.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Load the medium");

View File

@@ -86,7 +86,8 @@ test_sanitize_reset(void)
logging(LOG_VERBOSE, "Verify that the SANITIZE has started and that "
"TESTUNITREADY fails with SANITIZE_IN_PROGRESS");
ret = testunitready_sanitize(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify that STARTSTOPUNIT fails with "
@@ -155,7 +156,8 @@ test_sanitize_reset(void)
}
logging(LOG_VERBOSE, "Verify that the SANITIZE is still going.");
ret = testunitready_sanitize(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Wait until the SANITIZE operation has finished");

View File

@@ -45,7 +45,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==0 START==1");
@@ -55,7 +56,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==0");
@@ -65,7 +67,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==1");
@@ -75,7 +78,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==0");
@@ -85,7 +89,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==1");
@@ -95,7 +100,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==0");
@@ -105,7 +111,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==1");
@@ -115,7 +122,8 @@ test_startstopunit_noloej(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);

View File

@@ -46,7 +46,8 @@ test_startstopunit_pwrcnd(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -52,7 +52,8 @@ test_startstopunit_simple(void)
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is ejected.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
@@ -63,7 +64,8 @@ test_startstopunit_simple(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can read from the media.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
@@ -76,7 +78,8 @@ test_startstopunit_simple(void)
logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is ejected.");
ret = testunitready_nomedium(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_NO_MEDIUM);
CU_ASSERT_EQUAL(ret, 0);
@@ -87,6 +90,7 @@ test_startstopunit_simple(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify we can access the media again.");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_SANITIZE);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -30,6 +30,7 @@ test_testunitready_simple(void)
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test TESTUNITREADY");
ret = testunitready(iscsic, tgt_lun);
ret = testunitready(iscsic, tgt_lun,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
}