From 0dbffe1a5d4a9ed9877df46a520ebee03a95d140 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 26 Jan 2013 09:18:39 -0800 Subject: [PATCH] TESTS Add tests for WRITESAME16 to the new testsuite --- Makefile.am | 8 +- test-tool/iscsi-support.c | 146 +++++++++++++++++++ test-tool/iscsi-support.h | 14 ++ test-tool/iscsi-test-cu.c | 12 ++ test-tool/iscsi-test-cu.h | 7 + test-tool/test_writesame16_0blocks.c | 64 ++++++++ test-tool/test_writesame16_beyond_eol.c | 86 +++++++++++ test-tool/test_writesame16_simple.c | 64 ++++++++ test-tool/test_writesame16_unmap.c | 122 ++++++++++++++++ test-tool/test_writesame16_unmap_unaligned.c | 49 +++++++ test-tool/test_writesame16_wrprotect.c | 51 +++++++ 11 files changed, 622 insertions(+), 1 deletion(-) create mode 100644 test-tool/test_writesame16_0blocks.c create mode 100644 test-tool/test_writesame16_beyond_eol.c create mode 100644 test-tool/test_writesame16_simple.c create mode 100644 test-tool/test_writesame16_unmap.c create mode 100644 test-tool/test_writesame16_unmap_unaligned.c create mode 100644 test-tool/test_writesame16_wrprotect.c diff --git a/Makefile.am b/Makefile.am index 6aa69b4..0ac0087 100644 --- a/Makefile.am +++ b/Makefile.am @@ -242,7 +242,13 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.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 + test-tool/test_writesame10_unmap_unaligned.c \ + test-tool/test_writesame16_simple.c \ + test-tool/test_writesame16_beyond_eol.c \ + test-tool/test_writesame16_0blocks.c \ + test-tool/test_writesame16_wrprotect.c \ + test-tool/test_writesame16_unmap.c \ + test-tool/test_writesame16_unmap_unaligned.c endif diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 86ffe1f..f236d52 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -2571,6 +2571,152 @@ writesame10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba return 0; } +int +writesame16(struct iscsi_context *iscsi, int lun, uint64_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 WRITESAME16 LBA:%" PRIu64 " 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_writesame16_sync(iscsi, lun, lba, + data, datalen, num, + anchor, unmap_flag, wrprotect, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 returned SUCCESS."); + return 0; +} + +int +writesame16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_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 WRITESAME16 (Expecting LBA_OUT_OF_RANGE) LBA:%" PRIu64 " 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_writesame16_sync(iscsi, lun, lba, + data, datalen, num, + anchor, unmap_flag, wrprotect, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 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] WRITESAME16 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); + return 0; +} + +int +writesame16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_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 WRITESAME16 (Expecting INVALID_FIELD_IN_CDB) LBA:%" PRIu64 " 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_writesame16_sync(iscsi, lun, lba, + data, datalen, num, + anchor, unmap_flag, wrprotect, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 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] WRITESAME16 returned ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB."); + return 0; +} + + int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize) diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 462997c..fa79c03 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -68,6 +68,17 @@ do { \ } \ } while (0); +#define CHECK_FOR_LBPWS \ +do { \ + if (lbpws == 0) { \ + logging(LOG_VERBOSE, "[SKIPPED] Logical unit does not" \ + " have LBPWS. Skipping test"); \ + CU_PASS("[SKIPPED] Logical unit does not have LBPWS." \ + " Skipping test"); \ + return; \ + } \ +} while (0); + #define CHECK_FOR_LBPPB_GT_1 \ do { \ if (lbppb < 2) { \ @@ -216,6 +227,9 @@ int write16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, ui 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 writesame16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); +int writesame16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); +int writesame16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_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 a32b5fa..fa4a554 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -184,6 +184,16 @@ static CU_TestInfo tests_writesame10[] = { CU_TEST_INFO_NULL }; +static CU_TestInfo tests_writesame16[] = { + { (char *)"testWriteSame16Simple", test_writesame16_simple }, + { (char *)"testWriteSame16BeyondEol", test_writesame16_beyond_eol }, + { (char *)"testWriteSame16ZeroBlocks", test_writesame16_0blocks }, + { (char *)"testWriteSame16WriteProtect", test_writesame16_wrprotect }, + { (char *)"testWriteSame16Unmap", test_writesame16_unmap }, + { (char *)"testWriteSame16UnmapUnaligned", test_writesame16_unmap_unaligned }, + CU_TEST_INFO_NULL +}; + static CU_SuiteInfo suites[] = { { (char *)"TestTestUnitReady", test_setup, test_teardown, tests_testunitready }, @@ -215,6 +225,8 @@ static CU_SuiteInfo suites[] = { tests_write16 }, { (char *)"TestWriteSame10", test_setup, test_teardown, tests_writesame10 }, + { (char *)"TestWriteSame16", test_setup, test_teardown, + tests_writesame16 }, CU_SUITE_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 9351914..4335f59 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -119,4 +119,11 @@ void test_writesame10_wrprotect(void); void test_writesame10_unmap(void); void test_writesame10_unmap_unaligned(void); +void test_writesame16_simple(void); +void test_writesame16_beyond_eol(void); +void test_writesame16_0blocks(void); +void test_writesame16_wrprotect(void); +void test_writesame16_unmap(void); +void test_writesame16_unmap_unaligned(void); + #endif /* _ISCSI_TEST_CU_H_ */ diff --git a/test-tool/test_writesame16_0blocks.c b/test-tool/test_writesame16_0blocks.c new file mode 100644 index 0000000..963b6e0 --- /dev/null +++ b/test-tool/test_writesame16_0blocks.c @@ -0,0 +1,64 @@ +/* + 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_writesame16_0blocks(void) +{ + int ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks at LBA==0"); + ret = writesame16(iscsic, tgt_lun, 0, + block_size, 0, + 0, 0, 0, 0, NULL); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks one block past end-of-LUN"); + ret = writesame16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, + block_size, 0, + 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks at LBA==2^63"); + ret = writesame16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000, + block_size, 0, + 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks at LBA==-1"); + ret = writesame16_lbaoutofrange(iscsic, tgt_lun, -1, + block_size, 0, + 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); +} diff --git a/test-tool/test_writesame16_beyond_eol.c b/test-tool/test_writesame16_beyond_eol.c new file mode 100644 index 0000000..e15777b --- /dev/null +++ b/test-tool/test_writesame16_beyond_eol.c @@ -0,0 +1,86 @@ +/* + 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_writesame16_beyond_eol(void) +{ + int i, ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks one block beyond the end"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame16_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 WRITESAME16. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks at LBA==2^63"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks at LBA==-1"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame16_lbaoutofrange(iscsic, tgt_lun, -1, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test WRITESAME16 2-256 blocks all but one block beyond the end"); + for (i = 2; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame16_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_writesame16_simple.c b/test-tool/test_writesame16_simple.c new file mode 100644 index 0000000..b13b5db --- /dev/null +++ b/test-tool/test_writesame16_simple.c @@ -0,0 +1,64 @@ +/* + 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_writesame16_simple(void) +{ + int i, ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN"); + + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size); + + ret = writesame16(iscsic, tgt_lun, 0, + block_size, i, + 0, 0, 0, 0, buf); + free(buf); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + } + + logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN"); + for (i = 1; i <= 256; i++) { + unsigned char *buf = malloc(block_size ); + + ret = writesame16(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_writesame16_unmap.c b/test-tool/test_writesame16_unmap.c new file mode 100644 index 0000000..852d81f --- /dev/null +++ b/test-tool/test_writesame16_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_writesame16_unmap(void) +{ + int i, ret; + unsigned int j; + + CHECK_FOR_DATALOSS; + CHECK_FOR_THIN_PROVISIONING; + CHECK_FOR_LBPWS; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test WRITESAME16 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 = write16(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 WRITESAME16", i); + ret = writesame16(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 = read16(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 WRITESAME16 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 = write16(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 WRITESAME16", i); + ret = writesame16(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 = read16(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 WRITESAME16 ANCHOR==1 + UNMAP==0 is invalid"); + ret = writesame16_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 WRITESAME16 ANCHOR==1 + UNMAP==0"); + ret = writesame16(iscsic, tgt_lun, 0, + block_size, 1, + 1, 1, 0, 0, NULL); + } else { + logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0 no ANC_SUP so expecting to fail"); + ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, + block_size, 1, + 1, 1, 0, 0, NULL); + } + + CU_ASSERT_EQUAL(ret, 0); + +} diff --git a/test-tool/test_writesame16_unmap_unaligned.c b/test-tool/test_writesame16_unmap_unaligned.c new file mode 100644 index 0000000..ab9feeb --- /dev/null +++ b/test-tool/test_writesame16_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_writesame16_unmap_unaligned(void) +{ + int i, ret; + + CHECK_FOR_DATALOSS; + CHECK_FOR_THIN_PROVISIONING; + CHECK_FOR_LBPWS; + CHECK_FOR_LBPPB_GT_1; + CHECK_FOR_SBC; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test that unaligned WRITESAME16 Unmap fails. LBPPB==%d", lbppb); + for (i = 1; i < lbppb; i++) { + logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16 at LBA:%d", lbppb - i, i); + ret = writesame16_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_writesame16_wrprotect.c b/test-tool/test_writesame16_wrprotect.c new file mode 100644 index 0000000..8221ba8 --- /dev/null +++ b/test-tool/test_writesame16_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_writesame16_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 WRITESAME16 with non-zero WRPROTECT"); + buf = malloc(block_size); + for (i = 1; i < 8; i++) { + ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, + block_size, 1, + 0, 0, i, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + } + free(buf); +}