test-tool/test_compareandwrite_*: Stop at end of medium

Since the argument num_blocks - i is passed as the LBA argument
to COMPAREANDWRITE(), avoid that a negative number is passed.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
This commit is contained in:
Bart Van Assche
2017-10-30 16:57:57 -07:00
parent fee9eb9423
commit 8f468b14fc
4 changed files with 38 additions and 20 deletions

View File

@@ -31,7 +31,7 @@
void
test_compareandwrite_simple(void)
{
int i;
int i, n;
unsigned j;
int maxbl;
@@ -45,10 +45,14 @@ test_compareandwrite_simple(void)
maxbl = 256;
}
n = 256;
if (n + 0U > num_blocks)
n = num_blocks;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
"start of the LUN");
for (i = 1; i < 256; i++) {
logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-%d blocks at the "
"start of the LUN", n);
for (i = 1; i <= n; i++) {
logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:0", i);
memset(scratch, 'A', 2 * i * block_size);
if (maximum_transfer_length && maximum_transfer_length < i) {
@@ -97,9 +101,9 @@ test_compareandwrite_simple(void)
}
logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
"end of the LUN");
for (i = 1; i < 256; i++) {
logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-%d blocks at the "
"end of the LUN", n);
for (i = 1; i <= n; i++) {
logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:%" PRIu64,
i, num_blocks - i);
memset(scratch, 'A', 2 * i * block_size);