From 44d88e3bc6bef767cecaf01c139ef2da9eb39fb8 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 17 Sep 2014 14:27:00 -0700 Subject: [PATCH] TESTS: update synchronizecache to new api Signed-off-by: Ronnie Sahlberg --- test-tool/iscsi-support.c | 168 ++++++----------------------------- test-tool/iscsi-support.h | 6 +- test-tool/test_nomedia_sbc.c | 6 +- 3 files changed, 33 insertions(+), 147 deletions(-) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index b2e6e30..259a09e 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -1036,163 +1036,49 @@ verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) } int -synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int sync_nv, int immed) +synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE10 LBA:%d blocks:%d" - " sync_nv:%d immed:%d", + logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE10 (Expecting %s) LBA:%d" + " blocks:%d sync_nv:%d immed:%d", + scsi_status_str(status), lba, num, sync_nv, immed); - task = iscsi_synchronizecache10_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - logging(LOG_NORMAL, "[SKIPPED] SYNCHRONIZECAHCE10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE10 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_synchronizecache10(lba, num_blocks, sync_nv, immed); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SYNCHRONIZECAHCE10 returned SUCCESS."); - return 0; + task = iscsi_scsi_command_sync(iscsi, lun, task, NULL); + + ret = check_result("SYNCHRONIZECACHE10", iscsi, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -synchronizecache10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int sync_nv, int immed) +synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE10 (Expecting MEDIUM_NOT_PRESENT) LBA:%d blocks:%d" - " sync_nv:%d immed:%d", + logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE16 (Expecting %s) LBA:%" + PRIu64 " blocks:%d sync_nv:%d immed:%d", + scsi_status_str(status), lba, num, sync_nv, immed); - task = iscsi_synchronizecache10_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - logging(LOG_NORMAL, "[SKIPPED] SYNCHRONIZECAHCE10 is not implemented on target"); + task = scsi_cdb_synchronizecache16(lba, num_blocks, sync_nv, immed); + assert(task != NULL); + + task = iscsi_scsi_command_sync(iscsi, lun, task, NULL); + + ret = check_result("SYNCHRONIZECACHE16", iscsi, task, status, key, ascq, num_ascq); + if (task) { scsi_free_scsi_task(task); - return -2; } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE10 command successful. But should have failed with NOT_READY/MEDIUM_NOT_PRESENT*"); - scsi_free_scsi_task(task); - return -1; - } - if (task->status != SCSI_STATUS_CHECK_CONDITION - || task->sense.key != SCSI_SENSE_NOT_READY - || (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT - && task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN - && task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECAHCE10 Should have failed " - "with NOT_READY/MEDIUM_NOT_PRESENT* But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SYNCHRONIZECAHCE10 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num, int sync_nv, int immed) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE16 LBA:%" PRIu64 " blocks:%d" - " sync_nv:%d immed:%d", - lba, num, sync_nv, immed); - - task = iscsi_synchronizecache16_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE16 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - logging(LOG_NORMAL, "[SKIPPED] SYNCHRONIZECAHCE16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE16 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SYNCHRONIZECAHCE16 returned SUCCESS."); - return 0; -} - -int -synchronizecache16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num, int sync_nv, int immed) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE16 (Expecting MEDIUM_NOT_PRESENT) LBA:%" PRIu64 " blocks:%d" - " sync_nv:%d immed:%d", - lba, num, sync_nv, immed); - - task = iscsi_synchronizecache16_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE16 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - logging(LOG_NORMAL, "[SKIPPED] SYNCHRONIZECAHCE16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE16 command successful. But should have failed with NOT_READY/MEDIUM_NOT_PRESENT*"); - scsi_free_scsi_task(task); - return -1; - } - if (task->status != SCSI_STATUS_CHECK_CONDITION - || task->sense.key != SCSI_SENSE_NOT_READY - || (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT - && task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN - && task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE16 Should have failed " - "with NOT_READY/MEDIUM_NOT_PRESENT* But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SYNCHRONIZECAHCE16 returned MEDIUM_NOT_PRESENT."); - return 0; + return ret; } int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data) diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 2666db7..88676bc 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -283,10 +283,8 @@ int sanitize_conflict(struct iscsi_context *iscsi, int lun, int immed, int ause, int sanitize_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data); int sanitize_writeprotected(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data); int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start, int status, enum scsi_sense_key key, int *ascq, int num_ascq); -int synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed); -int synchronizecache10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed); -int synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed); -int synchronizecache16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed); +int synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int testunitready_clear_ua(struct iscsi_context *iscsi, int lun); int testunitready(struct iscsi_context *iscsi, int lun, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int mode_sense(struct iscsi_context *iscsi, int lun); diff --git a/test-tool/test_nomedia_sbc.c b/test-tool/test_nomedia_sbc.c index a7484a9..a19f138 100644 --- a/test-tool/test_nomedia_sbc.c +++ b/test-tool/test_nomedia_sbc.c @@ -53,7 +53,8 @@ test_nomedia_sbc(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test SYNCHRONIZECACHE10 when medium is ejected."); - ret = synchronizecache10_nomedium(iscsic, tgt_lun, 0, 1, 1, 1); + ret = synchronizecache10(iscsic, tgt_lun, 0, 1, 1, 1, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "SYNCHRONIZECACHE10"); @@ -62,7 +63,8 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test SYNCHRONIZECACHE16 when medium is ejected."); - ret = synchronizecache16_nomedium(iscsic, tgt_lun, 0, 1, 1, 1); + ret = synchronizecache16(iscsic, tgt_lun, 0, 1, 1, 1, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "SYNCHRONIZECACHE16");