From 67f4ceca6bc4b322a37dc5a8bd2884e1160ea149 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 14 Jul 2012 17:55:10 +1000 Subject: [PATCH] Add COMPAREANDWRITE and ORWRITE to the readonly tests --- test-tool/0300_readonly.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test-tool/0300_readonly.c b/test-tool/0300_readonly.c index 90a979a..bcda83f 100644 --- a/test-tool/0300_readonly.c +++ b/test-tool/0300_readonly.c @@ -51,6 +51,8 @@ int T0300_readonly(const char *initiator, const char *url, int data_loss, int sh printf("9, WRITEVERIFY10 at LUN 0 should fail.\n"); printf("10, WRITEVERIFY12 at LUN 0 should fail.\n"); printf("11, WRITEVERIFY16 at LUN 0 should fail.\n"); + printf("12, COMPAREANDWRITE at LUN 0 should fail.\n"); + printf("13, ORWRITE at LUN 0 should fail.\n"); printf("\n"); return 0; } @@ -479,6 +481,66 @@ test11: printf("[OK]\n"); test12: + /* Write one block at lba 0 */ + printf("COMPAREWRITE to LUN 0 ... "); + task = iscsi_compareandwrite_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test13; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("COMPAREANDWRITE command should fail when writing to readonly devices\n"); + ret++; + scsi_free_scsi_task(task); + goto test13; + } + if (task->status != SCSI_STATUS_CHECK_CONDITION + || task->sense.key != SCSI_SENSE_DATA_PROTECTION + || task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) { + printf("[FAILED]\n"); + printf("COMPAREANDWRITE failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n"); + ret++; + scsi_free_scsi_task(task); + goto test13; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +test13: + + /* Write one block at lba 0 */ + printf("ORWRITE to LUN 0 ... "); + task = iscsi_orwrite_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test14; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("ORWRITE command should fail when writing to readonly devices\n"); + ret++; + scsi_free_scsi_task(task); + goto test14; + } + if (task->status != SCSI_STATUS_CHECK_CONDITION + || task->sense.key != SCSI_SENSE_DATA_PROTECTION + || task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) { + printf("[FAILED]\n"); + printf("ORWRITE failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n"); + ret++; + scsi_free_scsi_task(task); + goto test14; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +test14: + finished: iscsi_logout_sync(iscsi);