From 6abb5ccc54ba493e6f4e2664e681cd715a6242dc Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 13 Sep 2012 15:12:30 -0700 Subject: [PATCH 01/11] TEST: change to the SPC-4 definition of ASCII --- test-tool/0400_inquiry_basic.c | 48 +++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/test-tool/0400_inquiry_basic.c b/test-tool/0400_inquiry_basic.c index 92af3b9..e70f1f4 100644 --- a/test-tool/0400_inquiry_basic.c +++ b/test-tool/0400_inquiry_basic.c @@ -186,36 +186,54 @@ test8: test9: printf("Verify VENDOR_IDENTIFICATION is in ASCII ... "); for (i = 8; i < 16; i++) { - if (!isascii(task->datain.data[i])) { - printf("[FAILED]\n"); - printf("VENDOR_IDENTIFICATION contains non-ASCII characters\n"); - ret = -1; - goto test10; + /* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */ + if (task->datain.data[i] == 0) { + continue; } + if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) { + continue; + } + + printf("[FAILED]\n"); + printf("VENDOR_IDENTIFICATION contains non-ASCII characters\n"); + ret = -1; + goto test10; } printf("[OK]\n"); test10: printf("Verify PRODUCT_IDENTIFICATION is in ASCII ... "); for (i = 16; i < 32; i++) { - if (!isascii(task->datain.data[i])) { - printf("[FAILED]\n"); - printf("PRODUCT_IDENTIFICATION contains non-ASCII characters\n"); - ret = -1; - goto test11; + /* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */ + if (task->datain.data[i] == 0) { + continue; } + if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) { + continue; + } + + printf("[FAILED]\n"); + printf("PRODUCT_IDENTIFICATION contains non-ASCII characters\n"); + ret = -1; + goto test11; } printf("[OK]\n"); test11: printf("Verify PRODUCT_REVISION_LEVEL is in ASCII ... "); for (i = 32; i < 36; i++) { - if (!isascii(task->datain.data[i])) { - printf("[FAILED]\n"); - printf("PRODUCT_REVISION_LEVEL contains non-ASCII characters\n"); - ret = -1; - goto test12; + /* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */ + if (task->datain.data[i] == 0) { + continue; } + if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) { + continue; + } + + printf("[FAILED]\n"); + printf("PRODUCT_REVISION_LEVEL contains non-ASCII characters\n"); + ret = -1; + goto test12; } printf("[OK]\n"); From 641027283b6b5f1338defcd5d281a40c06340a3f Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 18 Sep 2012 19:45:42 -0700 Subject: [PATCH 02/11] TESTS: Add a new test to check standard INQ alloclen Add a test for the standard INQUIRY data. The iscsi/scsi target should complete the request successfully for all values of buffersize/allocation_length of 1 to 255 bytes. Signed-off-by: Ronnie Sahlberg --- Makefile.am | 1 + test-tool/0401_inquiry_alloclen.c | 80 +++++++++++++++++++++++++++++++ test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 + 4 files changed, 83 insertions(+) create mode 100644 test-tool/0401_inquiry_alloclen.c diff --git a/Makefile.am b/Makefile.am index 8836a8d..59a5a02 100644 --- a/Makefile.am +++ b/Makefile.am @@ -128,6 +128,7 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0386_preventallow_2_it_nexuses.c \ test-tool/0390_mandatory_opcodes_sbc.c \ test-tool/0400_inquiry_basic.c \ + test-tool/0401_inquiry_alloclen.c \ \ test-tool/1000_cmdsn_invalid.c \ test-tool/1010_datasn_invalid.c \ diff --git a/test-tool/0401_inquiry_alloclen.c b/test-tool/0401_inquiry_alloclen.c new file mode 100644 index 0000000..b1011e9 --- /dev/null +++ b/test-tool/0401_inquiry_alloclen.c @@ -0,0 +1,80 @@ +/* + 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 +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_inquiry_standard *inq; + int ret, lun, i; + int full_size; + + printf("0401_inquiry_alloclen:\n"); + printf("===================\n"); + if (show_info) { + printf("Test INQUIRY with alloclen 0-255.\n"); + printf("1, Test standard inquiry with alloclen 0-255 is successful\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + + ret = 0; + + + + printf("Test INQUIRY with alloclen 0-255 ... "); + for (i = 1; i < 256; i++) { + task = iscsi_inquiry_sync(iscsi, lun, 0, 0, i); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test2; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("INQUIRY command with alloclen:%d failed : %s\n", i, iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + ret = -1; + goto test2; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test2: + + +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 6108256..29fa4c7 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -203,6 +203,7 @@ struct scsi_test tests[] = { /* inquiry*/ { "T0400_inquiry_basic", T0400_inquiry_basic }, +{ "T0401_inquiry_alloclen", T0401_inquiry_alloclen }, /* iSCSI protocol tests */ diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 83ad14e..007b8f3 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -157,6 +157,7 @@ int T0386_preventallow_2_itl_nexuses(const char *initiator, const char *url, int int T0390_mandatory_opcodes_sbc(const char *initiator, const char *url, int data_loss, int show_info); int T0400_inquiry_basic(const char *initiator, const char *url, int data_loss, int show_info); +int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss, int show_info); int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info); int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info); From 8f98cf3e128c8770fa0f1274a15fc046a2e23ff5 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 19 Sep 2012 18:23:54 -0700 Subject: [PATCH 03/11] INQUIRY: When alloc_len is set to 0 we should set XFER direction to NONOE, not READ --- lib/scsi-lowlevel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 56a66d6..ccad570 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -420,7 +420,11 @@ scsi_cdb_inquiry(int evpd, int page_code, int alloc_len) *(uint16_t *)&task->cdb[3] = htons(alloc_len); task->cdb_size = 6; - task->xfer_dir = SCSI_XFER_READ; + if (alloc_len > 0) { + task->xfer_dir = SCSI_XFER_READ; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = alloc_len; task->params.inquiry.evpd = evpd; From f5d8b613979d8d0462b37b081d4ffc4099e3479d Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 19 Sep 2012 18:25:07 -0700 Subject: [PATCH 04/11] TESTS: Change INQ alloc_len test to also test the case where alloc_len is 0 --- test-tool/0401_inquiry_alloclen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-tool/0401_inquiry_alloclen.c b/test-tool/0401_inquiry_alloclen.c index b1011e9..31a47c9 100644 --- a/test-tool/0401_inquiry_alloclen.c +++ b/test-tool/0401_inquiry_alloclen.c @@ -51,7 +51,7 @@ int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss printf("Test INQUIRY with alloclen 0-255 ... "); - for (i = 1; i < 256; i++) { + for (i = 0; i < 256; i++) { task = iscsi_inquiry_sync(iscsi, lun, 0, 0, i); if (task == NULL) { printf("[FAILED]\n"); From 62b86814095a27a95e68d425012fd941a89c4388 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 19 Sep 2012 19:43:01 -0700 Subject: [PATCH 05/11] SCSI: Fix all remaining places where alloc_len==0 means xfer direction should be == NONE --- lib/scsi-lowlevel.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index ccad570..6d5b98c 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -208,7 +208,11 @@ scsi_reportluns_cdb(int report_type, int alloc_len) *(uint32_t *)&task->cdb[6] = htonl(alloc_len); task->cdb_size = 12; - task->xfer_dir = SCSI_XFER_READ; + if (alloc_len != 0) { + task->xfer_dir = SCSI_XFER_READ; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = alloc_len; task->params.reportluns.report_type = report_type; @@ -420,7 +424,7 @@ scsi_cdb_inquiry(int evpd, int page_code, int alloc_len) *(uint16_t *)&task->cdb[3] = htons(alloc_len); task->cdb_size = 6; - if (alloc_len > 0) { + if (alloc_len != 0) { task->xfer_dir = SCSI_XFER_READ; } else { task->xfer_dir = SCSI_XFER_NONE; @@ -706,7 +710,11 @@ scsi_cdb_read6(uint32_t lba, uint32_t xferlen, int blocksize) task->cdb[4] = num_blocks; } - task->xfer_dir = SCSI_XFER_READ; + if (xferlen != 0) { + task->xfer_dir = SCSI_XFER_READ; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = xferlen; task->params.read6.lba = lba; @@ -1249,7 +1257,11 @@ scsi_cdb_unmap(int anchor, int group, uint16_t xferlen) *(uint16_t *)&task->cdb[7] = htons(xferlen); task->cdb_size = 10; - task->xfer_dir = SCSI_XFER_WRITE; + if (xferlen != 0) { + task->xfer_dir = SCSI_XFER_WRITE; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = xferlen; return task; @@ -1370,7 +1382,11 @@ scsi_cdb_modesense6(int dbd, enum scsi_modesense_page_control pc, task->cdb[4] = alloc_len; task->cdb_size = 6; - task->xfer_dir = SCSI_XFER_READ; + if (alloc_len != 0) { + task->xfer_dir = SCSI_XFER_READ; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = alloc_len; task->params.modesense6.dbd = dbd; @@ -1752,7 +1768,11 @@ scsi_cdb_serviceactionin16(enum scsi_service_action_in sa, uint32_t xferlen) *(uint32_t *)&task->cdb[10] = htonl(xferlen); task->cdb_size = 16; - task->xfer_dir = SCSI_XFER_READ; + if (xferlen != 0) { + task->xfer_dir = SCSI_XFER_READ; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = xferlen; task->params.serviceactionin.sa = sa; @@ -1792,7 +1812,11 @@ scsi_cdb_get_lba_status(uint64_t starting_lba, uint32_t alloc_len) *(uint32_t *)&task->cdb[10] = htonl(alloc_len); task->cdb_size = 16; - task->xfer_dir = SCSI_XFER_READ; + if (alloc_len != 0) { + task->xfer_dir = SCSI_XFER_READ; + } else { + task->xfer_dir = SCSI_XFER_NONE; + } task->expxferlen = alloc_len; task->params.serviceactionin.sa = SCSI_GET_LBA_STATUS; From 6e2f04455f65cf5e58bfb35e282828e96a8e4220 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 20 Sep 2012 18:27:04 -0700 Subject: [PATCH 06/11] TEST: Add a test that INQUIRY where EVPD==0 but PAGE_CODE!=0 is an error --- Makefile.am | 1 + test-tool/0402_inquiry_evpd.c | 87 +++++++++++++++++++++++++++++++++++ test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 + 4 files changed, 90 insertions(+) create mode 100644 test-tool/0402_inquiry_evpd.c diff --git a/Makefile.am b/Makefile.am index 59a5a02..b7b8b95 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,6 +129,7 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0390_mandatory_opcodes_sbc.c \ test-tool/0400_inquiry_basic.c \ test-tool/0401_inquiry_alloclen.c \ + test-tool/0402_inquiry_evpd.c \ \ test-tool/1000_cmdsn_invalid.c \ test-tool/1010_datasn_invalid.c \ diff --git a/test-tool/0402_inquiry_evpd.c b/test-tool/0402_inquiry_evpd.c new file mode 100644 index 0000000..6db9370 --- /dev/null +++ b/test-tool/0402_inquiry_evpd.c @@ -0,0 +1,87 @@ +/* + 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 +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0402_inquiry_evpd(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + int ret, lun, i; + + printf("0402_inquiry_evpd:\n"); + printf("===================\n"); + if (show_info) { + printf("Test the EVPD flag.\n"); + printf("1, Test that EVPD==0 and PC!=0 is an error\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + + ret = 0; + + + + printf("Test INQUIRY with EVPD==0 and PC!=0 ... "); + for (i = 1; i < 256; i++) { + task = iscsi_inquiry_sync(iscsi, lun, 0, i, 255); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto test2; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("INQUIRY should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + ret = -1; + goto test2; + } + if (task->status != SCSI_STATUS_CHECK_CONDITION + || task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST + || task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) { + printf("[FAILED]\n"); + printf("INQUIRY should have failed with wrong sense code. It failed with %s but should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + ret = -1; + goto test2; + } + scsi_free_scsi_task(task); + } + printf("[OK]\n"); + +test2: + + +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 29fa4c7..a7c9d06 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -204,6 +204,7 @@ struct scsi_test tests[] = { /* inquiry*/ { "T0400_inquiry_basic", T0400_inquiry_basic }, { "T0401_inquiry_alloclen", T0401_inquiry_alloclen }, +{ "T0402_inquiry_evpd", T0402_inquiry_evpd }, /* iSCSI protocol tests */ diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 007b8f3..76fdac2 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -158,6 +158,7 @@ int T0390_mandatory_opcodes_sbc(const char *initiator, const char *url, int data int T0400_inquiry_basic(const char *initiator, const char *url, int data_loss, int show_info); int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss, int show_info); +int T0402_inquiry_evpd(const char *initiator, const char *url, int data_loss, int show_info); int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info); int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info); From 703d9120bc1b13323c86f4ef49144f02126be904 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 20 Sep 2012 19:38:30 -0700 Subject: [PATCH 07/11] TEST: Add test for TESTUNITREADY Add an explicit test for this opcode. We already have plenty of implicit tests via the normal iscsi login functions. --- Makefile.am | 1 + test-tool/0000_testunitready_simple.c | 69 +++++++++++++++++++++++++++ test-tool/iscsi-test.c | 3 ++ test-tool/iscsi-test.h | 2 + 4 files changed, 75 insertions(+) create mode 100644 test-tool/0000_testunitready_simple.c diff --git a/Makefile.am b/Makefile.am index b7b8b95..4162795 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ dist_noinst_HEADERS += test-tool/iscsi-test.h bin_iscsi_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/test-tool bin_iscsi_test_LDFLAGS = -ldl bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ + test-tool/0000_testunitready_simple.c \ test-tool/0100_read10_simple.c test-tool/0101_read10_beyond_eol.c \ test-tool/0102_read10_0blocks.c test-tool/0103_read10_rdprotect.c \ test-tool/0104_read10_flags.c test-tool/0105_read10_invalid.c \ diff --git a/test-tool/0000_testunitready_simple.c b/test-tool/0000_testunitready_simple.c new file mode 100644 index 0000000..1cbbbc9 --- /dev/null +++ b/test-tool/0000_testunitready_simple.c @@ -0,0 +1,69 @@ +/* + 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 T0000_testunitready_simple(const char *initiator, const char *url, int data_loss _U_, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + int ret, i, lun; + + printf("0000_testunitready_simple:\n"); + printf("===================\n"); + if (show_info) { + printf("Test basic TESTUNITREADY functionality.\n"); + printf("1, Verify TESTUNITREADY works.\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + + printf("Test TESTUNITREADY ... "); + task = iscsi_testunitready_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", iscsi_get_error(iscsi)); + ret++; + goto test2; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("TEST UNIT READY command: failed with sense %s\n", iscsi_get_error(iscsi)); + ret++; + scsi_free_scsi_task(task); + goto test2; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +test2: + +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 a7c9d06..a8b3720 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -46,6 +46,9 @@ struct scsi_test { struct scsi_test tests[] = { /* SCSI protocol tests */ +/* testunitready*/ +{ "T0000_testunitready_simple", T0000_testunitready_simple }, + /* read10*/ { "T0100_read10_simple", T0100_read10_simple }, { "T0101_read10_beyond_eol", T0101_read10_beyond_eol }, diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 76fdac2..756567c 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -29,6 +29,8 @@ void wait_until_test_finished(struct iscsi_context *iscsi, struct iscsi_async_st struct iscsi_pdu; int (*local_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); +int T0000_testunitready_simple(const char *initiator, const char *url, int data_loss, int show_info); + int T0100_read10_simple(const char *initiator, const char *url, int data_loss, int show_info); int T0101_read10_beyond_eol(const char *initiator, const char *url, int data_loss, int show_info); int T0102_read10_0blocks(const char *initiator, const char *url, int data_loss, int show_info); From be4f2fdf66b90029f28bf4fea18cca0f0b65156f Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 21 Sep 2012 18:52:51 -0700 Subject: [PATCH 08/11] TESTS: Add a test that all mandatory SPC pages are supported by the target --- Makefile.am | 1 + test-tool/0403_inquiry_supported_vpd.c | 124 +++++++++++++++++++++++++ test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 + 4 files changed, 127 insertions(+) create mode 100644 test-tool/0403_inquiry_supported_vpd.c diff --git a/Makefile.am b/Makefile.am index 4162795..ec83693 100644 --- a/Makefile.am +++ b/Makefile.am @@ -131,6 +131,7 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0400_inquiry_basic.c \ test-tool/0401_inquiry_alloclen.c \ test-tool/0402_inquiry_evpd.c \ + test-tool/0403_inquiry_supported_vpd.c \ \ test-tool/1000_cmdsn_invalid.c \ test-tool/1010_datasn_invalid.c \ diff --git a/test-tool/0403_inquiry_supported_vpd.c b/test-tool/0403_inquiry_supported_vpd.c new file mode 100644 index 0000000..36d02c8 --- /dev/null +++ b/test-tool/0403_inquiry_supported_vpd.c @@ -0,0 +1,124 @@ +/* + 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 +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0403_inquiry_supported_vpd(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_inquiry_supported_pages *inq; + int ret, lun, i, j; + int full_size; + int page_code; + enum scsi_inquiry_pagecode required_spc_pages[] = { + SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES, + SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION + }; + + printf("0402_inquiry_supported_vpd:\n"); + printf("==========================\n"); + if (show_info) { + printf("Check the INQUIRY SUPPORTED VPD page.\n"); + printf("1, Check we can read the SUPPORTED VPD page.\n"); + printf("2, Verify we have all mandatory SPC VPD pages\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + + ret = 0; + + + + printf("Read SUPPORTED VPD data ... "); + /* See how big this inquiry data is */ + page_code = SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES; + task = iscsi_inquiry_sync(iscsi, lun, 1, page_code, 255); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("INQUIRY command failed : %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + ret = -1; + goto finished; + } + 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(iscsi, lun, 1, page_code, full_size)) == NULL) { + printf("[FAILED]\n"); + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + } + inq = scsi_datain_unmarshall(task); + if (inq == NULL) { + printf("[FAILED]\n"); + printf("failed to unmarshall inquiry datain blob\n"); + scsi_free_scsi_task(task); + ret = -1; + goto finished; + } + printf("[OK]\n"); + +test2: + printf("Verify we have all mandatory SPC VPD pages:\n"); + for (i = 0; i < sizeof(required_spc_pages) / sizeof(enum scsi_inquiry_pagecode); i++) { + printf("Verify the target supports page 0x%02x ... ", required_spc_pages[i]); + for (j = 0; j < inq->num_pages; j++) { + if (required_spc_pages[i] == inq->pages[j]) { + break; + } + } + if (j == inq->num_pages) { + printf("[FAILED]\n"); + printf("Target did not report page 0x%02x. This page is mandatory in SPC.\n", required_spc_pages[i]); + ret = -1; + } else { + printf("[OK]\n"); + } + } + + +test3: + scsi_free_scsi_task(task); + +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 a8b3720..5dd7e87 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -208,6 +208,7 @@ struct scsi_test tests[] = { { "T0400_inquiry_basic", T0400_inquiry_basic }, { "T0401_inquiry_alloclen", T0401_inquiry_alloclen }, { "T0402_inquiry_evpd", T0402_inquiry_evpd }, +{ "T0403_inquiry_supported_vpd", T0403_inquiry_supported_vpd }, /* iSCSI protocol tests */ diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 756567c..deecefd 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -161,6 +161,7 @@ int T0390_mandatory_opcodes_sbc(const char *initiator, const char *url, int data int T0400_inquiry_basic(const char *initiator, const char *url, int data_loss, int show_info); int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss, int show_info); int T0402_inquiry_evpd(const char *initiator, const char *url, int data_loss, int show_info); +int T0403_inquiry_supported_vpd(const char *initiator, const char *url, int data_loss, int show_info); int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info); int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info); From addc6e53d737773eceaaafc9b7ea0e92f0b1ae80 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 21 Sep 2012 19:32:00 -0700 Subject: [PATCH 09/11] TEST: fix typo in test name --- test-tool/0403_inquiry_supported_vpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-tool/0403_inquiry_supported_vpd.c b/test-tool/0403_inquiry_supported_vpd.c index 36d02c8..f28e7da 100644 --- a/test-tool/0403_inquiry_supported_vpd.c +++ b/test-tool/0403_inquiry_supported_vpd.c @@ -35,7 +35,7 @@ int T0403_inquiry_supported_vpd(const char *initiator, const char *url, int data SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION }; - printf("0402_inquiry_supported_vpd:\n"); + printf("0403_inquiry_supported_vpd:\n"); printf("==========================\n"); if (show_info) { printf("Check the INQUIRY SUPPORTED VPD page.\n"); From ba14452dc253fd59cd9faca4c78d73c77d9568e7 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 21 Sep 2012 20:15:04 -0700 Subject: [PATCH 10/11] TEST: Add a test that reads all reported VPD pages and validates qualifier, type and page-code in the returned data --- Makefile.am | 1 + test-tool/0404_inquiry_all_reported_vpd.c | 160 ++++++++++++++++++++++ test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 + 4 files changed, 163 insertions(+) create mode 100644 test-tool/0404_inquiry_all_reported_vpd.c diff --git a/Makefile.am b/Makefile.am index ec83693..a50bc91 100644 --- a/Makefile.am +++ b/Makefile.am @@ -132,6 +132,7 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0401_inquiry_alloclen.c \ test-tool/0402_inquiry_evpd.c \ test-tool/0403_inquiry_supported_vpd.c \ + test-tool/0404_inquiry_all_reported_vpd.c \ \ test-tool/1000_cmdsn_invalid.c \ test-tool/1010_datasn_invalid.c \ diff --git a/test-tool/0404_inquiry_all_reported_vpd.c b/test-tool/0404_inquiry_all_reported_vpd.c new file mode 100644 index 0000000..388b539 --- /dev/null +++ b/test-tool/0404_inquiry_all_reported_vpd.c @@ -0,0 +1,160 @@ +/* + 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 +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_inquiry_supported_pages *inq; + int ret, lun, i; + int full_size; + enum scsi_inquiry_pagecode page_code; + + printf("0404_inquiry_all_reported_vpd:\n"); + printf("==========================\n"); + if (show_info) { + printf("Check the INQUIRY SUPPORTED VPD page.\n"); + printf("1, Check we can read the SUPPORTED VPD page.\n"); + printf("2, Verify we can read each reported page and check the qualifier,device-type and page code on the returned data\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + + ret = 0; + + + + printf("Read SUPPORTED VPD data ... "); + /* See how big this inquiry data is */ + page_code = SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES; + task = iscsi_inquiry_sync(iscsi, lun, 1, page_code, 255); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("INQUIRY command failed : %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + ret = -1; + goto finished; + } + 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(iscsi, lun, 1, page_code, full_size)) == NULL) { + printf("[FAILED]\n"); + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + } + inq = scsi_datain_unmarshall(task); + if (inq == NULL) { + printf("[FAILED]\n"); + printf("failed to unmarshall inquiry datain blob\n"); + scsi_free_scsi_task(task); + ret = -1; + goto finished; + } + printf("[OK]\n"); + +test2: + printf("Read each page and verify the page size:\n"); + for (i = 0; i < inq->num_pages; i++) { + struct scsi_task *pc_task; + + printf("Verify page 0x%02x can be read ... ", inq->pages[i]); + pc_task = iscsi_inquiry_sync(iscsi, lun, 1, inq->pages[i], 255); + if (pc_task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + continue; + } + if (pc_task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Failed to read VPD page : %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(pc_task); + ret = -1; + continue; + } + printf("[OK]\n"); + + printf("Verify page 0x%02x qualifier ... ", inq->pages[i]); + if ((pc_task->datain.data[0] & 0xe0) >> 5 != inq->qualifier) { + printf("[FAILED]\n"); + printf("Qualifier differs between VPD pages\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(pc_task); + continue; + } else { + printf("[OK]\n"); + } + + printf("Verify page 0x%02x device type ... ", inq->pages[i]); + if (pc_task->datain.data[0] & 0x1f != inq->device_type) { + printf("[FAILED]\n"); + printf("Device Type differs between VPD pages\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(pc_task); + continue; + } else { + printf("[OK]\n"); + } + + printf("Verify page 0x%02x page code ... ", inq->pages[i]); + if (pc_task->datain.data[1] != inq->pages[i]) { + printf("[FAILED]\n"); + printf("Page code is wrong\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(pc_task); + continue; + } else { + printf("[OK]\n"); + } + + scsi_free_scsi_task(pc_task); + } + + +test3: + scsi_free_scsi_task(task); + +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 5dd7e87..558fbf9 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -209,6 +209,7 @@ struct scsi_test tests[] = { { "T0401_inquiry_alloclen", T0401_inquiry_alloclen }, { "T0402_inquiry_evpd", T0402_inquiry_evpd }, { "T0403_inquiry_supported_vpd", T0403_inquiry_supported_vpd }, +{ "T0404_inquiry_all_reported_vpd", T0404_inquiry_all_reported_vpd }, /* iSCSI protocol tests */ diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index deecefd..78caa41 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -162,6 +162,7 @@ int T0400_inquiry_basic(const char *initiator, const char *url, int data_loss, i int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss, int show_info); int T0402_inquiry_evpd(const char *initiator, const char *url, int data_loss, int show_info); int T0403_inquiry_supported_vpd(const char *initiator, const char *url, int data_loss, int show_info); +int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int data_loss, int show_info); int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info); int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info); From 38605202679ec8fb25fa52f77d91e49f6b85da4d Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 21 Sep 2012 20:26:40 -0700 Subject: [PATCH 11/11] TESTS: fix typo --- test-tool/0404_inquiry_all_reported_vpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-tool/0404_inquiry_all_reported_vpd.c b/test-tool/0404_inquiry_all_reported_vpd.c index 388b539..5397315 100644 --- a/test-tool/0404_inquiry_all_reported_vpd.c +++ b/test-tool/0404_inquiry_all_reported_vpd.c @@ -92,7 +92,7 @@ int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int d printf("[OK]\n"); test2: - printf("Read each page and verify the page size:\n"); + printf("Read each page and verify qualifier, type and page code:\n"); for (i = 0; i < inq->num_pages; i++) { struct scsi_task *pc_task;