TESTS add tests for VERIFY10 and VERIFY12

This commit is contained in:
Ronnie Sahlberg
2013-01-21 14:50:40 -08:00
parent 0e4e2e91bd
commit ab3dfae005
29 changed files with 1163 additions and 100 deletions

View File

@@ -197,6 +197,20 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
test-tool/test_read16_rdprotect.c \
test-tool/test_read16_flags.c \
test-tool/test_readcapacity10_simple.c \
test-tool/test_verify10_simple.c \
test-tool/test_verify10_beyond_eol.c \
test-tool/test_verify10_0blocks.c \
test-tool/test_verify10_vrprotect.c \
test-tool/test_verify10_flags.c \
test-tool/test_verify10_mismatch.c \
test-tool/test_verify10_mismatch_no_cmp.c \
test-tool/test_verify12_simple.c \
test-tool/test_verify12_beyond_eol.c \
test-tool/test_verify12_0blocks.c \
test-tool/test_verify12_vrprotect.c \
test-tool/test_verify12_flags.c \
test-tool/test_verify12_mismatch.c \
test-tool/test_verify12_mismatch_no_cmp.c \
test-tool/test_verify16_simple.c \
test-tool/test_verify16_beyond_eol.c \
test-tool/test_verify16_0blocks.c \

View File

