From b10641566e270474214873a9f96ff96b5c8748b4 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 11 Mar 2013 18:32:29 -0700 Subject: [PATCH] TESTS: Add tests for INQUIRY allocation length. Add special test that for SPC3+ devices we do have 16 bits of alloc length available. --- Makefile.am | 1 + test-tool/iscsi-test-cu.c | 1 + test-tool/iscsi-test-cu.h | 1 + test-tool/test_inquiry_alloc_length.c | 99 +++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 test-tool/test_inquiry_alloc_length.c diff --git a/Makefile.am b/Makefile.am index 34a063b..d932a2f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,6 +189,7 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/test_get_lba_status_simple.c \ test-tool/test_get_lba_status_beyond_eol.c \ test-tool/test_inquiry_standard.c \ + test-tool/test_inquiry_alloc_length.c \ test-tool/test_nomedia_sbc.c \ test-tool/test_orwrite_simple.c \ test-tool/test_orwrite_beyond_eol.c \ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 5f7e71a..cdc7f60 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -68,6 +68,7 @@ static CU_TestInfo tests_get_lba_status[] = { static CU_TestInfo tests_inquiry[] = { { (char *)"testInquiryStandard", test_inquiry_standard }, + { (char *)"testInquiryAllocLength", test_inquiry_alloc_length}, CU_TEST_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index bfebe5f..a92343f 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -44,6 +44,7 @@ void test_get_lba_status_simple(void); void test_get_lba_status_beyond_eol(void); void test_inquiry_standard(void); +void test_inquiry_alloc_length(void); void test_nomedia_sbc(void); diff --git a/test-tool/test_inquiry_alloc_length.c b/test-tool/test_inquiry_alloc_length.c new file mode 100644 index 0000000..3ba2179 --- /dev/null +++ b/test-tool/test_inquiry_alloc_length.c @@ -0,0 +1,99 @@ +/* + Copyright (C) 2013 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 "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-support.h" +#include "iscsi-test-cu.h" + +void +test_inquiry_alloc_length(void) +{ + int ret, i; + struct scsi_inquiry_standard *inq; + struct scsi_task *task2 = NULL; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test of the INQUIRY allocation length"); + + + logging(LOG_VERBOSE, "Verify we can read standard INQUIRY page with alloc length from 0-255"); + for (i = 0; i < 256 ; i++) { + if (task != NULL) { + scsi_free_scsi_task(task); + task = NULL; + } + ret = inquiry(iscsic, tgt_lun, 0, 0, i, &task); + CU_ASSERT_EQUAL(ret, 0); + } + logging(LOG_VERBOSE, "Verify we got at least 36 bytes of data when reading with alloc length 255"); + CU_ASSERT(task->datain.size >= 36); + + logging(LOG_VERBOSE, "Verify we can unmarshall the DATA-IN buffer"); + inq = scsi_datain_unmarshall(task); + CU_ASSERT_NOT_EQUAL(inq, NULL); + if (inq == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to unmarshall DATA-IN " + "buffer"); + return; + } + + logging(LOG_VERBOSE, "Verify peripheral-qualifier is 0"); + CU_ASSERT_EQUAL(inq->qualifier, 0); + + + + /* Final test. IF this claims SPC-3 or later then the target + supports 16-bit allocation lengths. Try reading INQ data + specifying 256 bytes as allocation length and make sure the + target responds properly. + */ + logging(LOG_VERBOSE, "If version is SPC-3 or later INQUIRY supports 16-bit allocation lengths"); + switch (inq->version) { + case 0x5: + case 0x6: + break; + default: + logging(LOG_NORMAL, "[SKIPPED] This device does not claim " + "SPC-3 or later"); + CU_PASS("[SKIPPED] Not SPC-3 or later"); + } + + logging(LOG_VERBOSE, "Version is SPC-3 or later. Read INQUIRY data using 16-bit allocation length"); + ret = inquiry(iscsic, tgt_lun, 0, 0, 256, &task2); + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "INQUIRY data should be the same when allocation length is 255 and 256 bytes"); + ret = task->datain.size != task2->datain.size; + CU_ASSERT_EQUAL(ret, 0); + ret = memcmp(task->datain.data, task2->datain.data, task->datain.size); + CU_ASSERT_EQUAL(ret, 0); + + + if (task != NULL) { + scsi_free_scsi_task(task); + task = NULL; + } + if (task2 != NULL) { + scsi_free_scsi_task(task2); + task2 = NULL; + } +}