TESTS: Add tests for ORWRITE

This commit is contained in:
Ronnie Sahlberg
2013-02-19 19:30:51 -08:00
parent 100fcd796d
commit 41754b45e8
11 changed files with 698 additions and 0 deletions

View File

@@ -179,6 +179,12 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
test-tool/iscsi-support.c \
test-tool/test_get_lba_status_simple.c \
test-tool/test_get_lba_status_beyond_eol.c \
test-tool/test_orwrite_simple.c \
test-tool/test_orwrite_beyond_eol.c \
test-tool/test_orwrite_0blocks.c \
test-tool/test_orwrite_wrprotect.c \
test-tool/test_orwrite_flags.c \
test-tool/test_orwrite_verify.c \
test-tool/test_prefetch10_simple.c \
test-tool/test_prefetch10_beyond_eol.c \
test-tool/test_prefetch10_0blocks.c \

View File

@@ -187,6 +187,187 @@ iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
return real_iscsi_queue_pdu(iscsi, pdu);
}
int
orwrite(struct iscsi_context *iscsi, int lun, uint64_t lba,
uint32_t datalen, int blocksize, int wrprotect,
int dpo, int fua, int fua_nv, int group,
unsigned char *data)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send ORWRITE LBA:%" PRIu64 " blocks:%d "
"wrprotect:%d dpo:%d fua:%d fua_nv:%d group:%d",
lba, datalen / blocksize, wrprotect,
dpo, fua, fua_nv, group);
if (!data_loss) {
printf("--dataloss flag is not set in. Skipping write\n");
return -1;
}
task = iscsi_orwrite_sync(iscsi, lun, lba,
data, datalen, blocksize,
wrprotect, dpo, fua, fua_nv, group);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE command: %s",
iscsi_get_error(iscsi));
return -1;
}
if (task->status != SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] ORWRITE command: "
"failed with sense. %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] ORWRITE returned SUCCESS.");
return 0;
}
int
orwrite_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba,
uint32_t datalen, int blocksize, int wrprotect,
int dpo, int fua, int fua_nv, int group,
unsigned char *data)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send ORWRITE (Expecting INVALID_FIELD_IN_CDB) "
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
"dpo:%d fua:%d fua_nv:%d group:%d",
lba, datalen / blocksize, wrprotect,
dpo, fua, fua_nv, group);
if (!data_loss) {
printf("--dataloss flag is not set in. Skipping write\n");
return -1;
}
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
wrprotect, dpo, fua, fua_nv, group);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE command: %s",
iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] ORWRITE 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] ORWRITE 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] ORWRITE returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB.");
return 0;
}
int
orwrite_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba,
uint32_t datalen, int blocksize, int wrprotect,
int dpo, int fua, int fua_nv, int group,
unsigned char *data)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send ORWRITE (Expecting LBA_OUT_OF_RANGE) "
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
"dpo:%d fua:%d fua_nv:%d group:%d",
lba, datalen / blocksize, wrprotect,
dpo, fua, fua_nv, group);
if (!data_loss) {
printf("--dataloss flag is not set in. Skipping write\n");
return -1;
}
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
wrprotect, dpo, fua, fua_nv, group);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE command: %s",
iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] ORWRITE successful but should "
"have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE");
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_LBA_OUT_OF_RANGE) {
logging(LOG_NORMAL, "[FAILED] ORWRITE failed with wrong sense. "
"Should have failed with ILLEGAL_REQUEST/"
"LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] ORWRITE returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.");
return 0;
}
int
orwrite_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba,
uint32_t datalen, int blocksize, int wrprotect,
int dpo, int fua, int fua_nv, int group,
unsigned char *data)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send ORWRITE (Expecting WRITE_PROTECTED) "
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
"dpo:%d fua:%d fua_nv:%d group:%d",
lba, datalen / blocksize, wrprotect,
dpo, fua, fua_nv, group);
if (!data_loss) {
printf("--dataloss flag is not set in. Skipping write\n");
return -1;
}
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
wrprotect, dpo, fua, fua_nv, group);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE command: %s",
iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] ORWRITE successful but should "
"have failed with DATA_PROTECTION/WRITE_PROTECTED");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
logging(LOG_NORMAL, "[FAILED] ORWRITE failed with wrong sense. "
"Should have failed with DATA_PRTOTECTION/"
"WRITE_PROTECTED. Sense:%s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] ORWRITE returned DATA_PROTECTION/WRITE_PROTECTED.");
return 0;
}
int
prin_task(struct iscsi_context *iscsi, int lun, int service_action,
int success_expected)

