Add tests from SANITIZE OVERWRITE parameter length

This commit is contained in:
Ronnie Sahlberg
2013-05-26 15:21:43 -07:00
parent e5e8d7e3ef
commit 4e08d27031
5 changed files with 126 additions and 1 deletions

View File

@@ -268,6 +268,7 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
test-tool/test_reserve6_lun_reset.c \
test-tool/test_sanitize_simple.c \
test-tool/test_sanitize_overwrite.c \
test-tool/test_sanitize_paramlen.c \
test-tool/test_startstopunit_simple.c \
test-tool/test_startstopunit_pwrcnd.c \
test-tool/test_startstopunit_noloej.c \

View File

@@ -364,7 +364,7 @@ scsi_cdb_sanitize(int immed, int ause, int sa, int param_len)
} else {
task->xfer_dir = SCSI_XFER_NONE;
}
task->expxferlen = param_len;
task->expxferlen = (param_len + 3) & 0xfffc;
return task;
}

View File

@@ -224,6 +224,7 @@ static CU_TestInfo tests_readonly[] = {
static CU_TestInfo tests_sanitize[] = {
{ (char *)"Sanitize", test_sanitize_simple },
{ (char *)"Overwrite", test_sanitize_overwrite },
{ (char *)"ParamLen", test_sanitize_paramlen },
CU_TEST_INFO_NULL
};

View File

@@ -153,6 +153,7 @@ void test_reserve6_lun_reset(void);
void test_sanitize_simple(void);
void test_sanitize_overwrite(void);
void test_sanitize_paramlen(void);
void test_startstopunit_simple(void);
void test_startstopunit_pwrcnd(void);

View File

@@ -0,0 +1,122 @@
/*
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);
}
}