Add tests for WRITE_ATOMIC_16

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2015-09-08 10:09:26 -07:00
parent 02fd6217cb
commit 6c16f9e322
12 changed files with 489 additions and 0 deletions

View File

@@ -143,6 +143,8 @@ iscsi_write12_sync
iscsi_write12_task
iscsi_write16_sync
iscsi_write16_task
iscsi_writeatomic16_sync
iscsi_writeatomic16_task
iscsi_orwrite_sync
iscsi_orwrite_task
iscsi_compareandwrite_sync
@@ -195,6 +197,7 @@ scsi_cdb_verify16
scsi_cdb_write10
scsi_cdb_write12
scsi_cdb_write16
scsi_cdb_writeatomic16
scsi_cdb_orwrite
scsi_cdb_writeverify10
scsi_cdb_writeverify12

View File

@@ -141,6 +141,8 @@ iscsi_write12_sync
iscsi_write12_task
iscsi_write16_sync
iscsi_write16_task
iscsi_writeatomic16_sync
iscsi_writeatomic16_task
iscsi_orwrite_sync
iscsi_orwrite_task
iscsi_compareandwrite_sync
@@ -193,6 +195,7 @@ scsi_cdb_verify16
scsi_cdb_write10
scsi_cdb_write12
scsi_cdb_write16
scsi_cdb_writeatomic16
scsi_cdb_orwrite
scsi_cdb_writeverify10
scsi_cdb_writeverify12

View File

@@ -172,6 +172,11 @@ iscsi_test_cu_SOURCES = iscsi-test-cu.c \
test_write16_wrprotect.c \
test_write16_dpofua.c \
test_write16_residuals.c \
test_writeatomic16_simple.c \
test_writeatomic16_beyond_eol.c \
test_writeatomic16_0blocks.c \
test_writeatomic16_wrprotect.c \
test_writeatomic16_dpofua.c \
test_writesame10_simple.c \
test_writesame10_beyond_eol.c \
test_writesame10_0blocks.c \

View File

