Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1757,6 +1757,58 @@ int compareandwrite(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int compareandwrite_miscompare(struct iscsi_context *iscsi, int lun,
|
||||
uint64_t lba, unsigned char *data,
|
||||
uint32_t len, int blocksize,
|
||||
int wrprotect, int dpo,
|
||||
int fua, int group_number)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send COMPARE_AND_WRITE LBA:%" PRIu64
|
||||
" LEN:%d WRPROTECT:%d (expecting MISCOMPARE)",
|
||||
lba, len, wrprotect);
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, lba,
|
||||
data, len, blocksize,
|
||||
wrprotect, dpo, fua, 0, group_number);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send COMPARE_AND_WRITE "
|
||||
"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] COMPARE_AND_WRITE is not "
|
||||
"implemented on target");
|
||||
scsi_free_scsi_task(task);
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE successful "
|
||||
"but should have failed with MISCOMPARE.");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_MISCOMPARE
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_MISCOMPARE_DURING_VERIFY) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE failed with "
|
||||
"the wrong sense code. Should have failed with "
|
||||
"MISCOMPARE/MISCOMPARE_DURING_VERIFY but failed with "
|
||||
"sense:%s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] COMPARE_AND_WRITE returned MISCOMPARE.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct scsi_task *get_lba_status_task(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
@@ -227,6 +227,7 @@ int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int m
|
||||
int inquiry_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize);
|
||||
struct scsi_task *get_lba_status_task(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);
|
||||
int compareandwrite(struct iscsi_context *iscsi, int lun, uint64_t lba, unsigned char *data, uint32_t len, int blocksize, int wrprotect, int dpo, int fua, int group_number);
|
||||
int compareandwrite_miscompare(struct iscsi_context *iscsi, int lun, uint64_t lba, unsigned char *data, uint32_t len, int blocksize, int wrprotect, int dpo, int fua, int group_number);
|
||||
int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);
|
||||
int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);
|
||||
int get_lba_status_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len);
|
||||
|
||||
@@ -62,6 +62,7 @@ int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
|
||||
*****************************************************************/
|
||||
static CU_TestInfo tests_compareandwrite[] = {
|
||||
{ (char *)"Simple", test_compareandwrite_simple },
|
||||
{ (char *)"Miscompare", test_compareandwrite_miscompare },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
@@ -395,86 +396,92 @@ static CU_TestInfo tests_writeverify16[] = {
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
typedef struct libiscsi_suite_info {
|
||||
const char *pName; /**< Suite name. */
|
||||
CU_InitializeFunc pInitFunc; /**< Suite initialization function. */
|
||||
CU_CleanupFunc pCleanupFunc; /**< Suite cleanup function */
|
||||
CU_TestInfo *pTests; /**< Test case array - must be NULL terminated. */
|
||||
} libiscsi_suite_info;
|
||||
|
||||
/* SCSI protocol tests */
|
||||
static CU_SuiteInfo scsi_suites[] = {
|
||||
{ (char *)"CompareAndWrite", test_setup, test_teardown,
|
||||
static libiscsi_suite_info scsi_suites[] = {
|
||||
{ "CompareAndWrite", test_setup, test_teardown,
|
||||
tests_compareandwrite },
|
||||
{ (char *)"GetLBAStatus", test_setup, test_teardown,
|
||||
{ "GetLBAStatus", test_setup, test_teardown,
|
||||
tests_get_lba_status },
|
||||
{ (char *)"Inquiry", test_setup, test_teardown,
|
||||
{ "Inquiry", test_setup, test_teardown,
|
||||
tests_inquiry },
|
||||
{ (char *)"Mandatory", test_setup, test_teardown,
|
||||
{ "Mandatory", test_setup, test_teardown,
|
||||
tests_mandatory },
|
||||
{ (char *)"ModeSense6", test_setup, test_teardown,
|
||||
{ "ModeSense6", test_setup, test_teardown,
|
||||
tests_modesense6 },
|
||||
{ (char *)"NoMedia", test_setup, test_teardown,
|
||||
{ "NoMedia", test_setup, test_teardown,
|
||||
tests_nomedia },
|
||||
{ (char *)"OrWrite", test_setup, test_teardown,
|
||||
{ "OrWrite", test_setup, test_teardown,
|
||||
tests_orwrite },
|
||||
{ (char *)"Prefetch10", test_setup, test_teardown,
|
||||
{ "Prefetch10", test_setup, test_teardown,
|
||||
tests_prefetch10 },
|
||||
{ (char *)"Prefetch16", test_setup, test_teardown,
|
||||
{ "Prefetch16", test_setup, test_teardown,
|
||||
tests_prefetch16 },
|
||||
{ (char *)"PreventAllow", test_setup, test_teardown,
|
||||
{ "PreventAllow", test_setup, test_teardown,
|
||||
tests_preventallow },
|
||||
{ (char *)"PrinReadKeys", test_setup, test_teardown,
|
||||
{ "PrinReadKeys", test_setup, test_teardown,
|
||||
tests_prin_read_keys },
|
||||
{ (char *)"PrinServiceactionRange", test_setup, test_teardown,
|
||||
{ "PrinServiceactionRange", test_setup, test_teardown,
|
||||
tests_prin_serviceaction_range },
|
||||
{ (char *)"ProutRegister", test_setup, test_teardown,
|
||||
{ "ProutRegister", test_setup, test_teardown,
|
||||
tests_prout_register },
|
||||
{ (char *)"ProutReserve", test_setup_pgr, test_teardown_pgr,
|
||||
{ "ProutReserve", test_setup_pgr, test_teardown_pgr,
|
||||
tests_prout_reserve },
|
||||
{ (char *)"Read6", test_setup, test_teardown,
|
||||
{ "Read6", test_setup, test_teardown,
|
||||
tests_read6 },
|
||||
{ (char *)"Read10", test_setup, test_teardown,
|
||||
{ "Read10", test_setup, test_teardown,
|
||||
tests_read10 },
|
||||
{ (char *)"Read12", test_setup, test_teardown,
|
||||
{ "Read12", test_setup, test_teardown,
|
||||
tests_read12 },
|
||||
{ (char *)"Read16", test_setup, test_teardown,
|
||||
{ "Read16", test_setup, test_teardown,
|
||||
tests_read16 },
|
||||
{ (char *)"ReadCapacity10", test_setup, test_teardown,
|
||||
{ "ReadCapacity10", test_setup, test_teardown,
|
||||
tests_readcapacity10 },
|
||||
{ (char *)"ReadCapacity16", test_setup, test_teardown,
|
||||
{ "ReadCapacity16", test_setup, test_teardown,
|
||||
tests_readcapacity16 },
|
||||
{ (char *)"ReadOnly", test_setup, test_teardown,
|
||||
{ "ReadOnly", test_setup, test_teardown,
|
||||
tests_readonly },
|
||||
{ (char *)"ReportSupportedOpcodes", test_setup, test_teardown,
|
||||
{ "ReportSupportedOpcodes", test_setup, test_teardown,
|
||||
tests_report_supported_opcodes },
|
||||
{ (char *)"Reserve6", test_setup, test_teardown,
|
||||
{ "Reserve6", test_setup, test_teardown,
|
||||
tests_reserve6 },
|
||||
{ (char *)"Sanitize", test_setup, test_teardown,
|
||||
{ "Sanitize", test_setup, test_teardown,
|
||||
tests_sanitize },
|
||||
{ (char *)"StartStopUnit", test_setup, test_teardown,
|
||||
{ "StartStopUnit", test_setup, test_teardown,
|
||||
tests_startstopunit },
|
||||
{ (char *)"UnitReady", test_setup, test_teardown,
|
||||
{ "UnitReady", test_setup, test_teardown,
|
||||
tests_testunitready },
|
||||
{ (char *)"Unmap", test_setup, test_teardown,
|
||||
{ "Unmap", test_setup, test_teardown,
|
||||
tests_unmap },
|
||||
{ (char *)"Verify10", test_setup, test_teardown,
|
||||
{ "Verify10", test_setup, test_teardown,
|
||||
tests_verify10 },
|
||||
{ (char *)"Verify12", test_setup, test_teardown,
|
||||
{ "Verify12", test_setup, test_teardown,
|
||||
tests_verify12 },
|
||||
{ (char *)"Verify16", test_setup, test_teardown,
|
||||
{ "Verify16", test_setup, test_teardown,
|
||||
tests_verify16 },
|
||||
{ (char *)"Write10", test_setup, test_teardown,
|
||||
{ "Write10", test_setup, test_teardown,
|
||||
tests_write10 },
|
||||
{ (char *)"Write12", test_setup, test_teardown,
|
||||
{ "Write12", test_setup, test_teardown,
|
||||
tests_write12 },
|
||||
{ (char *)"Write16", test_setup, test_teardown,
|
||||
{ "Write16", test_setup, test_teardown,
|
||||
tests_write16 },
|
||||
{ (char *)"WriteSame10", test_setup, test_teardown,
|
||||
{ "WriteSame10", test_setup, test_teardown,
|
||||
tests_writesame10 },
|
||||
{ (char *)"WriteSame16", test_setup, test_teardown,
|
||||
{ "WriteSame16", test_setup, test_teardown,
|
||||
tests_writesame16 },
|
||||
{ (char *)"WriteVerify10", test_setup, test_teardown,
|
||||
{ "WriteVerify10", test_setup, test_teardown,
|
||||
tests_writeverify10 },
|
||||
{ (char *)"WriteVerify12", test_setup, test_teardown,
|
||||
{ "WriteVerify12", test_setup, test_teardown,
|
||||
tests_writeverify12 },
|
||||
{ (char *)"WriteVerify16", test_setup, test_teardown,
|
||||
{ "WriteVerify16", test_setup, test_teardown,
|
||||
tests_writeverify16 },
|
||||
CU_SUITE_INFO_NULL
|
||||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_iscsi_cmdsn[] = {
|
||||
@@ -498,174 +505,174 @@ static CU_TestInfo tests_iscsi_residuals[] = {
|
||||
};
|
||||
|
||||
/* iSCSI protocol tests */
|
||||
static CU_SuiteInfo iscsi_suites[] = {
|
||||
{ (char *)"iSCSIcmdsn", test_setup, test_teardown,
|
||||
static libiscsi_suite_info iscsi_suites[] = {
|
||||
{ "iSCSIcmdsn", test_setup, test_teardown,
|
||||
tests_iscsi_cmdsn },
|
||||
{ (char *)"iSCSIResiduals", test_setup, test_teardown,
|
||||
{ "iSCSIResiduals", test_setup, test_teardown,
|
||||
tests_iscsi_residuals },
|
||||
CU_SUITE_INFO_NULL
|
||||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
/* All tests */
|
||||
static CU_SuiteInfo all_suites[] = {
|
||||
{ (char *)"CompareAndWrite", test_setup, test_teardown,
|
||||
static libiscsi_suite_info all_suites[] = {
|
||||
{ "CompareAndWrite", test_setup, test_teardown,
|
||||
tests_compareandwrite },
|
||||
{ (char *)"GetLBAStatus", test_setup, test_teardown,
|
||||
{ "GetLBAStatus", test_setup, test_teardown,
|
||||
tests_get_lba_status },
|
||||
{ (char *)"Inquiry", test_setup, test_teardown,
|
||||
{ "Inquiry", test_setup, test_teardown,
|
||||
tests_inquiry },
|
||||
{ (char *)"Mandatory", test_setup, test_teardown,
|
||||
{ "Mandatory", test_setup, test_teardown,
|
||||
tests_mandatory },
|
||||
{ (char *)"ModeSense6", test_setup, test_teardown,
|
||||
{ "ModeSense6", test_setup, test_teardown,
|
||||
tests_modesense6 },
|
||||
{ (char *)"NoMedia", test_setup, test_teardown,
|
||||
{ "NoMedia", test_setup, test_teardown,
|
||||
tests_nomedia },
|
||||
{ (char *)"OrWrite", test_setup, test_teardown,
|
||||
{ "OrWrite", test_setup, test_teardown,
|
||||
tests_orwrite },
|
||||
{ (char *)"Prefetch10", test_setup, test_teardown,
|
||||
{ "Prefetch10", test_setup, test_teardown,
|
||||
tests_prefetch10 },
|
||||
{ (char *)"Prefetch16", test_setup, test_teardown,
|
||||
{ "Prefetch16", test_setup, test_teardown,
|
||||
tests_prefetch16 },
|
||||
{ (char *)"PreventAllow", test_setup, test_teardown,
|
||||
{ "PreventAllow", test_setup, test_teardown,
|
||||
tests_preventallow },
|
||||
{ (char *)"PrinReadKeys", test_setup, test_teardown,
|
||||
{ "PrinReadKeys", test_setup, test_teardown,
|
||||
tests_prin_read_keys },
|
||||
{ (char *)"PrinServiceactionRange", test_setup, test_teardown,
|
||||
{ "PrinServiceactionRange", test_setup, test_teardown,
|
||||
tests_prin_serviceaction_range },
|
||||
{ (char *)"ProutRegister", test_setup, test_teardown,
|
||||
{ "ProutRegister", test_setup, test_teardown,
|
||||
tests_prout_register },
|
||||
{ (char *)"ProutReserve", test_setup_pgr, test_teardown_pgr,
|
||||
{ "ProutReserve", test_setup_pgr, test_teardown_pgr,
|
||||
tests_prout_reserve },
|
||||
{ (char *)"Read6", test_setup, test_teardown,
|
||||
{ "Read6", test_setup, test_teardown,
|
||||
tests_read6 },
|
||||
{ (char *)"Read10", test_setup, test_teardown,
|
||||
{ "Read10", test_setup, test_teardown,
|
||||
tests_read10 },
|
||||
{ (char *)"Read12", test_setup, test_teardown,
|
||||
{ "Read12", test_setup, test_teardown,
|
||||
tests_read12 },
|
||||
{ (char *)"Read16", test_setup, test_teardown,
|
||||
{ "Read16", test_setup, test_teardown,
|
||||
tests_read16 },
|
||||
{ (char *)"ReadCapacity10", test_setup, test_teardown,
|
||||
{ "ReadCapacity10", test_setup, test_teardown,
|
||||
tests_readcapacity10 },
|
||||
{ (char *)"ReadCapacity16", test_setup, test_teardown,
|
||||
{ "ReadCapacity16", test_setup, test_teardown,
|
||||
tests_readcapacity16 },
|
||||
{ (char *)"ReadOnly", test_setup, test_teardown,
|
||||
{ "ReadOnly", test_setup, test_teardown,
|
||||
tests_readonly },
|
||||
{ (char *)"ReportSupportedOpcodes", test_setup, test_teardown,
|
||||
{ "ReportSupportedOpcodes", test_setup, test_teardown,
|
||||
tests_report_supported_opcodes },
|
||||
{ (char *)"Reserve6", test_setup, test_teardown,
|
||||
{ "Reserve6", test_setup, test_teardown,
|
||||
tests_reserve6 },
|
||||
{ (char *)"Sanitize", test_setup, test_teardown,
|
||||
{ "Sanitize", test_setup, test_teardown,
|
||||
tests_sanitize },
|
||||
{ (char *)"StartStopUnit", test_setup, test_teardown,
|
||||
{ "StartStopUnit", test_setup, test_teardown,
|
||||
tests_startstopunit },
|
||||
{ (char *)"TestUnitReady", test_setup, test_teardown,
|
||||
{ "TestUnitReady", test_setup, test_teardown,
|
||||
tests_testunitready },
|
||||
{ (char *)"Unmap", test_setup, test_teardown,
|
||||
{ "Unmap", test_setup, test_teardown,
|
||||
tests_unmap },
|
||||
{ (char *)"Verify10", test_setup, test_teardown,
|
||||
{ "Verify10", test_setup, test_teardown,
|
||||
tests_verify10 },
|
||||
{ (char *)"Verify12", test_setup, test_teardown,
|
||||
{ "Verify12", test_setup, test_teardown,
|
||||
tests_verify12 },
|
||||
{ (char *)"Verify16", test_setup, test_teardown,
|
||||
{ "Verify16", test_setup, test_teardown,
|
||||
tests_verify16 },
|
||||
{ (char *)"Write10", test_setup, test_teardown,
|
||||
{ "Write10", test_setup, test_teardown,
|
||||
tests_write10 },
|
||||
{ (char *)"Write12", test_setup, test_teardown,
|
||||
{ "Write12", test_setup, test_teardown,
|
||||
tests_write12 },
|
||||
{ (char *)"Write16", test_setup, test_teardown,
|
||||
{ "Write16", test_setup, test_teardown,
|
||||
tests_write16 },
|
||||
{ (char *)"WriteSame10", test_setup, test_teardown,
|
||||
{ "WriteSame10", test_setup, test_teardown,
|
||||
tests_writesame10 },
|
||||
{ (char *)"WriteSame16", test_setup, test_teardown,
|
||||
{ "WriteSame16", test_setup, test_teardown,
|
||||
tests_writesame16 },
|
||||
{ (char *)"WriteVerify10", test_setup, test_teardown,
|
||||
{ "WriteVerify10", test_setup, test_teardown,
|
||||
tests_writeverify10 },
|
||||
{ (char *)"WriteVerify12", test_setup, test_teardown,
|
||||
{ "WriteVerify12", test_setup, test_teardown,
|
||||
tests_writeverify12 },
|
||||
{ (char *)"WriteVerify16", test_setup, test_teardown,
|
||||
{ "WriteVerify16", test_setup, test_teardown,
|
||||
tests_writeverify16 },
|
||||
{ (char *)"iSCSIcmdsn", test_setup, test_teardown,
|
||||
{ "iSCSIcmdsn", test_setup, test_teardown,
|
||||
tests_iscsi_cmdsn },
|
||||
{ (char *)"iSCSIResiduals", test_setup, test_teardown,
|
||||
{ "iSCSIResiduals", test_setup, test_teardown,
|
||||
tests_iscsi_residuals },
|
||||
CU_SUITE_INFO_NULL
|
||||
{ NULL, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
static CU_SuiteInfo scsi_usb_sbc_suites[] = {
|
||||
{ (char *)"CompareAndWrite", test_setup, test_teardown,
|
||||
static libiscsi_suite_info scsi_usb_sbc_suites[] = {
|
||||
{ "CompareAndWrite", test_setup, test_teardown,
|
||||
tests_compareandwrite },
|
||||
{ (char *)"GetLBAStatus", test_setup, test_teardown,
|
||||
{ "GetLBAStatus", test_setup, test_teardown,
|
||||
tests_get_lba_status },
|
||||
{ (char *)"Inquiry", test_setup, test_teardown,
|
||||
{ "Inquiry", test_setup, test_teardown,
|
||||
tests_inquiry },
|
||||
{ (char *)"Mandatory", test_setup, test_teardown,
|
||||
{ "Mandatory", test_setup, test_teardown,
|
||||
tests_mandatory },
|
||||
{ (char *)"ModeSense6", test_setup, test_teardown,
|
||||
{ "ModeSense6", test_setup, test_teardown,
|
||||
tests_modesense6 },
|
||||
{ (char *)"OrWrite", test_setup, test_teardown,
|
||||
{ "OrWrite", test_setup, test_teardown,
|
||||
tests_orwrite },
|
||||
{ (char *)"Prefetch10", test_setup, test_teardown,
|
||||
{ "Prefetch10", test_setup, test_teardown,
|
||||
tests_prefetch10 },
|
||||
{ (char *)"Prefetch16", test_setup, test_teardown,
|
||||
{ "Prefetch16", test_setup, test_teardown,
|
||||
tests_prefetch16 },
|
||||
{ (char *)"PrinReadKeys", test_setup, test_teardown,
|
||||
{ "PrinReadKeys", test_setup, test_teardown,
|
||||
tests_prin_read_keys },
|
||||
{ (char *)"PrinServiceactionRange", test_setup, test_teardown,
|
||||
{ "PrinServiceactionRange", test_setup, test_teardown,
|
||||
tests_prin_serviceaction_range },
|
||||
{ (char *)"ProutRegister", test_setup, test_teardown,
|
||||
{ "ProutRegister", test_setup, test_teardown,
|
||||
tests_prout_register },
|
||||
{ (char *)"ProutReserve", test_setup_pgr, test_teardown_pgr,
|
||||
{ "ProutReserve", test_setup_pgr, test_teardown_pgr,
|
||||
tests_prout_reserve },
|
||||
{ (char *)"Read6", test_setup, test_teardown,
|
||||
{ "Read6", test_setup, test_teardown,
|
||||
tests_read6 },
|
||||
{ (char *)"Read10", test_setup, test_teardown,
|
||||
{ "Read10", test_setup, test_teardown,
|
||||
tests_read10 },
|
||||
{ (char *)"Read12", test_setup, test_teardown,
|
||||
{ "Read12", test_setup, test_teardown,
|
||||
tests_read12 },
|
||||
{ (char *)"Read16", test_setup, test_teardown,
|
||||
{ "Read16", test_setup, test_teardown,
|
||||
tests_read16 },
|
||||
{ (char *)"ReadCapacity10", test_setup, test_teardown,
|
||||
{ "ReadCapacity10", test_setup, test_teardown,
|
||||
tests_readcapacity10 },
|
||||
{ (char *)"ReadCapacity16", test_setup, test_teardown,
|
||||
{ "ReadCapacity16", test_setup, test_teardown,
|
||||
tests_readcapacity16 },
|
||||
{ (char *)"ReadOnly", test_setup, test_teardown,
|
||||
{ "ReadOnly", test_setup, test_teardown,
|
||||
tests_readonly },
|
||||
{ (char *)"ReportSupportedOpcodes", test_setup, test_teardown,
|
||||
{ "ReportSupportedOpcodes", test_setup, test_teardown,
|
||||
tests_report_supported_opcodes },
|
||||
{ (char *)"Reserve6", test_setup, test_teardown,
|
||||
{ "Reserve6", test_setup, test_teardown,
|
||||
tests_reserve6 },
|
||||
{ (char *)"TestUnitReady", test_setup, test_teardown,
|
||||
{ "TestUnitReady", test_setup, test_teardown,
|
||||
tests_testunitready },
|
||||
{ (char *)"Unmap", test_setup, test_teardown,
|
||||
{ "Unmap", test_setup, test_teardown,
|
||||
tests_unmap },
|
||||
{ (char *)"Verify10", test_setup, test_teardown,
|
||||
{ "Verify10", test_setup, test_teardown,
|
||||
tests_verify10 },
|
||||
{ (char *)"Verify12", test_setup, test_teardown,
|
||||
{ "Verify12", test_setup, test_teardown,
|
||||
tests_verify12 },
|
||||
{ (char *)"Verify16", test_setup, test_teardown,
|
||||
{ "Verify16", test_setup, test_teardown,
|
||||
tests_verify16 },
|
||||
{ (char *)"Write10", test_setup, test_teardown,
|
||||
{ "Write10", test_setup, test_teardown,
|
||||
tests_write10 },
|
||||
{ (char *)"Write12", test_setup, test_teardown,
|
||||
{ "Write12", test_setup, test_teardown,
|
||||
tests_write12 },
|
||||
{ (char *)"Write16", test_setup, test_teardown,
|
||||
{ "Write16", test_setup, test_teardown,
|
||||
tests_write16 },
|
||||
{ (char *)"WriteSame10", test_setup, test_teardown,
|
||||
{ "WriteSame10", test_setup, test_teardown,
|
||||
tests_writesame10 },
|
||||
{ (char *)"WriteSame16", test_setup, test_teardown,
|
||||
{ "WriteSame16", test_setup, test_teardown,
|
||||
tests_writesame16 },
|
||||
{ (char *)"WriteVerify10", test_setup, test_teardown,
|
||||
{ "WriteVerify10", test_setup, test_teardown,
|
||||
tests_writeverify10 },
|
||||
{ (char *)"WriteVerify12", test_setup, test_teardown,
|
||||
{ "WriteVerify12", test_setup, test_teardown,
|
||||
tests_writeverify12 },
|
||||
{ (char *)"WriteVerify16", test_setup, test_teardown,
|
||||
{ "WriteVerify16", test_setup, test_teardown,
|
||||
tests_writeverify16 },
|
||||
CU_SUITE_INFO_NULL
|
||||
{ NULL, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
struct test_family {
|
||||
const char *name;
|
||||
CU_SuiteInfo *suites;
|
||||
libiscsi_suite_info *suites;
|
||||
};
|
||||
|
||||
static struct test_family families[] = {
|
||||
@@ -746,20 +753,20 @@ print_usage(void)
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int
|
||||
CU_ST_RETTYPE
|
||||
test_setup(void)
|
||||
{
|
||||
iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
if (iscsic == NULL) {
|
||||
fprintf(stderr,
|
||||
"error: Failed to login to target for test set-up\n");
|
||||
return 1;
|
||||
CU_ST_RETURN(1);
|
||||
}
|
||||
task = NULL;
|
||||
return 0;
|
||||
CU_ST_RETURN(0);
|
||||
}
|
||||
|
||||
int
|
||||
CU_ST_RETTYPE
|
||||
test_setup_pgr(void)
|
||||
{
|
||||
task = NULL;
|
||||
@@ -769,7 +776,7 @@ test_setup_pgr(void)
|
||||
if (iscsic == NULL) {
|
||||
fprintf(stderr,
|
||||
"error: Failed to login to target for test set-up\n");
|
||||
return 1;
|
||||
CU_ST_RETURN(1);
|
||||
}
|
||||
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun2);
|
||||
@@ -779,12 +786,12 @@ test_setup_pgr(void)
|
||||
iscsi_logout_sync(iscsic);
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsic = NULL;
|
||||
return 1;
|
||||
CU_ST_RETURN(1);
|
||||
}
|
||||
return 0;
|
||||
CU_ST_RETURN(0);
|
||||
}
|
||||
|
||||
int
|
||||
CU_ST_RETTYPE
|
||||
test_teardown(void)
|
||||
{
|
||||
if (task) {
|
||||
@@ -796,10 +803,10 @@ test_teardown(void)
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsic = NULL;
|
||||
}
|
||||
return 0;
|
||||
CU_ST_RETURN(0);
|
||||
}
|
||||
|
||||
int
|
||||
CU_ST_RETTYPE
|
||||
test_teardown_pgr(void)
|
||||
{
|
||||
test_teardown();
|
||||
@@ -807,14 +814,14 @@ test_teardown_pgr(void)
|
||||
free(read_write_buf);
|
||||
read_write_buf = NULL;
|
||||
}
|
||||
return 0;
|
||||
CU_ST_RETURN(0);
|
||||
}
|
||||
|
||||
static void
|
||||
list_all_tests(void)
|
||||
{
|
||||
struct test_family *fp;
|
||||
CU_SuiteInfo *sp;
|
||||
libiscsi_suite_info *sp;
|
||||
CU_TestInfo *tp;
|
||||
|
||||
for (fp = families; fp->name; fp++) {
|
||||
@@ -834,44 +841,44 @@ static CU_ErrorCode
|
||||
add_tests(const char *testname_re)
|
||||
{
|
||||
char *family_re = NULL;
|
||||
const char *suite_re = NULL;
|
||||
const char *test_re = NULL;
|
||||
char *suite_re = NULL;
|
||||
char *test_re = NULL;
|
||||
char *cp;
|
||||
struct test_family *fp;
|
||||
CU_SuiteInfo *sp;
|
||||
libiscsi_suite_info *sp;
|
||||
CU_TestInfo *tp;
|
||||
|
||||
|
||||
/* if not testname(s) register all tests and return */
|
||||
/* if not testname(s) register all tests */
|
||||
if (!testname_re) {
|
||||
return CU_register_suites(all_suites);
|
||||
}
|
||||
|
||||
/*
|
||||
* break testname_re into family/suite/test
|
||||
*
|
||||
* syntax is: FAMILY[.SUITE[.TEST]]
|
||||
*/
|
||||
family_re = strdup(testname_re);
|
||||
if ((cp = strchr(family_re, '.')) != NULL) {
|
||||
*cp++ = 0;
|
||||
suite_re = cp;
|
||||
if ((cp = strchr(suite_re, '.')) != NULL) {
|
||||
family_re = strdup("*");
|
||||
suite_re = strdup("*");
|
||||
test_re = strdup("*");
|
||||
} else {
|
||||
/*
|
||||
* break testname_re into family/suite/test
|
||||
*
|
||||
* syntax is: FAMILY[.SUITE[.TEST]]
|
||||
*/
|
||||
family_re = strdup(testname_re);
|
||||
if ((cp = strchr(family_re, '.')) != NULL) {
|
||||
*cp++ = 0;
|
||||
test_re = cp;
|
||||
suite_re = strdup(cp);
|
||||
if ((cp = strchr(suite_re, '.')) != NULL) {
|
||||
*cp++ = 0;
|
||||
test_re = strdup(cp);
|
||||
}
|
||||
}
|
||||
if (!suite_re)
|
||||
suite_re = strdup("*");
|
||||
if (!test_re)
|
||||
test_re = strdup("*");
|
||||
if (!family_re) {
|
||||
fprintf(stderr,
|
||||
"error: can't parse test family name: %s\n",
|
||||
family_re);
|
||||
return CUE_NOTEST;
|
||||
}
|
||||
}
|
||||
if (suite_re == NULL) {
|
||||
suite_re = "*";
|
||||
}
|
||||
if (test_re == NULL) {
|
||||
test_re = "*";
|
||||
}
|
||||
|
||||
if (!family_re) {
|
||||
fprintf(stderr, "error: can't parse test family name: %s\n",
|
||||
family_re);
|
||||
return CUE_NOTEST;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -904,8 +911,9 @@ add_tests(const char *testname_re)
|
||||
}
|
||||
|
||||
/* all done -- clean up */
|
||||
if (family_re)
|
||||
free(family_re);
|
||||
free(family_re);
|
||||
free(suite_re);
|
||||
free(test_re);
|
||||
|
||||
return CUE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,23 @@ extern struct iscsi_context *iscsic2;
|
||||
extern int tgt_lun2;
|
||||
extern unsigned char *read_write_buf;
|
||||
|
||||
int test_setup(void);
|
||||
int test_teardown(void);
|
||||
int test_setup_pgr(void);
|
||||
int test_teardown_pgr(void);
|
||||
#ifdef HAVE_CU_SUITEINFO_PSETUPFUNC
|
||||
/* libcunit version 2 */
|
||||
#define CU_ST_RETTYPE void
|
||||
#define CU_ST_RETURN(v) return
|
||||
#else
|
||||
/* libcunit version 1 */
|
||||
#define CU_ST_RETTYPE int
|
||||
#define CU_ST_RETURN(v) return v
|
||||
#endif
|
||||
|
||||
CU_ST_RETTYPE test_setup(void);
|
||||
CU_ST_RETTYPE test_teardown(void);
|
||||
CU_ST_RETTYPE test_setup_pgr(void);
|
||||
CU_ST_RETTYPE test_teardown_pgr(void);
|
||||
|
||||
void test_compareandwrite_simple(void);
|
||||
void test_compareandwrite_miscompare(void);
|
||||
|
||||
void test_get_lba_status_simple(void);
|
||||
void test_get_lba_status_beyond_eol(void);
|
||||
|
||||
136
test-tool/test_compareandwrite_miscompare.c
Normal file
136
test-tool/test_compareandwrite_miscompare.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-support.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
|
||||
void
|
||||
test_compareandwrite_miscompare(void)
|
||||
{
|
||||
int i, ret;
|
||||
unsigned j;
|
||||
unsigned char *buf = alloca(2 * 256 * block_size);
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
CHECK_FOR_SBC;
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
|
||||
"start of the LUN. One Byte miscompare in the final block.");
|
||||
for (i = 1; i < 256; i++) {
|
||||
logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:0", i);
|
||||
memset(buf, 'A', 2 * i * block_size);
|
||||
if (maximum_transfer_length && maximum_transfer_length < i) {
|
||||
break;
|
||||
}
|
||||
ret = write16(iscsic, tgt_lun, 0, i * block_size,
|
||||
block_size, 0, 0, 0, 0, 0, buf);
|
||||
if (ret == -2) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented.");
|
||||
CU_PASS("WRITE16 is not implemented.");
|
||||
return;
|
||||
}
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match.");
|
||||
buf[i * block_size - 27] = 'C';
|
||||
|
||||
|
||||
memset(buf + i * block_size, 'B', i * block_size);
|
||||
|
||||
logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' "
|
||||
"at LBA:0 (if they all contain 'A')", i);
|
||||
ret = compareandwrite_miscompare(iscsic, tgt_lun, 0,
|
||||
buf, 2 * i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (ret == -2) {
|
||||
CU_PASS("[SKIPPED] Target does not support "
|
||||
"COMPARE_AND_WRITE. Skipping test");
|
||||
return;
|
||||
}
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify "
|
||||
"they are still unchanged as 'A'", i);
|
||||
ret = read16(iscsic, tgt_lun, 0, i * block_size,
|
||||
block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
for (j = 0; j < i * block_size; j++) {
|
||||
if (buf[j] != 'A') {
|
||||
logging(LOG_VERBOSE, "[FAILED] Data changed "
|
||||
"eventhough there was a miscompare");
|
||||
CU_FAIL("Block was written to");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
|
||||
"end of the LUN");
|
||||
for (i = 1; i < 256; i++) {
|
||||
logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:%" PRIu64,
|
||||
i, num_blocks - i);
|
||||
memset(buf, 'A', 2 * i * block_size);
|
||||
if (maximum_transfer_length && maximum_transfer_length < i) {
|
||||
break;
|
||||
}
|
||||
ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size,
|
||||
block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match.");
|
||||
buf[i * block_size - 27] = 'C';
|
||||
|
||||
|
||||
memset(buf + i * block_size, 'B', i * block_size);
|
||||
|
||||
logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' "
|
||||
"at LBA:%" PRIu64 " (if they all contain 'A')",
|
||||
i, num_blocks - i);
|
||||
ret = compareandwrite_miscompare(iscsic, tgt_lun,
|
||||
num_blocks - i,
|
||||
buf, 2 * i * block_size, block_size, 0, 0, 0, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64
|
||||
"they are still unchanged as 'A'",
|
||||
i, num_blocks - i);
|
||||
ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
|
||||
block_size, 0, 0, 0, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
for (j = 0; j < i * block_size; j++) {
|
||||
if (buf[j] != 'A') {
|
||||
logging(LOG_VERBOSE, "[FAILED] Data changed "
|
||||
"eventhough there was a miscompare");
|
||||
CU_FAIL("Block was written to");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ test_preventallow_2_itnexuses(void)
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -70,7 +70,6 @@ test_read6_simple(void)
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] READ6 command: "
|
||||
"failed with sense. %s", iscsi_get_error(iscsic));
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ test_reserve6_itnexus_loss(void)
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -46,7 +46,7 @@ test_reserve6_logout(void)
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -57,7 +57,7 @@ test_reserve6_lun_reset(void)
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -56,7 +56,7 @@ test_reserve6_target_cold_reset(void)
|
||||
sleep(3);
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -57,7 +57,7 @@ test_reserve6_target_warm_reset(void)
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -40,7 +40,7 @@ test_sanitize_readonly(void)
|
||||
CHECK_FOR_DATALOSS;
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -40,7 +40,7 @@ test_sanitize_reservations(void)
|
||||
CHECK_FOR_DATALOSS;
|
||||
|
||||
logging(LOG_VERBOSE, "Create a second connection to the target");
|
||||
iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun);
|
||||
if (iscsic2 == NULL) {
|
||||
logging(LOG_VERBOSE, "Failed to login to target");
|
||||
return;
|
||||
|
||||
@@ -54,7 +54,7 @@ test_writesame16_unmap(void)
|
||||
if (ret == -2) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented.");
|
||||
CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test");
|
||||
return;
|
||||
goto finished;
|
||||
}
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
@@ -142,7 +142,7 @@ test_writesame16_unmap(void)
|
||||
"BlockLimits VPD is missing.");
|
||||
CU_FAIL("[FAILED] WRITESAME16 works but "
|
||||
"BlockLimits VPD is missing.");
|
||||
return;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
i = 256;
|
||||
@@ -247,5 +247,7 @@ test_writesame16_unmap(void)
|
||||
0, 1, 0, 0, buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user