diff --git a/test-tool/0000_testunitready_simple.c b/test-tool/0000_testunitready_simple.c index c699aff..818eb1c 100644 --- a/test-tool/0000_testunitready_simple.c +++ b/test-tool/0000_testunitready_simple.c @@ -23,7 +23,6 @@ int T0000_testunitready_simple(const char *initiator, const char *url, int data_loss _U_, int show_info) { struct iscsi_context *iscsi; - struct scsi_task *task; int ret, lun; printf("0000_testunitready_simple:\n"); @@ -43,23 +42,10 @@ int T0000_testunitready_simple(const char *initiator, const char *url, int data_ ret=0; - printf("Test TESTUNITREADY ... "); - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send TEST UNIT READY command: %s\n", iscsi_get_error(iscsi)); - ret++; + ret = testunitready(iscsi, lun); + if (ret != 0) { goto finished; } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("TEST UNIT READY command: failed with sense %s\n", iscsi_get_error(iscsi)); - ret++; - scsi_free_scsi_task(task); - goto finished; - } - scsi_free_scsi_task(task); - printf("[OK]\n"); finished: iscsi_logout_sync(iscsi); diff --git a/test-tool/0360_startstopunit_simple.c b/test-tool/0360_startstopunit_simple.c index 917bde3..53d9a09 100644 --- a/test-tool/0360_startstopunit_simple.c +++ b/test-tool/0360_startstopunit_simple.c @@ -33,9 +33,9 @@ int T0360_startstopunit_simple(const char *initiator, const char *url, int data_ printf("===================\n"); if (show_info) { printf("Test basic STARTSTOPUNIT functionality.\n"); - printf("1, Verify we can eject the media with IMMED==1\n"); + printf("1, Verify we can eject removable the media with IMMED==1\n"); printf("2, Verify we can load the media back again with IMMED==1\n"); - printf("3, Verify we can eject the media with IMMED==0\n"); + printf("3, Verify we can eject removable the media with IMMED==0\n"); printf("4, Verify we can load the media back again with IMMED==0\n"); printf("\n"); return 0; @@ -96,50 +96,32 @@ int T0360_startstopunit_simple(const char *initiator, const char *url, int data_ printf("[FAILED]\n"); printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto test2; + goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto test2; - } - scsi_free_scsi_task(task); - - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send TESTUNITREADY command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test2; - } - if (removable) { - 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)) { - printf("[FAILED]\n"); - printf("TESTUNITREADY after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n"); - ret = -1; - scsi_free_scsi_task(task); - goto test2; - } - } else { - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("TESTUNITREADY command: failed with sense after STARTSTOPUNIT %s\n", iscsi_get_error(iscsi)); - ret = -1; - scsi_free_scsi_task(task); - goto test2; - } + goto finished; } scsi_free_scsi_task(task); printf("[OK]\n"); + if (removable) { + printf("Medium is removable. Check with TESTUNITREADY that was removed.\n"); + ret = testunitready_nomedium(iscsi, lun); + if (ret != 0) { + goto finished; + } + } else { + printf("Medium is not removable. Check with TESTUNITREADY that medium is still present.\n"); + ret = testunitready(iscsi, lun); + if (ret != 0) { + goto finished; + } + } -test2: printf("STARTSTOPUNIT try to mount the media again with IMMED==1 ... "); task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1); @@ -147,36 +129,24 @@ test2: printf("[FAILED]\n"); printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto test3; + goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto test3; - } - scsi_free_scsi_task(task); - - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send TESTUNITREADY command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test3; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("TESTUNITREADY command: failed with sense after STARTSTOPUNIT %s\n", iscsi_get_error(iscsi)); - ret = -1; - scsi_free_scsi_task(task); - goto test3; + goto finished; } scsi_free_scsi_task(task); printf("[OK]\n"); + printf("Check with TESTUNITREADY that the medium is present.\n"); + ret = testunitready(iscsi, lun); + if (ret != 0) { + goto finished; + } -test3: printf("STARTSTOPUNIT try to eject the media with IMMED==0 ... "); task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 0, 1, 0); @@ -184,50 +154,32 @@ test3: printf("[FAILED]\n"); printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto test4; + goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto test4; - } - scsi_free_scsi_task(task); - - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send TESTUNITREADY command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test4; - } - if (removable) { - 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)) { - printf("[FAILED]\n"); - printf("TESTUNITREADY after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n"); - ret = -1; - scsi_free_scsi_task(task); - goto test4; - } - } else { - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("TESTUNITREADY command: failed with sense after STARTSTOPUNIT %s\n", iscsi_get_error(iscsi)); - ret = -1; - scsi_free_scsi_task(task); - goto test4; - } + goto finished; } scsi_free_scsi_task(task); printf("[OK]\n"); + if (removable) { + printf("Medium is removable. Check with TESTUNITREADY that was removed.\n"); + ret = testunitready_nomedium(iscsi, lun); + if (ret != 0) { + goto finished; + } + } else { + printf("Medium is not removable. Check with TESTUNITREADY that medium is still present.\n"); + ret = testunitready(iscsi, lun); + if (ret != 0) { + goto finished; + } + } -test4: printf("STARTSTOPUNIT try to mount the media again with IMMED==0 ... "); task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 0, 1, 1); @@ -235,36 +187,25 @@ test4: printf("[FAILED]\n"); printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto test5; + goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto test5; - } - scsi_free_scsi_task(task); - - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send TESTUNITREADY command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test5; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("TESTUNITREADY command: failed with sense after STARTSTOPUNIT %s\n", iscsi_get_error(iscsi)); - ret = -1; - scsi_free_scsi_task(task); - goto test5; + goto finished; } scsi_free_scsi_task(task); printf("[OK]\n"); -test5: + printf("Check with TESTUNITREADY that the medium is present.\n"); + ret = testunitready(iscsi, lun); + if (ret != 0) { + goto finished; + } + finished: iscsi_logout_sync(iscsi); diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index e95dcb8..ddf686b 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -721,6 +721,56 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun, return 0; } +int testunitready(struct iscsi_context *iscsi, int lun) +{ + struct scsi_task *task; + + printf("Send TESTUNITREADY ... "); + task = iscsi_testunitready_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TESTUNITREADY command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("TESTUNITREADY command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + return 0; +} + +int testunitready_nomedium(struct iscsi_context *iscsi, int lun) +{ + struct scsi_task *task; + + printf("Send TESTUNITREADY expecting it to fail with CHECK_CONDITION/NOT_READY/MEDIUM_NOT_PRESENT ... "); + task = iscsi_testunitready_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TESTUNITREADY command: %s\n", + iscsi_get_error(iscsi)); + 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)) { + printf("[FAILED]\n"); + printf("TESTUNITREADY Should have failed with NOT_READY/MEDIUM_NOT_PRESENT*\n"); + scsi_free_scsi_task(task); + return -1; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + return 0; +} int main(int argc, const char *argv[]) { diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index b2664d3..7ec134f 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -252,5 +252,7 @@ int release(struct iscsi_context *iscsi, int lun, unsigned long long key, struct resvn_type_info *rtip); int verify_reserved_as(struct iscsi_context *iscsi, int lun, unsigned long long key, struct resvn_type_info *rtip); +int testunitready(struct iscsi_context *iscsi, int lun); +int testunitready_nomedium(struct iscsi_context *iscsi, int lun); #endif /* _ISCSI_TEST_H_ */