TESTS: Create helpers for VERIFY16 and switch all tests over to use them

This commit is contained in:
Ronnie Sahlberg
2012-12-26 09:25:45 -08:00
parent eb2a586cc4
commit 3c960c1d42
7 changed files with 261 additions and 269 deletions

View File

@@ -1256,6 +1256,148 @@ int verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *
return 0;
}
int verify16(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int verify16_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
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("VERIFY16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int verify16_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting MISCOMPARE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command successful but should have failed with MISCOMPARE\n");
scsi_free_scsi_task(task);
return -1;
}
if (task->sense.key != SCSI_SENSE_MISCOMPARE) {
printf("[FAILED]\n");
printf("VERIFY16 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s\n", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting LBA_OUT_OF_RANGE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command successful but should have failed with LBA_OUT_OF_RANGE\n");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("VERIFY16 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int main(int argc, const char *argv[])
{
poptContext pc;