@@ -76,7 +76,7 @@ int T0130_verify10_simple(const char *initiator, const char *url)
/* verify the first 1 - 256 blocks at the start of the LUN */
printf("Verify first 1-256 blocks.\n");
for (i = 1; i <= 256; i++) {
ret = verify10(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
ret = verify10(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -82,7 +82,7 @@ int T0131_verify10_mismatch(const char *initiator, const char *url)
/* flip a random byte in the data */
buf[offset] ^= 'X';
ret = verify10_miscompare(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
ret = verify10_miscompare(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -82,7 +82,7 @@ int T0132_verify10_mismatch_no_cmp(const char *initiator, const char *url)
/* flip a random byte in the data */
buf[offset] ^= 'X';
ret = verify10(iscsi, lun, buf, i * block_size, 0, 0, 1, 0, block_size);
ret = verify10(iscsi, lun, 0, i * block_size, block_size, 0, 1, 0, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -57,7 +57,7 @@ int T0133_verify10_beyondeol(const char *initiator, const char *url)
/* verify 2 - 256 blocks beyond the end of the device */
printf("Verifying 2-256 blocks beyond end-of-device.\n");
for (i = 2; i <= 256; i++) {
ret = verify10_lbaoutofrange(iscsi, lun, buf, i * block_size, num_blocks, 0, 1, 1, block_size);
ret = verify10_lbaoutofrange(iscsi, lun, num_blocks, i * block_size, block_size, 0, 1, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -76,7 +76,7 @@ int T0280_verify12_simple(const char *initiator, const char *url)
/* verify the first 1 - 256 blocks at the start of the LUN */
printf("Verify first 1-256 blocks.\n");
for (i = 1; i <= 256; i++) {
ret = verify12(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
ret = verify12(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -81,7 +81,7 @@ int T0281_verify12_mismatch(const char *initiator, const char *url)
/* flip a random byte in the data */
buf[offset] ^= 'X';
ret = verify12_miscompare(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
ret = verify12_miscompare(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -82,7 +82,7 @@ int T0282_verify12_mismatch_no_cmp(const char *initiator, const char *url)
/* flip a random byte in the data */
buf[offset] ^= 'X';
ret = verify12(iscsi, lun, buf, i * block_size, 0, 0, 1, 0, block_size);
ret = verify12(iscsi, lun, 0, i * block_size, block_size, 0, 1, 0, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -58,7 +58,7 @@ int T0283_verify12_beyondeol(const char *initiator, const char *url)
/* verify 2 - 256 blocks beyond the end of the device */
printf("Verifying 2-256 blocks beyond end-of-device.\n");
for (i = 2; i <= 256; i++) {
ret = verify12_lbaoutofrange(iscsi, lun, buf, i * block_size, num_blocks, 0, 1, 1, block_size);
ret = verify12_lbaoutofrange(iscsi, lun, num_blocks, i * block_size, block_size, 0, 1, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -308,14 +308,14 @@ int T0370_nomedia(const char *initiator, const char *url)
printf("Test VERIFY10.\n");
ret = verify10_nomedium(iscsi, lun, buf, block_size, 0, 0, 0, 1, block_size);
ret = verify10_nomedium(iscsi, lun, 0, block_size, block_size, 0, 0, 1, buf);
if (ret != 0) {
goto finished;
}
printf("Test VERIFY12.\n");
ret = verify12_nomedium(iscsi, lun, buf, block_size, 0, 0, 0, 1, block_size);
ret = verify12_nomedium(iscsi, lun, 0, block_size, block_size, 0, 0, 1, buf);
if (ret != 0) {
goto finished;
}

View File

@@ -1428,294 +1428,358 @@ readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi)
}
int
verify10(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY10 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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) {
printf("[SKIPPED]\n");
printf("VERIFY10 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] VERIFY10 command: failed with sense. %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY10 returned SUCCESS.");
return 0;
}
int
verify10_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY10 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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) {
printf("[SKIPPED]\n");
printf("VERIFY10 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] VERIFY10 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)) {
printf("[FAILED]\n");
printf("VERIFY10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
logging(LOG_NORMAL, "[FAILED] VERIFY10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT* but failed with %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY10 returned NOT_READY/MEDIUM_NOT_PRESENT.");
return 0;
}
int
verify10_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify10_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting MISCOMPARE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting MISCOMPARE)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY10 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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) {
printf("[SKIPPED]\n");
printf("VERIFY10 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY10 command successful but should have failed with MISCOMPARE\n");
logging(LOG_NORMAL, "[FAILED] VERIFY10 successful but should have failed with MISCOMPARE");
scsi_free_scsi_task(task);
return -1;
}
if (task->sense.key != SCSI_SENSE_MISCOMPARE) {
printf("[FAILED]\n");
printf("VERIFY10 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s\n", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] VERIFY10 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY10 returned MISCOMPARE.");
return 0;
}
int
verify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting LBA_OUT_OF_RANGE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting LBA_OUT_OF_RANGE)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY10 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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) {
printf("[SKIPPED]\n");
printf("VERIFY10 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY10 command successful but should have failed with LBA_OUT_OF_RANGE\n");
logging(LOG_NORMAL, "[FAILED] VERIFY10 successful but should have failed with LBA_OUT_OF_RANGE");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("VERIFY10 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] VERIFY10 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY10 returned LBA_OUT_OF_RANGE.");
return 0;
}
int
verify12(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
logging(LOG_VERBOSE, "Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting INVALID_FIELD_IN_CDB)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY12 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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) {
printf("[SKIPPED]\n");
printf("VERIFY12 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] VERIFY10 successful but should have failed with LBA_OUT_OF_RANGE");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
logging(LOG_NORMAL, "[FAILED] VERIFY10 should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB. Sense:%s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY10 returned INVALID_FIELD_IN_CDB.");
return 0;
}
int
verify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] VERIFY12 command: failed with sense. %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY12 returned SUCCESS.");
return 0;
}
int
verify12_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY12 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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) {
printf("[SKIPPED]\n");
printf("VERIFY12 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] VERIFY12 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)) {
printf("[FAILED]\n");
printf("VERIFY12 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
logging(LOG_NORMAL, "[FAILED] VERIFY12 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT* but failed with %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY12 returned NOT_READY/MEDIUM_NOT_PRESENT.");
return 0;
}
int
verify12_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify12_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting MISCOMPARE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting MISCOMPARE)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY12 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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) {
printf("[SKIPPED]\n");
printf("VERIFY12 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY12 command successful but should have failed with MISCOMPARE\n");
logging(LOG_NORMAL, "[FAILED] VERIFY12 successful but should have failed with MISCOMPARE");
scsi_free_scsi_task(task);
return -1;
}
if (task->sense.key != SCSI_SENSE_MISCOMPARE) {
printf("[FAILED]\n");
printf("VERIFY12 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s\n", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] VERIFY12 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY12 returned MISCOMPARE.");
return 0;
}
int
verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize)
verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
printf("Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting LBA_OUT_OF_RANGE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
logging(LOG_VERBOSE, "Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting LBA_OUT_OF_RANGE)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY12 command: %s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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) {
printf("[SKIPPED]\n");
printf("VERIFY12 is not implemented on target\n");
logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY12 command successful but should have failed with LBA_OUT_OF_RANGE\n");
logging(LOG_NORMAL, "[FAILED] VERIFY12 successful but should have failed with LBA_OUT_OF_RANGE");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("VERIFY12 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
logging(LOG_NORMAL, "[FAILED] VERIFY12 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY12 returned LBA_OUT_OF_RANGE.");
return 0;
}
int
verify12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting INVALID_FIELD_IN_CDB)", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] VERIFY12 successful but should have failed with LBA_OUT_OF_RANGE");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
logging(LOG_NORMAL, "[FAILED] VERIFY12 should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB. Sense:%s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] VERIFY12 returned INVALID_FIELD_IN_CDB.");
return 0;
}

View File

@@ -131,14 +131,16 @@ int read16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen,
int read16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
int read16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi);
int verify10(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify10_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify10_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify12(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify12_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify12_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify10_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify12_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);
int verify16_miscompare(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data);

View File

@@ -102,6 +102,28 @@ static CU_TestInfo tests_readcapacity10[] = {
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_verify10[] = {
{ (char *)"testVerify10Simple", test_verify10_simple },
{ (char *)"testVerify10BeyondEol", test_verify10_beyond_eol },
{ (char *)"testVerify10ZeroBlocks", test_verify10_0blocks },
{ (char *)"testVerify10VerifyProtect", test_verify10_vrprotect },
{ (char *)"testVerify10Flags", test_verify10_flags },
{ (char *)"testVerify10mismatch", test_verify10_mismatch },
{ (char *)"testVerify10mismatch_no_cmp", test_verify10_mismatch_no_cmp },
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_verify12[] = {
{ (char *)"testVerify12Simple", test_verify12_simple },
{ (char *)"testVerify12BeyondEol", test_verify12_beyond_eol },
{ (char *)"testVerify12ZeroBlocks", test_verify12_0blocks },
{ (char *)"testVerify12VerifyProtect", test_verify12_vrprotect },
{ (char *)"testVerify12Flags", test_verify12_flags },
{ (char *)"testVerify12mismatch", test_verify12_mismatch },
{ (char *)"testVerify12mismatch_no_cmp", test_verify12_mismatch_no_cmp },
CU_TEST_INFO_NULL
};
static CU_TestInfo tests_verify16[] = {
{ (char *)"testVerify16Simple", test_verify16_simple },
{ (char *)"testVerify16BeyondEol", test_verify16_beyond_eol },
@@ -153,6 +175,10 @@ static CU_SuiteInfo suites[] = {
tests_read16 },
{ (char *)"TestReadCapacity10", test_setup, test_teardown,
tests_readcapacity10 },
{ (char *)"TestVerify10", test_setup, test_teardown,
tests_verify10 },
{ (char *)"TestVerify12", test_setup, test_teardown,
tests_verify12 },
{ (char *)"TestVerify16", test_setup, test_teardown,
tests_verify16 },
{ (char *)"TestWrite10", test_setup, test_teardown,

View File

@@ -64,6 +64,22 @@ void test_read16_flags(void);
void test_readcapacity10_simple(void);
void test_verify10_simple(void);
void test_verify10_beyond_eol(void);
void test_verify10_0blocks(void);
void test_verify10_vrprotect(void);
void test_verify10_flags(void);
void test_verify10_mismatch(void);
void test_verify10_mismatch_no_cmp(void);
void test_verify12_simple(void);
void test_verify12_beyond_eol(void);
void test_verify12_0blocks(void);
void test_verify12_vrprotect(void);
void test_verify12_flags(void);
void test_verify12_mismatch(void);
void test_verify12_mismatch_no_cmp(void);
void test_verify16_simple(void);
void test_verify16_beyond_eol(void);
void test_verify16_0blocks(void);

View File

@@ -34,7 +34,6 @@ test_read10_beyond_eol(void)
return;
}
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test READ10 1-256 blocks one block beyond the end");
for (i = 1; i <= 256; i++) {

View File

@@ -0,0 +1,57 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_verify10_0blocks(void)
{
int ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 0-blocks at LBA==0");
ret = verify10(iscsic, tgt_lun, 0, 0, block_size,
0, 0, 1, NULL);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY10 0-blocks one block past end-of-LUN");
ret = verify10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0,
block_size, 0, 0, 1, NULL);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY10 0-blocks at LBA==2^31");
ret = verify10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0,
block_size, 0, 0, 1, NULL);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY10 0-blocks at LBA==-1");
ret = verify10_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size,
0, 0, 1, NULL);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -0,0 +1,83 @@
/*
Copyright (C) 2013 Ronnie Sahlberg <ronneisahlberg@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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_verify10_beyond_eol(void)
{
int i, ret;
if (num_blocks >= 0x80000000) {
CU_PASS("LUN is too big for read-beyond-eol tests with VERIFY10. Skipping test.\n");
return;
}
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 1-256 blocks one block beyond the end");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 2 - i,
i * block_size, block_size,
0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY10 1-256 blocks at LBA==2^31");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify10_lbaoutofrange(iscsic, tgt_lun, 0x80000000,
i * block_size, block_size,
0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY10 1-256 blocks at LBA==-1");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify10_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size,
block_size, 0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY10 2-256 blocks all but one block beyond the end");
for (i = 2; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify10_lbaoutofrange(iscsic, tgt_lun, num_blocks,
i * block_size, block_size,
0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,59 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify10_flags(void)
{
int ret;
unsigned char *buf = malloc(block_size);
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 flags");
ret = read10(iscsic, tgt_lun, 0, block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY10 with DPO==1");
ret = verify10(iscsic, tgt_lun, 0, block_size,
block_size, 0, 1, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test");
free(buf);
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY10 with BYTCHK==1");
ret = verify10(iscsic, tgt_lun, 0, block_size,
block_size, 0, 0, 1, buf);
CU_ASSERT_EQUAL(ret, 0);
free(buf);
}

View File

@@ -0,0 +1,76 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify10_mismatch(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 for blocks 1-255");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read10(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify10_miscompare(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 1, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY10 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify10_miscompare(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,77 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify10_mismatch_no_cmp(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 without BYTCHK for blocks 1-255");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read10(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify10(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY10 without BYTCHK of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify10(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,66 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify10_simple(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = read10(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
ret = verify10(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 1, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY10 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = read10(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
ret = verify10(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,53 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify10_vrprotect(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY10 with non-zero VRPROTECT");
for (i = 1; i < 8; i++) {
unsigned char *buf = malloc(block_size);
ret = read10(iscsic, tgt_lun, 0, block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
ret = verify10_invalidfieldincdb(iscsic, tgt_lun, 0, block_size,
block_size, i, 0, 1, buf);
free(buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,57 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_verify12_0blocks(void)
{
int ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 0-blocks at LBA==0");
ret = verify12(iscsic, tgt_lun, 0, 0, block_size,
0, 0, 1, NULL);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY12 0-blocks one block past end-of-LUN");
ret = verify12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0,
block_size, 0, 0, 1, NULL);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY12 0-blocks at LBA==2^31");
ret = verify12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0,
block_size, 0, 0, 1, NULL);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY12 0-blocks at LBA==-1");
ret = verify12_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size,
0, 0, 1, NULL);
CU_ASSERT_EQUAL(ret, 0);
}

View File

@@ -0,0 +1,83 @@
/*
Copyright (C) 2013 Ronnie Sahlberg <ronneisahlberg@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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
void
test_verify12_beyond_eol(void)
{
int i, ret;
if (num_blocks >= 0x80000000) {
CU_PASS("LUN is too big for read-beyond-eol tests with VERIFY12. Skipping test.\n");
return;
}
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 1-256 blocks one block beyond the end");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 2 - i,
i * block_size, block_size,
0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY12 1-256 blocks at LBA==2^31");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify12_lbaoutofrange(iscsic, tgt_lun, 0x80000000,
i * block_size, block_size,
0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY12 1-256 blocks at LBA==-1");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify12_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size,
block_size, 0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY12 2-256 blocks all but one block beyond the end");
for (i = 2; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = verify12_lbaoutofrange(iscsic, tgt_lun, num_blocks,
i * block_size, block_size,
0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,59 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify12_flags(void)
{
int ret;
unsigned char *buf = malloc(block_size);
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 flags");
ret = read12(iscsic, tgt_lun, 0, block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY12 with DPO==1");
ret = verify12(iscsic, tgt_lun, 0, block_size,
block_size, 0, 1, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test");
free(buf);
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test VERIFY12 with BYTCHK==1");
ret = verify12(iscsic, tgt_lun, 0, block_size,
block_size, 0, 0, 1, buf);
CU_ASSERT_EQUAL(ret, 0);
free(buf);
}

View File

@@ -0,0 +1,76 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify12_mismatch(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 for blocks 1-255");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read12(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify12_miscompare(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 1, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY12 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify12_miscompare(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,77 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify12_mismatch_no_cmp(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 without BYTCHK for blocks 1-255");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read12(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify12(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY12 without BYTCHK of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
int offset = random() % (i * block_size);
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
/* flip a random byte in the data */
buf[offset] ^= 'X';
logging(LOG_VERBOSE, "Flip some bits in the data");
ret = verify12(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,66 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify12_simple(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = read12(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
ret = verify12(iscsic, tgt_lun, 0, i * block_size,
block_size, 0, 0, 1, buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test");
free(buf);
return;
}
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
logging(LOG_VERBOSE, "Test VERIFY12 of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) {
unsigned char *buf = malloc(block_size * i);
ret = read12(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
ret = verify12(iscsic, tgt_lun, num_blocks +1 - i,
i * block_size, block_size, 0, 0, 1, buf);
free(buf);
CU_ASSERT_EQUAL(ret, 0);
}
}

View File

@@ -0,0 +1,53 @@
/*
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 <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
void
test_verify12_vrprotect(void)
{
int i, ret;
logging(LOG_VERBOSE, "");
logging(LOG_VERBOSE, "Test VERIFY12 with non-zero VRPROTECT");
for (i = 1; i < 8; i++) {
unsigned char *buf = malloc(block_size);
ret = read12(iscsic, tgt_lun, 0, block_size,
block_size, 0, 0, 0, 0, 0, buf);
CU_ASSERT_EQUAL(ret, 0);
ret = verify12_invalidfieldincdb(iscsic, tgt_lun, 0, block_size,
block_size, i, 0, 1, buf);
free(buf);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
}
}