diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index a51c87e..7c8786c 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -294,6 +294,20 @@ do { \ CU_ASSERT_EQUAL(_r, 0); \ } while (0); +#define WRITEATOMIC16(...) \ + do { \ + int _r; \ + _r = writeatomic16(__VA_ARGS__); \ + if (_r == -2) { \ + logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 " \ + "is not implemented."); \ + CU_PASS("[SKIPPED] Target does not support " \ + "WRITEATOMIC16. Skipping test"); \ + return; \ + } \ + CU_ASSERT_EQUAL(_r, 0); \ + } while (0); + #define WRITESAME10(...) \ do { \ int _r; \ diff --git a/test-tool/test_writeatomic16_0blocks.c b/test-tool/test_writeatomic16_0blocks.c index e74a3ae..19d272f 100644 --- a/test-tool/test_writeatomic16_0blocks.c +++ b/test-tool/test_writeatomic16_0blocks.c @@ -27,7 +27,7 @@ void test_writeatomic16_0blocks(void) { - int align, ret; + int align; CHECK_FOR_DATALOSS; CHECK_FOR_SBC; @@ -41,33 +41,19 @@ test_writeatomic16_0blocks(void) align = inq_bl->atomic_align ? inq_bl->atomic_align : 1; logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==0"); - ret = writeatomic16(sd, 0, 0, block_size, - 0, 0, 0, 0, NULL, - EXPECT_STATUS_GOOD); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks one alignment past end-of-LUN"); - ret = writeatomic16(sd, num_blocks + align, 0, - block_size, 0, 0, 0, 0, NULL, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); - + WRITEATOMIC16(sd, num_blocks + align, 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==2^63"); - ret = writeatomic16(sd, 0x8000000000000000ULL, 0, - block_size, 0, 0, 0, 0, NULL, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); - + WRITEATOMIC16(sd, 0x8000000000000000ULL, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); logging(LOG_VERBOSE, "Test WRITEATOMIC16 0-blocks at LBA==-"); - ret = writeatomic16(sd, -align, 0, block_size, - 0, 0, 0, 0, NULL, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, -align, 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); } diff --git a/test-tool/test_writeatomic16_beyond_eol.c b/test-tool/test_writeatomic16_beyond_eol.c index 2829f4c..ac53a33 100644 --- a/test-tool/test_writeatomic16_beyond_eol.c +++ b/test-tool/test_writeatomic16_beyond_eol.c @@ -29,7 +29,7 @@ void test_writeatomic16_beyond_eol(void) { - int align, i, gran, ret; + int align, i, gran; const size_t bufsz = 256 * 2 * block_size; CHECK_FOR_DATALOSS; @@ -45,28 +45,18 @@ test_writeatomic16_beyond_eol(void) memset(scratch, 0xa6, bufsz); align = inq_bl->atomic_align ? inq_bl->atomic_align : 1; gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1; - ret = writeatomic16(sd, 0, - block_size * gran, - block_size, 0, 0, 0, 0, scratch, - EXPECT_STATUS_GOOD); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, block_size * gran, block_size, 0, 0, 0, 0, scratch, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks blocks beyond the end"); for (i = gran; i <= 256; i += gran) { if (maximum_transfer_length && maximum_transfer_length < i) { break; } - - ret = writeatomic16(sd, num_blocks - i, - 2 * i * block_size, block_size, - 0, 0, 0, 0, scratch, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, num_blocks - i, + 2 * i * block_size, block_size, + 0, 0, 0, 0, scratch, + EXPECT_LBA_OOB); } logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks at LBA==2^63"); @@ -74,35 +64,30 @@ test_writeatomic16_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeatomic16(sd, 0x8000000000000000ULL, - i * block_size, block_size, - 0, 0, 0, 0, scratch, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0x8000000000000000ULL, + i * block_size, block_size, + 0, 0, 0, 0, scratch, + EXPECT_LBA_OOB); } - logging(LOG_VERBOSE, "Test WRITEATOMIC16 1-256 blocks at LBA==-"); for (i = gran; i <= 256; i += gran) { if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeatomic16(sd, -align, i * block_size, - block_size, 0, 0, 0, 0, scratch, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, -align, i * block_size, + block_size, 0, 0, 0, 0, scratch, + EXPECT_LBA_OOB); } - logging(LOG_VERBOSE, "Test WRITEATOMIC16 2-256 blocks all but one block beyond the end"); for (i = 2 * gran; i <= 256; i += gran) { if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeatomic16(sd, num_blocks - gran, - i * block_size, block_size, - 0, 0, 0, 0, scratch, - EXPECT_LBA_OOB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, num_blocks - gran, + i * block_size, block_size, + 0, 0, 0, 0, scratch, + EXPECT_LBA_OOB); } } diff --git a/test-tool/test_writeatomic16_dpofua.c b/test-tool/test_writeatomic16_dpofua.c index 389f404..e743f0b 100644 --- a/test-tool/test_writeatomic16_dpofua.c +++ b/test-tool/test_writeatomic16_dpofua.c @@ -69,51 +69,35 @@ test_writeatomic16_dpofua(void) logging(LOG_VERBOSE, "Test WRITEATOMIC16 with DPO==1"); memset(scratch, 0xa6, block_size); if (dpofua) { - ret = writeatomic16(sd, 0, gran * block_size, - block_size, 0, 1, 0, 0, scratch, - EXPECT_STATUS_GOOD); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, + block_size, 0, 1, 0, 0, scratch, + EXPECT_STATUS_GOOD); } else { - ret = writeatomic16(sd, 0, gran * block_size, - block_size, 0, 1, 0, 0, scratch, - EXPECT_INVALID_FIELD_IN_CDB); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, + block_size, 0, 1, 0, 0, scratch, + EXPECT_INVALID_FIELD_IN_CDB); } logging(LOG_VERBOSE, "Test WRITEATOMIC16 with FUA==1"); if (dpofua) { - ret = writeatomic16(sd, 0, gran * block_size, - block_size, 0, 0, 1, 0, scratch, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, + block_size, 0, 0, 1, 0, scratch, + EXPECT_STATUS_GOOD); } else { - ret = writeatomic16(sd, 0, gran * block_size, - block_size, 0, 0, 1, 0, scratch, - EXPECT_INVALID_FIELD_IN_CDB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, + block_size, 0, 0, 1, 0, scratch, + EXPECT_INVALID_FIELD_IN_CDB); } logging(LOG_VERBOSE, "Test WRITEATOMIC16 with DPO==1 FUA==1"); if (dpofua) { - ret = writeatomic16(sd, 0, gran * block_size, - block_size, 0, 1, 1, 0, scratch, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, + block_size, 0, 1, 1, 0, scratch, + EXPECT_STATUS_GOOD); } else { - ret = writeatomic16(sd, 0, gran * block_size, - block_size, 0, 1, 1, 0, scratch, - EXPECT_INVALID_FIELD_IN_CDB); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, + block_size, 0, 1, 1, 0, scratch, + EXPECT_INVALID_FIELD_IN_CDB); } diff --git a/test-tool/test_writeatomic16_simple.c b/test-tool/test_writeatomic16_simple.c index 41f33f8..649ec5e 100644 --- a/test-tool/test_writeatomic16_simple.c +++ b/test-tool/test_writeatomic16_simple.c @@ -30,7 +30,7 @@ void test_writeatomic16_simple(void) { - int i, gran, ret; + int i, gran; const size_t bufsz = 256 * block_size; CHECK_FOR_DATALOSS; @@ -45,16 +45,8 @@ test_writeatomic16_simple(void) memset(scratch, 0, bufsz); gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1; - ret = writeatomic16(sd, 0, - block_size * gran, - block_size, 0, 0, 0, 0, scratch, - EXPECT_STATUS_GOOD); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, block_size * gran, block_size, 0, 0, 0, 0, scratch, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test WRITEATOMIC16 of 1-256 blocks at the start of the LUN"); memset(scratch, 0xa6, 256 * block_size); @@ -62,10 +54,9 @@ test_writeatomic16_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeatomic16(sd, 0, i * block_size, - block_size, 0, 0, 0, 0, scratch, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, scratch, + EXPECT_STATUS_GOOD); } logging(LOG_VERBOSE, "Test WRITEATOMIC16 of 1-256 blocks at the end of the LUN"); @@ -73,10 +64,8 @@ test_writeatomic16_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeatomic16(sd, num_blocks - i, - i * block_size, block_size, - 0, 0, 0, 0, scratch, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, num_blocks - i, i * block_size, block_size, + 0, 0, 0, 0, scratch, + EXPECT_STATUS_GOOD); } } diff --git a/test-tool/test_writeatomic16_wrprotect.c b/test-tool/test_writeatomic16_wrprotect.c index 85343cc..4ffd5f3 100644 --- a/test-tool/test_writeatomic16_wrprotect.c +++ b/test-tool/test_writeatomic16_wrprotect.c @@ -30,7 +30,7 @@ void test_writeatomic16_wrprotect(void) { - int i, gran, ret; + int i, gran; CHECK_FOR_DATALOSS; CHECK_FOR_SBC; @@ -44,34 +44,17 @@ test_writeatomic16_wrprotect(void) gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1; memset(scratch, 0, block_size); - ret = writeatomic16(sd, 0, - block_size * gran, - block_size, 0, 0, 0, 0, scratch, - EXPECT_STATUS_GOOD); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); - + WRITEATOMIC16(sd, 0, block_size * gran, block_size, 0, 0, 0, 0, scratch, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test WRITEATOMIC16 with non-zero WRPROTECT"); - memset(scratch, 0xa6, block_size); if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = writeatomic16(sd, 0, - gran * block_size, block_size, - i, 0, 0, 0, scratch, - EXPECT_INVALID_FIELD_IN_CDB); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITEATOMIC16 is not implemented."); - CU_PASS("WRITEATOMIC16 is not implemented."); - return; - } - CU_ASSERT_EQUAL(ret, 0); + WRITEATOMIC16(sd, 0, gran * block_size, block_size, + i, 0, 0, 0, scratch, + EXPECT_INVALID_FIELD_IN_CDB); } return; }