From ab3dfae0054346e45d66a0af5188ab5404404313 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 21 Jan 2013 14:50:40 -0800 Subject: [PATCH] TESTS add tests for VERIFY10 and VERIFY12 --- Makefile.am | 14 ++ test-tool/0130_verify10_simple.c | 2 +- test-tool/0131_verify10_mismatch.c | 2 +- test-tool/0132_verify10_mismatch_no_cmp.c | 2 +- test-tool/0133_verify10_beyondeol.c | 2 +- test-tool/0280_verify12_simple.c | 2 +- test-tool/0281_verify12_mismatch.c | 2 +- test-tool/0282_verify12_mismatch_no_cmp.c | 2 +- test-tool/0283_verify12_beyondeol.c | 2 +- test-tool/0370_nomedia.c | 4 +- test-tool/iscsi-support.c | 226 ++++++++++++++-------- test-tool/iscsi-support.h | 18 +- test-tool/iscsi-test-cu.c | 26 +++ test-tool/iscsi-test-cu.h | 16 ++ test-tool/test_read10_beyond_eol.c | 1 - test-tool/test_verify10_0blocks.c | 57 ++++++ test-tool/test_verify10_beyond_eol.c | 83 ++++++++ test-tool/test_verify10_flags.c | 59 ++++++ test-tool/test_verify10_mismatch.c | 76 ++++++++ test-tool/test_verify10_mismatch_no_cmp.c | 77 ++++++++ test-tool/test_verify10_simple.c | 66 +++++++ test-tool/test_verify10_vrprotect.c | 53 +++++ test-tool/test_verify12_0blocks.c | 57 ++++++ test-tool/test_verify12_beyond_eol.c | 83 ++++++++ test-tool/test_verify12_flags.c | 59 ++++++ test-tool/test_verify12_mismatch.c | 76 ++++++++ test-tool/test_verify12_mismatch_no_cmp.c | 77 ++++++++ test-tool/test_verify12_simple.c | 66 +++++++ test-tool/test_verify12_vrprotect.c | 53 +++++ 29 files changed, 1163 insertions(+), 100 deletions(-) create mode 100644 test-tool/test_verify10_0blocks.c create mode 100644 test-tool/test_verify10_beyond_eol.c create mode 100644 test-tool/test_verify10_flags.c create mode 100644 test-tool/test_verify10_mismatch.c create mode 100644 test-tool/test_verify10_mismatch_no_cmp.c create mode 100644 test-tool/test_verify10_simple.c create mode 100644 test-tool/test_verify10_vrprotect.c create mode 100644 test-tool/test_verify12_0blocks.c create mode 100644 test-tool/test_verify12_beyond_eol.c create mode 100644 test-tool/test_verify12_flags.c create mode 100644 test-tool/test_verify12_mismatch.c create mode 100644 test-tool/test_verify12_mismatch_no_cmp.c create mode 100644 test-tool/test_verify12_simple.c create mode 100644 test-tool/test_verify12_vrprotect.c diff --git a/Makefile.am b/Makefile.am index d825958..58dcbd9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/test-tool/0130_verify10_simple.c b/test-tool/0130_verify10_simple.c index ad19d58..07b9c24 100644 --- a/test-tool/0130_verify10_simple.c +++ b/test-tool/0130_verify10_simple.c @@ -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; } diff --git a/test-tool/0131_verify10_mismatch.c b/test-tool/0131_verify10_mismatch.c index 47bf2f3..c8fdaa9 100644 --- a/test-tool/0131_verify10_mismatch.c +++ b/test-tool/0131_verify10_mismatch.c @@ -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; } diff --git a/test-tool/0132_verify10_mismatch_no_cmp.c b/test-tool/0132_verify10_mismatch_no_cmp.c index 19a4943..244162d 100644 --- a/test-tool/0132_verify10_mismatch_no_cmp.c +++ b/test-tool/0132_verify10_mismatch_no_cmp.c @@ -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; } diff --git a/test-tool/0133_verify10_beyondeol.c b/test-tool/0133_verify10_beyondeol.c index 6476b25..060a29a 100644 --- a/test-tool/0133_verify10_beyondeol.c +++ b/test-tool/0133_verify10_beyondeol.c @@ -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; } diff --git a/test-tool/0280_verify12_simple.c b/test-tool/0280_verify12_simple.c index c220007..fd7faa9 100644 --- a/test-tool/0280_verify12_simple.c +++ b/test-tool/0280_verify12_simple.c @@ -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; } diff --git a/test-tool/0281_verify12_mismatch.c b/test-tool/0281_verify12_mismatch.c index 12c405a..672b3dc 100644 --- a/test-tool/0281_verify12_mismatch.c +++ b/test-tool/0281_verify12_mismatch.c @@ -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; } diff --git a/test-tool/0282_verify12_mismatch_no_cmp.c b/test-tool/0282_verify12_mismatch_no_cmp.c index 10a54af..0ae2595 100644 --- a/test-tool/0282_verify12_mismatch_no_cmp.c +++ b/test-tool/0282_verify12_mismatch_no_cmp.c @@ -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; } diff --git a/test-tool/0283_verify12_beyondeol.c b/test-tool/0283_verify12_beyondeol.c index 4d14f34..4206037 100644 --- a/test-tool/0283_verify12_beyondeol.c +++ b/test-tool/0283_verify12_beyondeol.c @@ -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; } diff --git a/test-tool/0370_nomedia.c b/test-tool/0370_nomedia.c index 09d713e..0aadde0 100644 --- a/test-tool/0370_nomedia.c +++ b/test-tool/0370_nomedia.c @@ -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; } diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 3da027a..07c6073 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -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; } diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index dd45895..99f3dab 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -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); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index e5de1e4..64c14c1 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -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, diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 914dc2a..dffe1c0 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -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); diff --git a/test-tool/test_read10_beyond_eol.c b/test-tool/test_read10_beyond_eol.c index d61bd41..80ec331 100644 --- a/test-tool/test_read10_beyond_eol.c +++ b/test-tool/test_read10_beyond_eol.c @@ -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++) { diff --git a/test-tool/test_verify10_0blocks.c b/test-tool/test_verify10_0blocks.c new file mode 100644 index 0000000..6270f08 --- /dev/null +++ b/test-tool/test_verify10_0blocks.c @@ -0,0 +1,57 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); +} diff --git a/test-tool/test_verify10_beyond_eol.c b/test-tool/test_verify10_beyond_eol.c new file mode 100644 index 0000000..470336f --- /dev/null +++ b/test-tool/test_verify10_beyond_eol.c @@ -0,0 +1,83 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify10_flags.c b/test-tool/test_verify10_flags.c new file mode 100644 index 0000000..1185403 --- /dev/null +++ b/test-tool/test_verify10_flags.c @@ -0,0 +1,59 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); +} diff --git a/test-tool/test_verify10_mismatch.c b/test-tool/test_verify10_mismatch.c new file mode 100644 index 0000000..9710d3d --- /dev/null +++ b/test-tool/test_verify10_mismatch.c @@ -0,0 +1,76 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify10_mismatch_no_cmp.c b/test-tool/test_verify10_mismatch_no_cmp.c new file mode 100644 index 0000000..6411dcd --- /dev/null +++ b/test-tool/test_verify10_mismatch_no_cmp.c @@ -0,0 +1,77 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify10_simple.c b/test-tool/test_verify10_simple.c new file mode 100644 index 0000000..b51df7c --- /dev/null +++ b/test-tool/test_verify10_simple.c @@ -0,0 +1,66 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify10_vrprotect.c b/test-tool/test_verify10_vrprotect.c new file mode 100644 index 0000000..673d50c --- /dev/null +++ b/test-tool/test_verify10_vrprotect.c @@ -0,0 +1,53 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify12_0blocks.c b/test-tool/test_verify12_0blocks.c new file mode 100644 index 0000000..dcee04f --- /dev/null +++ b/test-tool/test_verify12_0blocks.c @@ -0,0 +1,57 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); +} diff --git a/test-tool/test_verify12_beyond_eol.c b/test-tool/test_verify12_beyond_eol.c new file mode 100644 index 0000000..8165108 --- /dev/null +++ b/test-tool/test_verify12_beyond_eol.c @@ -0,0 +1,83 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify12_flags.c b/test-tool/test_verify12_flags.c new file mode 100644 index 0000000..cffa10a --- /dev/null +++ b/test-tool/test_verify12_flags.c @@ -0,0 +1,59 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); +} diff --git a/test-tool/test_verify12_mismatch.c b/test-tool/test_verify12_mismatch.c new file mode 100644 index 0000000..c2c3dc9 --- /dev/null +++ b/test-tool/test_verify12_mismatch.c @@ -0,0 +1,76 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify12_mismatch_no_cmp.c b/test-tool/test_verify12_mismatch_no_cmp.c new file mode 100644 index 0000000..dc9783c --- /dev/null +++ b/test-tool/test_verify12_mismatch_no_cmp.c @@ -0,0 +1,77 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify12_simple.c b/test-tool/test_verify12_simple.c new file mode 100644 index 0000000..02f7ec4 --- /dev/null +++ b/test-tool/test_verify12_simple.c @@ -0,0 +1,66 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +} diff --git a/test-tool/test_verify12_vrprotect.c b/test-tool/test_verify12_vrprotect.c new file mode 100644 index 0000000..0563d9c --- /dev/null +++ b/test-tool/test_verify12_vrprotect.c @@ -0,0 +1,53 @@ + +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include + +#include + +#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); + } +}