test/iscsi: add pdu test

As part of this commit, stop building the iscsi
tests on FreeBSD.  This new pdu test links in
object files from the iscsi library, some of which
do not build currently on FreeBSD with our default
error/warning levels.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Icb6a3dc17aa62882d0477f7734d2701ea09a3f36
This commit is contained in:
Jim Harris 2016-11-22 12:47:04 -07:00
parent 97cc39e1ef
commit 4db2eb4053
7 changed files with 267 additions and 3 deletions

View File

@ -85,7 +85,6 @@ run_test test/lib/json/json.sh
run_test test/lib/jsonrpc/jsonrpc.sh run_test test/lib/jsonrpc/jsonrpc.sh
run_test test/lib/log/log.sh run_test test/lib/log/log.sh
run_test test/lib/scsi/scsi.sh run_test test/lib/scsi/scsi.sh
run_test test/lib/iscsi/iscsi.sh
run_test test/lib/util/util.sh run_test test/lib/util/util.sh
timing_exit lib timing_exit lib
@ -105,6 +104,8 @@ if [ $(uname -s) = Linux ]; then
run_test ./test/iscsi_tgt/ext4test/ext4test.sh run_test ./test/iscsi_tgt/ext4test/ext4test.sh
run_test ./test/iscsi_tgt/rbd/rbd.sh run_test ./test/iscsi_tgt/rbd/rbd.sh
timing_exit iscsi_tgt timing_exit iscsi_tgt
run_test test/lib/iscsi/iscsi.sh
fi fi
timing_enter nvmf timing_enter nvmf

View File

@ -34,7 +34,10 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
DIRS-y = bdev env event log iscsi json jsonrpc nvme nvmf scsi ioat util DIRS-y = bdev env event log json jsonrpc nvme nvmf scsi ioat util
ifeq ($(OS),Linux)
DIRS-y += iscsi
endif
.PHONY: all clean $(DIRS-y) .PHONY: all clean $(DIRS-y)

View File

@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
DIRS-y = param target_node DIRS-y = param pdu target_node
.PHONY: all clean $(DIRS-y) .PHONY: all clean $(DIRS-y)

View File

@ -159,3 +159,10 @@ void
spdk_scsi_task_set_status(struct spdk_scsi_task *task, int sc, int sk, int asc, int ascq) spdk_scsi_task_set_status(struct spdk_scsi_task *task, int sc, int sk, int asc, int ascq)
{ {
} }
void
spdk_scsi_task_set_data(struct spdk_scsi_task *task, void *data, uint32_t len)
{
task->iovs[0].iov_base = data;
task->iovs[0].iov_len = len;
}

View File

@ -16,4 +16,8 @@ timing_enter target_node
$testdir/target_node/target_node_ut $testdir/target_node/target_node.conf $testdir/target_node/target_node_ut $testdir/target_node/target_node.conf
timing_exit target_node timing_exit target_node
timing_enter pdu
$testdir/pdu/pdu
timing_exit pdu
timing_exit iscsi timing_exit iscsi

View File

@ -0,0 +1,59 @@
#
# BSD LICENSE
#
# Copyright (c) Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
SPDK_LIB_LIST = log util cunit trace conf
CFLAGS += $(DPDK_INC)
CFLAGS += -I$(SPDK_ROOT_DIR)/test
CFLAGS += -I$(SPDK_ROOT_DIR)/lib
LIBS += $(SPDK_LIB_LINKER_ARGS) $(ENV_LINKER_ARGS)
LIBS += -lcunit -lcrypto
ISCSI_OBJS = iscsi crc32c md5 param
OBJS += $(ISCSI_OBJS:%=$(SPDK_ROOT_DIR)/lib/iscsi/%.o)
APP = pdu
C_SRCS = pdu.c
all: $(APP)
$(APP): $(OBJS) $(SPDK_LIB_FILES)
$(LINK_C)
clean:
$(CLEAN_C) $(APP)
include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk

190
test/lib/iscsi/pdu/pdu.c Normal file
View File

