From f6705d469107403e5e23dbf21656c12c1a490dbc Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 14 Jul 2012 10:54:15 +1000 Subject: [PATCH] TESTS: Add tests for writing beyond the end of the LUN for WRITEVERIFY10/12/16 --- Makefile.am | 5 +- test-tool/0101_read10_beyond_eol.c | 2 +- test-tool/0214_read12_beyondeol.c | 76 +++++++-- test-tool/0314_writeverify10_beyondeol.c | 197 +++++++++++++++++++++++ test-tool/0324_writeverify12_beyondeol.c | 197 +++++++++++++++++++++++ test-tool/0334_writeverify16_beyondeol.c | 189 ++++++++++++++++++++++ test-tool/iscsi-test.c | 3 + test-tool/iscsi-test.h | 3 + 8 files changed, 653 insertions(+), 19 deletions(-) create mode 100644 test-tool/0314_writeverify10_beyondeol.c create mode 100644 test-tool/0324_writeverify12_beyondeol.c create mode 100644 test-tool/0334_writeverify16_beyondeol.c diff --git a/Makefile.am b/Makefile.am index a3d0a80..eb59919 100644 --- a/Makefile.am +++ b/Makefile.am @@ -96,8 +96,11 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0294_write10_beyondeol.c \ test-tool/0300_readonly.c \ test-tool/0310_writeverify10_simple.c test-tool/0311_writeverify10_wrprotect.c \ + test-tool/0314_writeverify10_beyondeol.c \ test-tool/0320_writeverify12_simple.c test-tool/0321_writeverify12_wrprotect.c \ - test-tool/0330_writeverify16_simple.c test-tool/0331_writeverify16_wrprotect.c + test-tool/0324_writeverify12_beyondeol.c \ + test-tool/0330_writeverify16_simple.c test-tool/0331_writeverify16_wrprotect.c \ + test-tool/0334_writeverify16_beyondeol.c endif # LD_PRELOAD library. diff --git a/test-tool/0101_read10_beyond_eol.c b/test-tool/0101_read10_beyond_eol.c index 550be36..a753010 100644 --- a/test-tool/0101_read10_beyond_eol.c +++ b/test-tool/0101_read10_beyond_eol.c @@ -33,7 +33,7 @@ int T0101_read10_beyond_eol(const char *initiator, const char *url, int data_los if (show_info) { printf("Test that READ10 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 2^31 (only on LUNs < 2TB)\n"); + printf("2, Read 1-256 blocks at LBA 2^31 (only on LUNs < 1TB)\n"); printf("3, Read 1-256 blocks at LBA -1 (only on LUN < 2TB)\n"); printf("4, Read 2-256 blocks all but one beyond end-of-lun.\n"); printf("\n"); diff --git a/test-tool/0214_read12_beyondeol.c b/test-tool/0214_read12_beyondeol.c index 80d123d..0b0cb29 100644 --- a/test-tool/0214_read12_beyondeol.c +++ b/test-tool/0214_read12_beyondeol.c @@ -34,7 +34,8 @@ 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("2, Read 1-256 blocks at LBA 2^31 (Only on LUN < 1TB)\n"); + printf("2, Read 1-256 blocks at LBA -1 (Only on LUN < 2TB)\n"); printf("\n"); return 0; } @@ -79,60 +80,101 @@ int T0214_read12_beyondeol(const char *initiator, const char *url, int data_loss task = iscsi_read12_sync(iscsi, lun, num_blocks, 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; + printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test2; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Read12 command should fail when reading beyond end of device\n"); - ret = -1; + printf("READ12 command should fail when reading beyond end of device\n"); + ret++; scsi_free_scsi_task(task); - goto finished; + goto test2; } 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; + ret++; scsi_free_scsi_task(task); - goto finished; + goto test2; } scsi_free_scsi_task(task); } printf("[OK]\n"); + + test2: /* read 1 - 256 blocks at LBA -1 */ printf("Reading 1-256 blocks at LBA -1 ... "); + if (num_blocks >= 0xffffffff) { + printf("LUN is too big, skipping test\n"); + goto test3; + } 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; + printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test3; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); - printf("Read12 command should fail when reading from LBA -1\n"); - ret = -1; + printf("READ12 command should fail when reading from LBA -1\n"); + ret++; scsi_free_scsi_task(task); - goto finished; + goto test3; } 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; + ret++; scsi_free_scsi_task(task); - goto finished; + goto test3; } scsi_free_scsi_task(task); } printf("[OK]\n"); + test3: + /* read 1 - 256 blocks at LBA -1 */ + printf("Reading 1-256 blocks at LBA -1 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test4; + } + 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++; + goto test4; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("READ12 command should fail when reading from LBA -1\n"); + ret++; + scsi_free_scsi_task(task); + goto test4; + } + 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++; + scsi_free_scsi_task(task); + goto test4; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); +test4: finished: iscsi_logout_sync(iscsi); diff --git a/test-tool/0314_writeverify10_beyondeol.c b/test-tool/0314_writeverify10_beyondeol.c new file mode 100644 index 0000000..73d6aa3 --- /dev/null +++ b/test-tool/0314_writeverify10_beyondeol.c @@ -0,0 +1,197 @@ +/* + Copyright (C) 2012 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0314_writeverify10_beyondeol(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_readcapacity16 *rc16; + int ret, i, lun; + uint32_t block_size; + uint32_t num_blocks; + unsigned char data[258 * 512]; + + printf("0314_writeverify10_beyond_eol:\n"); + printf("=======================\n"); + if (show_info) { + printf("Test that WRITEVERIFY10 fails if writing beyond end-of-lun.\n"); + printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n"); + printf("2, Writing 1-256 blocks at LBA 2^31 should fail. (Only on LUN < 1TB)\n"); + printf("3, Writing 1-256 blocks at LBA -1 should fail. (Only on LUN < 2TB)\n"); + printf("4, Writing 1-256 blocks all but one block beyond eol\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + /* find the size of the LUN */ + task = iscsi_readcapacity16_sync(iscsi, lun); + if (task == NULL) { + printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + rc16 = scsi_datain_unmarshall(task); + if (rc16 == NULL) { + printf("failed to unmarshall READCAPACITY10 data. %s\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + block_size = rc16->block_length; + num_blocks = rc16->returned_lba; + scsi_free_scsi_task(task); + + if (!data_loss) { + printf("--dataloss flag is not set. Skipping test\n"); + ret = -1; + goto finished; + } + + + ret = 0; + + /* read 1 - 256 blocks beyond the end of the device */ + printf("Writing 1-256 blocks with one block beyond end-of-device ... "); + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify10_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test2; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY10 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test2; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test2: + + /* read 1 - 256 blocks at lba 2^31 */ + printf("Writing 1-256 blocks at LBA 2^31 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test3; + } + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify10_sync(iscsi, lun, 0x80000000, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test3; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY10 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test3; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test3: + + /* read 1 - 256 blocks at lba -1 */ + printf("Writing 1-256 blocks at LBA -1 ... "); + if (num_blocks >= 0xffffffff) { + printf("LUN is too big, skipping test\n"); + goto test3; + } + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify10_sync(iscsi, lun, 0xffffffff, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test4; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY10 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test4; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test4: + /* read 2-256 blocks, all but one block beyond the eol */ + printf("Writing 1-255 blocks beyond eol starting at last block ... "); + for (i=2; i<=256; i++) { + task = iscsi_writeverify10_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test5; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY10 beyond end-of-lun did not return sense.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + 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("WRITEVERIFY10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + + +test5: + +finished: + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return ret; +} diff --git a/test-tool/0324_writeverify12_beyondeol.c b/test-tool/0324_writeverify12_beyondeol.c new file mode 100644 index 0000000..48add60 --- /dev/null +++ b/test-tool/0324_writeverify12_beyondeol.c @@ -0,0 +1,197 @@ +/* + Copyright (C) 2012 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0324_writeverify12_beyondeol(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_readcapacity16 *rc16; + int ret, i, lun; + uint32_t block_size; + uint32_t num_blocks; + unsigned char data[258 * 512]; + + printf("0324_writeverify12_beyond_eol:\n"); + printf("=======================\n"); + if (show_info) { + printf("Test that WRITEVERIFY12 fails if writing beyond end-of-lun.\n"); + printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n"); + printf("2, Writing 1-256 blocks at LBA 2^31 should fail. (Only on LUN < 1TB)\n"); + printf("3, Writing 1-256 blocks at LBA -1 should fail. (Only on LUN < 2TB)\n"); + printf("4, Writing 1-256 blocks all but one block beyond eol\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + /* find the size of the LUN */ + task = iscsi_readcapacity16_sync(iscsi, lun); + if (task == NULL) { + printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + rc16 = scsi_datain_unmarshall(task); + if (rc16 == NULL) { + printf("failed to unmarshall READCAPACITY10 data. %s\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + block_size = rc16->block_length; + num_blocks = rc16->returned_lba; + scsi_free_scsi_task(task); + + if (!data_loss) { + printf("--dataloss flag is not set. Skipping test\n"); + ret = -1; + goto finished; + } + + + ret = 0; + + /* read 1 - 256 blocks beyond the end of the device */ + printf("Writing 1-256 blocks with one block beyond end-of-device ... "); + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify12_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test2; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY12 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test2; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test2: + + /* read 1 - 256 blocks at lba 2^31 */ + printf("Writing 1-256 blocks at LBA 2^31 ... "); + if (num_blocks > 0x80000000) { + printf("LUN is too big, skipping test\n"); + goto test3; + } + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify12_sync(iscsi, lun, 0x80000000, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test3; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY12 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test3; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test3: + + /* read 1 - 256 blocks at lba -1 */ + printf("Writing 1-256 blocks at LBA -1 ... "); + if (num_blocks >= 0xffffffff) { + printf("LUN is too big, skipping test\n"); + goto test3; + } + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify12_sync(iscsi, lun, 0xffffffff, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test4; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY12 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test4; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test4: + /* read 2-256 blocks, all but one block beyond the eol */ + printf("Writing 1-255 blocks beyond eol starting at last block ... "); + for (i=2; i<=256; i++) { + task = iscsi_writeverify12_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test5; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY12 beyond end-of-lun did not return sense.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + 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("WRITEVERIFY12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + + +test5: + +finished: + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return ret; +} diff --git a/test-tool/0334_writeverify16_beyondeol.c b/test-tool/0334_writeverify16_beyondeol.c new file mode 100644 index 0000000..fd1c1f5 --- /dev/null +++ b/test-tool/0334_writeverify16_beyondeol.c @@ -0,0 +1,189 @@ +/* + Copyright (C) 2012 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0334_writeverify16_beyondeol(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_readcapacity16 *rc16; + int ret, i, lun; + uint32_t block_size; + uint64_t num_blocks; + unsigned char data[258 * 512]; + + printf("0334_writeverify16_beyond_eol:\n"); + printf("=======================\n"); + if (show_info) { + printf("Test that WRITEVERIFY10 fails if writing beyond end-of-lun.\n"); + printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n"); + printf("2, Writing 1-256 blocks at LBA 2^63 should fail.\n"); + printf("3, Writing 1-256 blocks at LBA -1 should fail.\n"); + printf("4, Writing 1-256 blocks all but one block beyond eol\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + /* find the size of the LUN */ + task = iscsi_readcapacity16_sync(iscsi, lun); + if (task == NULL) { + printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + rc16 = scsi_datain_unmarshall(task); + if (rc16 == NULL) { + printf("failed to unmarshall READCAPACITY10 data. %s\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + block_size = rc16->block_length; + num_blocks = rc16->returned_lba; + scsi_free_scsi_task(task); + + if (!data_loss) { + printf("--dataloss flag is not set. Skipping test\n"); + ret = -1; + goto finished; + } + + + ret = 0; + + /* read 1 - 256 blocks beyond the end of the device */ + printf("Writing 1-256 blocks with one block beyond end-of-device ... "); + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify16_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test2; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY16 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test2; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test2: + + /* read 1 - 256 blocks at lba 2^63 */ + printf("Writing 1-256 blocks at LBA 2^63 ... "); + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify16_sync(iscsi, lun, 0x8000000000000000, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test3; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY16 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test3; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test3: + + /* read 1 - 256 blocks at lba -1 */ + printf("Writing 1-256 blocks at LBA -1 ... "); + for (i = 1; i <= 256; i++) { + task = iscsi_writeverify16_sync(iscsi, lun, 0xffffffffffffffff, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test4; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY16 command should fail when writing beyond end of device\n"); + ret++; + scsi_free_scsi_task(task); + goto test4; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test4: + /* read 2-256 blocks, all but one block beyond the eol */ + printf("Writing 1-255 blocks beyond eol starting at last block ... "); + for (i=2; i<=256; i++) { + task = iscsi_writeverify16_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test5; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("WRITEVERIFY16 beyond end-of-lun did not return sense.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + 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("WRITEVERIFY16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + + +test5: + +finished: + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return ret; +} diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index 5e513f7..c4e65c5 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -145,14 +145,17 @@ struct scsi_test tests[] = { /* writeverify10*/ { "T0310_writeverify10_simple", T0310_writeverify10_simple }, { "T0311_writeverify10_wrprotect", T0311_writeverify10_wrprotect }, +{ "T0314_writeverify10_beyondeol", T0314_writeverify10_beyondeol }, /* writeverify12*/ { "T0320_writeverify12_simple", T0320_writeverify12_simple }, { "T0321_writeverify12_wrprotect", T0321_writeverify12_wrprotect }, +{ "T0324_writeverify12_beyondeol", T0324_writeverify12_beyondeol }, /* writeverify16*/ { "T0330_writeverify16_simple", T0330_writeverify16_simple }, { "T0331_writeverify16_wrprotect", T0331_writeverify16_wrprotect }, +{ "T0334_writeverify16_beyondeol", T0334_writeverify16_beyondeol }, { NULL, NULL } }; diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 8e3278e..abc6854 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -105,9 +105,12 @@ int T0300_readonly(const char *initiator, const char *url, int data_loss, int sh int T0310_writeverify10_simple(const char *initiator, const char *url, int data_loss, int show_info); int T0311_writeverify10_wrprotect(const char *initiator, const char *url, int data_loss, int show_info); +int T0314_writeverify10_beyondeol(const char *initiator, const char *url, int data_loss, int show_info); int T0320_writeverify12_simple(const char *initiator, const char *url, int data_loss, int show_info); int T0321_writeverify12_wrprotect(const char *initiator, const char *url, int data_loss, int show_info); +int T0324_writeverify12_beyondeol(const char *initiator, const char *url, int data_loss, int show_info); int T0330_writeverify16_simple(const char *initiator, const char *url, int data_loss, int show_info); int T0331_writeverify16_wrprotect(const char *initiator, const char *url, int data_loss, int show_info); +int T0334_writeverify16_beyondeol(const char *initiator, const char *url, int data_loss, int show_info);