From b4cdf0727139223aafa2a9a20243564a2d2d911a Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 9 Sep 2015 06:48:49 -0700 Subject: [PATCH] Add tests that BlockLimits VPD matches the AtomicWrite16 support Signed-off-by: Ronnie Sahlberg --- test-tool/Makefile.am | 1 + test-tool/iscsi-test-cu.c | 1 + test-tool/iscsi-test-cu.h | 1 + test-tool/test_inquiry_block_limits.c | 8 +- test-tool/test_writeatomic16_vpd.c | 102 ++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 test-tool/test_writeatomic16_vpd.c diff --git a/test-tool/Makefile.am b/test-tool/Makefile.am index fa3728e..1745685 100644 --- a/test-tool/Makefile.am +++ b/test-tool/Makefile.am @@ -177,6 +177,7 @@ iscsi_test_cu_SOURCES = iscsi-test-cu.c \ test_writeatomic16_0blocks.c \ test_writeatomic16_wrprotect.c \ test_writeatomic16_dpofua.c \ + test_writeatomic16_vpd.c \ test_writesame10_simple.c \ test_writesame10_beyond_eol.c \ test_writesame10_0blocks.c \ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 20cf5b7..c290c95 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -385,6 +385,7 @@ static CU_TestInfo tests_writeatomic16[] = { { (char *)"ZeroBlocks", test_writeatomic16_0blocks }, { (char *)"WriteProtect", test_writeatomic16_wrprotect }, { (char *)"DpoFua", test_writeatomic16_dpofua }, + { (char *)"VPD", test_writeatomic16_vpd }, CU_TEST_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index a4d5967..3550a93 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -256,6 +256,7 @@ void test_writeatomic16_beyond_eol(void); void test_writeatomic16_0blocks(void); void test_writeatomic16_wrprotect(void); void test_writeatomic16_dpofua(void); +void test_writeatomic16_vpd(void); void test_writesame10_simple(void); void test_writesame10_beyond_eol(void); diff --git a/test-tool/test_inquiry_block_limits.c b/test-tool/test_inquiry_block_limits.c index 3976088..7582719 100644 --- a/test-tool/test_inquiry_block_limits.c +++ b/test-tool/test_inquiry_block_limits.c @@ -178,10 +178,6 @@ test_inquiry_block_limits(void) finished: - if (bl_task != NULL) { - scsi_free_scsi_task(bl_task); - } - if (lbp_task != NULL) { - scsi_free_scsi_task(lbp_task); - } + scsi_free_scsi_task(bl_task); + scsi_free_scsi_task(lbp_task); } diff --git a/test-tool/test_writeatomic16_vpd.c b/test-tool/test_writeatomic16_vpd.c new file mode 100644 index 0000000..75c98b7 --- /dev/null +++ b/test-tool/test_writeatomic16_vpd.c @@ -0,0 +1,102 @@ +/* + Copyright (C) 2015 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 + +#include + +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +void +test_writeatomic16_vpd(void) +{ + int ret; + struct scsi_inquiry_block_limits *bl; + struct scsi_task *bl_task = NULL; + unsigned char *buf = alloca(block_size); + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test WRITEATOMIC16 VPD data"); + + CHECK_FOR_SBC; + CHECK_FOR_DATALOSS; + + + logging(LOG_VERBOSE, "Block device. Verify that we can read Block " + "Limits VPD"); + ret = inquiry(sd, &bl_task, + 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 255, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); + if (ret != 0) { + logging(LOG_NORMAL, "[FAILURE] failed to read Block Limits VDP"); + CU_FAIL("[FAILURE] failed to read Block Limits VDP"); + goto finished; + } + bl = scsi_datain_unmarshall(bl_task); + if (bl == NULL) { + logging(LOG_NORMAL, "[FAILURE] failed to unmarshall Block Limits VDP"); + CU_FAIL("[FAILURE] failed to unmarshall Block Limits VDP"); + goto finished; + } + + + logging(LOG_VERBOSE, "Check if WRITEATOMIC16 is supported"); + memset(buf, 0x00, block_size); + ret = writeatomic16(sd, 0, block_size, + block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); + + if (ret == 0) { + logging(LOG_VERBOSE, "WRITEATOMIC16 IS supported by the target."); + logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero"); + if (!bl->max_atomic_xfer_len) { + logging(LOG_VERBOSE, "[WARNING] MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero but target supports ATOMICWRITE16"); + CU_FAIL("[WARNING] MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero but target supports ATOMICWRITE16"); + + } + } + if (ret == -2) { + logging(LOG_VERBOSE, "WRITEATOMIC16 is NOT supported by the target."); + + logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero"); + if (bl->max_atomic_xfer_len) { + logging(LOG_VERBOSE, "MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero but target does not support ATOMICWRITE16"); + CU_FAIL("MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero but target does not support ATOMICWRITE16"); + } + + logging(LOG_VERBOSE, "Verify that ATOMIC_ALIGNMENT is zero"); + if (bl->atomic_align) { + logging(LOG_VERBOSE, "ATOMIC_ALIGNMENT is non-zero but target does not support ATOMICWRITE16"); + CU_FAIL("ATOMIC_ALIGNMENT is non-zero but target does not support ATOMICWRITE16"); + } + + logging(LOG_VERBOSE, "Verify that ATOMIC_GRANULARITY is zero"); + if (bl->atomic_gran) { + logging(LOG_VERBOSE, "ATOMIC_GRANULARITY is non-zero but target does not support ATOMICWRITE16"); + CU_FAIL("ATOMIC_GRANULARITY is non-zero but target does not support ATOMICWRITE16"); + } + } + + +finished: + scsi_free_scsi_task(bl_task); +}