@ -0,0 +1,190 @@
/*-
* BSD LICENSE
*
* Copyright (c) Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <spdk/endian.h>
#include "spdk/scsi.h"
#include "CUnit/Basic.h"
#include "../common.c"
#include "iscsi/acceptor.h"
#include "iscsi/portal_grp.h"
struct spdk_iscsi_tgt_node *
spdk_iscsi_find_tgt_node(const char *target_name)
{
return NULL;
}
int
spdk_iscsi_tgt_node_access(struct spdk_iscsi_conn *conn,
struct spdk_iscsi_tgt_node *target,
const char *iqn, const char *addr)
{
return 0;
}
int
spdk_iscsi_send_tgts(struct spdk_iscsi_conn *conn, const char *iiqn,
const char *iaddr,
const char *tiqn, uint8_t *data, int alloc_len, int data_len)
{
return 0;
}
void
spdk_iscsi_acceptor_stop(void)
{
}
int
spdk_iscsi_portal_grp_close_all(void)
{
return 0;
}
static void
maxburstlength_test(void)
{
struct spdk_iscsi_sess sess;
struct spdk_iscsi_conn conn;
struct spdk_scsi_dev dev;
struct spdk_scsi_lun lun;
struct spdk_iscsi_pdu *req_pdu;
struct spdk_iscsi_pdu *data_out_pdu;
struct iscsi_bhs_scsi_req *req;
struct iscsi_bhs_r2t *r2t;
struct iscsi_bhs_data_out *data_out;
struct spdk_iscsi_pdu *response_pdu;
int rc;
memset(&sess, 0, sizeof(sess));
memset(&conn, 0, sizeof(conn));
memset(&dev, 0, sizeof(dev));
memset(&lun, 0, sizeof(lun));
req_pdu = spdk_get_pdu();
data_out_pdu = spdk_get_pdu();
sess.ExpCmdSN = 0;
sess.MaxCmdSN = 64;
sess.session_type = SESSION_TYPE_NORMAL;
sess.MaxBurstLength = 1024;
lun.id = 0;
dev.maxlun = 1;
dev.lun[0] = &lun;
conn.full_feature = 1;
conn.sess = &sess;
conn.dev = &dev;
conn.state = ISCSI_CONN_STATE_RUNNING;
TAILQ_INIT(&conn.write_pdu_list);
TAILQ_INIT(&conn.active_r2t_tasks);
req_pdu->bhs.opcode = ISCSI_OP_SCSI;
req_pdu->data_segment_len = 0;
req = (struct iscsi_bhs_scsi_req *)&req_pdu->bhs;
to_be32(&req->cmd_sn, 0);
to_be32(&req->expected_data_xfer_len, 1028);
to_be32(&req->itt, 0x1234);
req->write = 1;
req->final = 1;
g_spdk_iscsi.MaxRecvDataSegmentLength = 1024;
rc = spdk_iscsi_execute(&conn, req_pdu);
CU_ASSERT_FATAL(rc == 0);
response_pdu = TAILQ_FIRST(&conn.write_pdu_list);
CU_ASSERT(response_pdu != NULL);
/*
* Confirm that a correct R2T reply was sent in reponse to the
* SCSI request.
*/
TAILQ_REMOVE(&conn.write_pdu_list, response_pdu, tailq);
CU_ASSERT(response_pdu->bhs.opcode == ISCSI_OP_R2T);
r2t = (struct iscsi_bhs_r2t *)&response_pdu->bhs;
CU_ASSERT(from_be32(&r2t->desired_xfer_len) == 1024);
CU_ASSERT(from_be32(&r2t->buffer_offset) == 0);
CU_ASSERT(from_be32(&r2t->itt) == 0x1234);
data_out_pdu->bhs.opcode = ISCSI_OP_SCSI_DATAOUT;
data_out_pdu->bhs.flags = ISCSI_FLAG_FINAL;
data_out_pdu->data_segment_len = 1028;
data_out = (struct iscsi_bhs_data_out *)&data_out_pdu->bhs;
data_out->itt = r2t->itt;
data_out->ttt = r2t->ttt;
DSET24(data_out->data_segment_len, 1028);
rc = spdk_iscsi_execute(&conn, data_out_pdu);
CU_ASSERT(rc == SPDK_ISCSI_CONNECTION_FATAL);
}
int
main(int argc, char **argv)
{
CU_pSuite suite = NULL;
unsigned int num_failures;
if (CU_initialize_registry() != CUE_SUCCESS) {
return CU_get_error();
}
suite = CU_add_suite("iscsi_suite", NULL, NULL);
if (suite == NULL) {
CU_cleanup_registry();
return CU_get_error();
}
if (
CU_add_test(suite, "maxburstlength test", maxburstlength_test) == NULL
) {
CU_cleanup_registry();
return CU_get_error();
}
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
num_failures = CU_get_number_of_failures();
CU_cleanup_registry();
return num_failures;
}