TEST: Add simple test for GET_LBA_STATUS
This commit is contained in:
@@ -176,6 +176,7 @@ bin_iscsi_test_cu_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/test-tool \
|
||||
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_prefetch10_simple.c \
|
||||
test-tool/test_prefetch10_beyond_eol.c \
|
||||
test-tool/test_prefetch10_0blocks.c \
|
||||
|
||||
@@ -789,6 +789,40 @@ testunitready_conflict(struct iscsi_context *iscsi, int lun)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send GET_LBA_STATUS LBA:%" PRIu64 " blocks:%d "
|
||||
"len:%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 command: "
|
||||
"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 SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int immed, int group)
|
||||
{
|
||||
|
||||
@@ -179,9 +179,9 @@ int verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf);
|
||||
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 testunitready(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_nomedium(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_conflict(struct iscsi_context *iscsi, int lun);
|
||||
|
||||
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 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);
|
||||
@@ -201,6 +201,9 @@ int read16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
int read16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_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 readcapacity16(struct iscsi_context *iscsi, int lun, int alloc_len);
|
||||
int testunitready(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_nomedium(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_conflict(struct iscsi_context *iscsi, int lun);
|
||||
int unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);
|
||||
int verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
|
||||
int verify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
|
||||
@@ -234,6 +237,5 @@ int writesame16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba
|
||||
int writesame16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data);
|
||||
|
||||
|
||||
int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize);
|
||||
|
||||
#endif /* _ISCSI_SUPPORT_H_ */
|
||||
|
||||
@@ -60,6 +60,11 @@ int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
|
||||
* list of tests and test suites
|
||||
*
|
||||
*****************************************************************/
|
||||
static CU_TestInfo tests_get_lba_status[] = {
|
||||
{ (char *)"testGetLBAStatusSimple", test_get_lba_status_simple },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_prefetch10[] = {
|
||||
{ (char *)"testPrefetch10Simple", test_prefetch10_simple },
|
||||
{ (char *)"testPrefetch10BeyondEol", test_prefetch10_beyond_eol },
|
||||
@@ -221,6 +226,8 @@ static CU_TestInfo tests_prin_read_keys[] = {
|
||||
};
|
||||
|
||||
static CU_SuiteInfo suites[] = {
|
||||
{ (char *)"TestGetLBAStatus", test_setup, test_teardown,
|
||||
tests_get_lba_status },
|
||||
{ (char *)"TestPrefetch10", test_setup, test_teardown,
|
||||
tests_prefetch10 },
|
||||
{ (char *)"TestPrefetch16", test_setup, test_teardown,
|
||||
|
||||
@@ -35,6 +35,8 @@ extern struct scsi_task *task;
|
||||
int test_setup(void);
|
||||
int test_teardown(void);
|
||||
|
||||
void test_get_lba_status_simple(void);
|
||||
|
||||
void test_prefetch10_simple(void);
|
||||
void test_prefetch10_beyond_eol(void);
|
||||
void test_prefetch10_0blocks(void);
|
||||
|
||||
50
test-tool/test_get_lba_status_simple.c
Normal file
50
test-tool/test_get_lba_status_simple.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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_simple(void)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
logging(LOG_VERBOSE, "");
|
||||
logging(LOG_VERBOSE, "Test GET_LBA_STATUS of 1-256 blocks at the start of the LUN");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = get_lba_status(iscsic, tgt_lun, 0, 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 of 1-256 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = get_lba_status(iscsic, tgt_lun, num_blocks - i, 24);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user