test-tool: Move all_zeroes() helper function to iscsi-support.c
This patch does not change any functionality. Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
5231923bc8
commit
2d412530c1
@@ -118,6 +118,26 @@ int maximum_transfer_length;
|
||||
|
||||
int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
|
||||
|
||||
static const unsigned char zeroBlock[4096];
|
||||
|
||||
/**
|
||||
* Returns 1 if and only if buf[0..size-1] is zero.
|
||||
*/
|
||||
int all_zeroes(const unsigned char *buf, unsigned size)
|
||||
{
|
||||
unsigned j, e;
|
||||
|
||||
for (j = 0; j < size; j += e) {
|
||||
e = size - j;
|
||||
if (e > sizeof(zeroBlock))
|
||||
e = sizeof(zeroBlock);
|
||||
if (memcmp(buf + j, zeroBlock, e) != 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *scsi_status_str(int status)
|
||||
{
|
||||
switch(status) {
|
||||
|
||||
@@ -257,6 +257,8 @@ static inline int pr_type_is_all_registrants(
|
||||
}
|
||||
}
|
||||
|
||||
int all_zeroes(const unsigned char *buf, unsigned size);
|
||||
|
||||
int prin_task(struct scsi_device *sdev, int service_action,
|
||||
int success_expected);
|
||||
int prin_read_keys(struct scsi_device *sdev, struct scsi_task **tp,
|
||||
|
||||
@@ -219,12 +219,9 @@ check_lun_is_wiped(unsigned char *buf, uint64_t lba)
|
||||
}
|
||||
|
||||
if (rc16->lbprz) {
|
||||
unsigned char *zbuf = alloca(256 * block_size);
|
||||
memset(zbuf, 0, 256 * block_size);
|
||||
|
||||
logging(LOG_VERBOSE, "LBPRZ==1 All blocks "
|
||||
"should read back as 0");
|
||||
if (memcmp(zbuf, rbuf, 256 * block_size)) {
|
||||
if (all_zeroes(rbuf, 256 * block_size) == 0) {
|
||||
logging(LOG_NORMAL, "[FAILED] Blocks did not "
|
||||
"read back as zero");
|
||||
CU_FAIL("[FAILED] Blocks did not read back "
|
||||
|
||||
@@ -43,8 +43,6 @@ test_unmap_simple(void)
|
||||
int i, ret;
|
||||
struct unmap_list list[257];
|
||||
unsigned char *buf = alloca(256 * block_size);
|
||||
unsigned char *zbuf = alloca(256 * block_size);
|
||||
memset(zbuf, 0, 256 * block_size);
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test basic UNMAP");
|
||||
@@ -77,7 +75,7 @@ test_unmap_simple(void)
|
||||
if (rc16 && rc16->lbprz) {
|
||||
logging(LOG_VERBOSE, "LBPRZ==1 All UNMAPPED blocks "
|
||||
"should read back as 0");
|
||||
if (memcmp(buf, zbuf, i * block_size)) {
|
||||
if (all_zeroes(buf, i * block_size) == 0) {
|
||||
logging(LOG_NORMAL, "[FAILED] Blocks did not "
|
||||
"read back as zero");
|
||||
CU_FAIL("[FAILED] Blocks did not read back "
|
||||
@@ -112,7 +110,7 @@ test_unmap_simple(void)
|
||||
if (rc16 && rc16->lbprz) {
|
||||
logging(LOG_VERBOSE, "LBPRZ==1 All UNMAPPED blocks "
|
||||
"should read back as 0");
|
||||
if (memcmp(buf, zbuf, i * block_size)) {
|
||||
if (all_zeroes(buf, i * block_size) == 0) {
|
||||
logging(LOG_NORMAL, "[FAILED] Blocks did not "
|
||||
"read back as zero");
|
||||
CU_FAIL("[FAILED] Blocks did not read back "
|
||||
|
||||
@@ -26,23 +26,6 @@
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
|
||||
static const unsigned char zeroBlock[4096];
|
||||
|
||||
static int all_zeroes(const unsigned char *buf, unsigned size)
|
||||
{
|
||||
unsigned j, e;
|
||||
|
||||
for (j = 0; j < size; j += sizeof(zeroBlock)) {
|
||||
e = size - j;
|
||||
if (sizeof(zeroBlock) < e)
|
||||
e = sizeof(zeroBlock);
|
||||
if (memcmp(buf + j, zeroBlock, e) != 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
test_writesame10_unmap(void)
|
||||
{
|
||||
|
||||
@@ -29,17 +29,13 @@ void
|
||||
test_writesame10_unmap_until_end(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned int i, j;
|
||||
unsigned char *zeroBlock;
|
||||
unsigned int i;
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
CHECK_FOR_THIN_PROVISIONING;
|
||||
CHECK_FOR_LBPWS10;
|
||||
CHECK_FOR_SBC;
|
||||
|
||||
zeroBlock = alloca(block_size);
|
||||
memset(zeroBlock, 0, block_size);
|
||||
|
||||
if (inq_bl->wsnz) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] WRITESAME10 does not support 0-blocks.");
|
||||
CU_PASS("[SKIPPED] WRITESAME10 does not support 0-blocks.");
|
||||
@@ -74,9 +70,7 @@ test_writesame10_unmap_until_end(void)
|
||||
i * block_size, block_size,
|
||||
0, 0, 0, 0, 0, buf,
|
||||
EXPECT_STATUS_GOOD);
|
||||
for (j = 0; j < i; j++) {
|
||||
CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0);
|
||||
}
|
||||
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||
} else {
|
||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||
"and verify zero test");
|
||||
|
||||
@@ -25,23 +25,6 @@
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
|
||||
static const unsigned char zeroBlock[4096];
|
||||
|
||||
static int all_zeroes(const unsigned char *buf, unsigned size)
|
||||
{
|
||||
unsigned j, e;
|
||||
|
||||
for (j = 0; j < size; j += sizeof(zeroBlock)) {
|
||||
e = size - j;
|
||||
if (sizeof(zeroBlock) < e)
|
||||
e = sizeof(zeroBlock);
|
||||
if (memcmp(buf + j, zeroBlock, e) != 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
test_writesame16_unmap(void)
|
||||
{
|
||||
|
||||
@@ -30,9 +30,8 @@ void
|
||||
test_writesame16_unmap_until_end(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned int i, j;
|
||||
unsigned int i;
|
||||
unsigned char *buf = alloca(256 * block_size);
|
||||
unsigned char *zeroBlock;
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
CHECK_FOR_THIN_PROVISIONING;
|
||||
@@ -45,9 +44,6 @@ test_writesame16_unmap_until_end(void)
|
||||
return;
|
||||
}
|
||||
|
||||
zeroBlock = alloca(block_size);
|
||||
memset(zeroBlock, 0, block_size);
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN by setting number-of-blocks==0");
|
||||
memset(buf, 0xa6, 256 * block_size);
|
||||
@@ -79,9 +75,7 @@ test_writesame16_unmap_until_end(void)
|
||||
i * block_size, block_size,
|
||||
0, 0, 0, 0, 0, buf,
|
||||
EXPECT_STATUS_GOOD);
|
||||
for (j = 0; j < i; j++) {
|
||||
CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0);
|
||||
}
|
||||
CU_ASSERT(all_zeroes(buf, i * block_size));
|
||||
} else {
|
||||
logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
|
||||
"and verify zero test");
|
||||
|
||||
Reference in New Issue
Block a user