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:
Ronnie Sahlberg
2012-09-03 08:58:56 -07:00
parent 5639b92d95
commit 77fc2497f7
46 changed files with 197 additions and 95 deletions

View File

@@ -28,18 +28,20 @@ int T0105_read10_invalid(const char *initiator, const char *url, int data_loss _
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("0105_read10_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;
}
@@ -50,6 +52,29 @@ int T0105_read10_invalid(const char *initiator, const char *url, int data_loss _
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;
@@ -95,7 +120,7 @@ int T0105_read10_invalid(const char *initiator, const char *url, int data_loss _
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("Read10 returned incorrect residual overflow.\n");
ret = -1;
@@ -141,7 +166,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("Read10 returned incorrect residual underflow.\n");
ret = -1;
@@ -184,7 +209,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("Read10 returned incorrect residual overflow.\n");
ret = -1;
@@ -195,8 +220,8 @@ test3:
printf("[OK]\n");
test4:
/* Try a read of 2 blocks but xferlength == 512 */
printf("Read10 2 blocks but with iscsi ExpectedDataTransferLength==512 ... ");
/* Try a read of 2 blocks but xferlength == 'block_size' */
printf("Read10 2 blocks but with iscsi ExpectedDataTransferLength==%d ... ", block_size);
task = malloc(sizeof(struct scsi_task));
if (task == NULL) {
@@ -210,7 +235,7 @@ test4:
task->cdb[8] = 2;
task->cdb_size = 10;
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");
@@ -221,12 +246,12 @@ test4:
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Read10 of 2 blocks with iscsi ExpectedDataTransferLength==512 should succeed.\n");
printf("Read10 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("Read10 returned incorrect residual overflow.\n");
ret = -1;