From a1590cf30c8b5608683e1fc26b8586265d0c6443 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 9 Feb 2013 14:12:28 -0800 Subject: [PATCH] TEST: Add simple test for GET_LBA_STATUS --- Makefile.am | 1 + test-tool/iscsi-support.c | 34 ++++++++++++++++++ test-tool/iscsi-support.h | 10 +++--- test-tool/iscsi-test-cu.c | 7 ++++ test-tool/iscsi-test-cu.h | 2 ++ test-tool/test_get_lba_status_simple.c | 50 ++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 test-tool/test_get_lba_status_simple.c diff --git a/Makefile.am b/Makefile.am index 012abcd..b6635fc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 17a2d26..4a25ffc 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.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) { diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 520bf95..80ec1fe 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -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_ */ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 10ca8f9..649b3ea 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -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, diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index a240f17..a6cc7bd 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -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); diff --git a/test-tool/test_get_lba_status_simple.c b/test-tool/test_get_lba_status_simple.c new file mode 100644 index 0000000..b8485a9 --- /dev/null +++ b/test-tool/test_get_lba_status_simple.c @@ -0,0 +1,50 @@ +/* + Copyright (C) 2013 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_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); + } +}