diff --git a/Makefile.am b/Makefile.am index 98b40f2..8fda3be 100644 --- a/Makefile.am +++ b/Makefile.am @@ -237,11 +237,13 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/test_read12_0blocks.c \ test-tool/test_read12_rdprotect.c \ test-tool/test_read12_flags.c \ + test-tool/test_read12_residuals.c \ test-tool/test_read16_simple.c \ test-tool/test_read16_beyond_eol.c \ test-tool/test_read16_0blocks.c \ test-tool/test_read16_rdprotect.c \ test-tool/test_read16_flags.c \ + test-tool/test_read16_residuals.c \ test-tool/test_readcapacity10_simple.c \ test-tool/test_readcapacity16_simple.c \ test-tool/test_readcapacity16_alloclen.c \ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 699148a..183f4b5 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -187,6 +187,7 @@ static CU_TestInfo tests_read12[] = { { (char *)"testRead12ZeroBlocks", test_read12_0blocks }, { (char *)"testRead12ReadProtect", test_read12_rdprotect }, { (char *)"testRead12Flags", test_read12_flags }, + { (char *)"testRead12Residuals", test_read12_residuals }, CU_TEST_INFO_NULL }; @@ -196,6 +197,7 @@ static CU_TestInfo tests_read16[] = { { (char *)"testRead16ZeroBlocks", test_read16_0blocks }, { (char *)"testRead16ReadProtect", test_read16_rdprotect }, { (char *)"testRead16Flags", test_read16_flags }, + { (char *)"testRead16Residuals", test_read16_residuals }, CU_TEST_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 30b3d76..22bab0d 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -114,12 +114,14 @@ void test_read12_beyond_eol(void); void test_read12_0blocks(void); void test_read12_rdprotect(void); void test_read12_flags(void); +void test_read12_residuals(void); void test_read16_simple(void); void test_read16_beyond_eol(void); void test_read16_0blocks(void); void test_read16_rdprotect(void); void test_read16_flags(void); +void test_read16_residuals(void); void test_readcapacity10_simple(void); diff --git a/test-tool/test_read10_residuals.c b/test-tool/test_read10_residuals.c index 928af8a..aadff5f 100644 --- a/test-tool/test_read10_residuals.c +++ b/test-tool/test_read10_residuals.c @@ -1,4 +1,8 @@ /* + Copyright (C) 2013 by Ronnie Sahlberg + + Based on test_read10_invalid.c : + Copyright (C) 2012 by Lee Duncan This program is free software; you can redistribute it and/or modify diff --git a/test-tool/test_read12_residuals.c b/test-tool/test_read12_residuals.c new file mode 100644 index 0000000..e729dac --- /dev/null +++ b/test-tool/test_read12_residuals.c @@ -0,0 +1,226 @@ +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "iscsi-private.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + + +void +test_read12_residuals(void) +{ + struct scsi_task *task_ret; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test READ12 commands with residuals"); + logging(LOG_VERBOSE, "Block size is %zu", block_size); + + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ12; + task->cdb[9] = 1; + task->cdb_size = 12; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 0; + + /* + * we dont want autoreconnect since some targets will drop the session + * on this condition. + */ + iscsi_set_noautoreconnect(iscsic, 1); + + + logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0"); + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify residual overflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "overflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + + logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow", + block_size); + if (task->residual != block_size) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + block_size, task->residual); + } + CU_ASSERT_EQUAL(task->residual, block_size); + scsi_free_scsi_task(task); + task = NULL; + + /* in case the previous test failed the session */ + iscsi_set_noautoreconnect(iscsic, 0); + + + logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000"); + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ12; + task->cdb[9] = 1; + task->cdb_size = 12; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 10000; + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify we got one whole block back from the target"); + if (task->datain.size != (int)block_size) { + logging(LOG_VERBOSE, "[FAILED] Target returned %u bytes " + "of data but should have returned %zu bytes.", + task->datain.size,block_size); + } + CU_ASSERT_EQUAL(task->datain.size, (int)block_size); + + logging(LOG_VERBOSE, "Verify residual underflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "underflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW); + + logging(LOG_VERBOSE, "Verify we got %zu bytes of residual underflow", + 10000 - block_size); + if (task->residual != 10000 - block_size) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + 10000 - block_size, task->residual); + } + CU_ASSERT_EQUAL(task->residual, 10000 - block_size); + scsi_free_scsi_task(task); + task = NULL; + + + logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==200"); + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ12; + task->cdb[9] = 1; + task->cdb_size = 12; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 200; + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify we got 200 bytes back from the target"); + CU_ASSERT_EQUAL(task->datain.size, 200); + + logging(LOG_VERBOSE, "Verify residual overflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "overflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + + logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow", + block_size - 200); + if (task->residual != block_size - 200) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + block_size - 200, task->residual); + } + CU_ASSERT_EQUAL(task->residual, block_size - 200); + + scsi_free_scsi_task(task); + task = NULL; + + + + logging(LOG_VERBOSE, "Try reading two blocks but iSCSI expected " + "transfer length==%zu (==one block)", block_size); + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ12; + task->cdb[9] = 2; + task->cdb_size = 12; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = block_size; + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify we got one whole block back from the target"); + CU_ASSERT_EQUAL(task->datain.size, (int)block_size); + + logging(LOG_VERBOSE, "Verify residual overflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "overflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + + logging(LOG_VERBOSE, "Verify we got one block of residual overflow"); + if (task->residual != block_size) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + block_size, task->residual); + } + CU_ASSERT_EQUAL(task->residual, block_size); + + scsi_free_scsi_task(task); + task = NULL; +} diff --git a/test-tool/test_read16_residuals.c b/test-tool/test_read16_residuals.c new file mode 100644 index 0000000..1a7b9fc --- /dev/null +++ b/test-tool/test_read16_residuals.c @@ -0,0 +1,226 @@ +/* + Copyright (C) 2013 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 + +#include "iscsi.h" +#include "iscsi-private.h" +#include "scsi-lowlevel.h" +#include "iscsi-test-cu.h" + + +void +test_read16_residuals(void) +{ + struct scsi_task *task_ret; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test READ16 commands with residuals"); + logging(LOG_VERBOSE, "Block size is %zu", block_size); + + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ16; + task->cdb[13] = 1; + task->cdb_size = 16; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 0; + + /* + * we dont want autoreconnect since some targets will drop the session + * on this condition. + */ + iscsi_set_noautoreconnect(iscsic, 1); + + + logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0"); + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify residual overflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "overflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + + logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow", + block_size); + if (task->residual != block_size) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + block_size, task->residual); + } + CU_ASSERT_EQUAL(task->residual, block_size); + scsi_free_scsi_task(task); + task = NULL; + + /* in case the previous test failed the session */ + iscsi_set_noautoreconnect(iscsic, 0); + + + logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000"); + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ16; + task->cdb[13] = 1; + task->cdb_size = 16; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 10000; + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify we got one whole block back from the target"); + if (task->datain.size != (int)block_size) { + logging(LOG_VERBOSE, "[FAILED] Target returned %u bytes " + "of data but should have returned %zu bytes.", + task->datain.size,block_size); + } + CU_ASSERT_EQUAL(task->datain.size, (int)block_size); + + logging(LOG_VERBOSE, "Verify residual underflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "underflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW); + + logging(LOG_VERBOSE, "Verify we got %zu bytes of residual underflow", + 10000 - block_size); + if (task->residual != 10000 - block_size) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + 10000 - block_size, task->residual); + } + CU_ASSERT_EQUAL(task->residual, 10000 - block_size); + scsi_free_scsi_task(task); + task = NULL; + + + logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==200"); + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ16; + task->cdb[13] = 1; + task->cdb_size = 16; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = 200; + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify we got 200 bytes back from the target"); + CU_ASSERT_EQUAL(task->datain.size, 200); + + logging(LOG_VERBOSE, "Verify residual overflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "overflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + + logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow", + block_size - 200); + if (task->residual != block_size - 200) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + block_size - 200, task->residual); + } + CU_ASSERT_EQUAL(task->residual, block_size - 200); + + scsi_free_scsi_task(task); + task = NULL; + + + + logging(LOG_VERBOSE, "Try reading two blocks but iSCSI expected " + "transfer length==%zu (==one block)", block_size); + task = malloc(sizeof(struct scsi_task)); + CU_ASSERT_PTR_NOT_NULL(task); + + memset(task, 0, sizeof(struct scsi_task)); + task->cdb[0] = SCSI_OPCODE_READ16; + task->cdb[13] = 2; + task->cdb_size = 16; + task->xfer_dir = SCSI_XFER_READ; + task->expxferlen = block_size; + + task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + CU_ASSERT_PTR_NOT_NULL(task_ret); + + logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); + if (task->status != SCSI_STATUS_GOOD) { + logging(LOG_VERBOSE, "[FAILED] Target returned error %s", + iscsi_get_error(iscsic)); + } + CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); + + logging(LOG_VERBOSE, "Verify we got one whole block back from the target"); + CU_ASSERT_EQUAL(task->datain.size, (int)block_size); + + logging(LOG_VERBOSE, "Verify residual overflow flag is set"); + if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) { + logging(LOG_VERBOSE, "[FAILED] Target did not set residual " + "overflow flag"); + } + CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + + logging(LOG_VERBOSE, "Verify we got one block of residual overflow"); + if (task->residual != block_size) { + logging(LOG_VERBOSE, "[FAILED] Target did not set correct " + "amount of residual. Expected %zu but got %zu.", + block_size, task->residual); + } + CU_ASSERT_EQUAL(task->residual, block_size); + + scsi_free_scsi_task(task); + task = NULL; +}