From 03ce9dc4b1adb3b4710e154a11ac7ac757c36b52 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 5 Jul 2013 20:15:52 -0700 Subject: [PATCH] TESTS: Verify that SANITIZE does wipe the data --- test-tool/test_sanitize_block_erase.c | 66 +++++++++++++++++++++++++- test-tool/test_sanitize_crypto_erase.c | 43 +++++++++++++++++ test-tool/test_sanitize_overwrite.c | 46 ++++++++++++++++++ test-tool/test_unmap_simple.c | 24 ++++++---- 4 files changed, 169 insertions(+), 10 deletions(-) diff --git a/test-tool/test_sanitize_block_erase.c b/test-tool/test_sanitize_block_erase.c index fdd4094..b4bfa82 100644 --- a/test-tool/test_sanitize_block_erase.c +++ b/test-tool/test_sanitize_block_erase.c @@ -189,12 +189,65 @@ check_unmap(void) scsi_free_scsi_task(task_ret); } +static void +init_lun_with_data(unsigned char *buf, uint64_t lba) +{ + int ret; + + memset(buf, 'a', 256 * block_size); + ret = write16(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); +} + +static void +check_lun_is_wiped(unsigned char *buf, uint64_t lba) +{ + int ret; + unsigned char *rbuf = alloca(256 * block_size); + + ret = read16(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, rbuf); + CU_ASSERT_EQUAL(ret, 0); + + if (rc16 == NULL) { + return; + } + + if (rc16->lbprz) { + unsigned char *zbuf = alloca(256 * block_size); + memset(zbuf, 0, 256 * block_size); + + logging(LOG_VERBOSE, "LBPRZ==1 All blocks " + "should read back as 0"); + if (memcmp(zbuf, rbuf, 256 * 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"); + } + } else { + logging(LOG_VERBOSE, "LBPRZ==0 Blocks should not read back as " + "all 'a' any more"); + if (!memcmp(buf, rbuf, 256 * block_size)) { + logging(LOG_NORMAL, "[FAILED] Blocks were not wiped"); + CU_FAIL("[FAILED] Blocks were not wiped"); + } else { + logging(LOG_VERBOSE, "[SUCCESS] Blocks were wiped"); + } + } +} + void test_sanitize_block_erase(void) { int ret; struct iscsi_data data; struct scsi_command_descriptor *cd; + unsigned char *buf = alloca(256 * block_size); logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test SANITIZE BLOCK ERASE"); @@ -260,12 +313,23 @@ test_sanitize_block_erase(void) logging(LOG_NORMAL, "This is a HDD device"); } - logging(LOG_VERBOSE, "Test we can perform basic BLOCK ERASE SANITIZE"); + logging(LOG_VERBOSE, "Write 'a' to the first 256 LBAs"); + init_lun_with_data(buf, 0); + logging(LOG_VERBOSE, "Write 'a' to the last 256 LBAs"); + init_lun_with_data(buf, num_blocks - 256); + + + logging(LOG_VERBOSE, "Test we can perform basic BLOCK ERASE SANITIZE"); ret = sanitize(iscsic, tgt_lun, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); CU_ASSERT_EQUAL(ret, 0); + logging(LOG_VERBOSE, "Check that the first 256 LBAs are wiped."); + check_lun_is_wiped(buf, 0); + logging(LOG_VERBOSE, "Check that the last 256 LBAs are wiped."); + check_lun_is_wiped(buf, num_blocks - 256); + data.size = 8; data.data = alloca(data.size); memset(data.data, 0, data.size); diff --git a/test-tool/test_sanitize_crypto_erase.c b/test-tool/test_sanitize_crypto_erase.c index 11cbd8d..c7ad5a8 100644 --- a/test-tool/test_sanitize_crypto_erase.c +++ b/test-tool/test_sanitize_crypto_erase.c @@ -26,6 +26,7 @@ #include "scsi-lowlevel.h" #include "iscsi-test-cu.h" + static void check_wacereq(void) { @@ -98,12 +99,42 @@ check_wacereq(void) scsi_free_scsi_task(task_ret); } +static void +init_lun_with_data(unsigned char *buf, uint64_t lba) +{ + int ret; + + memset(buf, 'a', 256 * block_size); + ret = write16(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); +} + +static void +check_lun_is_wiped(unsigned char *buf, uint64_t lba) +{ + int ret; + unsigned char *rbuf = alloca(256 * block_size); + + ret = read16(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, rbuf); + CU_ASSERT_EQUAL(ret, 0); + + if (!memcmp(buf, rbuf, 256 * block_size)) { + logging(LOG_NORMAL, "[FAILED] Blocks were not wiped"); + CU_FAIL("[FAILED] Blocks were not wiped"); + } else { + logging(LOG_VERBOSE, "[SUCCESS] Blocks were wiped"); + } +} + void test_sanitize_crypto_erase(void) { int ret; struct iscsi_data data; struct scsi_command_descriptor *cd; + unsigned char *buf = alloca(256 * block_size); logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test SANITIZE CRYPTO ERASE"); @@ -143,11 +174,23 @@ test_sanitize_crypto_erase(void) } + logging(LOG_VERBOSE, "Write 'a' to the first 256 LBAs"); + init_lun_with_data(buf, 0); + logging(LOG_VERBOSE, "Write 'a' to the last 256 LBAs"); + init_lun_with_data(buf, num_blocks - 256); + + logging(LOG_VERBOSE, "Test we can perform basic CRYPTO ERASE SANITIZE"); ret = sanitize(iscsic, tgt_lun, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); CU_ASSERT_EQUAL(ret, 0); + logging(LOG_VERBOSE, "Check that the first 256 LBAs are wiped."); + check_lun_is_wiped(buf, 0); + logging(LOG_VERBOSE, "Check that the last 256 LBAs are wiped."); + check_lun_is_wiped(buf, num_blocks - 256); + +return; data.size = 8; data.data = alloca(data.size); diff --git a/test-tool/test_sanitize_overwrite.c b/test-tool/test_sanitize_overwrite.c index b8fa691..2c6100d 100644 --- a/test-tool/test_sanitize_overwrite.c +++ b/test-tool/test_sanitize_overwrite.c @@ -26,6 +26,42 @@ #include "scsi-lowlevel.h" #include "iscsi-test-cu.h" +static void +init_lun_with_data(uint64_t lba) +{ + int ret; + unsigned char *buf = alloca(256 * block_size); + + memset(buf, 'a', 256 * block_size); + ret = write16(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); +} + +static void +check_lun_is_wiped(uint64_t lba, char c) +{ + int ret; + unsigned char *rbuf = alloca(256 * block_size); + unsigned char *zbuf = alloca(256 * block_size); + + ret = read16(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, rbuf); + CU_ASSERT_EQUAL(ret, 0); + + memset(zbuf, c, 256 * block_size); + + if (memcmp(zbuf, rbuf, 256 * 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"); + } +} + void test_sanitize_overwrite(void) { @@ -72,6 +108,11 @@ test_sanitize_overwrite(void) logging(LOG_NORMAL, "This is a SSD device"); } + logging(LOG_VERBOSE, "Write 'a' to the first 256 LBAs"); + init_lun_with_data(0); + logging(LOG_VERBOSE, "Write 'a' to the last 256 LBAs"); + init_lun_with_data(num_blocks - 256); + logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE with initialization pattern of one full block"); data.size = block_size + 4; data.data = alloca(data.size); @@ -85,6 +126,11 @@ test_sanitize_overwrite(void) 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); CU_ASSERT_EQUAL(ret, 0); + logging(LOG_VERBOSE, "Check that the first 256 LBAs are wiped."); + check_lun_is_wiped(0, 0xaa); + logging(LOG_VERBOSE, "Check that the last 256 LBAs are wiped."); + check_lun_is_wiped(num_blocks - 256, 0xaa); + logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE with initialization pattern of one half block"); data.size = block_size / 2 + 4; diff --git a/test-tool/test_unmap_simple.c b/test-tool/test_unmap_simple.c index 5a80cd1..83afabc 100644 --- a/test-tool/test_unmap_simple.c +++ b/test-tool/test_unmap_simple.c @@ -25,6 +25,16 @@ #include "iscsi-support.h" #include "iscsi-test-cu.h" +static void +init_lun_with_data(unsigned char *buf, uint64_t lba) +{ + int ret; + + memset(buf, 'a', 256 * block_size); + ret = write10(iscsic, tgt_lun, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); +} void test_unmap_simple(void) @@ -44,12 +54,9 @@ test_unmap_simple(void) 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); + init_lun_with_data(buf, 0); for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "UNMAP blocks 0-%d", i); @@ -80,11 +87,10 @@ test_unmap_simple(void) 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); + init_lun_with_data(buf, 0); + CU_ASSERT_EQUAL(ret, 0); for (i = 0; i < 256; i++) { list[i].lba = i;