diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index a2dde82..ed73fe7 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -195,6 +195,34 @@ do { \ CU_ASSERT_EQUAL(_r, 0); \ } while (0); +#define EXTENDEDCOPY(...) \ + do { \ + int _r; \ + _r = extendedcopy(__VA_ARGS__); \ + if (_r == -2) { \ + logging(LOG_NORMAL, "[SKIPPED] EXTENDEDCOPY " \ + "is not implemented."); \ + CU_PASS("[SKIPPED] Target does not support " \ + "EXTENDEDCOPY. Skipping test"); \ + return; \ + } \ + CU_ASSERT_EQUAL(_r, 0); \ + } while (0); + +#define RECEIVE_COPY_RESULTS(...) \ + do { \ + int _r; \ + _r = receive_copy_results(__VA_ARGS__); \ + if (_r == -2) { \ + logging(LOG_NORMAL, "[SKIPPED] RECEIVE_COPY" \ + "_RESULTS is not implemented."); \ + CU_PASS("[SKIPPED] Target does not support " \ + "RECEIVE_COPY_RESULTS. Skipping test"); \ + return; \ + } \ + CU_ASSERT_EQUAL(_r, 0); \ + } while (0); + #define RELEASE6(...) \ do { \ int _r; \ diff --git a/test-tool/test_extendedcopy_descr_limits.c b/test-tool/test_extendedcopy_descr_limits.c index cfaa1ea..f5240fb 100644 --- a/test-tool/test_extendedcopy_descr_limits.c +++ b/test-tool/test_extendedcopy_descr_limits.c @@ -52,11 +52,10 @@ int init_xcopy_descr(unsigned char *buf, int offset, int num_tgt_desc, void test_extendedcopy_descr_limits(void) { - int ret; struct scsi_task *edl_task; struct iscsi_data data; unsigned char *xcopybuf; - struct scsi_copy_results_op_params *opp; + struct scsi_copy_results_op_params *opp = NULL; int tgt_desc_len = 0, seg_desc_len = 0; unsigned int alloc_len; @@ -66,14 +65,8 @@ test_extendedcopy_descr_limits(void) CHECK_FOR_DATALOSS; logging(LOG_VERBOSE, "Issue RECEIVE COPY RESULTS (OPERATING PARAMS)"); - ret = receive_copy_results(&edl_task, sd, SCSI_COPY_RESULTS_OP_PARAMS, 0, - (void **)&opp, EXPECT_STATUS_GOOD); - if (ret < 0) { - CU_PASS("[SKIPPED] Target does not support " - "RECEIVE_COPY_RESULTS. Skipping test"); - goto out; - } - CU_ASSERT_EQUAL(ret, 0); + RECEIVE_COPY_RESULTS(&edl_task, sd, SCSI_COPY_RESULTS_OP_PARAMS, 0, + (void **)&opp, EXPECT_STATUS_GOOD); /* Allocate buffer to accommodate (MAX+1) target and * segment descriptors */ @@ -93,13 +86,7 @@ test_extendedcopy_descr_limits(void) &tgt_desc_len, &seg_desc_len); populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_TOO_MANY_DESCR); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - goto out; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_TOO_MANY_DESCR); logging(LOG_VERBOSE, "Test sending more than supported segment descriptors"); @@ -109,8 +96,7 @@ test_extendedcopy_descr_limits(void) &tgt_desc_len, &seg_desc_len); populate_param_header(xcopybuf, 2, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_TOO_MANY_DESCR); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_TOO_MANY_DESCR); logging(LOG_VERBOSE, "Test sending descriptors > Maximum Descriptor List Length"); @@ -122,10 +108,8 @@ test_extendedcopy_descr_limits(void) &tgt_desc_len, &seg_desc_len); populate_param_header(xcopybuf, 3, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_PARAM_LIST_LEN_ERR); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_PARAM_LIST_LEN_ERR); } -out: scsi_free_scsi_task(edl_task); } diff --git a/test-tool/test_extendedcopy_descr_type.c b/test-tool/test_extendedcopy_descr_type.c index 454b89e..7a2914a 100644 --- a/test-tool/test_extendedcopy_descr_type.c +++ b/test-tool/test_extendedcopy_descr_type.c @@ -49,7 +49,6 @@ int init_xcopybuf(unsigned char *buf, int tgt_desc_type, int seg_desc_type, void test_extendedcopy_descr_type(void) { - int ret; int tgt_desc_len = 0, seg_desc_len = 0, alloc_len; struct iscsi_data data; unsigned char *xcopybuf; @@ -74,13 +73,7 @@ test_extendedcopy_descr_type(void) populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_UNSUPP_DESCR_CODE); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_UNSUPP_DESCR_CODE); logging(LOG_VERBOSE, "Send Stream-to-Stream Copy segment descriptor"); memset(xcopybuf, 0, alloc_len); @@ -90,6 +83,5 @@ test_extendedcopy_descr_type(void) populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_UNSUPP_DESCR_CODE); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_UNSUPP_DESCR_CODE); } diff --git a/test-tool/test_extendedcopy_param.c b/test-tool/test_extendedcopy_param.c index 4b50792..3d12c3d 100644 --- a/test-tool/test_extendedcopy_param.c +++ b/test-tool/test_extendedcopy_param.c @@ -30,7 +30,6 @@ void test_extendedcopy_param(void) { - int ret; int tgt_desc_len = 0, seg_desc_len = 0, offset = XCOPY_DESC_OFFSET; struct iscsi_data data; unsigned char *xcopybuf; @@ -62,24 +61,16 @@ test_extendedcopy_param(void) "Test parameter list length truncating target descriptor"); data.size = XCOPY_DESC_OFFSET + get_desc_len(IDENT_DESCR_TGT_DESCR) - 1; - ret = extendedcopy(sd, &data, EXPECT_PARAM_LIST_LEN_ERR); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_PARAM_LIST_LEN_ERR); logging(LOG_VERBOSE, "Test parameter list length truncating segment descriptor"); data.size = XCOPY_DESC_OFFSET + get_desc_len(IDENT_DESCR_TGT_DESCR) + get_desc_len(BLK_TO_BLK_SEG_DESCR) - 1; - ret = extendedcopy(sd, &data, EXPECT_PARAM_LIST_LEN_ERR); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_PARAM_LIST_LEN_ERR); logging(LOG_VERBOSE, "Test parameter list length = 0"); data.size = 0; - ret = extendedcopy(sd, &data, EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_STATUS_GOOD); } diff --git a/test-tool/test_extendedcopy_simple.c b/test-tool/test_extendedcopy_simple.c index fa823e8..222216b 100644 --- a/test-tool/test_extendedcopy_simple.c +++ b/test-tool/test_extendedcopy_simple.c @@ -30,7 +30,6 @@ void test_extendedcopy_simple(void) { - int ret; int tgt_desc_len = 0, seg_desc_len = 0, offset = XCOPY_DESC_OFFSET; struct iscsi_data data; unsigned char *xcopybuf; @@ -45,14 +44,8 @@ test_extendedcopy_simple(void) logging(LOG_VERBOSE, "Write 2048 blocks of 'A' at LBA:0"); memset(buf1, 'A', 2048*block_size); - ret = write16(sd, 0, 2048*block_size, block_size, 0, 0, 0, 0, 0, - buf1, EXPECT_STATUS_GOOD); - if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); - CU_PASS("WRITE16 is not implemented."); - goto finished; - } - CU_ASSERT_EQUAL(ret, 0); + WRITE16(sd, 0, 2048*block_size, block_size, 0, 0, 0, 0, 0, + buf1, EXPECT_STATUS_GOOD); data.size = XCOPY_DESC_OFFSET + get_desc_len(IDENT_DESCR_TGT_DESCR) + @@ -75,25 +68,17 @@ test_extendedcopy_simple(void) populate_param_header(xcopybuf, 1, 0, LIST_ID_USAGE_DISCARD, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_STATUS_GOOD); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - goto finished; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Read 2048 blocks from end of the LUN"); - ret = read16(sd, NULL, num_blocks - 2048, 2048*block_size, - block_size, 0, 0, 0, 0, 0, buf2, - EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + read16(sd, NULL, num_blocks - 2048, 2048*block_size, + block_size, 0, 0, 0, 0, 0, buf2, + EXPECT_STATUS_GOOD); - ret = memcmp(buf1, buf2, 2048); - if (ret != 0) + if (memcmp(buf1, buf2, 2048)) { CU_FAIL("Blocks were not copied correctly"); - - finished: + } + free(buf1); free(buf2); } diff --git a/test-tool/test_extendedcopy_validate_seg_descr.c b/test-tool/test_extendedcopy_validate_seg_descr.c index c481099..41a637c 100644 --- a/test-tool/test_extendedcopy_validate_seg_descr.c +++ b/test-tool/test_extendedcopy_validate_seg_descr.c @@ -30,7 +30,6 @@ void test_extendedcopy_validate_seg_descr(void) { - int ret; int tgt_desc_len = 0, seg_desc_len = 0, offset = XCOPY_DESC_OFFSET; struct iscsi_data data; unsigned char *xcopybuf; @@ -58,13 +57,7 @@ test_extendedcopy_validate_seg_descr(void) populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_COPY_ABORTED); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_COPY_ABORTED); logging(LOG_VERBOSE, "Number of copy blocks beyond destination block device capacity"); @@ -80,6 +73,5 @@ test_extendedcopy_validate_seg_descr(void) populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_COPY_ABORTED); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_COPY_ABORTED); } diff --git a/test-tool/test_extendedcopy_validate_tgt_descr.c b/test-tool/test_extendedcopy_validate_tgt_descr.c index 484af62..8975e16 100644 --- a/test-tool/test_extendedcopy_validate_tgt_descr.c +++ b/test-tool/test_extendedcopy_validate_tgt_descr.c @@ -30,7 +30,6 @@ void test_extendedcopy_validate_tgt_descr(void) { - int ret; int tgt_desc_len = 0, seg_desc_len = 0, offset = XCOPY_DESC_OFFSET; struct iscsi_data data; unsigned char *xcopybuf; @@ -58,13 +57,7 @@ test_extendedcopy_validate_tgt_descr(void) populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_INVALID_FIELD_IN_CDB); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - return; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_INVALID_FIELD_IN_CDB); logging(LOG_VERBOSE, "Test NUL bit in target descriptor"); /* NUL bit */ @@ -79,6 +72,5 @@ test_extendedcopy_validate_tgt_descr(void) populate_param_header(xcopybuf, 1, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_COPY_ABORTED); - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_COPY_ABORTED); } diff --git a/test-tool/test_receive_copy_results_copy_status.c b/test-tool/test_receive_copy_results_copy_status.c index 99c5f0d..8125a80 100644 --- a/test-tool/test_receive_copy_results_copy_status.c +++ b/test-tool/test_receive_copy_results_copy_status.c @@ -30,7 +30,6 @@ void test_receive_copy_results_copy_status(void) { - int ret; struct scsi_task *cs_task; struct scsi_copy_results_copy_status *csp; int tgt_desc_len = 0, seg_desc_len = 0; @@ -42,16 +41,10 @@ test_receive_copy_results_copy_status(void) logging(LOG_VERBOSE, "Test RECEIVE COPY RESULTS, COPY STATUS"); logging(LOG_VERBOSE, "No copy in progress"); - ret = receive_copy_results(&cs_task, sd, SCSI_COPY_RESULTS_COPY_STATUS, - list_id, NULL, EXPECT_INVALID_FIELD_IN_CDB); + RECEIVE_COPY_RESULTS(&cs_task, sd, SCSI_COPY_RESULTS_COPY_STATUS, + list_id, NULL, EXPECT_INVALID_FIELD_IN_CDB); scsi_free_scsi_task(cs_task); cs_task = NULL; - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "RECEIVE_COPY_STATUS. Skipping test"); - goto out; - } - CU_ASSERT_EQUAL(ret, 0); CHECK_FOR_DATALOSS; @@ -77,20 +70,12 @@ test_receive_copy_results_copy_status(void) populate_param_header(xcopybuf, list_id, 0, 0, 0, tgt_desc_len, seg_desc_len, 0); - ret = extendedcopy(sd, &data, EXPECT_STATUS_GOOD); - if (ret == -2) { - CU_PASS("[SKIPPED] Target does not support " - "EXTENDED_COPY. Skipping test"); - goto out; - } - CU_ASSERT_EQUAL(ret, 0); + EXTENDEDCOPY(sd, &data, EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Copy Status for the above Extended Copy command"); - ret = receive_copy_results(&cs_task, sd, SCSI_COPY_RESULTS_COPY_STATUS, - list_id, (void **)&csp, EXPECT_STATUS_GOOD); - CU_ASSERT_EQUAL(ret, 0); + RECEIVE_COPY_RESULTS(&cs_task, sd, SCSI_COPY_RESULTS_COPY_STATUS, + list_id, (void **)&csp, EXPECT_STATUS_GOOD); -out: scsi_free_scsi_task(cs_task); } diff --git a/test-tool/test_receive_copy_results_op_params.c b/test-tool/test_receive_copy_results_op_params.c index f900c8c..05a8b83 100644 --- a/test-tool/test_receive_copy_results_op_params.c +++ b/test-tool/test_receive_copy_results_op_params.c @@ -30,26 +30,19 @@ void test_receive_copy_results_op_params(void) { - int ret; - struct scsi_task *op_task; + struct scsi_task *op_task = NULL; struct scsi_copy_results_op_params *opp; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test RECEIVE COPY RESULTS, OPERATING PARAMS"); - ret = receive_copy_results(&op_task, sd, SCSI_COPY_RESULTS_OP_PARAMS, 0, - (void **)&opp, EXPECT_STATUS_GOOD); - if (ret == -2) { - CU_PASS("[SKIPPED] RECEIVE_COPY_RESULT is not implemented."); - goto out; - } - CU_ASSERT_EQUAL(ret, 0); + RECEIVE_COPY_RESULTS(&op_task, sd, SCSI_COPY_RESULTS_OP_PARAMS, 0, + (void **)&opp, EXPECT_STATUS_GOOD); logging(LOG_NORMAL, "max_target_desc=%d, max_seg_desc=%d", opp->max_target_desc_count, opp->max_segment_desc_count); -out: scsi_free_scsi_task(op_task); }