diff --git a/Makefile.am b/Makefile.am index 67beb1a..60fe904 100644 --- a/Makefile.am +++ b/Makefile.am @@ -177,16 +177,21 @@ bin_iscsi_test_cu_LDFLAGS = -ldl -lcunit bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/iscsi-support.c \ test-tool/test_testunitready_simple.c \ + test-tool/test_read6_simple.c \ + test-tool/test_read6_beyond_eol.c \ + test-tool/test_read6_0blocks.c \ test-tool/test_read10_simple.c \ test-tool/test_read10_beyond_eol.c \ test-tool/test_read10_0blocks.c \ test-tool/test_read10_rdprotect.c \ test-tool/test_read10_flags.c \ test-tool/test_read10_invalid.c \ - test-tool/test_readcapacity10_simple.c \ - test-tool/test_read6_simple.c \ - test-tool/test_read6_beyond_eol.c \ - test-tool/test_read6_0blocks.c + test-tool/test_read12_simple.c \ + test-tool/test_read12_beyond_eol.c \ + test-tool/test_read12_0blocks.c \ + test-tool/test_read12_rdprotect.c \ + test-tool/test_read12_flags.c \ + test-tool/test_readcapacity10_simple.c endif diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index fab9371..b62c3b0 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -1143,6 +1143,135 @@ read10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, return 0; } +int +read12(struct iscsi_context *iscsi, int lun, uint32_t lba, + uint32_t datalen, int blocksize, int rdprotect, + int dpo, int fua, int fua_nv, int group, + unsigned char *data) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send READ12 LBA:%d blocks:%d rdprotect:%d " + "dpo:%d fua:%d fua_nv:%d group:%d", + lba, datalen / blocksize, rdprotect, + dpo, fua, fua_nv, group); + + task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, + rdprotect, dpo, fua, fua_nv, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send READ12 command: %s", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] READ12 command: " + "failed with sense. %s", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + if (data != NULL) { + memcpy(data, task->datain.data, task->datain.size); + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] READ12 returned SUCCESS."); + return 0; +} + +int +read12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, + uint32_t datalen, int blocksize, int rdprotect, + int dpo, int fua, int fua_nv, int group, + unsigned char *data) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send READ12 (Expecting INVALID_FIELD_IN_CDB) " + "LBA:%d blocks:%d rdprotect:%d " + "dpo:%d fua:%d fua_nv:%d group:%d", + lba, datalen / blocksize, rdprotect, + dpo, fua, fua_nv, group); + + task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, + rdprotect, dpo, fua, fua_nv, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send READ12 command: %s", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] READ12 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] READ12 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; + } + + if (data != NULL) { + memcpy(data, task->datain.data, task->datain.size); + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] READ12 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); + return 0; +} + +int +read12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, + uint32_t datalen, int blocksize, int rdprotect, + int dpo, int fua, int fua_nv, int group, + unsigned char *data) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send READ12 (Expecting LBA_OUT_OF_RANGE) " + "LBA:%d blocks:%d rdprotect:%d " + "dpo:%d fua:%d fua_nv:%d group:%d", + lba, datalen / blocksize, rdprotect, + dpo, fua, fua_nv, group); + + task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, + rdprotect, dpo, fua, fua_nv, group); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send READ12 command: %s", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] READ12 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] READ12 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; + } + + if (data != NULL) { + memcpy(data, task->datain.data, task->datain.size); + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] READ12 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); + return 0; +} + int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi) { diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 8d60195..fb9404d 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -124,6 +124,9 @@ int read6_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint int read10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); int read10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); int read10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); +int read12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); +int read12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); +int read12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi); int verify10(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize); int verify10_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index c28b356..14b1079 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -79,6 +79,15 @@ static CU_TestInfo tests_read10[] = { CU_TEST_INFO_NULL }; +static CU_TestInfo tests_read12[] = { + { (char *)"testRead12Simple", test_read12_simple }, + { (char *)"testRead12BeyondEol", test_read12_beyond_eol }, + { (char *)"testRead12ZeroBlocks", test_read12_0blocks }, + { (char *)"testRead12ReadProtect", test_read12_rdprotect }, + { (char *)"testRead12Flags", test_read12_flags }, + CU_TEST_INFO_NULL +}; + static CU_TestInfo tests_readcapacity10[] = { { (char *)"testReadCapacity10Simple", test_readcapacity10_simple }, CU_TEST_INFO_NULL @@ -91,6 +100,8 @@ static CU_SuiteInfo suites[] = { tests_read6 }, { (char *)"TestRead10", test_setup, test_teardown, tests_read10 }, + { (char *)"TestRead12", test_setup, test_teardown, + tests_read12 }, { (char *)"TestReadCapacity10", test_setup, test_teardown, tests_readcapacity10 }, CU_SUITE_INFO_NULL diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 33f2145..68394cb 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -50,6 +50,12 @@ void test_read10_rdprotect(void); void test_read10_flags(void); void test_read10_invalid(void); +void test_read12_simple(void); +void test_read12_beyond_eol(void); +void test_read12_0blocks(void); +void test_read12_rdprotect(void); +void test_read12_flags(void); + void test_readcapacity10_simple(void); #endif /* _ISCSI_TEST_CU_H_ */ diff --git a/test-tool/test_read12_0blocks.c b/test-tool/test_read12_0blocks.c new file mode 100644 index 0000000..05a894f --- /dev/null +++ b/test-tool/test_read12_0blocks.c @@ -0,0 +1,58 @@ +/* + 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_read12_0blocks(void) +{ + int ret; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test READ12 0-blocks at LBA==0"); + ret = read12(iscsic, tgt_lun, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + if (num_blocks > 0x80000000) { + CU_PASS("[SKIPPED] LUN is too big"); + return; + } + + logging(LOG_VERBOSE, "Test READ12 0-blocks one block past end-of-LUN"); + ret = read12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test READ12 0-blocks at LBA==2^31"); + ret = read12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, block_size, + 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test READ12 0-blocks at LBA==-1"); + ret = read10_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); +} diff --git a/test-tool/test_read12_beyond_eol.c b/test-tool/test_read12_beyond_eol.c new file mode 100644 index 0000000..d66012d --- /dev/null +++ b/test-tool/test_read12_beyond_eol.c @@ -0,0 +1,72 @@ +/* + 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_read12_beyond_eol(void) +{ + int i, ret; + + if (num_blocks >= 0x80000000) { + CU_PASS("LUN is too big for read-beyond-eol tests with READ12. Skipping test.\n"); + return; + } + + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test READ12 1-256 blocks one block beyond the end"); + for (i = 1; i <= 256; i++) { + ret = read12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 2 - i, + i * block_size, block_size, + 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test READ12 1-256 blocks at LBA==2^31"); + for (i = 1; i <= 256; i++) { + ret = read12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, + i * block_size, block_size, + 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test READ12 1-256 blocks at LBA==-1"); + for (i = 1; i <= 256; i++) { + ret = read12_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test READ12 2-256 blocks all but one block beyond the end"); + for (i = 2; i <= 256; i++) { + ret = read12_lbaoutofrange(iscsic, tgt_lun, num_blocks, + i * block_size, block_size, + 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_read12_flags.c b/test-tool/test_read12_flags.c new file mode 100644 index 0000000..4bbbc64 --- /dev/null +++ b/test-tool/test_read12_flags.c @@ -0,0 +1,76 @@ +/* + 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_read12_flags(void) +{ + int ret; + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test READ12 flags"); + + /* This test is only valid for SBC devices */ + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + CU_PASS("[SKIPPED] LUN is not SBC device. Skipping test"); + return; + } + + + logging(LOG_VERBOSE, "Test READ12 with DPO==1"); + ret = read12(iscsic, tgt_lun, 0, + block_size, block_size, + 0, 1, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test READ12 with FUA==1 FUA_NV==0"); + ret = read12(iscsic, tgt_lun, 0, + block_size, block_size, + 0, 0, 1, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test READ12 with FUA==1 FUA_NV==1"); + ret = read12(iscsic, tgt_lun, 0, + block_size, block_size, + 0, 0, 1, 1, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test READ12 with FUA==0 FUA_NV==1"); + ret = read12(iscsic, tgt_lun, 0, + block_size, block_size, + 0, 0, 0, 1, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + + + logging(LOG_VERBOSE, "Test READ12 with DPO==1 FUA==1 FUA_NV==1"); + ret = read12(iscsic, tgt_lun, 0, + block_size, block_size, + 0, 1, 1, 1, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); +} diff --git a/test-tool/test_read12_rdprotect.c b/test-tool/test_read12_rdprotect.c new file mode 100644 index 0000000..29be897 --- /dev/null +++ b/test-tool/test_read12_rdprotect.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_read12_rdprotect(void) +{ + int i, ret; + + + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + CU_PASS("[SKIPPED] LUN is not SBC device. Skipping test"); + return; + } + + /* + * Try out different non-zero values for RDPROTECT. + * They should all fail. + */ + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test READ12 with non-zero RDPROTECT"); + for (i = 1; i < 8; i++) { + ret = read12_invalidfieldincdb(iscsic, tgt_lun, 0, + block_size, block_size, + i, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_read12_simple.c b/test-tool/test_read12_simple.c new file mode 100644 index 0000000..2147589 --- /dev/null +++ b/test-tool/test_read12_simple.c @@ -0,0 +1,50 @@ + +/* + 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_read12_simple(void) +{ + int i, ret; + + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test READ12 of 1-256 blocks at the start of the LUN"); + for (i = 1; i <= 256; i++) { + ret = read12(iscsic, tgt_lun, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } + + + logging(LOG_VERBOSE, "Test READ12 of 1-256 blocks at the end of the LUN"); + for (i = 1; i <= 256; i++) { + ret = read12(iscsic, tgt_lun, num_blocks +1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } +}