TESTS: Fix the writeatomic tests for targets where atomic granularity != 1

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2015-09-10 17:20:06 -07:00
parent fd55600d39
commit fa9df7fdd3
6 changed files with 78 additions and 48 deletions

View File

@@ -43,8 +43,8 @@ test_writeatomic16_0blocks(void)
}
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,
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks one alignment past end-of-LUN");
ret = writeatomic16(sd, num_blocks + inq_bl->atomic_align, 0,
block_size, 0, 0, 0, 0, NULL,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
@@ -57,8 +57,8 @@ test_writeatomic16_0blocks(void)
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==-1");
ret = writeatomic16(sd, -1, 0, block_size,
logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==-<alignment>");
ret = writeatomic16(sd, -inq_bl->atomic_align, 0, block_size,
0, 0, 0, 0, NULL,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);

View File

@@ -28,35 +28,43 @@
void
test_writeatomic16_beyond_eol(void)
{
int i, ret;
unsigned char *buf = alloca(256 * block_size);
int i, gran, ret;
unsigned char *buf = alloca(256 * 2 * 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");
gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
ret = writeatomic16(sd, 0,
block_size * gran,
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 1-256 blocks <granularity> blocks beyond the end");
memset(buf, 0xa6, 256 * block_size);
for (i = 1; i <= 256; i++) {
for (i = inq_bl->atomic_gran; i <= 256; i += inq_bl->atomic_gran) {
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,
ret = writeatomic16(sd, num_blocks - i,
2 * 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++) {
for (i = inq_bl->atomic_gran; i <= 256; i += inq_bl->atomic_gran) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
@@ -67,12 +75,12 @@ test_writeatomic16_beyond_eol(void)
}
logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks at LBA==-1");
for (i = 1; i <= 256; i++) {
logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks at LBA==-<alignment>");
for (i = inq_bl->atomic_gran; i <= 256; i += inq_bl->atomic_gran) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, -1, i * block_size,
ret = writeatomic16(sd, -inq_bl->atomic_align, i * block_size,
block_size, 0, 0, 0, 0, buf,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
@@ -80,11 +88,11 @@ test_writeatomic16_beyond_eol(void)
logging(LOG_VERBOSE, "Test WRITEATOMIC16 2-256 blocks all but one block beyond the end");
for (i = 2; i <= 256; i++) {
for (i = 2 * inq_bl->atomic_gran; i <= 256; i += inq_bl->atomic_gran) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}
ret = writeatomic16(sd, num_blocks - 1,
ret = writeatomic16(sd, num_blocks - inq_bl->atomic_gran,
i * block_size, block_size, 0, 0, 0, 0, buf,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);

View File

@@ -28,12 +28,12 @@
void
test_writeatomic16_dpofua(void)
{
int ret, dpofua, usage_data_dpofua;
int ret, gran, 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);
unsigned char *buf;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test WRITEATOMIC16 DPO/FUA flags");
@@ -41,6 +41,9 @@ test_writeatomic16_dpofua(void)
CHECK_FOR_SBC;
CHECK_FOR_DATALOSS;
gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
buf = alloca(gran * block_size);
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,
@@ -62,7 +65,7 @@ test_writeatomic16_dpofua(void)
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with DPO==1");
memset(buf, 0xa6, block_size);
if (dpofua) {
ret = writeatomic16(sd, 0, block_size,
ret = writeatomic16(sd, 0, gran * block_size,
block_size, 0, 1, 0, 0, buf,
EXPECT_STATUS_GOOD);
if (ret == -2) {
@@ -72,7 +75,7 @@ test_writeatomic16_dpofua(void)
}
CU_ASSERT_EQUAL(ret, 0);
} else {
ret = writeatomic16(sd, 0, block_size,
ret = writeatomic16(sd, 0, gran * block_size,
block_size, 0, 1, 0, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
if (ret == -2) {
@@ -85,12 +88,12 @@ test_writeatomic16_dpofua(void)
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with FUA==1");
if (dpofua) {
ret = writeatomic16(sd, 0, block_size,
ret = writeatomic16(sd, 0, gran * block_size,
block_size, 0, 0, 1, 0, buf,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
} else {
ret = writeatomic16(sd, 0, block_size,
ret = writeatomic16(sd, 0, gran * block_size,
block_size, 0, 0, 1, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
CU_ASSERT_EQUAL(ret, 0);
@@ -98,12 +101,12 @@ test_writeatomic16_dpofua(void)
logging(LOG_VERBOSE, "Test WRITEATOMIC16 with DPO==1 FUA==1");
if (dpofua) {
ret = writeatomic16(sd, 0, block_size,
ret = writeatomic16(sd, 0, gran * block_size,
block_size, 0, 1, 1, 0, buf,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0);
} else {
ret = writeatomic16(sd, 0, block_size,
ret = writeatomic16(sd, 0, gran * block_size,
block_size, 0, 1, 1, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
CU_ASSERT_EQUAL(ret, 0);

View File

@@ -29,7 +29,7 @@
void
test_writeatomic16_simple(void)
{
int i, ret;
int i, gran, ret;
unsigned char *buf = alloca(256 * block_size);
@@ -37,25 +37,34 @@ test_writeatomic16_simple(void)
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
ret = writeatomic16(sd, 0,
block_size * gran,
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 start of the LUN");
memset(buf, 0xa6, 256 * block_size);
for (i = 1; i <= 256; i++) {
for (i = inq_bl->atomic_gran; i <= 256; i += inq_bl->atomic_gran) {
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++) {
for (i = inq_bl->atomic_gran; i <= 256; i += inq_bl->atomic_gran) {
if (maximum_transfer_length && maximum_transfer_length < i) {
break;
}

View File

@@ -61,11 +61,7 @@ test_writeatomic16_vpd(void)
logging(LOG_VERBOSE, "Check if WRITEATOMIC16 is supported");
if (bl->atomic_gran) {
gran = bl->atomic_gran;
} else {
gran = 1;
}
gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
buf = alloca(block_size * gran);
memset(buf, 0x00, block_size * gran);
ret = writeatomic16(sd, 0, block_size * gran,

View File

@@ -29,24 +29,38 @@
void
test_writeatomic16_wrprotect(void)
{
int i, ret;
int i, gran, ret;
unsigned char *buf = alloca(block_size);
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
/*
* 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;
gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
ret = writeatomic16(sd, 0,
block_size * gran,
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 with non-zero WRPROTECT");
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,
gran * block_size, block_size,
i, 0, 0, 0, buf,
EXPECT_INVALID_FIELD_IN_CDB);
if (ret == -2) {