TESTS: Create helpers for VERIFY16 and switch all tests over to use them
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
@@ -28,7 +29,7 @@ int T0273_verify16_beyondeol(const char *initiator, const char *url, int data_lo
|
||||
int ret, i, lun;
|
||||
uint32_t block_size;
|
||||
uint64_t num_blocks;
|
||||
unsigned char buf[4096 * 256];
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0273_verify16_beyond_eol:\n");
|
||||
printf("========================\n");
|
||||
@@ -71,112 +72,36 @@ int T0273_verify16_beyondeol(const char *initiator, const char *url, int data_lo
|
||||
num_blocks = rc16->returned_lba;
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
|
||||
ret = 0;
|
||||
buf = malloc(256 * block_size);
|
||||
|
||||
/* verify 2 - 256 blocks beyond the end of the device */
|
||||
printf("Verifying 2-256 blocks beyond end-of-device ... ");
|
||||
printf("Verifying 2-256 blocks beyond end-of-device.\n");
|
||||
for (i = 2; i <= 256; i++) {
|
||||
task = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, num_blocks, 0, 1, 1, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
ret = verify16_lbaoutofrange(iscsi, lun, buf, i * block_size, num_blocks, 0, 1, 1, block_size);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("VERIFY16 command should fail when reading beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
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("VERIFY16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
/* verify 1 - 256 blocks at LBA 2^63 */
|
||||
printf("Verify 1-256 blocks at LBA 2^63 ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, 0x8000000000000000ULL, 0, 1, 1, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
printf("Verifying 1-256 blocks at LBA 2^63.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify16_lbaoutofrange(iscsi, lun, buf, i * block_size, 0x8000000000000000, 0, 1, 1, block_size);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("VERIFY16 command should fail when reading at LBA 2^63\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
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("VERIFY16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
/* verify 1 - 256 blocks at LBA -1 */
|
||||
printf("Verifying 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, -1LL, 0, 1, 1, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto test2;
|
||||
printf("Verifying 1-256 blocks at LBA -1.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify16_lbaoutofrange(iscsi, lun, buf, i * block_size, 0xffffffffffffffff, 0, 1, 1, block_size);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("VERIFY16 command should fail when reading at LBA -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test2;
|
||||
}
|
||||
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("VERIFY16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test2;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
test2:
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user