From d908c1a642a19de66306b8dbe426921c06afedd9 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 3 Jun 2012 10:16:18 +1000 Subject: [PATCH] TESTS: Improve the tests when reading from LBA -1 Signed-off-by: Ronnie Sahlberg --- test-tool/0204_read16_beyondeol.c | 39 ++++++++++++++++++++++++++++++ test-tool/0214_read12_beyondeol.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/test-tool/0204_read16_beyondeol.c b/test-tool/0204_read16_beyondeol.c index 2981e07..a617f78 100644 --- a/test-tool/0204_read16_beyondeol.c +++ b/test-tool/0204_read16_beyondeol.c @@ -34,6 +34,7 @@ int T0204_read16_beyondeol(const char *initiator, const char *url, int data_loss if (show_info) { printf("Test that READ16 fails if reading beyond end-of-lun.\n"); printf("1, Read 1-256 blocks one block beyond end-of-lun.\n"); + printf("2, Read 1-256 blocks at LBA -1\n"); printf("\n"); return 0; } @@ -89,10 +90,48 @@ int T0204_read16_beyondeol(const char *initiator, const char *url, int data_loss scsi_free_scsi_task(task); goto finished; } + 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("READ16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } scsi_free_scsi_task(task); } printf("[OK]\n"); + /* read 1 - 256 blocks at LBA -1 */ + printf("Reading 1-256 blocks at LBA -1 ... "); + for (i = 2; i <= 257; i++) { + task = iscsi_read16_sync(iscsi, lun, -1, i * block_size, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read16 command should fail when reading at LBA -1\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + 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("READ16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + 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/0214_read12_beyondeol.c b/test-tool/0214_read12_beyondeol.c index 9578d90..80d123d 100644 --- a/test-tool/0214_read12_beyondeol.c +++ b/test-tool/0214_read12_beyondeol.c @@ -34,6 +34,7 @@ int T0214_read12_beyondeol(const char *initiator, const char *url, int data_loss if (show_info) { printf("Test that READ12 fails if reading beyond end-of-lun.\n"); printf("1, Read 1-256 blocks one block beyond end-of-lun.\n"); + printf("2, Read 1-256 blocks at LBA -1\n"); printf("\n"); return 0; } @@ -89,6 +90,45 @@ int T0214_read12_beyondeol(const char *initiator, const char *url, int data_loss scsi_free_scsi_task(task); goto finished; } + 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("READ12 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + + /* read 1 - 256 blocks at LBA -1 */ + printf("Reading 1-256 blocks at LBA -1 ... "); + for (i = 2; i <= 257; i++) { + task = iscsi_read12_sync(iscsi, lun, -1, i * block_size, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read12 command should fail when reading from LBA -1\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + 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("READ12 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } scsi_free_scsi_task(task); } printf("[OK]\n");