From 34fd477ede5e6043b7446b8184b6e28c779e394a Mon Sep 17 00:00:00 2001 From: Anastasia Kovaleva Date: Wed, 27 Jan 2021 11:58:00 +0300 Subject: [PATCH] test-tool: Allow CHECK CONDITION in response to overflow/underflow According to the RFC 7143 11.4.5.1: "Targets may set the residual count,and initiators may use it when the response code is Command Completed at Target (even if the status returned is not GOOD)." Therefore valid retuned status may be not only GOOD. Also this check: task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT would make Underflow/Overflow response universal for FC/ISCSI. --- test-tool/test_write10_residuals.c | 35 +++++++++++++++--------------- test-tool/test_write12_residuals.c | 35 +++++++++++++++--------------- test-tool/test_write16_residuals.c | 35 +++++++++++++++--------------- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/test-tool/test_write10_residuals.c b/test-tool/test_write10_residuals.c index 911c39c..a8cbf94 100644 --- a/test-tool/test_write10_residuals.c +++ b/test-tool/test_write10_residuals.c @@ -26,6 +26,12 @@ #include "scsi-lowlevel.h" #include "iscsi-test-cu.h" +static int check_status (struct scsi_task *task) { + return (task->status == SCSI_STATUS_GOOD || + (task->status == SCSI_STATUS_CHECK_CONDITION && + task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && + task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT)); +} void test_write10_residuals(void) @@ -33,7 +39,6 @@ test_write10_residuals(void) struct scsi_task *task_ret; unsigned char buf[10000]; struct iscsi_data data; - int ok; unsigned int i; logging(LOG_VERBOSE, LOG_BLANK_LINE); @@ -75,11 +80,11 @@ test_write10_residuals(void) return; } logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -121,11 +126,11 @@ test_write10_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual underflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { @@ -163,15 +168,11 @@ test_write10_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - ok = task->status == SCSI_STATUS_GOOD || - (task->status == SCSI_STATUS_CHECK_CONDITION && - task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && - task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT); - if (!ok) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT(ok); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -212,11 +213,11 @@ test_write10_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -265,11 +266,11 @@ test_write10_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual underflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { @@ -337,11 +338,11 @@ test_write10_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { diff --git a/test-tool/test_write12_residuals.c b/test-tool/test_write12_residuals.c index 02819ba..fb27f9d 100644 --- a/test-tool/test_write12_residuals.c +++ b/test-tool/test_write12_residuals.c @@ -26,6 +26,12 @@ #include "scsi-lowlevel.h" #include "iscsi-test-cu.h" +static int check_status (struct scsi_task *task) { + return (task->status == SCSI_STATUS_GOOD || + (task->status == SCSI_STATUS_CHECK_CONDITION && + task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && + task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT)); +} void test_write12_residuals(void) @@ -33,7 +39,6 @@ test_write12_residuals(void) struct scsi_task *task_ret; unsigned char buf[10000]; struct iscsi_data data; - int ok; unsigned int i; logging(LOG_VERBOSE, LOG_BLANK_LINE); @@ -75,11 +80,11 @@ test_write12_residuals(void) return; } logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -121,11 +126,11 @@ test_write12_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual underflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { @@ -163,15 +168,11 @@ test_write12_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - ok = task->status == SCSI_STATUS_GOOD || - (task->status == SCSI_STATUS_CHECK_CONDITION && - task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && - task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT); - if (!ok) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT(ok); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -212,11 +213,11 @@ test_write12_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -264,11 +265,11 @@ test_write12_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual underflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { @@ -336,11 +337,11 @@ test_write12_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { diff --git a/test-tool/test_write16_residuals.c b/test-tool/test_write16_residuals.c index 7088cac..3e48d85 100644 --- a/test-tool/test_write16_residuals.c +++ b/test-tool/test_write16_residuals.c @@ -26,6 +26,12 @@ #include "scsi-lowlevel.h" #include "iscsi-test-cu.h" +static int check_status (struct scsi_task *task) { + return (task->status == SCSI_STATUS_GOOD || + (task->status == SCSI_STATUS_CHECK_CONDITION && + task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && + task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT)); +} void test_write16_residuals(void) @@ -33,7 +39,6 @@ test_write16_residuals(void) struct scsi_task *task_ret; unsigned char buf[10000]; struct iscsi_data data; - int ok; unsigned int i; logging(LOG_VERBOSE, LOG_BLANK_LINE); @@ -75,11 +80,11 @@ test_write16_residuals(void) return; } logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -121,11 +126,11 @@ test_write16_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual underflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { @@ -163,15 +168,11 @@ test_write16_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - ok = task->status == SCSI_STATUS_GOOD || - (task->status == SCSI_STATUS_CHECK_CONDITION && - task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && - task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT); - if (!ok) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT(ok); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -212,11 +213,11 @@ test_write16_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { @@ -264,11 +265,11 @@ test_write16_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual underflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { @@ -336,11 +337,11 @@ test_write16_residuals(void) CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); - if (task->status != SCSI_STATUS_GOOD) { + if (!check_status(task)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", iscsi_get_error(sd->iscsi_ctx)); } - CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + CU_ASSERT(check_status(task)); logging(LOG_VERBOSE, "Verify residual overflow flag is set"); if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {