TEST: Add test for EVPD bit for INQUIRY commands

This commit is contained in:
Ronnie Sahlberg
2013-03-12 18:29:24 -07:00
parent b10641566e
commit e84b71af15
6 changed files with 78 additions and 0 deletions

View File

@@ -190,6 +190,7 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.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_inquiry_evpd.c \
test-tool/test_nomedia_sbc.c \
test-tool/test_orwrite_simple.c \
test-tool/test_orwrite_beyond_eol.c \

View File

@@ -5134,3 +5134,39 @@ inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsi
return 0;
}
int
inquiry_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send INQUIRY (Expecting INVALID_FIELD_IN_CDB) evpd:%d page_code:%d alloc_len:%d",
evpd, page_code, maxsize);
task = iscsi_inquiry_sync(iscsi, lun, evpd, page_code, maxsize);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send INQUIRY command: "
"%s", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] INQUIRY 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] INQUIRY 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] INQUIRY returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB.");
return 0;
}

View File

@@ -211,6 +211,7 @@ int verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf)
int verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf);
int verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf);
int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize, struct scsi_task **save_task);
int inquiry_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize);
int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);
int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);
int get_lba_status_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);

View File

@@ -69,6 +69,7 @@ static CU_TestInfo tests_get_lba_status[] = {
static CU_TestInfo tests_inquiry[] = {
{ (char *)"testInquiryStandard", test_inquiry_standard },
{ (char *)"testInquiryAllocLength", test_inquiry_alloc_length},
{ (char *)"testInquiryEVPD", test_inquiry_evpd},
CU_TEST_INFO_NULL
};

View File

@@ -45,6 +45,7 @@ void test_get_lba_status_beyond_eol(void);
void test_inquiry_standard(void);
void test_inquiry_alloc_length(void);
void test_inquiry_evpd(void);
void test_nomedia_sbc(void);

View File

@@ -0,0 +1,38 @@
/*
Copyright (C) 2013 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_inquiry_evpd(void)
{
int ret;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test of the INQUIRY EVPD bit");
logging(LOG_VERBOSE, "Verify that INQUIRY with EVPD==0 and PC!=0 is an error");
ret = inquiry_invalidfieldincdb(iscsic, tgt_lun, 0, 1, 256);
CU_ASSERT_EQUAL(ret, 0);
}