From 9aaf1e5de43c4814bd392722b84b22cd383a4076 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 22 Apr 2011 12:03:51 +1000 Subject: [PATCH] Add tests for invalid READ6 commands --- test-tool/0122_read6_invalid.c | 255 +++++++++++++++++++++++++++++++++ test-tool/Makefile | 2 +- test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 + 4 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 test-tool/0122_read6_invalid.c diff --git a/test-tool/0122_read6_invalid.c b/test-tool/0122_read6_invalid.c new file mode 100644 index 0000000..baedf96 --- /dev/null +++ b/test-tool/0122_read6_invalid.c @@ -0,0 +1,255 @@ +/* + Copyright (C) 2010 by 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 +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0122_read6_invalid(const char *initiator, const char *url) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct iscsi_data data; + char buf[512]; + int ret, lun; + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + + ret = 0; + + /* Try a read of 1 block but xferlength == 0 */ + printf("Read6 1 block but with iscsi ExpectedDataTransferLength==0 ... "); + + task = malloc(sizeof(struct scsi_task)); + if (task == NULL) { + printf("Failed to allocate task structure\n"); + ret = -1; + goto finished; + } + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ6; + task->cdb[4] = 1; + task->cdb_size = 6; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 0; + + if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read6 of 1 block with iscsi ExpectedDataTransferLength==0 should not fail.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test2; + } + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != 512) { + printf("[FAILED]\n"); + printf("Read6 returned incorrect residual overflow.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + + +test2: + /* Try a read of 1 block but xferlength == 1024 */ + printf("Read10 1 block but with iscsi ExpectedDataTransferLength==1024 ... "); + + task = malloc(sizeof(struct scsi_task)); + if (task == NULL) { + printf("Failed to allocate task structure\n"); + ret = -1; + goto finished; + } + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ6; + task->cdb[4] = 1; + task->cdb_size = 6; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 1024; + + if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read6 of 1 block with iscsi ExpectedDataTransferLength==1024 should not fail.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test3; + } + if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW || task->residual != 512) { + printf("[FAILED]\n"); + printf("Read6 returned incorrect residual underflow.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + + +test3: + /* Try a read of 1 block but xferlength == 200 */ + printf("Read6 1 block but with iscsi ExpectedDataTransferLength==200 ... "); + + task = malloc(sizeof(struct scsi_task)); + if (task == NULL) { + printf("Failed to allocate task structure\n"); + ret = -1; + goto finished; + } + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ6; + task->cdb[4] = 1; + task->cdb_size = 6; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 200; + + if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read6 of 1 block with iscsi ExpectedDataTransferLength==200 should not fail.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test4; + } + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != 312) { + printf("[FAILED]\n"); + printf("Read6 returned incorrect residual overflow.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +test4: + /* Try a read of 2 blocks but xferlength == 512 */ + printf("Read6 2 blocks but with iscsi ExpectedDataTransferLength==512 ... "); + + task = malloc(sizeof(struct scsi_task)); + if (task == NULL) { + printf("Failed to allocate task structure\n"); + ret = -1; + goto finished; + } + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ6; + task->cdb[4] = 2; + task->cdb_size = 6; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 512; + + if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read6 of 2 blocks with iscsi ExpectedDataTransferLength==512 should succeed.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW || task->residual != 512) { + printf("[FAILED]\n"); + printf("Read6 returned incorrect residual overflow.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto test5; + } + + scsi_free_scsi_task(task); + printf("[OK]\n"); + + +test5: + /* Try a read of 1 block but make it a data-out write on the iscsi layer */ + printf("Read6 of 1 block but sent as data-out write in iscsi layer ... "); + + task = malloc(sizeof(struct scsi_task)); + if (task == NULL) { + printf("Failed to allocate task structure\n"); + ret = -1; + goto finished; + } + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ6; + task->cdb[4] = 1; + task->cdb_size = 6; + task->xfer_dir = SCSI_XFER_WRITE; + task->expxferlen = sizeof(buf); + + data.size = sizeof(buf); + data.data = &buf[0]; + + if (iscsi_scsi_command_sync(iscsi, lun, task, &data) == NULL) { + printf("[FAILED]\n"); + printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi)); + ret = -1; + + goto finished; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Read6 of 1 block but iscsi data-out write should fail.\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +finished: + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return ret; +} diff --git a/test-tool/Makefile b/test-tool/Makefile index 49ef2dd..110c03c 100644 --- a/test-tool/Makefile +++ b/test-tool/Makefile @@ -4,7 +4,7 @@ CFLAGS=-g -O0 -fPIC -Wall -W -I. -I./include -I../include "-D_U_=__attribute__(( TESTS=0100_read10_simple.o 0101_read10_beyond_eol.o 0102_read10_0blocks.o \ 0103_read10_rdprotect.o 0104_read10_flags.o 0105_read10_invalid.o \ 0110_readcapacity10_simple.o 0111_readcapacity10_pmi.o \ -0120_read6_simple.o 0121_read6_beyond_eol.o +0120_read6_simple.o 0121_read6_beyond_eol.o 0122_read6_invalid.o all: iscsi-test diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index 4ae4d58..5e3f7d2 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -51,6 +51,7 @@ struct scsi_test tests[] = { /* read6*/ { "T0120_read6_simple", T0120_read6_simple }, { "T0121_read6_beyond_eol", T0121_read6_beyond_eol }, +{ "T0122_read6_invalid", T0122_read6_invalid }, { NULL, NULL } }; diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index b38ca97..24ccc74 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -32,3 +32,4 @@ int T0111_readcapacity10_pmi(const char *initiator, const char *url); int T0120_read6_simple(const char *initiator, const char *url); int T0121_read6_beyond_eol(const char *initiator, const char *url); +int T0122_read6_invalid(const char *initiator, const char *url);