TEST: Add test for 0 blocks for UNMAP and fix num_blocks which was off by one
across the testsuite
This commit is contained in:
@@ -200,6 +200,7 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
|
||||
test-tool/test_readcapacity16_simple.c \
|
||||
test-tool/test_readcapacity16_alloclen.c \
|
||||
test-tool/test_unmap_simple.c \
|
||||
test-tool/test_unmap_0blocks.c \
|
||||
test-tool/test_verify10_simple.c \
|
||||
test-tool/test_verify10_beyond_eol.c \
|
||||
test-tool/test_verify10_0blocks.c \
|
||||
|
||||
@@ -110,6 +110,7 @@ static CU_TestInfo tests_readcapacity16[] = {
|
||||
|
||||
static CU_TestInfo tests_unmap[] = {
|
||||
{ (char *)"testUnmapSimple", test_unmap_simple },
|
||||
{ (char *)"testUnmapZeroBlocks", test_unmap_0blocks },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
@@ -518,7 +519,7 @@ main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
block_size = rc10->block_size;
|
||||
num_blocks = rc10->lba;
|
||||
num_blocks = rc10->lba + 1;
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_readcapacity16_sync(iscsic, lun);
|
||||
@@ -538,7 +539,7 @@ main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
block_size = rc16->block_length;
|
||||
num_blocks = rc16->returned_lba;
|
||||
num_blocks = rc16->returned_lba + 1;
|
||||
lbpme = rc16->lbpme;
|
||||
lbppb = 1 << rc16->lbppbe;
|
||||
lbpme = rc16->lbpme;
|
||||
|
||||
@@ -68,6 +68,7 @@ void test_readcapacity16_simple(void);
|
||||
void test_readcapacity16_alloclen(void);
|
||||
|
||||
void test_unmap_simple(void);
|
||||
void test_unmap_0blocks(void);
|
||||
|
||||
void test_verify10_simple(void);
|
||||
void test_verify10_beyond_eol(void);
|
||||
|
||||
@@ -43,7 +43,7 @@ test_read10_simple(void)
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ10 of 1-256 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ test_read12_simple(void)
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ12 of 1-256 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ test_read16_simple(void)
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ16 of 1-256 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = read16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ test_read6_simple(void)
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ6 of 1-255 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = read6(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read6(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
61
test-tool/test_unmap_0blocks.c
Normal file
61
test-tool/test_unmap_0blocks.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
/*
|
||||
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_unmap_0blocks(void)
|
||||
{
|
||||
int i, ret;
|
||||
struct unmap_list list[257];
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
CHECK_FOR_THIN_PROVISIONING;
|
||||
CHECK_FOR_SBC;
|
||||
|
||||
logging(LOG_VERBOSE, "");
|
||||
logging(LOG_VERBOSE, "Test UNMAP of 0 blocks at LBA:0-255 as a single descriptor");
|
||||
for (i = 0; i < 256; i++) {
|
||||
list[0].lba = i;
|
||||
list[0].num = 0;
|
||||
ret = unmap(iscsic, tgt_lun, 0, list, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "Test UNMAP of 0 blocks at LBA:0-255 with one descriptor per block");
|
||||
for (i = 0; i < 256; i++) {
|
||||
list[i].lba = i;
|
||||
list[i].num = 0;
|
||||
ret = unmap(iscsic, tgt_lun, 0, list, i);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "Test UNMAP of 0 blocks at end-of-LUN");
|
||||
list[0].lba = num_blocks;
|
||||
list[0].num = 0;
|
||||
ret = unmap(iscsic, tgt_lun, 0, list, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
@@ -47,10 +47,10 @@ test_unmap_simple(void)
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the LUN with one descriptor per block");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
list[i].lba = i-1;
|
||||
for (i = 0; i < 256; i++) {
|
||||
list[i].lba = i;
|
||||
list[i].num = 1;
|
||||
ret = unmap(iscsic, tgt_lun, 0, list, i);
|
||||
ret = unmap(iscsic, tgt_lun, 0, list, i + 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ test_verify10_mismatch(void)
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -68,7 +68,7 @@ test_verify10_mismatch(void)
|
||||
buf[offset] ^= 'X';
|
||||
logging(LOG_VERBOSE, "Flip some bits in the data");
|
||||
|
||||
ret = verify10_miscompare(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify10_miscompare(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 1, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -61,7 +61,7 @@ test_verify10_mismatch_no_cmp(void)
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -69,7 +69,7 @@ test_verify10_mismatch_no_cmp(void)
|
||||
buf[offset] ^= 'X';
|
||||
logging(LOG_VERBOSE, "Flip some bits in the data");
|
||||
|
||||
ret = verify10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -54,11 +54,11 @@ test_verify10_simple(void)
|
||||
for (i = 1; i <= 256; i++) {
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
|
||||
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = verify10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 1, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -60,7 +60,7 @@ test_verify12_mismatch(void)
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -68,7 +68,7 @@ test_verify12_mismatch(void)
|
||||
buf[offset] ^= 'X';
|
||||
logging(LOG_VERBOSE, "Flip some bits in the data");
|
||||
|
||||
ret = verify12_miscompare(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify12_miscompare(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 1, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -61,7 +61,7 @@ test_verify12_mismatch_no_cmp(void)
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -69,7 +69,7 @@ test_verify12_mismatch_no_cmp(void)
|
||||
buf[offset] ^= 'X';
|
||||
logging(LOG_VERBOSE, "Flip some bits in the data");
|
||||
|
||||
ret = verify12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -54,11 +54,11 @@ test_verify12_simple(void)
|
||||
for (i = 1; i <= 256; i++) {
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
|
||||
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = verify12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 1, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -60,7 +60,7 @@ test_verify16_mismatch(void)
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
ret = read16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -68,7 +68,7 @@ test_verify16_mismatch(void)
|
||||
buf[offset] ^= 'X';
|
||||
logging(LOG_VERBOSE, "Flip some bits in the data");
|
||||
|
||||
ret = verify16_miscompare(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify16_miscompare(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 1, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -61,7 +61,7 @@ test_verify16_mismatch_no_cmp(void)
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
ret = read16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -69,7 +69,7 @@ test_verify16_mismatch_no_cmp(void)
|
||||
buf[offset] ^= 'X';
|
||||
logging(LOG_VERBOSE, "Flip some bits in the data");
|
||||
|
||||
ret = verify16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -54,11 +54,11 @@ test_verify16_simple(void)
|
||||
for (i = 1; i <= 256; i++) {
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
|
||||
ret = read16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = read16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = verify16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = verify16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 1, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -49,7 +49,7 @@ test_write10_simple(void)
|
||||
for (i = 1; i <= 256; i++) {
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
|
||||
ret = write10(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = write10(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -49,7 +49,7 @@ test_write12_simple(void)
|
||||
for (i = 1; i <= 256; i++) {
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
|
||||
ret = write12(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = write12(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -50,7 +50,7 @@ test_write16_simple(void)
|
||||
for (i = 1; i <= 256; i++) {
|
||||
unsigned char *buf = malloc(block_size * i);
|
||||
|
||||
ret = write16(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
ret = write16(iscsic, tgt_lun, num_blocks - i,
|
||||
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
|
||||
free(buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
Reference in New Issue
Block a user