From d7be22fa2fe64245a86cc8603748da8cab7d1372 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 21 Jan 2013 17:13:48 -0800 Subject: [PATCH] TESTS: add READCAPACITY16 tests --- Makefile.am | 2 ++ test-tool/iscsi-support.c | 33 +++++++++++++++++++ test-tool/iscsi-support.h | 1 + test-tool/iscsi-test-cu.c | 8 +++++ test-tool/iscsi-test-cu.h | 3 ++ test-tool/test_readcapacity16_alloclen.c | 42 ++++++++++++++++++++++++ test-tool/test_readcapacity16_simple.c | 40 ++++++++++++++++++++++ 7 files changed, 129 insertions(+) create mode 100644 test-tool/test_readcapacity16_alloclen.c create mode 100644 test-tool/test_readcapacity16_simple.c diff --git a/Makefile.am b/Makefile.am index 58dcbd9..841e5f4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -197,6 +197,8 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/test_read16_rdprotect.c \ test-tool/test_read16_flags.c \ test-tool/test_readcapacity10_simple.c \ + test-tool/test_readcapacity16_simple.c \ + test-tool/test_readcapacity16_alloclen.c \ test-tool/test_verify10_simple.c \ test-tool/test_verify10_beyond_eol.c \ test-tool/test_verify10_0blocks.c \ diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 07c6073..8f2f9e0 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -1427,6 +1427,39 @@ readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi) return 0; } +int +readcapacity16(struct iscsi_context *iscsi, int lun, int alloc_len) +{ + struct scsi_task *task; + + + logging(LOG_VERBOSE, "Send READCAPACITY16 alloc_len:%d", alloc_len); + + task = scsi_cdb_serviceactionin16(SCSI_READCAPACITY16, alloc_len); + if (task == NULL) { + logging(LOG_NORMAL, "Out-of-memory: Failed to create " + "READCAPACITY16 cdb."); + return -1; + } + task = iscsi_scsi_command_sync(iscsi, lun, task, NULL); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send READCAPACITY16 command: %s", + iscsi_get_error(iscsi)); + return -1; + } + + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] READCAPACITY16 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] READCAPACITY16 returned SUCCESS."); + return 0; +} + 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) { diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 99f3dab..6c7dcf1 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -131,6 +131,7 @@ int read16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int read16_invalidfieldincdb(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 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 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); int verify10_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 64c14c1..6e58be2 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -102,6 +102,12 @@ static CU_TestInfo tests_readcapacity10[] = { CU_TEST_INFO_NULL }; +static CU_TestInfo tests_readcapacity16[] = { + { (char *)"testReadCapacity16Simple", test_readcapacity16_simple }, + { (char *)"testReadCapacity16Alloclen", test_readcapacity16_alloclen }, + CU_TEST_INFO_NULL +}; + static CU_TestInfo tests_verify10[] = { { (char *)"testVerify10Simple", test_verify10_simple }, { (char *)"testVerify10BeyondEol", test_verify10_beyond_eol }, @@ -175,6 +181,8 @@ static CU_SuiteInfo suites[] = { tests_read16 }, { (char *)"TestReadCapacity10", test_setup, test_teardown, tests_readcapacity10 }, + { (char *)"TestReadCapacity16", test_setup, test_teardown, + tests_readcapacity16 }, { (char *)"TestVerify10", test_setup, test_teardown, tests_verify10 }, { (char *)"TestVerify12", test_setup, test_teardown, diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index dffe1c0..b6d6912 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -64,6 +64,9 @@ void test_read16_flags(void); void test_readcapacity10_simple(void); +void test_readcapacity16_simple(void); +void test_readcapacity16_alloclen(void); + void test_verify10_simple(void); void test_verify10_beyond_eol(void); void test_verify10_0blocks(void); diff --git a/test-tool/test_readcapacity16_alloclen.c b/test-tool/test_readcapacity16_alloclen.c new file mode 100644 index 0000000..d0530dc --- /dev/null +++ b/test-tool/test_readcapacity16_alloclen.c @@ -0,0 +1,42 @@ + +/* + 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_readcapacity16_alloclen(void) +{ + int i, ret; + + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test that READCAPACITY16 with alloc_len 0-15 is not an error"); + + for (i = 0; i < 16; i++) { + ret = readcapacity16(iscsic, tgt_lun, i); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_readcapacity16_simple.c b/test-tool/test_readcapacity16_simple.c new file mode 100644 index 0000000..83af45c --- /dev/null +++ b/test-tool/test_readcapacity16_simple.c @@ -0,0 +1,40 @@ + +/* + 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_readcapacity16_simple(void) +{ + int ret; + + + logging(LOG_VERBOSE, ""); + logging(LOG_VERBOSE, "Test that READCAPACITY16 works"); + + ret = readcapacity16(iscsic, tgt_lun, 16); + CU_ASSERT_EQUAL(ret, 0); +}