TESTS: Start fixing up the tests so we can test-suite them properly
Dont call READCAPACITY from every single test. Remove two arguments from the test signatures and turn them into globals. remove the ret++ silliness. Tests return 0 : all ok, -2, skipped or -1 : test failed
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0381_preventallow_eject(const char *initiator, const char *url, int data_loss, int show_info)
|
||||
int T0381_preventallow_eject(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
@@ -94,8 +94,8 @@ int T0381_preventallow_eject(const char *initiator, const char *url, int data_lo
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
goto test2;
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
@@ -105,45 +105,43 @@ int T0381_preventallow_eject(const char *initiator, const char *url, int data_lo
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test2;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
printf("[OK]\n");
|
||||
|
||||
test2:
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
goto test3;
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test3;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
test3:
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
goto test4;
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
@@ -151,16 +149,14 @@ test3:
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
test4:
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
goto test5;
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
@@ -169,18 +165,14 @@ test4:
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test5;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
printf("[OK]\n");
|
||||
|
||||
test5:
|
||||
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
|
||||
Reference in New Issue
Block a user