From f699503f8cb7c9a450dc15ee47db2db77de4289c Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 21 Feb 2016 08:04:36 -0800 Subject: [PATCH] Tests: Create helper macro for COMPAREANDWRITE Signed-off-by: Ronnie Sahlberg --- test-tool/iscsi-support.h | 14 ++++++ test-tool/test_compareandwrite_dpofua.c | 46 ++++++++----------- test-tool/test_compareandwrite_miscompare.c | 48 +++++++------------- test-tool/test_compareandwrite_simple.c | 48 +++++++------------- test-tool/test_multipathio_compareandwrite.c | 24 ++++------ 5 files changed, 72 insertions(+), 108 deletions(-) diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 6793590..7f5e3d8 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -181,6 +181,20 @@ do { \ } \ } while (0); +#define COMPAREANDWRITE(...) \ + do { \ + int _r; \ + _r = compareandwrite(__VA_ARGS__); \ + if (_r == -2) { \ + logging(LOG_NORMAL, "[SKIPPED] COMPAREANDWRITE " \ + "is not implemented."); \ + CU_PASS("[SKIPPED] Target does not support " \ + "COMPAREANDWRITE. Skipping test"); \ + return; \ + } \ + CU_ASSERT_EQUAL(_r, 0); \ + } while (0); + #define VERIFY10(...) \ do { \ int _r; \ diff --git a/test-tool/test_compareandwrite_dpofua.c b/test-tool/test_compareandwrite_dpofua.c index 77d18da..4fb6f5c 100644 --- a/test-tool/test_compareandwrite_dpofua.c +++ b/test-tool/test_compareandwrite_dpofua.c @@ -71,45 +71,35 @@ test_compareandwrite_dpofua(void) logging(LOG_VERBOSE, "Test COMPAREANDWRITE with DPO==1"); if (dpofua) { - ret = compareandwrite(sd, 0, scratch, 2 * block_size, - block_size, 0, 1, 0, 0, - EXPECT_STATUS_GOOD); + COMPAREANDWRITE(sd, 0, scratch, 2 * block_size, + block_size, 0, 1, 0, 0, + EXPECT_STATUS_GOOD); } else { - ret = compareandwrite(sd, 0, scratch, 2 * block_size, - block_size, 0, 1, 0, 0, - EXPECT_INVALID_FIELD_IN_CDB); + COMPAREANDWRITE(sd, 0, scratch, 2 * block_size, + block_size, 0, 1, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); } - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] REPORT_SUPPORTED_OPCODES not " - "implemented. Skipping this part of the test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test COMPAREANDWRITE with FUA==1"); if (dpofua) { - ret = compareandwrite(sd, 0, scratch, 2 * block_size, - block_size, 0, 0, 1, 0, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, 0, scratch, 2 * block_size, + block_size, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); } else { - ret = compareandwrite(sd, 0, scratch, 2 * block_size, - block_size, 0, 0, 1, 0, - EXPECT_INVALID_FIELD_IN_CDB); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, 0, scratch, 2 * block_size, + block_size, 0, 0, 1, 0, + EXPECT_INVALID_FIELD_IN_CDB); } logging(LOG_VERBOSE, "Test COMPAREANDWRITE with DPO==1 FUA==1"); if (dpofua) { - ret = compareandwrite(sd, 0, scratch, 2 * block_size, - block_size, 0, 1, 1, 0, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, 0, scratch, 2 * block_size, + block_size, 0, 1, 1, 0, + EXPECT_STATUS_GOOD); } else { - ret = compareandwrite(sd, 0, scratch, 2 * block_size, - block_size, 0, 1, 1, 0, - EXPECT_INVALID_FIELD_IN_CDB); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, 0, scratch, 2 * block_size, + block_size, 0, 1, 1, 0, + EXPECT_INVALID_FIELD_IN_CDB); } logging(LOG_VERBOSE, "Try fetching REPORT_SUPPORTED_OPCODES " diff --git a/test-tool/test_compareandwrite_miscompare.c b/test-tool/test_compareandwrite_miscompare.c index a02093b..5da9727 100644 --- a/test-tool/test_compareandwrite_miscompare.c +++ b/test-tool/test_compareandwrite_miscompare.c @@ -72,17 +72,10 @@ test_compareandwrite_miscompare(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite(sd, 0, - scratch, 2 * i * block_size, - block_size, 0, 0, 0, 0, - EXPECT_INVALID_FIELD_IN_CDB); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "COMPARE_AND_WRITE. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); - + COMPAREANDWRITE(sd, 0, + scratch, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); continue; } @@ -90,16 +83,10 @@ test_compareandwrite_miscompare(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:0 (if they all contain 'A')", i); - ret = compareandwrite(sd, 0, - scratch, 2 * i * block_size, block_size, - 0, 0, 0, 0, - EXPECT_MISCOMPARE); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "COMPARE_AND_WRITE. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, 0, + scratch, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_MISCOMPARE); logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify " "they are still unchanged as 'A'", i); @@ -142,12 +129,10 @@ test_compareandwrite_miscompare(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite(sd, 0, - scratch, 2 * i * block_size, - block_size, 0, 0, 0, 0, - EXPECT_INVALID_FIELD_IN_CDB); - CU_ASSERT_EQUAL(ret, 0); - + COMPAREANDWRITE(sd, 0, + scratch, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); continue; } memset(scratch + i * block_size, 'B', i * block_size); @@ -155,11 +140,10 @@ test_compareandwrite_miscompare(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:%" PRIu64 " (if they all contain 'A')", i, num_blocks - i); - ret = compareandwrite(sd, num_blocks - i, - scratch, 2 * i * block_size, block_size, - 0, 0, 0, 0, - EXPECT_MISCOMPARE); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, num_blocks - i, + scratch, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_MISCOMPARE); logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64 "they are still unchanged as 'A'", diff --git a/test-tool/test_compareandwrite_simple.c b/test-tool/test_compareandwrite_simple.c index 0d9f62f..3b08cf7 100644 --- a/test-tool/test_compareandwrite_simple.c +++ b/test-tool/test_compareandwrite_simple.c @@ -69,17 +69,10 @@ test_compareandwrite_simple(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite(sd, 0, - scratch, 2 * i * block_size, - block_size, 0, 0, 0, 0, - EXPECT_INVALID_FIELD_IN_CDB); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "COMPARE_AND_WRITE. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); - + COMPAREANDWRITE(sd, 0, + scratch, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); continue; } @@ -87,16 +80,10 @@ test_compareandwrite_simple(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:0 (if they all contain 'A')", i); - ret = compareandwrite(sd, 0, - scratch, 2 * i * block_size, block_size, - 0, 0, 0, 0, - EXPECT_STATUS_GOOD); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "COMPARE_AND_WRITE. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, 0, + scratch, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify " "they are all 'B'", i); @@ -136,12 +123,10 @@ test_compareandwrite_simple(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite(sd, 0, - scratch, 2 * i * block_size, - block_size, 0, 0, 0, 0, - EXPECT_INVALID_FIELD_IN_CDB); - CU_ASSERT_EQUAL(ret, 0); - + COMPAREANDWRITE(sd, 0, + scratch, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); continue; } memset(scratch + i * block_size, 'B', i * block_size); @@ -149,11 +134,10 @@ test_compareandwrite_simple(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:%" PRIu64 " (if they all contain 'A')", i, num_blocks - i); - ret = compareandwrite(sd, num_blocks - i, - scratch, 2 * i * block_size, block_size, - 0, 0, 0, 0, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(sd, num_blocks - i, + scratch, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64 " and verify they are all 'B'", diff --git a/test-tool/test_multipathio_compareandwrite.c b/test-tool/test_multipathio_compareandwrite.c index 2de0cca..b58ad6d 100644 --- a/test-tool/test_multipathio_compareandwrite.c +++ b/test-tool/test_multipathio_compareandwrite.c @@ -78,27 +78,19 @@ test_multipathio_compareandwrite(void) /* write data is the second half, wrap around */ memset(scratch + io_bl * block_size, path + 1, io_bl * block_size); - - ret = compareandwrite(mp_sds[path], i, - scratch, 2 * io_bl * block_size, - block_size, 0, 0, 0, 0, - EXPECT_STATUS_GOOD); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "COMPARE_AND_WRITE. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(mp_sds[path], i, + scratch, 2 * io_bl * block_size, + block_size, 0, 0, 0, 0, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test bad COMPARE_AND_WRITE(%d->%d)", path, path + 1); - ret = compareandwrite(mp_sds[path], i, - scratch, 2 * io_bl * block_size, - block_size, 0, 0, 0, 0, - EXPECT_MISCOMPARE); - CU_ASSERT_EQUAL(ret, 0); + COMPAREANDWRITE(mp_sds[path], i, + scratch, 2 * io_bl * block_size, + block_size, 0, 0, 0, 0, + EXPECT_MISCOMPARE); } } }