From f8298d013cbe93e2ac0c99201a2800e5ee7c95f4 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 26 Jan 2013 09:05:02 -0800 Subject: [PATCH] TESTS: Add WRITESAME10 tests to the new testsuite --- Makefile.am | 8 +- test-tool/0180_writesame10_unmap.c | 2 - test-tool/0190_writesame16_unmap.c | 2 - test-tool/iscsi-support.c | 147 +++++++++++++++++++ test-tool/iscsi-support.h | 28 +++- test-tool/iscsi-test-cu.c | 47 ++++++ test-tool/iscsi-test-cu.h | 7 + test-tool/test_writesame10_0blocks.c | 69 +++++++++ test-tool/test_writesame10_beyond_eol.c | 91 ++++++++++++ test-tool/test_writesame10_simple.c | 65 ++++++++ test-tool/test_writesame10_unmap.c | 122 +++++++++++++++ test-tool/test_writesame10_unmap_unaligned.c | 49 +++++++ test-tool/test_writesame10_wrprotect.c | 51 +++++++ 13 files changed, 682 insertions(+), 6 deletions(-) create mode 100644 test-tool/test_writesame10_0blocks.c create mode 100644 test-tool/test_writesame10_beyond_eol.c create mode 100644 test-tool/test_writesame10_simple.c create mode 100644 test-tool/test_writesame10_unmap.c create mode 100644 test-tool/test_writesame10_unmap_unaligned.c create mode 100644 test-tool/test_writesame10_wrprotect.c diff --git a/Makefile.am b/Makefile.am index a5f0489..6aa69b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -236,7 +236,13 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/test_write16_beyond_eol.c \ test-tool/test_write16_0blocks.c \ test-tool/test_write16_wrprotect.c \ - test-tool/test_write16_flags.c + test-tool/test_write16_flags.c \ + test-tool/test_writesame10_simple.c \ + test-tool/test_writesame10_beyond_eol.c \ + test-tool/test_writesame10_0blocks.c \ + test-tool/test_writesame10_wrprotect.c \ + test-tool/test_writesame10_unmap.c \ + test-tool/test_writesame10_unmap_unaligned.c endif diff --git a/test-tool/0180_writesame10_unmap.c b/test-tool/0180_writesame10_unmap.c index 6ca4741..1f26330 100644 --- a/test-tool/0180_writesame10_unmap.c +++ b/test-tool/0180_writesame10_unmap.c @@ -27,8 +27,6 @@ int T0180_writesame10_unmap(const char *initiator, const char *url) int full_size; struct scsi_inquiry_logical_block_provisioning *inq_lbp; int ret, i, lun; - int lbpws10 = 0; - int anc_sup = 0; printf("0180_writesame10_unmap:\n"); printf("=======================\n"); diff --git a/test-tool/0190_writesame16_unmap.c b/test-tool/0190_writesame16_unmap.c index 1ced2ee..ad78aeb 100644 --- a/test-tool/0190_writesame16_unmap.c +++ b/test-tool/0190_writesame16_unmap.c @@ -27,8 +27,6 @@ int T0190_writesame16_unmap(const char *initiator, const char *url) int full_size; struct scsi_inquiry_logical_block_provisioning *inq_lbp; int ret, i, lun; - int lbpws = 0; - int anc_sup = 0; printf("0190_writesame16_unmap:\n"); printf("=======================\n"); diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 1af7ea4..86ffe1f 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -57,6 +57,9 @@ enum scsi_inquiry_peripheral_device_type device_type; int sccs; int encserv; int data_loss; +int lbpws10; +int lbpws; +int anc_sup; int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); @@ -2423,6 +2426,150 @@ write16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, return 0; } +int +writesame10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send WRITESAME10 LBA:%d blocks:%d " + "wrprotect:%d anchor:%d unmap:%d group:%d", + lba, num, wrprotect, + anchor, unmap_flag, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = iscsi_writesame10_sync(iscsi, lun, lba, + data, datalen, num, + anchor, unmap_flag, wrprotect, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 command: %s", + 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) { + logging(LOG_NORMAL, "[SKIPPED] WRITESAME10 is not implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] WRITESAME10 command: " + "failed with sense. %s", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] WRITESAME10 returned SUCCESS."); + return 0; +} + +int +writesame10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting LBA_OUT_OF_RANGE) LBA:%d blocks:%d " + "wrprotect:%d anchor:%d unmap:%d group:%d", + lba, num, wrprotect, + anchor, unmap_flag, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = iscsi_writesame10_sync(iscsi, lun, lba, + data, datalen, num, + anchor, unmap_flag, wrprotect, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 command: %s", + 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) { + logging(LOG_NORMAL, "[SKIPPED] WRITESAME10 is not implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] WRITESAME10 successful but should " + "have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE"); + 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) { + logging(LOG_NORMAL, "[FAILED] WRITESAME10 failed with wrong sense. " + "Should have failed with ILLEGAL_REQUEST/" + "LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] WRITESAME10 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); + return 0; +} + +int +writesame10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting INVALID_FIELD_IN_CDB) LBA:%d blocks:%d " + "wrprotect:%d anchor:%d unmap:%d group:%d", + lba, num, wrprotect, + anchor, unmap_flag, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = iscsi_writesame10_sync(iscsi, lun, lba, + data, datalen, num, + anchor, unmap_flag, wrprotect, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 command: %s", + 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) { + logging(LOG_NORMAL, "[SKIPPED] WRITESAME10 is not implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] WRITESAME10 successful but should " + "have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB"); + 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_INVALID_FIELD_IN_CDB) { + logging(LOG_NORMAL, "[FAILED] WRITESAME10 failed with wrong sense. " + "Should have failed with ILLEGAL_REQUEST/" + "INVALID_FIELD_IN_CDB. Sense:%s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] WRITESAME10 returned ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB."); + return 0; +} int diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index b4f82c3..462997c 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -48,7 +48,7 @@ do { \ #define CHECK_FOR_THIN_PROVISIONING \ do { \ - if (lbpme == 0){ \ + if (lbpme == 0) { \ logging(LOG_VERBOSE, "[SKIPPED] Logical unit is fully" \ " provisioned. Skipping test"); \ CU_PASS("[SKIPPED] Logical unit is fully provisioned." \ @@ -57,6 +57,26 @@ do { \ } \ } while (0); +#define CHECK_FOR_LBPWS10 \ +do { \ + if (lbpws10 == 0) { \ + logging(LOG_VERBOSE, "[SKIPPED] Logical unit does not" \ + " have LBPWS10. Skipping test"); \ + CU_PASS("[SKIPPED] Logical unit does not have LBPWS10." \ + " Skipping test"); \ + return; \ + } \ +} while (0); + +#define CHECK_FOR_LBPPB_GT_1 \ +do { \ + if (lbppb < 2) { \ + logging(LOG_VERBOSE, "[SKIPPED] LBPPB < 2. Skipping test"); \ + CU_PASS("[SKIPPED] LBPPB < 2. Skipping test"); \ + return; \ + } \ +} while (0); + #define CHECK_FOR_SBC \ do { \ if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {\ @@ -78,6 +98,9 @@ extern int removable; extern enum scsi_inquiry_peripheral_device_type device_type; extern int sccs; extern int encserv; +extern int lbpws10; +extern int lbpws; +extern int anc_sup; struct iscsi_context *iscsi_context_login(const char *initiatorname, const char *url, int *lun); @@ -190,6 +213,9 @@ int write12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, ui int write16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); int write16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); int write16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); +int writesame10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); +int writesame10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); +int writesame10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 4b07998..a32b5fa 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -174,6 +174,16 @@ static CU_TestInfo tests_write16[] = { CU_TEST_INFO_NULL }; +static CU_TestInfo tests_writesame10[] = { + { (char *)"testWriteSame10Simple", test_writesame10_simple }, + { (char *)"testWriteSame10BeyondEol", test_writesame10_beyond_eol }, + { (char *)"testWriteSame10ZeroBlocks", test_writesame10_0blocks }, + { (char *)"testWriteSame10WriteProtect", test_writesame10_wrprotect }, + { (char *)"testWriteSame10Unmap", test_writesame10_unmap }, + { (char *)"testWriteSame10UnmapUnaligned", test_writesame10_unmap_unaligned }, + CU_TEST_INFO_NULL +}; + static CU_SuiteInfo suites[] = { { (char *)"TestTestUnitReady", test_setup, test_teardown, tests_testunitready }, @@ -203,6 +213,8 @@ static CU_SuiteInfo suites[] = { tests_write12 }, { (char *)"TestWrite16", test_setup, test_teardown, tests_write16 }, + { (char *)"TestWriteSame10", test_setup, test_teardown, + tests_writesame10 }, CU_SUITE_INFO_NULL }; @@ -576,6 +588,41 @@ main(int argc, char *argv[]) encserv = inq->encserv; scsi_free_scsi_task(task); + /* if thin provisioned we also need to read the VPD page for it */ + if (lbpme != 0) { + struct scsi_inquiry_logical_block_provisioning *inq_lbp; + + task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64); + if (task == NULL || task->status != SCSI_STATUS_GOOD) { + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic)); + return -1; + } + full_size = scsi_datain_getfullsize(task); + if (full_size > task->datain.size) { + scsi_free_scsi_task(task); + + /* we need more data for the full list */ + if ((task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) { + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic)); + scsi_free_scsi_task(task); + return -1; + } + } + + inq_lbp = scsi_datain_unmarshall(task); + if (inq_lbp == NULL) { + printf("failed to unmarshall inquiry datain blob\n"); + scsi_free_scsi_task(task); + return -1; + } + + lbpws10 = inq_lbp->lbpws10; + lbpws = inq_lbp->lbpws; + anc_sup = inq_lbp->anc_sup; + + scsi_free_scsi_task(task); + } + iscsi_logout_sync(iscsic); iscsi_destroy_context(iscsic); diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index de205e7..9351914 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -112,4 +112,11 @@ void test_write16_0blocks(void); void test_write16_wrprotect(void); void test_write16_flags(void); +void test_writesame10_simple(void); +void test_writesame10_beyond_eol(void); +void test_writesame10_0blocks(void); +void test_writesame10_wrprotect(void); +void test_writesame10_unmap(void); +void test_writesame10_unmap_unaligned(void); + #endif /* _ISCSI_TEST_CU_H_ */ diff --git a/test-tool/test_writesame10_0blocks.c b/test-tool/test_writesame10_0blocks.c new file mode 100644 index 0000000..0ad900e --- /dev/null +++ b/test-tool/test_writesame10_0blocks.c @@ -0,0 +1,69 @@ +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +void +test_writesame10_0blocks(void) +{ + int ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + if (num_blocks >= 0x80000000) { + CU_PASS("LUN is too big for write-beyond-eol tests with WRITESAME10. Skipping test.\n"); + return; + } + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks at LBA==0"); + ret = writesame10(iscsic, tgt_lun, 0, + block_size, 0, + 0, 0, 0, 0, NULL); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks one block past end-of-LUN"); + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, + block_size, 0, + 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks at LBA==2^31"); + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, + block_size, 0, + 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks at LBA==-1"); + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, -1, + block_size, 0, + 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); +} diff --git a/test-tool/test_writesame10_beyond_eol.c b/test-tool/test_writesame10_beyond_eol.c new file mode 100644 index 0000000..b1b2549 --- /dev/null +++ b/test-tool/test_writesame10_beyond_eol.c @@ -0,0 +1,91 @@ +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + + +void +test_writesame10_beyond_eol(void) +{ + int i, ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + if (num_blocks >= 0x80000000) { + CU_PASS("LUN is too big for write-beyond-eol tests with WRITESAME10. Skipping test.\n"); + return; + } + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks one block beyond the end"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks - i + 1, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks at LBA==2^31"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks at LBA==-1"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, -1, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test WRITESAME10 2-256 blocks all but one block beyond the end"); + for (i = 2; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_writesame10_simple.c b/test-tool/test_writesame10_simple.c new file mode 100644 index 0000000..c6de61c --- /dev/null +++ b/test-tool/test_writesame10_simple.c @@ -0,0 +1,65 @@ + +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-support.h" +#include "iscsi-test-cu.h" + + +void +test_writesame10_simple(void) +{ + int i, ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the start of the LUN"); + + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame10(iscsic, tgt_lun, 0, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + } + + logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the end of the LUN"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size ); + + ret = writesame10(iscsic, tgt_lun, num_blocks - i, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + CU_ASSERT_EQUAL(ret, 0); + } + +} diff --git a/test-tool/test_writesame10_unmap.c b/test-tool/test_writesame10_unmap.c new file mode 100644 index 0000000..730148c --- /dev/null +++ b/test-tool/test_writesame10_unmap.c @@ -0,0 +1,122 @@ + +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-support.h" +#include "iscsi-test-cu.h" + + +void +test_writesame10_unmap(void) +{ + int i, ret; + unsigned int j; + + CHECK_FOR_DATALOSS; + CHECK_FOR_THIN_PROVISIONING; + CHECK_FOR_LBPWS10; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the start of the LUN"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size * i); + + logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); + memset(buf, 0xff, block_size * i); + ret = write10(iscsic, tgt_lun, 0, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); + ret = writesame10(iscsic, tgt_lun, 0, + block_size, i, + 0, 1, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Read %d blocks and verify they are now zero", i); + ret = read10(iscsic, tgt_lun, 0, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf); + for (j = 0; j < block_size * i; j++) { + if (buf[j] != 0) { + CU_ASSERT_EQUAL(buf[j], 0); + } + } + free(buf); + } + + + logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the end of the LUN"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size * i); + + logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); + memset(buf, 0xff, block_size * i); + ret = write10(iscsic, tgt_lun, num_blocks - i, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); + ret = writesame10(iscsic, tgt_lun, num_blocks - i, + block_size, i, + 0, 1, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Read %d blocks and verify they are now zero", i); + ret = read10(iscsic, tgt_lun, num_blocks - i, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf); + for (j = 0; j < block_size * i; j++) { + if (buf[j] != 0) { + CU_ASSERT_EQUAL(buf[j], 0); + } + } + free(buf); + } + + logging(LOG_VERBOSE, "Verify that WRITESAME10 ANCHOR==1 + UNMAP==0 is invalid"); + ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, + block_size, 1, + 1, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + + if (anc_sup) { + logging(LOG_VERBOSE, "Test WRITESAME10 ANCHOR==1 + UNMAP==0"); + ret = writesame10(iscsic, tgt_lun, 0, + block_size, 1, + 1, 1, 0, 0, NULL); + } else { + logging(LOG_VERBOSE, "Test WRITESAME10 ANCHOR==1 + UNMAP==0 no ANC_SUP so expecting to fail"); + ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, + block_size, 1, + 1, 1, 0, 0, NULL); + } + + CU_ASSERT_EQUAL(ret, 0); + +} diff --git a/test-tool/test_writesame10_unmap_unaligned.c b/test-tool/test_writesame10_unmap_unaligned.c new file mode 100644 index 0000000..1ad7d0a --- /dev/null +++ b/test-tool/test_writesame10_unmap_unaligned.c @@ -0,0 +1,49 @@ + +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-support.h" +#include "iscsi-test-cu.h" + + +void +test_writesame10_unmap_unaligned(void) +{ + int i, ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_THIN_PROVISIONING; + CHECK_FOR_LBPWS10; + CHECK_FOR_LBPPB_GT_1; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test that unaligned WRITESAME10 Unmap fails. LBPPB==%d", lbppb); + for (i = 1; i < lbppb; i++) { + logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10 at LBA:%d", lbppb - i, i); + ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, i, + block_size, lbppb - i, + 0, 1, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_writesame10_wrprotect.c b/test-tool/test_writesame10_wrprotect.c new file mode 100644 index 0000000..fea783f --- /dev/null +++ b/test-tool/test_writesame10_wrprotect.c @@ -0,0 +1,51 @@ +/* + Copyright (C) 2013 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 +#include + +#include + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +void +test_writesame10_wrprotect(void) +{ + int i, ret; + unsigned char *buf; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + /* + * Try out different non-zero values for WRPROTECT. + * They should all fail. + */ + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME10 with non-zero WRPROTECT"); + buf = malloc(block_size); + for (i = 1; i < 8; i++) { + ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, + block_size, 1, + 0, 0, i, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + } + free(buf); +}