View File

@@ -273,6 +273,10 @@ int writeverify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t d
int writeverify16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data);
int writeverify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data);
int writeverify16_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data);
int orwrite(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
int orwrite_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
int orwrite_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
int orwrite_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);

View File

@@ -66,6 +66,16 @@ static CU_TestInfo tests_get_lba_status[] = {
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_orwrite[] = {
{ (char *)"testOrWriteSimple", test_orwrite_simple },
{ (char *)"testOrWriteBeyondEol", test_orwrite_beyond_eol },
{ (char *)"testOrWriteZeroBlocks", test_orwrite_0blocks },
{ (char *)"testOrWriteProtect", test_orwrite_wrprotect },
{ (char *)"testOrWriteFlags", test_orwrite_flags },
{ (char *)"testOrWriteVerify", test_orwrite_verify },
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_prefetch10[] = {
{ (char *)"testPrefetch10Simple", test_prefetch10_simple },
{ (char *)"testPrefetch10BeyondEol", test_prefetch10_beyond_eol },
@@ -286,6 +296,8 @@ static CU_TestInfo tests_writeverify16[] = {
static CU_SuiteInfo suites[] = {
{ (char *)"TestGetLBAStatus", test_setup, test_teardown,
tests_get_lba_status },
{ (char *)"TestOrWrite", test_setup, test_teardown,
tests_orwrite },
{ (char *)"TestPrefetch10", test_setup, test_teardown,
tests_prefetch10 },
{ (char *)"TestPrefetch16", test_setup, test_teardown,

View File

@@ -43,6 +43,13 @@ int test_teardown_pgr(void);
void test_get_lba_status_simple(void);
void test_get_lba_status_beyond_eol(void);
void test_orwrite_simple(void);
void test_orwrite_beyond_eol(void);
void test_orwrite_0blocks(void);
void test_orwrite_wrprotect(void);
void test_orwrite_flags(void);
void test_orwrite_verify(void);
void test_prefetch10_simple(void);
void test_prefetch10_beyond_eol(void);
void test_prefetch10_0blocks(void);

View File

@@ -0,0 +1,64 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_orwrite_0blocks(void)
{
int ret;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test ORWRITE 0-blocks at LBA==0");
ret = orwrite(iscsic, tgt_lun, 0,
0, block_size,
0, 0, 0, 0, 0, NULL);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support ORWRITE. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE 0-blocks one block past end-of-LUN");
ret = orwrite_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1,
0, block_size,
0, 0, 0, 0, 0, NULL);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE 0-blocks at LBA==2^63");
ret = orwrite_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000,
0, block_size,
0, 0, 0, 0, 0, NULL);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE 0-blocks at LBA==-1");
ret = orwrite_lbaoutofrange(iscsic, tgt_lun, -1,
0, block_size,
0, 0, 0, 0, 0, NULL);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -0,0 +1,90 @@
/*
Copyright (C) 2013 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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_orwrite_beyond_eol(void)
{
int i, ret;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test ORWRITE 1-256 blocks one block beyond the end");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = orwrite_lbaoutofrange(iscsic, tgt_lun,
num_blocks + 1 - i,
i * block_size, block_size,
0, 0, 0, 0, 0, buf);
free(buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support ORWRITE. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test ORWRITE 1-256 blocks at LBA==2^63");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = orwrite_lbaoutofrange(iscsic, tgt_lun,
0x8000000000000000,
i * block_size, block_size,
0, 0, 0, 0, 0, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test ORWRITE 1-256 blocks at LBA==-1");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = orwrite_lbaoutofrange(iscsic, tgt_lun,
-1,
i * block_size, block_size,
0, 0, 0, 0, 0, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test ORWRITE 2-256 blocks all but one block beyond the end");
for (i = 2; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = orwrite_lbaoutofrange(iscsic, tgt_lun,
num_blocks - 1,
i * block_size, block_size,
0, 0, 0, 0, 0, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,80 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_orwrite_flags(void)
{
int ret;
unsigned char *buf;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test ORWRITE flags");
buf = malloc(block_size);
logging(LOG_VERBOSE, "Test ORWRITE with DPO==1");
ret = orwrite(iscsic, tgt_lun, 0,
block_size, block_size,
0, 1, 0, 0, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test");
free(buf);
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE with FUA==1 FUA_NV==0");
ret = orwrite(iscsic, tgt_lun, 0,
block_size, block_size,
0, 0, 1, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE with FUA==1 FUA_NV==1");
ret = orwrite(iscsic, tgt_lun, 0,
block_size, block_size,
0, 0, 1, 1, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE with FUA==0 FUA_NV==1");
ret = orwrite(iscsic, tgt_lun, 0,
block_size, block_size,
0, 0, 0, 1, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test ORWRITE with DPO==1 FUA==1 FUA_NV==1");
ret = orwrite(iscsic, tgt_lun, 0,
block_size, block_size,
0, 1, 1, 1, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
free(buf);
}

View File

@@ -0,0 +1,63 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_orwrite_simple(void)
{
int i, ret;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test ORWRITE of 1-256 blocks at the start of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = orwrite(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support ORWRITE. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test ORWRITE of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = orwrite(iscsic, tgt_lun, num_blocks - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,135 @@
/*
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 <string.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_orwrite_verify(void)
{
int i, ret;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test ORWRITE of 1-256 blocks at the start of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
unsigned char *readbuf = malloc(block_size * i);
logging(LOG_VERBOSE, "Write %d blocks of all-zero", i);
memset(buf, 0, block_size * i);
ret = write16(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "OrWrite %d blocks with 0xa5", i);
memset(buf, 0xa5, block_size * i);
ret = orwrite(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support ORWRITE. Skipping test");
free(buf);
free(readbuf);
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read %d blocks back", i);
ret = read16(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, readbuf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify that the blocks are all 0xa5");
ret = memcmp(buf, readbuf, block_size * i);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "OrWrite %d blocks with 0x5a", i);
memset(buf, 0x5a, block_size * i);
ret = orwrite(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read %d blocks back", i);
ret = read16(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, readbuf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify that the blocks are all 0xff");
memset(buf, 0xff, block_size * i);
ret = memcmp(buf, readbuf, block_size * i);
CU_ASSERT_EQUAL(ret, 0);
free(buf);
free(readbuf);
}
logging(LOG_VERBOSE, "Test ORWRITE of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
unsigned char *readbuf = malloc(block_size * i);
logging(LOG_VERBOSE, "Write %d blocks of all-zero", i);
memset(buf, 0, block_size * i);
ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "OrWrite %d blocks with 0xa5", i);
memset(buf, 0xa5, block_size * i);
ret = orwrite(iscsic, tgt_lun, num_blocks - i, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read %d blocks back", i);
ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
block_size, 0, 0, 0, 0, 0, readbuf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify that the blocks are all 0xa5");
ret = memcmp(buf, readbuf, block_size * i);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "OrWrite %d blocks with 0x5a", i);
memset(buf, 0x5a, block_size * i);
ret = orwrite(iscsic, tgt_lun, num_blocks - i, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read %d blocks back", i);
ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
block_size, 0, 0, 0, 0, 0, readbuf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Verify that the blocks are all 0xff");
memset(buf, 0xff, block_size * i);
ret = memcmp(buf, readbuf, block_size * i);
CU_ASSERT_EQUAL(ret, 0);
free(buf);
free(readbuf);
}
}

View File

@@ -0,0 +1,56 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_orwrite_wrprotect(void)
{
int i, ret;
unsigned char *buf;
CHECK_FOR_DATALOSS;
CHECK_FOR_SBC;
/*
* Try out different non-zero values for WRPROTECT.
* They should all fail.
*/
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test ORWRITE with non-zero WRPROTECT");
buf = malloc(block_size);
for (i = 1; i < 8; i++) {
ret = orwrite_invalidfieldincdb(iscsic, tgt_lun, 0,
block_size, block_size,
i, 0, 0, 0, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support ORWRITE. Skipping test");
free(buf);
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
free(buf);
}