TESTS: Create helpers for verify12 and switch all tests to use them

This commit is contained in:
Ronnie Sahlberg
2012-12-25 16:14:45 -08:00
parent 12179de245
commit 61ad9b1972
7 changed files with 252 additions and 212 deletions

View File

@@ -16,6 +16,7 @@
*/
#include <stdio.h>
#include <string.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
@@ -24,10 +25,10 @@ int T0280_verify12_simple(const char *initiator, const char *url, int data_loss
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_task *vtask;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
unsigned char *buf = NULL;
printf("0280_verify12_simple:\n");
printf("=====================\n");
@@ -68,73 +69,47 @@ int T0280_verify12_simple(const char *initiator, const char *url, int data_loss
scsi_free_scsi_task(task);
buf = malloc(256 * block_size);
if (buf == NULL) {
printf("Failed to allocate buffer.\n");
ret = -1;
goto finished;
}
printf("Read first 256 blocks.\n");
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
memcpy(buf, task->datain.data, task->datain.size);
scsi_free_scsi_task(task);
ret = 0;
/* read and verify the first 1 - 256 blocks at the start of the LUN */
printf("Read+verify first 1-256 blocks ... ");
/* 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++) {
unsigned char *buf;
task = iscsi_read12_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
ret = verify12(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
buf = task->datain.data;
if (buf == NULL) {
printf("[FAILED]\n");
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
vtask = iscsi_verify12_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
if (vtask == NULL) {
printf("[FAILED]\n");
printf("Failed to send verify12 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
if (vtask->status == SCSI_STATUS_CHECK_CONDITION
&& vtask->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& vtask->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
ret = -2;
goto finished;
}
if (vtask->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Verify12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
goto test2;
}
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
}
printf("[OK]\n");
test2:
finished:
free(buf);
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;