From cee82ad135f7f012212c5a0f23fb0c04139d47d6 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 5 Jul 2013 13:32:49 -0700 Subject: [PATCH] TESTS: Add tests for the reserved bits/bytes in SANITIZE --- Makefile.am | 5 +- test-tool/iscsi-test-cu.c | 5 +- test-tool/iscsi-test-cu.h | 5 +- .../test_sanitize_block_erase_reserved.c | 85 +++++++++++++++++ .../test_sanitize_crypto_erase_reserved.c | 85 +++++++++++++++++ test-tool/test_sanitize_overwrite_reserved.c | 95 +++++++++++++++++++ 6 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 test-tool/test_sanitize_block_erase_reserved.c create mode 100644 test-tool/test_sanitize_crypto_erase_reserved.c create mode 100644 test-tool/test_sanitize_overwrite_reserved.c diff --git a/Makefile.am b/Makefile.am index 1e0a677..4d861ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -268,10 +268,13 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/test_reserve6_target_cold_reset.c \ test-tool/test_reserve6_lun_reset.c \ test-tool/test_sanitize_block_erase.c \ + test-tool/test_sanitize_block_erase_reserved.c \ test-tool/test_sanitize_crypto_erase.c \ - test-tool/test_sanitize_overwrite.c \ + test-tool/test_sanitize_crypto_erase_reserved.c \ test-tool/test_sanitize_exit_failure_mode.c \ test-tool/test_sanitize_invalid_serviceaction.c \ + test-tool/test_sanitize_overwrite.c \ + test-tool/test_sanitize_overwrite_reserved.c \ test-tool/test_startstopunit_simple.c \ test-tool/test_startstopunit_pwrcnd.c \ test-tool/test_startstopunit_noloej.c \ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 7ddb199..9971aa1 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -228,10 +228,13 @@ static CU_TestInfo tests_readonly[] = { static CU_TestInfo tests_sanitize[] = { { (char *)"BlockErase", test_sanitize_block_erase }, + { (char *)"BlockEraseReserved", test_sanitize_block_erase_reserved }, { (char *)"CryptoErase", test_sanitize_crypto_erase }, + { (char *)"CryptoEraseReserved", test_sanitize_crypto_erase_reserved }, { (char *)"ExitFailureMode", test_sanitize_exit_failure_mode }, - { (char *)"Overwrite", test_sanitize_overwrite }, { (char *)"InvalidServiceAction", test_sanitize_invalid_serviceaction }, + { (char *)"Overwrite", test_sanitize_overwrite }, + { (char *)"OverwriteReserved", test_sanitize_overwrite_reserved }, CU_TEST_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 4b8d6b4..e25c1ba 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -154,10 +154,13 @@ void test_reserve6_target_warm_reset(void); void test_reserve6_lun_reset(void); void test_sanitize_block_erase(void); +void test_sanitize_block_erase_reserved(void); void test_sanitize_crypto_erase(void); -void test_sanitize_overwrite(void); +void test_sanitize_crypto_erase_reserved(void); void test_sanitize_exit_failure_mode(void); void test_sanitize_invalid_serviceaction(void); +void test_sanitize_overwrite(void); +void test_sanitize_overwrite_reserved(void); void test_startstopunit_simple(void); void test_startstopunit_pwrcnd(void); diff --git a/test-tool/test_sanitize_block_erase_reserved.c b/test-tool/test_sanitize_block_erase_reserved.c new file mode 100644 index 0000000..681a942 --- /dev/null +++ b/test-tool/test_sanitize_block_erase_reserved.c @@ -0,0 +1,85 @@ +/* + 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 + +#include "iscsi.h" +#include "iscsi-private.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +static int change_num; + +static int my_iscsi_queue_pdu(struct iscsi_context *iscsi _U_, struct iscsi_pdu *pdu) +{ + switch (change_num) { + case 1: + /* Set reserved bit 0x40 in byte 1 of the CDB */ + pdu->outdata.data[33] |= 0x40; + break; + case 2: + case 3: + case 4: + case 5: + case 6: + /* Set reserved byte in the CDB */ + pdu->outdata.data[32 + change_num] = change_num; + break; + } + + change_num = 0; + return 0; +} + +void test_sanitize_block_erase_reserved(void) +{ + int i, ret; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test SANITIZE BLOCK_ERASE Reserved bits/bytes"); + + CHECK_FOR_SANITIZE; + + local_iscsi_queue_pdu = my_iscsi_queue_pdu; + + + logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " + "bit in byte 1 set to 1"); + change_num = 1; + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE BLOCK_ERASE is not " + "implemented on target."); + CU_PASS("SANITIZE is not implemented."); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + + for (i = 2; i < 7; i++) { + logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " + "byte %d set to non-zero", i); + change_num = i; + + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_sanitize_crypto_erase_reserved.c b/test-tool/test_sanitize_crypto_erase_reserved.c new file mode 100644 index 0000000..c8a65a9 --- /dev/null +++ b/test-tool/test_sanitize_crypto_erase_reserved.c @@ -0,0 +1,85 @@ +/* + 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 + +#include "iscsi.h" +#include "iscsi-private.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +static int change_num; + +static int my_iscsi_queue_pdu(struct iscsi_context *iscsi _U_, struct iscsi_pdu *pdu) +{ + switch (change_num) { + case 1: + /* Set reserved bit 0x40 in byte 1 of the CDB */ + pdu->outdata.data[33] |= 0x40; + break; + case 2: + case 3: + case 4: + case 5: + case 6: + /* Set reserved byte in the CDB */ + pdu->outdata.data[32 + change_num] = change_num; + break; + } + + change_num = 0; + return 0; +} + +void test_sanitize_crypto_erase_reserved(void) +{ + int i, ret; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test SANITIZE CRYPTO_ERASE Reserved bits/bytes"); + + CHECK_FOR_SANITIZE; + + local_iscsi_queue_pdu = my_iscsi_queue_pdu; + + + logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " + "bit in byte 1 set to 1"); + change_num = 1; + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE CRYPTO_ERASE is not " + "implemented on target."); + CU_PASS("SANITIZE is not implemented."); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + + for (i = 2; i < 7; i++) { + logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " + "byte %d set to non-zero", i); + change_num = i; + + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + CU_ASSERT_EQUAL(ret, 0); + } +} diff --git a/test-tool/test_sanitize_overwrite_reserved.c b/test-tool/test_sanitize_overwrite_reserved.c new file mode 100644 index 0000000..80fadc6 --- /dev/null +++ b/test-tool/test_sanitize_overwrite_reserved.c @@ -0,0 +1,95 @@ +/* + 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 +#include + +#include "iscsi.h" +#include "iscsi-private.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + +static int change_num; + +static int my_iscsi_queue_pdu(struct iscsi_context *iscsi _U_, struct iscsi_pdu *pdu) +{ + switch (change_num) { + case 1: + /* Set reserved bit 0x40 in byte 1 of the CDB */ + pdu->outdata.data[33] |= 0x40; + break; + case 2: + case 3: + case 4: + case 5: + case 6: + /* Set reserved byte in the CDB */ + pdu->outdata.data[32 + change_num] = change_num; + break; + } + + change_num = 0; + return 0; +} + +void test_sanitize_overwrite_reserved(void) +{ + int i, ret; + struct iscsi_data data; + + data.size = block_size + 4; + data.data = alloca(data.size); + memset(&data.data[4], 0xaa, block_size); + + data.data[0] = 0x01; + data.data[1] = 0x00; + data.data[2] = block_size >> 8; + data.data[3] = block_size & 0xff; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE Reserved bits/bytes"); + + CHECK_FOR_SANITIZE; + + local_iscsi_queue_pdu = my_iscsi_queue_pdu; + + logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " + "bit in byte 1 set to 1"); + change_num = 1; + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] SANITIZE OVERWRITE is not " + "implemented on target."); + CU_PASS("SANITIZE is not implemented."); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + + for (i = 2; i < 7; i++) { + logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " + "byte %d set to non-zero", i); + change_num = i; + + ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, + 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + CU_ASSERT_EQUAL(ret, 0); + } +}