TESTS: convert READ6 tests to the new framework
This commit is contained in:
@@ -183,7 +183,10 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
|
||||
test-tool/test_read10_rdprotect.c \
|
||||
test-tool/test_read10_flags.c \
|
||||
test-tool/test_read10_invalid.c \
|
||||
test-tool/test_readcapacity10_simple.c
|
||||
test-tool/test_readcapacity10_simple.c \
|
||||
test-tool/test_read6_simple.c \
|
||||
test-tool/test_read6_beyond_eol.c \
|
||||
test-tool/test_read6_0blocks.c
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -940,6 +940,80 @@ prefetch16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
read6(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
uint32_t datalen, int blocksize,
|
||||
unsigned char *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send READ6 LBA:%d blocks:%d",
|
||||
lba, datalen / blocksize);
|
||||
|
||||
task = iscsi_read6_sync(iscsi, lun, lba, datalen, blocksize);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send READ6 command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] READ6 command: "
|
||||
"failed with sense. %s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (data != NULL) {
|
||||
memcpy(data, task->datain.data, task->datain.size);
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] READ6 returned SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
read6_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
uint32_t datalen, int blocksize,
|
||||
unsigned char *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send READ6 (Expecting LBA_OUT_OF_RANGE) "
|
||||
"LBA:%d blocks:%d",
|
||||
lba, datalen / blocksize);
|
||||
|
||||
task = iscsi_read6_sync(iscsi, lun, lba, datalen, blocksize);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send READ6 command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] READ6 successful but should "
|
||||
"have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
logging(LOG_NORMAL, "[FAILED] READ6 failed with wrong sense. "
|
||||
"Should have failed with ILLEGAL_REQUEST/"
|
||||
"LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (data != NULL) {
|
||||
memcpy(data, task->datain.data, task->datain.size);
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] READ6 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
read10(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
uint32_t datalen, int blocksize, int rdprotect,
|
||||
|
||||
@@ -119,6 +119,8 @@ int prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int
|
||||
int prefetch16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group);
|
||||
int prefetch16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group);
|
||||
int prefetch16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group);
|
||||
int read6(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, unsigned char *data);
|
||||
int read6_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, unsigned char *data);
|
||||
int read10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
|
||||
int read10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
|
||||
int read10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
|
||||
|
||||
@@ -62,6 +62,13 @@ static CU_TestInfo tests_testunitready[] = {
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_read6[] = {
|
||||
{ (char *)"testRead6Simple", test_read6_simple },
|
||||
{ (char *)"testRead6BeyondEol", test_read6_beyond_eol },
|
||||
{ (char *)"testRead6ZeroBlocks", test_read6_0blocks },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_read10[] = {
|
||||
{ (char *)"testRead10Simple", test_read10_simple },
|
||||
{ (char *)"testRead10BeyondEol", test_read10_beyond_eol },
|
||||
@@ -80,6 +87,8 @@ static CU_TestInfo tests_readcapacity10[] = {
|
||||
static CU_SuiteInfo suites[] = {
|
||||
{ (char *)"TestTestUnitReady", test_setup, test_teardown,
|
||||
tests_testunitready },
|
||||
{ (char *)"TestRead6", test_setup, test_teardown,
|
||||
tests_read6 },
|
||||
{ (char *)"TestRead10", test_setup, test_teardown,
|
||||
tests_read10 },
|
||||
{ (char *)"TestReadCapacity10", test_setup, test_teardown,
|
||||
|
||||
@@ -37,6 +37,12 @@ int test_teardown(void);
|
||||
|
||||
void test_testunitready_simple(void);
|
||||
|
||||
void test_read6_simple(void);
|
||||
void test_read6_beyond_eol(void);
|
||||
void test_read6_0blocks(void);
|
||||
void test_read6_rdprotect(void);
|
||||
void test_read6_flags(void);
|
||||
|
||||
void test_read10_simple(void);
|
||||
void test_read10_beyond_eol(void);
|
||||
void test_read10_0blocks(void);
|
||||
|
||||
45
test-tool/test_read6_0blocks.c
Normal file
45
test-tool/test_read6_0blocks.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
void
|
||||
test_read6_0blocks(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
logging(LOG_VERBOSE, "");
|
||||
logging(LOG_VERBOSE, "Test READ6 0-blocks at LBA==0");
|
||||
ret = read6(iscsic, tgt_lun, 0, 0, block_size, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
if (num_blocks > 0x1fffff) {
|
||||
CU_PASS("[SKIPPED] LUN is too big");
|
||||
return;
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ6 0-blocks one block past end-of-LUN");
|
||||
ret = read6_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0,
|
||||
block_size, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
64
test-tool/test_read6_beyond_eol.c
Normal file
64
test-tool/test_read6_beyond_eol.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
|
||||
void
|
||||
test_read6_beyond_eol(void)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
if (num_blocks >= 0x1fffff) {
|
||||
CU_PASS("LUN is too big for read-beyond-eol tests with READ6. Skipping test.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "");
|
||||
logging(LOG_VERBOSE, "Test READ6 1-255 blocks one block beyond the end");
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = read6_lbaoutofrange(iscsic, tgt_lun, num_blocks + 2 - i,
|
||||
i * block_size, block_size,
|
||||
NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ6 1-255 blocks at LBA==0x1fffff");
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = read6_lbaoutofrange(iscsic, tgt_lun, 0x1fffff,
|
||||
i * block_size, block_size,
|
||||
NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ6 2-255 blocks all but one block beyond the end");
|
||||
for (i = 2; i <= 255; i++) {
|
||||
ret = read6_lbaoutofrange(iscsic, tgt_lun, num_blocks,
|
||||
i * block_size, block_size,
|
||||
NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
}
|
||||
50
test-tool/test_read6_simple.c
Normal file
50
test-tool/test_read6_simple.c
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-support.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
|
||||
void
|
||||
test_read6_simple(void)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "");
|
||||
logging(LOG_VERBOSE, "Test READ6 of 1-255 blocks at the start of the LUN");
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = read6(iscsic, tgt_lun, 0, i * block_size,
|
||||
block_size, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test READ6 of 1-255 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 255; i++) {
|
||||
ret = read6(iscsic, tgt_lun, num_blocks +1 - i,
|
||||
i * block_size, block_size, NULL);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user