From b0c57802bc659e66ebfb4ac5c0c69fa2e4d6879f Mon Sep 17 00:00:00 2001 From: jpocas Date: Wed, 30 Apr 2014 16:22:27 -0400 Subject: [PATCH] - test_unmap_simple: was assuming that zero buffer was already cleared, which is not guaranteed and resulted in spurious failures - writesame10_unmap_until_end, writesame16_unmap, writesame16_unmap_until_end were doing an CU_ASSERT *PER-BYTE* in the verification phase, which was very CPU-intensive. This change uses memcmp on a whole block which finishes much quicker. --- test-tool/test_unmap_simple.c | 1 + test-tool/test_writesame10_unmap_until_end.c | 15 +++++---- test-tool/test_writesame16_unmap.c | 32 +++++++++----------- test-tool/test_writesame16_unmap_until_end.c | 15 +++++---- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/test-tool/test_unmap_simple.c b/test-tool/test_unmap_simple.c index 50cf65b..d080ae5 100644 --- a/test-tool/test_unmap_simple.c +++ b/test-tool/test_unmap_simple.c @@ -43,6 +43,7 @@ test_unmap_simple(void) 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"); diff --git a/test-tool/test_writesame10_unmap_until_end.c b/test-tool/test_writesame10_unmap_until_end.c index 60e3b57..c0b1801 100644 --- a/test-tool/test_writesame10_unmap_until_end.c +++ b/test-tool/test_writesame10_unmap_until_end.c @@ -28,14 +28,18 @@ void test_writesame10_unmap_until_end(void) { - int i, ret; - unsigned int j; + int ret; + unsigned int i, j; + unsigned char *zeroBlock; CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; CHECK_FOR_LBPWS10; CHECK_FOR_SBC; + zeroBlock = malloc(block_size); + memset(zeroBlock, 0, block_size); + logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the end of the LUN by setting number-of-blocks==0"); for (i = 1; i <= 256; i++) { @@ -63,10 +67,8 @@ test_writesame10_unmap_until_end(void) ret = read10(iscsic, tgt_lun, num_blocks - i, i * block_size, block_size, 0, 0, 0, 0, 0, buf); - for (j = 0; j < block_size * i; j++) { - if (buf[j] != 0) { - CU_ASSERT_EQUAL(buf[j], 0); - } + for (j = 0; j < i; j++) { + CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } } else { logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read " @@ -74,4 +76,5 @@ test_writesame10_unmap_until_end(void) } free(buf); } + free(zeroBlock); } diff --git a/test-tool/test_writesame16_unmap.c b/test-tool/test_writesame16_unmap.c index 206484f..08da0ed 100644 --- a/test-tool/test_writesame16_unmap.c +++ b/test-tool/test_writesame16_unmap.c @@ -28,9 +28,10 @@ void test_writesame16_unmap(void) { - int i, ret; - unsigned int j; + int ret; + unsigned int i, j; unsigned char *buf; + unsigned char *zeroBlock; CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; @@ -40,6 +41,8 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN"); buf = malloc(65536 * block_size); + zeroBlock = malloc(block_size); + memset(zeroBlock, 0, block_size); for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); @@ -67,10 +70,8 @@ test_writesame16_unmap(void) ret = read16(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); - for (j = 0; j < block_size * i; j++) { - if (buf[j] != 0) { - CU_ASSERT_EQUAL(buf[j], 0); - } + for (j = 0; j < i; j++) { + CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } } else { logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read " @@ -103,10 +104,8 @@ test_writesame16_unmap(void) ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size, block_size, 0, 0, 0, 0, 0, buf); - for (j = 0; j < block_size * i; j++) { - if (buf[j] != 0) { - CU_ASSERT_EQUAL(buf[j], 0); - } + for (j = 0; j < i; j++) { + CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } } else { logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read " @@ -176,10 +175,8 @@ test_writesame16_unmap(void) ret = read16(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); - for (j = 0; j < block_size * i; j++) { - if (buf[j] != 0) { - CU_ASSERT_EQUAL(buf[j], 0); - } + for (j = 0; j < i; j++) { + CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } } else { logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read " @@ -228,10 +225,8 @@ test_writesame16_unmap(void) ret = read16(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); - for (j = 0; j < block_size * i; j++) { - if (buf[j] != 0) { - CU_ASSERT_EQUAL(buf[j], 0); - } + for (j = 0; j < i; j++) { + CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } } else { logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read " @@ -251,4 +246,5 @@ test_writesame16_unmap(void) finished: free(buf); + free(zeroBlock); } diff --git a/test-tool/test_writesame16_unmap_until_end.c b/test-tool/test_writesame16_unmap_until_end.c index 8860c05..369822c 100644 --- a/test-tool/test_writesame16_unmap_until_end.c +++ b/test-tool/test_writesame16_unmap_until_end.c @@ -29,15 +29,19 @@ void test_writesame16_unmap_until_end(void) { - int i, ret; - unsigned int j; + int ret; + unsigned int i, j; unsigned char *buf = alloca(256 * block_size); + unsigned char *zeroBlock; CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; CHECK_FOR_LBPWS; CHECK_FOR_SBC; + zeroBlock = malloc(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"); for (i = 1; i <= 256; i++) { @@ -67,14 +71,13 @@ test_writesame16_unmap_until_end(void) ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size, block_size, 0, 0, 0, 0, 0, buf); - for (j = 0; j < block_size * i; j++) { - if (buf[j] != 0) { - CU_ASSERT_EQUAL(buf[j], 0); - } + for (j = 0; j < i; j++) { + CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } } else { logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read " "and verify zero test"); } } + free(zeroBlock); }