From b1983aeec173b36e69b9e0fa786443834edcec02 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 5 Jul 2013 19:34:56 -0700 Subject: [PATCH] TESTS: UNMAP make sure we read the blocks back as 0 after unmap --- test-tool/test_sanitize_block_erase.c | 1 + .../test_sanitize_block_erase_reserved.c | 1 + test-tool/test_sanitize_crypto_erase.c | 1 + .../test_sanitize_crypto_erase_reserved.c | 1 + test-tool/test_sanitize_exit_failure_mode.c | 1 + test-tool/test_sanitize_overwrite.c | 1 + test-tool/test_sanitize_overwrite_reserved.c | 1 + test-tool/test_unmap_simple.c | 67 +++++++++++++++++-- 8 files changed, 70 insertions(+), 4 deletions(-) diff --git a/test-tool/test_sanitize_block_erase.c b/test-tool/test_sanitize_block_erase.c index a7ee723..fdd4094 100644 --- a/test-tool/test_sanitize_block_erase.c +++ b/test-tool/test_sanitize_block_erase.c @@ -200,6 +200,7 @@ test_sanitize_block_erase(void) logging(LOG_VERBOSE, "Test SANITIZE BLOCK ERASE"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; logging(LOG_NORMAL, "Check that SANITIZE BLOCK_ERASE is supported " "in REPORT_SUPPORTED_OPCODES"); diff --git a/test-tool/test_sanitize_block_erase_reserved.c b/test-tool/test_sanitize_block_erase_reserved.c index 681a942..b6ad9e3 100644 --- a/test-tool/test_sanitize_block_erase_reserved.c +++ b/test-tool/test_sanitize_block_erase_reserved.c @@ -55,6 +55,7 @@ void test_sanitize_block_erase_reserved(void) logging(LOG_VERBOSE, "Test SANITIZE BLOCK_ERASE Reserved bits/bytes"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; local_iscsi_queue_pdu = my_iscsi_queue_pdu; diff --git a/test-tool/test_sanitize_crypto_erase.c b/test-tool/test_sanitize_crypto_erase.c index 6ef8742..11cbd8d 100644 --- a/test-tool/test_sanitize_crypto_erase.c +++ b/test-tool/test_sanitize_crypto_erase.c @@ -109,6 +109,7 @@ test_sanitize_crypto_erase(void) logging(LOG_VERBOSE, "Test SANITIZE CRYPTO ERASE"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; logging(LOG_NORMAL, "Check that SANITIZE CRYPTO_ERASE is supported " "in REPORT_SUPPORTED_OPCODES"); diff --git a/test-tool/test_sanitize_crypto_erase_reserved.c b/test-tool/test_sanitize_crypto_erase_reserved.c index c8a65a9..2afb0e7 100644 --- a/test-tool/test_sanitize_crypto_erase_reserved.c +++ b/test-tool/test_sanitize_crypto_erase_reserved.c @@ -55,6 +55,7 @@ void test_sanitize_crypto_erase_reserved(void) logging(LOG_VERBOSE, "Test SANITIZE CRYPTO_ERASE Reserved bits/bytes"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; local_iscsi_queue_pdu = my_iscsi_queue_pdu; diff --git a/test-tool/test_sanitize_exit_failure_mode.c b/test-tool/test_sanitize_exit_failure_mode.c index af3f6ab..511f847 100644 --- a/test-tool/test_sanitize_exit_failure_mode.c +++ b/test-tool/test_sanitize_exit_failure_mode.c @@ -37,6 +37,7 @@ test_sanitize_exit_failure_mode(void) logging(LOG_VERBOSE, "Test SANITIZE EXIT FAILURE MODE"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; logging(LOG_NORMAL, "Check that SANITIZE EXIT FAILURE MODE is " "supported in REPORT_SUPPORTED_OPCODES"); diff --git a/test-tool/test_sanitize_overwrite.c b/test-tool/test_sanitize_overwrite.c index f6342a9..b8fa691 100644 --- a/test-tool/test_sanitize_overwrite.c +++ b/test-tool/test_sanitize_overwrite.c @@ -37,6 +37,7 @@ test_sanitize_overwrite(void) logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; logging(LOG_NORMAL, "Check that SANITIZE OVERWRITE is supported " "in REPORT_SUPPORTED_OPCODES"); diff --git a/test-tool/test_sanitize_overwrite_reserved.c b/test-tool/test_sanitize_overwrite_reserved.c index 80fadc6..46a2424 100644 --- a/test-tool/test_sanitize_overwrite_reserved.c +++ b/test-tool/test_sanitize_overwrite_reserved.c @@ -66,6 +66,7 @@ void test_sanitize_overwrite_reserved(void) logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE Reserved bits/bytes"); CHECK_FOR_SANITIZE; + CHECK_FOR_DATALOSS; local_iscsi_queue_pdu = my_iscsi_queue_pdu; diff --git a/test-tool/test_unmap_simple.c b/test-tool/test_unmap_simple.c index 6f9b139..5a80cd1 100644 --- a/test-tool/test_unmap_simple.c +++ b/test-tool/test_unmap_simple.c @@ -16,6 +16,7 @@ */ #include +#include #include @@ -30,26 +31,84 @@ test_unmap_simple(void) { int i, ret; struct unmap_list list[257]; + unsigned char *buf = alloca(256 * block_size); + unsigned char *zbuf = alloca(256 * block_size); + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test basic UNMAP"); CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; CHECK_FOR_SBC; - logging(LOG_VERBOSE, LOG_BLANK_LINE); - logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the LUN as a single descriptor"); + + logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the " + "LUN as a single descriptor"); + logging(LOG_VERBOSE, "Write 'a' to the first 256 LBAs"); + memset(buf, 'a', 256 * block_size); + memset(zbuf, 0, 256 * block_size); + ret = write10(iscsic, tgt_lun, 0, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + for (i = 1; i <= 256; i++) { + logging(LOG_VERBOSE, "UNMAP blocks 0-%d", i); list[0].lba = 0; list[0].num = i; ret = unmap(iscsic, tgt_lun, 0, list, 1); CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Read blocks 0-%d", i); + ret = read10(iscsic, tgt_lun, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + + if (rc16 && rc16->lbprz) { + logging(LOG_VERBOSE, "LBPRZ==1 All UNMAPPED blocks " + "should read back as 0"); + if (memcmp(buf, zbuf, i * block_size)) { + logging(LOG_NORMAL, "[FAILED] Blocks did not " + "read back as zero"); + CU_FAIL("[FAILED] Blocks did not read back " + "as zero"); + } else { + logging(LOG_VERBOSE, "[SUCCESS] Blocks read " + "back as zero"); + } + } } - - logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the LUN with one descriptor per block"); + logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the " + "LUN with one descriptor per block"); + logging(LOG_VERBOSE, "Write 'a' to the first 256 LBAs"); + memset(buf, 'a', 256 * block_size); + memset(zbuf, 0, 256 * block_size); + ret = write10(iscsic, tgt_lun, 0, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); for (i = 0; i < 256; i++) { list[i].lba = i; list[i].num = 1; ret = unmap(iscsic, tgt_lun, 0, list, i + 1); CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Read blocks 0-%d", i); + ret = read10(iscsic, tgt_lun, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + + if (rc16 && rc16->lbprz) { + logging(LOG_VERBOSE, "LBPRZ==1 All UNMAPPED blocks " + "should read back as 0"); + if (memcmp(buf, zbuf, i * block_size)) { + logging(LOG_NORMAL, "[FAILED] Blocks did not " + "read back as zero"); + CU_FAIL("[FAILED] Blocks did not read back " + "as zero"); + } else { + logging(LOG_VERBOSE, "[SUCCESS] Blocks read " + "back as zero"); + } + } } }