Tests: Update the SANITIZE tests

This commit is contained in:
Ronnie Sahlberg
2013-05-26 19:36:35 -07:00
parent 58dde352f1
commit b193e08be8
11 changed files with 266 additions and 149 deletions

View File

@@ -266,9 +266,10 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
test-tool/test_reserve6_target_warm_reset.c \
test-tool/test_reserve6_target_cold_reset.c \
test-tool/test_reserve6_lun_reset.c \
test-tool/test_sanitize_simple.c \
test-tool/test_sanitize_block_erase.c \
test-tool/test_sanitize_crypto_erase.c \
test-tool/test_sanitize_overwrite.c \
test-tool/test_sanitize_paramlen.c \
test-tool/test_sanitize_exit_failure_mode.c \
test-tool/test_sanitize_invalid_serviceaction.c \
test-tool/test_startstopunit_simple.c \
test-tool/test_startstopunit_pwrcnd.c \

View File

@@ -27,7 +27,7 @@ int T0430_report_all_supported_ops(const char *initiator, const char *url)
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_report_supported_op_codes *rsoc;
struct scsi_report_supported_op_codes *tmp_rsoc;
struct scsi_command_descriptor *desc;
int ret, lun;
int full_size, desc_size;
@@ -95,8 +95,8 @@ int T0430_report_all_supported_ops(const char *initiator, const char *url)
goto finished;
}
}
rsoc = scsi_datain_unmarshall(task);
if (rsoc == NULL) {
tmp_rsoc = scsi_datain_unmarshall(task);
if (tmp_rsoc == NULL) {
printf("[FAILED]\n");
printf("failed to unmarshall REPORT SUPPORTED OPCODES datain blob\n");
scsi_free_scsi_task(task);
@@ -104,13 +104,13 @@ int T0430_report_all_supported_ops(const char *initiator, const char *url)
goto finished;
}
printf("Supported Commands: %d\n", rsoc->num_descriptors);
printf("Supported Commands: %d\n", tmp_rsoc->num_descriptors);
printf("=======================\n");
for (i = 0; i < rsoc->num_descriptors; i++) {
for (i = 0; i < tmp_rsoc->num_descriptors; i++) {
printf("op:%x\tsa:%x\tcdb length:%d\n",
rsoc->descriptors[i].opcode,
rsoc->descriptors[i].sa,
rsoc->descriptors[i].cdb_len);
tmp_rsoc->descriptors[i].opcode,
tmp_rsoc->descriptors[i].sa,
tmp_rsoc->descriptors[i].cdb_len);
}
printf("\n[OK]\n");
@@ -163,8 +163,8 @@ int T0430_report_all_supported_ops(const char *initiator, const char *url)
goto finished;
}
}
rsoc = scsi_datain_unmarshall(task);
if (rsoc == NULL) {
tmp_rsoc = scsi_datain_unmarshall(task);
if (tmp_rsoc == NULL) {
printf("[FAILED]\n");
printf("failed to unmarshall REPORT SUPPORTED OPCODES datain blob\n");
scsi_free_scsi_task(task);
@@ -172,12 +172,12 @@ int T0430_report_all_supported_ops(const char *initiator, const char *url)
goto finished;
}
printf("Supported Commands (with timeout information): %d\n", rsoc->num_descriptors);
printf("Supported Commands (with timeout information): %d\n", tmp_rsoc->num_descriptors);
printf("=======================\n");
desc_size = sizeof (struct scsi_command_descriptor)
+ sizeof (struct scsi_op_timeout_descriptor);
desc = &rsoc->descriptors[0];
for (i = 0; i < rsoc->num_descriptors; i++) {
desc = &tmp_rsoc->descriptors[0];
for (i = 0; i < tmp_rsoc->num_descriptors; i++) {
printf("op:%x\tsa:%x\tcdb_length:%d\ttimeout info: length:%d\tcommand specific:%x\tnominal processing%d\trecommended%d\n",
desc->opcode,
desc->sa,

View File

@@ -50,6 +50,7 @@ struct scsi_inquiry_standard *inq;
struct scsi_inquiry_logical_block_provisioning *inq_lbp;
struct scsi_inquiry_block_limits *inq_bl;
struct scsi_readcapacity16 *rc16;
struct scsi_report_supported_op_codes *rsop;
size_t block_size;
uint64_t num_blocks;
@@ -5840,3 +5841,21 @@ inquiry_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int evpd, int pa
return 0;
}
struct scsi_command_descriptor *
get_command_descriptor(int opcode, int sa)
{
int i;
if (rsop == NULL) {
return NULL;
}
for (i = 0; i < rsop->num_descriptors; i++) {
if (rsop->descriptors[i].opcode == opcode
&& rsop->descriptors[i].sa == sa) {
return &rsop->descriptors[i];
}
}
return NULL;
}

View File

@@ -143,6 +143,7 @@ extern struct scsi_inquiry_standard *inq;
extern struct scsi_inquiry_logical_block_provisioning *inq_lbp;
extern struct scsi_inquiry_block_limits *inq_bl;
extern struct scsi_readcapacity16 *rc16;
extern struct scsi_report_supported_op_codes *rsop;
extern size_t block_size;
extern uint64_t num_blocks;
@@ -165,6 +166,7 @@ void wait_until_test_finished(struct iscsi_context *iscsi, struct iscsi_async_st
struct iscsi_pdu;
int (*local_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
struct scsi_command_descriptor *get_command_descriptor(int opcode, int sa);
/*
* PGR support

View File

@@ -222,9 +222,10 @@ static CU_TestInfo tests_readonly[] = {
};
static CU_TestInfo tests_sanitize[] = {
{ (char *)"Sanitize", test_sanitize_simple },
{ (char *)"BlockErase", test_sanitize_block_erase },
{ (char *)"CryptoErase", test_sanitize_crypto_erase },
{ (char *)"ExitFailureMode", test_sanitize_exit_failure_mode },
{ (char *)"Overwrite", test_sanitize_overwrite },
{ (char *)"ParamLen", test_sanitize_paramlen },
{ (char *)"InvalidServiceAction", test_sanitize_invalid_serviceaction },
CU_TEST_INFO_NULL
};
@@ -895,6 +896,7 @@ main(int argc, char *argv[])
struct scsi_task *inq_lbp_task = NULL;
struct scsi_task *inq_bl_task = NULL;
struct scsi_task *rc16_task = NULL;
struct scsi_task *rsop_task = NULL;
int full_size;
int is_usb;
static struct option long_opts[] = {
@@ -1134,6 +1136,23 @@ main(int argc, char *argv[])
}
}
rsop_task = iscsi_report_supported_opcodes_sync(iscsic, lun,
1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535);
if (rsop_task == NULL) {
printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n",
iscsi_get_error(iscsic));
iscsi_destroy_context(iscsic);
return -1;
}
if (rsop_task->status == SCSI_STATUS_GOOD) {
rsop = scsi_datain_unmarshall(rsop_task);
if (rsop == NULL) {
printf("failed to unmarshall REPORT_SUPPORTED_OPCODES "
"data. %s\n",
iscsi_get_error(iscsic));
scsi_free_scsi_task(rsop_task);
}
}
/* check if the device is write protected or not */
task = iscsi_modesense6_sync(iscsic, lun, 0, SCSI_MODESENSE_PC_CURRENT,
@@ -1208,6 +1227,9 @@ main(int argc, char *argv[])
if (rc16_task != NULL) {
scsi_free_scsi_task(rc16_task);
}
if (rsop_task != NULL) {
scsi_free_scsi_task(rsop_task);
}
return 0;
}

View File

@@ -151,9 +151,10 @@ void test_reserve6_target_cold_reset(void);
void test_reserve6_target_warm_reset(void);
void test_reserve6_lun_reset(void);
void test_sanitize_simple(void);
void test_sanitize_block_erase(void);
void test_sanitize_crypto_erase(void);
void test_sanitize_overwrite(void);
void test_sanitize_paramlen(void);
void test_sanitize_exit_failure_mode(void);
void test_sanitize_invalid_serviceaction(void);
void test_startstopunit_simple(void);

View File

@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alloca.h>
#include <CUnit/CUnit.h>
@@ -26,23 +27,42 @@
#include "iscsi-test-cu.h"
void
test_sanitize_simple(void)
test_sanitize_block_erase(void)
{
int ret;
struct iscsi_data data;
struct scsi_command_descriptor *cd;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test basic SANITIZE");
logging(LOG_VERBOSE, "Test SANITIZE BLOCK ERASE");
CHECK_FOR_SANITIZE;
logging(LOG_NORMAL, "Check that SANITIZE BLOCK_ERASE is supported "
"in REPORT_SUPPORTED_OPCODES");
cd = get_command_descriptor(SCSI_OPCODE_SANITIZE,
SCSI_SANITIZE_BLOCK_ERASE);
if (cd == NULL) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE BLOCK_ERASE is not "
"implemented according to REPORT_SUPPORTED_OPCODES.");
CU_PASS("SANITIZE is not implemented.");
return;
}
logging(LOG_VERBOSE, "Test we can perform basic BLOCK ERASE SANITIZE");
ret = sanitize(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
data.size = 8;
data.data = alloca(data.size);
memset(data.data, 0, data.size);
logging(LOG_VERBOSE, "BLOCK_ERASE parameter list length must be 0");
logging(LOG_VERBOSE, "Test that non-zero param length is an error for "
"BLOCK ERASE");
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_BLOCK_ERASE, 8, &data);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -0,0 +1,62 @@
/*
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alloca.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_sanitize_crypto_erase(void)
{
int ret;
struct iscsi_data data;
struct scsi_command_descriptor *cd;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test SANITIZE CRYPTO ERASE");
CHECK_FOR_SANITIZE;
logging(LOG_NORMAL, "Check that SANITIZE CRYPTO_ERASE is supported "
"in REPORT_SUPPORTED_OPCODES");
cd = get_command_descriptor(SCSI_OPCODE_SANITIZE,
SCSI_SANITIZE_CRYPTO_ERASE);
if (cd == NULL) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE CRYPTO_ERASE is not "
"implemented according to REPORT_SUPPORTED_OPCODES.");
CU_PASS("SANITIZE is not implemented.");
return;
}
data.size = 8;
data.data = alloca(data.size);
memset(data.data, 0, data.size);
logging(LOG_VERBOSE, "CRYPTO_ERASE parameter list length must be 0");
logging(LOG_VERBOSE, "Test that non-zero param length is an error for "
"CRYPTO ERASE");
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 8, &data);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -0,0 +1,65 @@
/*
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alloca.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_sanitize_exit_failure_mode(void)
{
int ret;
struct iscsi_data data;
struct scsi_command_descriptor *cd;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test SANITIZE EXIT FAILURE MODE");
CHECK_FOR_SANITIZE;
logging(LOG_NORMAL, "Check that SANITIZE EXIT FAILURE MODE is "
"supported in REPORT_SUPPORTED_OPCODES");
cd = get_command_descriptor(SCSI_OPCODE_SANITIZE,
SCSI_SANITIZE_EXIT_FAILURE_MODE);
if (cd == NULL) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE EXIT FAILURE MODE is "
"not implemented according to "
"REPORT_SUPPORTED_OPCODES.");
CU_PASS("SANITIZE is not implemented.");
return;
}
data.size = 8;
data.data = alloca(data.size);
memset(data.data, 0, data.size);
logging(LOG_VERBOSE, "EXIT_FAILURE_MODE parameter list length must "
"be 0");
logging(LOG_VERBOSE, "Test that non-zero param length is an error for "
"EXIT_FAILURE_MODE");
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_EXIT_FAILURE_MODE, 8, &data);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -29,14 +29,25 @@
void
test_sanitize_overwrite(void)
{
int ret;
int i, ret;
struct iscsi_data data;
struct scsi_command_descriptor *cd;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE");
CHECK_FOR_SANITIZE;
logging(LOG_NORMAL, "Check that SANITIZE OVERWRITE is supported "
"in REPORT_SUPPORTED_OPCODES");
cd = get_command_descriptor(SCSI_OPCODE_SANITIZE,
SCSI_SANITIZE_OVERWRITE);
if (cd == NULL) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE OVERWRITE is not "
"implemented according to REPORT_SUPPORTED_OPCODES.");
CU_PASS("SANITIZE is not implemented.");
return;
}
logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE with initialization pattern of one full block");
data.size = block_size + 4;
@@ -72,4 +83,40 @@ test_sanitize_overwrite(void)
ret = sanitize(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "OVERWRITE parameter list length must "
"be > 4 and < blocksize+5");
for (i = 0; i < 5; i++) {
logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an "
"error.", i);
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_OVERWRITE, i, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not "
"implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
}
logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an "
"error.", i);
data.size = block_size + 8;
data.data = alloca(data.size);
memset(data.data, 0, data.size);
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_OVERWRITE, block_size + 5, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not "
"implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -1,122 +0,0 @@
/*
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alloca.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_sanitize_paramlen(void)
{
int i, ret;
struct iscsi_data data;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test SANITIZE ParameterListLength");
CHECK_FOR_SANITIZE;
data.size = 8;
data.data = alloca(data.size);
memset(data.data, 0, data.size);
logging(LOG_VERBOSE, "BLOCK_ERASE parameter list length must be 0");
logging(LOG_VERBOSE, "Test that non-zero param length is an error for "
"BLOCK ERASE");
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_BLOCK_ERASE, 8, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "CRYPTO_ERASE parameter list length must be 0");
logging(LOG_VERBOSE, "Test that non-zero param length is an error for "
"CRYPTO ERASE");
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 8, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "EXIT_FAILURE_MODE parameter list length must "
"be 0");
logging(LOG_VERBOSE, "Test that non-zero param length is an error for "
"EXIT_FAILURE_MODE");
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_EXIT_FAILURE_MODE, 8, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "OVERWRITE parameter list length must "
"be > 4 and < blocksize+5");
for (i = 0; i < 5; i++) {
logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an "
"error.", i);
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_OVERWRITE, i, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not "
"implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
}
logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an "
"error.", i);
data.size = block_size + 8;
data.data = alloca(data.size);
memset(data.data, 0, data.size);
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_OVERWRITE, block_size + 5, &data);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not "
"implemented.");
CU_PASS("SANITIZE is not implemented.");
return;
} else {
CU_ASSERT_EQUAL(ret, 0);
}
}