TESTS: Add beyond eol test for GET_LBA_STATUS

This commit is contained in:
Ronnie Sahlberg
2013-02-18 18:11:05 -08:00
parent 07bb4d04d2
commit 5fe7eb573c
6 changed files with 96 additions and 0 deletions

View File

@@ -178,6 +178,7 @@ 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_get_lba_status_simple.c \
test-tool/test_get_lba_status_beyond_eol.c \
test-tool/test_prefetch10_simple.c \
test-tool/test_prefetch10_beyond_eol.c \
test-tool/test_prefetch10_0blocks.c \

View File

@@ -927,6 +927,46 @@ int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t
return 0;
}
int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send GET_LBA_STATUS (expecting LBA_OUT_OF_RANGE) LBA:%" PRIu64 " blocks:%d",
lba, len);
task = iscsi_get_lba_status_sync(iscsi, lun, lba, len);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send GET_LBA_STATUS "
"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] GET_LBA_STATUS is not "
"implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS returned SUCCESS. 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] GET_LBA_STATUS failed with the wrong sense code. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE but failed with sense:%s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] GET_LBA_STATUS returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.");
return 0;
}
int
prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int immed, int group)
{

View File

@@ -189,6 +189,7 @@ 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);
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 prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group);
int prefetch10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group);
int prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group);

View File

@@ -62,6 +62,7 @@ int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
*****************************************************************/
static CU_TestInfo tests_get_lba_status[] = {
{ (char *)"testGetLBAStatusSimple", test_get_lba_status_simple },
{ (char *)"testGetLBAStatusBeyondEol", test_get_lba_status_beyond_eol },
CU_TEST_INFO_NULL
};

View File

@@ -41,6 +41,7 @@ int test_setup_pgr(void);
int test_teardown_pgr(void);
void test_get_lba_status_simple(void);
void test_get_lba_status_beyond_eol(void);
void test_prefetch10_simple(void);
void test_prefetch10_beyond_eol(void);

View File

@@ -0,0 +1,52 @@
/*
Copyright (C) 2013 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_get_lba_status_beyond_eol(void)
{
int ret;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS one block beyond the end of the LUN");
ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 24);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA 2^63");
ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000, 24);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA -1");
ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, 0xffffffffffffffff, 24);
CU_ASSERT_EQUAL(ret, 0);
}