From 27ea207fd458370dce6a8e033b43091a512fc7ac Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 24 Jun 2012 07:43:28 +1000 Subject: [PATCH] Improve WRITE10/12/16 tests --- test-tool/0223_write16_0blocks.c | 70 +++++++++++++++++++++++----- test-tool/0233_write12_0blocks.c | 78 ++++++++++++++++++++++++++----- test-tool/0293_write10_0blocks.c | 80 ++++++++++++++++++++++++++------ 3 files changed, 191 insertions(+), 37 deletions(-) diff --git a/test-tool/0223_write16_0blocks.c b/test-tool/0223_write16_0blocks.c index 6797dd3..dcd002d 100644 --- a/test-tool/0223_write16_0blocks.c +++ b/test-tool/0223_write16_0blocks.c @@ -36,6 +36,8 @@ int T0223_write16_0blocks(const char *initiator, const char *url, int data_loss, printf("1, Read at LBA:0 should work.\n"); printf("2, Read at LBA:end-of-lun should work.\n"); printf("3, Read at LBA:end-of-lun+1 should fail.\n"); + printf("4, Read at LBA:2^63 should fail.\n"); + printf("5, Read at LBA:-1 should fail.\n"); printf("\n"); return 0; } @@ -78,57 +80,101 @@ int T0223_write16_0blocks(const char *initiator, const char *url, int data_loss, } - printf("Write16 0blocks at LBA:0 "); + printf("WRITE16 0blocks at LBA:0 "); task = iscsi_write16_sync(iscsi, lun, 0, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test2; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + printf("WRITE16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test2; } printf("[OK]\n"); - printf("Write16 0blocks at LBA: "); + +test2: + printf("WRITE16 0blocks at LBA: "); task = iscsi_write16_sync(iscsi, lun, num_blocks, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test3; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + printf("WRITE16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test3; } printf("[OK]\n"); - printf("Write16 0blocks at LBA: "); + +test3: + printf("WRITE16 0blocks at LBA: "); task = iscsi_write16_sync(iscsi, lun, num_blocks + 1, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test4; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write16 command: Should fail when writing 0blocks beyond end\n"); + printf("WRITE16 command: Should fail when writing 0blocks beyond end\n"); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test4; } printf("[OK]\n"); +test4: + printf("WRITE16 0blocks at LBA 2^63 ... "); + task = iscsi_write16_sync(iscsi, lun, 0x8000000000000000, NULL, 0, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test5; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITE16 command: Should fail when writing 0blocks at 2^31\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + printf("[OK]\n"); + + +test5: + printf("WRITE16 0blocks at LBA -1 ... "); + task = iscsi_write16_sync(iscsi, lun, -1, NULL, 0, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test6; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITE16 command: Should fail when writing 0blocks at -1\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test6; + } + printf("[OK]\n"); + + +test6: + finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); diff --git a/test-tool/0233_write12_0blocks.c b/test-tool/0233_write12_0blocks.c index 9a1716b..0f8a608 100644 --- a/test-tool/0233_write12_0blocks.c +++ b/test-tool/0233_write12_0blocks.c @@ -36,6 +36,8 @@ int T0233_write12_0blocks(const char *initiator, const char *url, int data_loss, printf("1, Read at LBA:0 should work.\n"); printf("2, Read at LBA:end-of-lun should work.\n"); printf("3, Read at LBA:end-of-lun+1 should fail.\n"); + printf("4, Read at LBA:2^63 should fail (only on LUNs < 2TB).\n"); + printf("5, Read at LBA:-1 should fail (only on LUNs < 2TB).\n"); printf("\n"); return 0; } @@ -78,57 +80,109 @@ int T0233_write12_0blocks(const char *initiator, const char *url, int data_loss, } - printf("Write12 0blocks at LBA:0 "); + printf("WRITE12 0blocks at LBA:0 "); task = iscsi_write12_sync(iscsi, lun, 0, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test2; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + printf("WRITE12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test2; } printf("[OK]\n"); - printf("Write12 0blocks at LBA: "); + +test2: + printf("WRITE12 0blocks at LBA: "); task = iscsi_write12_sync(iscsi, lun, num_blocks, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test3; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + printf("WRITE12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test3; } printf("[OK]\n"); - printf("Write12 0blocks at LBA: "); + +test3: + printf("WRITE12 0blocks at LBA: "); task = iscsi_write12_sync(iscsi, lun, num_blocks + 1, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test4; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write12 command: Should fail when writing 0blocks beyond end\n"); + printf("WRITE12 command: Should fail when writing 0blocks beyond end\n"); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test4; } printf("[OK]\n"); +test4: + printf("WRITE12 0blocks at LBA 2^31 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test5; + } + task = iscsi_write12_sync(iscsi, lun, 0x80000000, NULL, 0, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test5; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITE12 command: Should fail when writing 0blocks at 2^31\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + printf("[OK]\n"); + + +test5: + printf("WRITE12 0blocks at LBA -1 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test5; + } + task = iscsi_write12_sync(iscsi, lun, -1, NULL, 0, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test6; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITE12 command: Should fail when writing 0blocks at -1\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test6; + } + printf("[OK]\n"); + + +test6: + finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); diff --git a/test-tool/0293_write10_0blocks.c b/test-tool/0293_write10_0blocks.c index 23a80ac..889605e 100644 --- a/test-tool/0293_write10_0blocks.c +++ b/test-tool/0293_write10_0blocks.c @@ -27,7 +27,7 @@ int T0293_write10_0blocks(const char *initiator, const char *url, int data_loss, struct scsi_readcapacity16 *rc16; int ret = 0, lun; uint32_t block_size; - uint32_t num_blocks; + uint64_t num_blocks; printf("0293_write10_0blocks:\n"); printf("====================\n"); @@ -36,6 +36,8 @@ int T0293_write10_0blocks(const char *initiator, const char *url, int data_loss, printf("1, Read at LBA:0 should work.\n"); printf("2, Read at LBA:end-of-lun should work.\n"); printf("3, Read at LBA:end-of-lun+1 should fail.\n"); + printf("4, Read at LBA:2^63 should fail (only on LUNs < 2TB).\n"); + printf("5, Read at LBA:-1 should fail (only on LUNs < 2TB).\n"); printf("\n"); return 0; } @@ -78,57 +80,109 @@ int T0293_write10_0blocks(const char *initiator, const char *url, int data_loss, } - printf("Write10 0blocks at LBA:0 "); + printf("WRITE10 0blocks at LBA:0 "); task = iscsi_write10_sync(iscsi, lun, 0, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test2; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + printf("WRITE10 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test2; } printf("[OK]\n"); - printf("Write10 0blocks at LBA: "); + +test2: + printf("WRITE10 0blocks at LBA: "); task = iscsi_write10_sync(iscsi, lun, num_blocks, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test3; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + printf("WRITE10 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test3; } printf("[OK]\n"); - printf("Write10 0blocks at LBA: "); + +test3: + printf("WRITE10 0blocks at LBA: "); task = iscsi_write10_sync(iscsi, lun, num_blocks + 1, NULL, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi)); ret = -1; - goto finished; + goto test4; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Write10 command: Should fail when writing 0blocks beyond end\n"); + printf("WRITE10 command: Should fail when writing 0blocks beyond end\n"); ret = -1; scsi_free_scsi_task(task); - goto finished; + goto test4; } printf("[OK]\n"); +test4: + printf("WRITE10 0blocks at LBA 2^31 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test5; + } + task = iscsi_write10_sync(iscsi, lun, 0x80000000, NULL, 0, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test5; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITE10 command: Should fail when writing 0blocks at 2^31\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + printf("[OK]\n"); + + +test5: + printf("WRITE10 0blocks at LBA -1 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test5; + } + task = iscsi_write10_sync(iscsi, lun, -1, NULL, 0, block_size, 0, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test6; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITE10 command: Should fail when writing 0blocks at -1\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test6; + } + printf("[OK]\n"); + + +test6: + finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi);