TESTS: Add a simple test for SANITIZE OVERWRITE
This commit is contained in:
@@ -267,6 +267,7 @@ 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_simple.c \
|
||||
test-tool/test_sanitize_overwrite.c \
|
||||
test-tool/test_startstopunit_simple.c \
|
||||
test-tool/test_startstopunit_pwrcnd.c \
|
||||
test-tool/test_startstopunit_noloej.c \
|
||||
|
||||
@@ -1350,6 +1350,54 @@ int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sanitize_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send SANITIZE (Expecting INVALID_FIELD_IN_CDB) "
|
||||
"IMMED:%d AUSE:%d SA:%d "
|
||||
"PARAM_LEN:%d",
|
||||
immed, ause, sa, param_len);
|
||||
|
||||
task = iscsi_sanitize_sync(iscsi, lun, immed, ause, sa, param_len,
|
||||
data);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] Failed to send SANITIZE command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not "
|
||||
"implemented on target");
|
||||
scsi_free_scsi_task(task);
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] SANITIZE successful but should "
|
||||
"have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
logging(LOG_NORMAL, "[FAILED] SANITIZE failed with wrong "
|
||||
"sense. Should have failed with ILLEGAL_REQUEST/"
|
||||
"INVALID_FIELD_IN_CDB. Sense:%s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] SANITIZE returned ILLEGAL_REQUEST/"
|
||||
"INVALID_FIELD_IB_CDB.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
@@ -261,6 +261,7 @@ int release6(struct iscsi_context *iscsi, int lun);
|
||||
int reserve6(struct iscsi_context *iscsi, int lun);
|
||||
int reserve6_conflict(struct iscsi_context *iscsi, int lun);
|
||||
int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data);
|
||||
int sanitize_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data);
|
||||
int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start);
|
||||
int startstopunit_preventremoval(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start);
|
||||
int synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed);
|
||||
|
||||
@@ -223,6 +223,7 @@ static CU_TestInfo tests_readonly[] = {
|
||||
|
||||
static CU_TestInfo tests_sanitize[] = {
|
||||
{ (char *)"Sanitize", test_sanitize_simple },
|
||||
{ (char *)"Overwrite", test_sanitize_overwrite },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ void test_reserve6_target_warm_reset(void);
|
||||
void test_reserve6_lun_reset(void);
|
||||
|
||||
void test_sanitize_simple(void);
|
||||
void test_sanitize_overwrite(void);
|
||||
|
||||
void test_startstopunit_simple(void);
|
||||
void test_startstopunit_pwrcnd(void);
|
||||
|
||||
84
test-tool/test_sanitize_overwrite.c
Normal file
84
test-tool/test_sanitize_overwrite.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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_overwrite(void)
|
||||
{
|
||||
int ret;
|
||||
struct iscsi_data data;
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE");
|
||||
|
||||
CHECK_FOR_SANITIZE;
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Parameter list length <= 4 is an error");
|
||||
logging(LOG_VERBOSE, "Test that parameter list length == 0 fails");
|
||||
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
|
||||
0, 0, SCSI_SANITIZE_OVERWRITE, 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);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test that parameter list length == 4 fails");
|
||||
data.size = 4;
|
||||
data.data = alloca(data.size);
|
||||
memset(data.data, 0, data.size);
|
||||
ret = sanitize_invalidfieldincdb(iscsic, tgt_lun,
|
||||
0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Parameter list length >= blocksize + 5 is an "
|
||||
"error");
|
||||
logging(LOG_VERBOSE, "Test that parameter list length == blocksize + 8 "
|
||||
"fails");
|
||||
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, data.size, &data);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test SANITIZE OVERWRITE of full block of 0xaa");
|
||||
data.size = block_size + 4;
|
||||
data.data[0] = 0x01;
|
||||
data.data[1] = 0x00;
|
||||
data.data[2] = block_size >> 8;
|
||||
data.data[3] = block_size & 0xff;
|
||||
memset(&data.data[4], 0xaa, block_size);
|
||||
ret = sanitize(iscsic, tgt_lun,
|
||||
0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user