TESTS: Change all tests to use 'block_size' instead of hardcoded 512
This should allow the testst to work corectly on block devices with 4k blocksize too.
This commit is contained in:
@@ -27,18 +27,20 @@ int T0122_read6_invalid(const char *initiator, const char *url, int data_loss _U
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
struct iscsi_data data;
|
||||
char buf[512];
|
||||
char buf[4096];
|
||||
struct scsi_readcapacity10 *rc10;
|
||||
uint32_t block_size;
|
||||
int ret, lun;
|
||||
|
||||
printf("0122_read6_invalid:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test various protocol violations.\n");
|
||||
printf("1, Read 1 block but set xferlength to 0. Should result in residual overflow of 512 bytes.\n");
|
||||
printf("2, Read 1 block but set xferlength to 1024. Should result in residual underflow of 512 bytes.\n");
|
||||
printf("3, Read 1 block but set xferlength to 200. Should result in residual overflow of 312 bytes.\n");
|
||||
printf("4, Read 2 blocks but set xferlength to 512. Should result in residual overflow of 512 bytes.\n");
|
||||
printf("5, Read 1 block but send one block as data-out write on the iSCSI level. Should result in both residual overflow and underflow of 512 bytes.\n");
|
||||
printf("1, Read 1 block but set xferlength to 0. Should result in residual overflow of 'block_size' bytes.\n");
|
||||
printf("2, Read 1 block but set xferlength to 2*'block_size'. Should result in residual underflow of 'block_size' bytes.\n");
|
||||
printf("3, Read 1 block but set xferlength to 200. Should result in residual overflow of 'block_size' - 200 bytes.\n");
|
||||
printf("4, Read 2 blocks but set xferlength to 'block_size'. Should result in residual overflow of 'block_size' bytes.\n");
|
||||
printf("5, Read 1 block but send one block as data-out write on the iSCSI level. Should result in both residual overflow and underflow of 'block_size' bytes.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -49,6 +51,29 @@ int T0122_read6_invalid(const char *initiator, const char *url, int data_loss _U
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* find the size of the LUN */
|
||||
task = iscsi_readcapacity10_sync(iscsi, lun, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("Failed to send readcapacity10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("Readcapacity command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
rc10 = scsi_datain_unmarshall(task);
|
||||
if (rc10 == NULL) {
|
||||
printf("failed to unmarshall readcapacity10 data. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
block_size = rc10->block_size;
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
@@ -93,7 +118,7 @@ int T0122_read6_invalid(const char *initiator, const char *url, int data_loss _U
|
||||
scsi_free_scsi_task(task);
|
||||
goto test2;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != 512) {
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
@@ -139,7 +164,7 @@ test2:
|
||||
scsi_free_scsi_task(task);
|
||||
goto test3;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW || task->residual != 512) {
|
||||
if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW || task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual underflow.\n");
|
||||
ret = -1;
|
||||
@@ -182,7 +207,7 @@ test3:
|
||||
scsi_free_scsi_task(task);
|
||||
goto test4;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != 312) {
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != block_size - 200) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
@@ -193,8 +218,8 @@ test3:
|
||||
printf("[OK]\n");
|
||||
|
||||
test4:
|
||||
/* Try a read of 2 blocks but xferlength == 512 */
|
||||
printf("Read6 2 blocks but with iscsi ExpectedDataTransferLength==512 ... ");
|
||||
/* Try a read of 2 blocks but xferlength == block_size */
|
||||
printf("Read6 2 blocks but with iscsi ExpectedDataTransferLength==%d ... ", block_size);
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
@@ -208,7 +233,7 @@ test4:
|
||||
task->cdb[4] = 2;
|
||||
task->cdb_size = 6;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 512;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
@@ -219,12 +244,12 @@ test4:
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 of 2 blocks with iscsi ExpectedDataTransferLength==512 should succeed.\n");
|
||||
printf("Read6 of 2 blocks with iscsi ExpectedDataTransferLength==%d should succeed.\n", block_size);
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test5;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != 512) {
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
|
||||
Reference in New Issue
Block a user