@@ -2185,6 +2185,38 @@ write16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize,
return ret;
}
int
writeatomic16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq)
{
struct scsi_task *task;
struct iscsi_data d;
int ret;
logging(LOG_VERBOSE, "Send WRITEATOMIC16 (Expecting %s) LBA:%" PRIu64
" blocks:%d wrprotect:%d dpo:%d fua:%d group:%d",
scsi_status_str(status),
lba, datalen / blocksize, wrprotect,
dpo, fua, group);
if (!data_loss) {
printf("--dataloss flag is not set in. Skipping write\n");
return -1;
}
task = scsi_cdb_writeatomic16(lba, datalen, blocksize, wrprotect,
dpo, fua, group);
assert(task != NULL);
d.data = data;
d.size = datalen;
send_scsi_command(sdev, task, &d);
ret = check_result("WRITEATOMIC16", sdev, task, status, key, ascq, num_ascq);
scsi_free_scsi_task(task);
return ret;
}
int
writesame10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq)
{

View File

@@ -313,6 +313,7 @@ int verify16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int block
int write10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int write12(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int write16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int writeatomic16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int writesame10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int writesame16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int writeverify10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);

View File

@@ -379,6 +379,15 @@ static CU_TestInfo tests_write16[] = {
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_writeatomic16[] = {
{ (char *)"Simple", test_writeatomic16_simple },
{ (char *)"BeyondEol", test_writeatomic16_beyond_eol },
{ (char *)"ZeroBlocks", test_writeatomic16_0blocks },
{ (char *)"WriteProtect", test_writeatomic16_wrprotect },
{ (char *)"DpoFua", test_writeatomic16_dpofua },
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_writesame10[] = {
{ (char *)"Simple", test_writesame10_simple },
{ (char *)"BeyondEol", test_writesame10_beyond_eol },
@@ -487,6 +496,7 @@ static libiscsi_suite_info scsi_suites[] = {
{ "Write10", NON_PGR_FUNCS, tests_write10 },
{ "Write12", NON_PGR_FUNCS, tests_write12 },
{ "Write16", NON_PGR_FUNCS, tests_write16 },
{ "WriteAtomic16", NON_PGR_FUNCS, tests_writeatomic16 },
{ "WriteSame10", NON_PGR_FUNCS, tests_writesame10 },
{ "WriteSame16", NON_PGR_FUNCS, tests_writesame16 },
{ "WriteVerify10", NON_PGR_FUNCS, tests_writeverify10 },
@@ -571,6 +581,7 @@ static libiscsi_suite_info all_suites[] = {
{ "Write10", NON_PGR_FUNCS, tests_write10 },
{ "Write12", NON_PGR_FUNCS, tests_write12 },
{ "Write16", NON_PGR_FUNCS, tests_write16 },
{ "WriteAtomic16", NON_PGR_FUNCS, tests_writeatomic16 },
{ "WriteSame10", NON_PGR_FUNCS, tests_writesame10 },
{ "WriteSame16", NON_PGR_FUNCS, tests_writesame16 },
{ "WriteVerify10", NON_PGR_FUNCS, tests_writeverify10 },
@@ -608,6 +619,7 @@ static libiscsi_suite_info linux_suites[] = {
{ "Write10", NON_PGR_FUNCS, tests_write10 },
{ "Write12", NON_PGR_FUNCS, tests_write12 },
{ "Write16", NON_PGR_FUNCS, tests_write16 },
{ "WriteAtomic16", NON_PGR_FUNCS, tests_writeatomic16 },
{ "WriteSame10", NON_PGR_FUNCS, tests_writesame10 },
{ "WriteSame16", NON_PGR_FUNCS, tests_writesame16 },
{ "WriteVerify10", NON_PGR_FUNCS, tests_writeverify10 },

View File

@@ -251,6 +251,12 @@ void test_write16_wrprotect(void);
void test_write16_dpofua(void);
void test_write16_residuals(void);
void test_writeatomic16_simple(void);
void test_writeatomic16_beyond_eol(void);
void test_writeatomic16_0blocks(void);
void test_writeatomic16_wrprotect(void);
void test_writeatomic16_dpofua(void);
void test_writesame10_simple(void);
void test_writesame10_beyond_eol(void);
void test_writesame10_0blocks(void);

View File

@@ -0,0 +1,65 @@
/*
Copyright (C) 2015 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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_writeatomic16_0blocks(void)
{
int ret;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==0");
ret = writeatomic16(sd, 0, 0, block_size,
0, 0, 0, 0, NULL,
EXPECT_STATUS_GOOD);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented.");
CU_PASS("WRITEATOMIC16 is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks one block past end-of-LUN");
ret = writeatomic16(sd, num_blocks + 1, 0,
block_size, 0, 0, 0, 0, NULL,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==2^63");
ret = writeatomic16(sd, 0x8000000000000000ULL, 0,
block_size, 0, 0, 0, 0, NULL,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==-1");
ret = writeatomic16(sd, -1, 0, block_size,
0, 0, 0, 0, NULL,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -0,0 +1,92 @@
/*
Copyright (C) 2015 Ronnie Sahlberg <ronneisahlberg@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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_writeatomic16_beyond_eol(void)
{
int i, ret;
unsigned char *buf = alloca(256 * block_size);
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks one block beyond the end");
memset(buf, 0xa6, 256 * block_size);
for (i = 1; i <= 256; i++) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, num_blocks + 1 - i,
i * block_size, block_size, 0, 0, 0, 0, buf,
EXPECT_LBA_OOB);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented.");
CU_PASS("WRITEATOMIC16 is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks at LBA==2^63");
for (i = 1; i <= 256; i++) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, 0x8000000000000000ULL,
i * block_size, block_size, 0, 0, 0, 0, buf,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks at LBA==-1");
for (i = 1; i <= 256; i++) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, -1, i * block_size,
block_size, 0, 0, 0, 0, buf,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 2-256 blocks all but one block beyond the end");
for (i = 2; i <= 256; i++) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, num_blocks - 1,
i * block_size, block_size, 0, 0, 0, 0, buf,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,140 @@
/*
Copyright (C) 2015 by Ronnie Sahlberg <sahlberg@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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_writeatomic16_dpofua(void)
{
int ret, dpofua, usage_data_dpofua;
struct scsi_task *ms_task = NULL;
struct scsi_mode_sense *ms;
struct scsi_task *rso_task = NULL;
struct scsi_report_supported_op_codes_one_command *rsoc;
unsigned char *buf = alloca(block_size);
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 DPO/FUA flags");
CHECK_FOR_SBC;
CHECK_FOR_DATALOSS;
logging(LOG_VERBOSE, "Read the DPOFUA flag from mode sense data");
ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT,
SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD");
ms = scsi_datain_unmarshall(ms_task);
dpofua = ms && (ms->device_specific_parameter & 0x10);
scsi_free_scsi_task(ms_task);
if (dpofua) {
logging(LOG_VERBOSE, "DPOFUA flag is set. Device should allow "
"DPO/FUA flags in CDBs");
} else {
logging(LOG_VERBOSE, "DPOFUA flag is clear. Device should fail "
"CDBs with DPO/FUA set");
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with DPO==1");
memset(buf, 0xa6, block_size);
if (dpofua) {
ret = writeatomic16(sd, 0, block_size,
block_size, 0, 1, 0, 0, buf,
EXPECT_STATUS_GOOD);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented.");
CU_PASS("WRITEATOMIC16 is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
} else {
ret = writeatomic16(sd, 0, block_size,
block_size, 0, 1, 0, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented.");
CU_PASS("WRITEATOMIC16 is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with FUA==1");
if (dpofua) {
ret = writeatomic16(sd, 0, block_size,
block_size, 0, 0, 1, 0, buf,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
} else {
ret = writeatomic16(sd, 0, block_size,
block_size, 0, 0, 1, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with DPO==1 FUA==1");
if (dpofua) {
ret = writeatomic16(sd, 0, block_size,
block_size, 0, 1, 1, 0, buf,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
} else {
ret = writeatomic16(sd, 0, block_size,
block_size, 0, 1, 1, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Try fetching REPORT_SUPPORTED_OPCODES "
"for WRITEATOMIC16");
ret = report_supported_opcodes(sd, &rso_task,
0, SCSI_REPORT_SUPPORTING_OPCODE,
SCSI_OPCODE_WRITE_ATOMIC16,
0,
65535,
EXPECT_STATUS_GOOD);
if (ret == -2) {
logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. "
"Skipping this part of the test");
return;
}
logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer");
rsoc = scsi_datain_unmarshall(rso_task);
CU_ASSERT_NOT_EQUAL(rsoc, NULL);
usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1;
if (dpofua) {
logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags "
"are set in the CDB_USAGE_DATA");
CU_ASSERT_EQUAL(usage_data_dpofua, 0x18);
} else {
logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA "
"flags are clear in the CDB_USAGE_DATA");
CU_ASSERT_EQUAL(usage_data_dpofua, 0x00);
}
scsi_free_scsi_task(rso_task);
}

View File

@@ -0,0 +1,67 @@
/*
Copyright (C) 2015 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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_writeatomic16_simple(void)
{
int i, ret;
unsigned char *buf = alloca(256 * block_size);
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 of 1-256 blocks at the start of the LUN");
memset(buf, 0xa6, 256 * block_size);
for (i = 1; i <= 256; i++) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, 0, i * block_size,
block_size, 0, 0, 0, 0, buf,
EXPECT_STATUS_GOOD);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented.");
CU_PASS("WRITEATOMIC16 is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, num_blocks - i,
i * block_size, block_size, 0, 0, 0, 0, buf,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,63 @@
/*
Copyright (C) 2015 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 <stdlib.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_writeatomic16_wrprotect(void)
{
int i, ret;
unsigned char *buf = alloca(block_size);
/*
* Try out different non-zero values for WRPROTECT.
*/
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with non-zero WRPROTECT");
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
memset(buf, 0xa6, block_size);
if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) {
logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail.");
for (i = 1; i < 8; i++) {
ret = writeatomic16(sd, 0,
block_size, block_size,
i, 0, 0, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented.");
CU_PASS("WRITEATOMIC16 is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
return;
}
logging(LOG_NORMAL, "No tests for devices that support protection information yet.");
}