2016-07-27 16:32:00 +00:00
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
#include "spdk_cunit.h"
|
|
|
|
|
2018-02-13 16:09:42 +00:00
|
|
|
#include "scsi/task.c"
|
|
|
|
#include "scsi/lun.c"
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:42:37 +00:00
|
|
|
#include "spdk_internal/mock.h"
|
2018-11-12 13:58:15 +00:00
|
|
|
/* These unit tests aren't multithreads, but we need to allocate threads since
|
|
|
|
* the lun.c code will register pollers.
|
|
|
|
*/
|
|
|
|
#include "common/lib/ut_multithread.c"
|
2017-08-29 23:42:37 +00:00
|
|
|
|
2017-05-16 20:03:11 +00:00
|
|
|
/* Unit test bdev mockup */
|
|
|
|
struct spdk_bdev {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
2018-11-29 08:19:56 +00:00
|
|
|
/* Unit test poller mockup */
|
|
|
|
struct spdk_poller {
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("scsi", SPDK_LOG_SCSI)
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
struct spdk_scsi_globals g_spdk_scsi;
|
|
|
|
|
|
|
|
static bool g_lun_execute_fail = false;
|
|
|
|
static int g_lun_execute_status = SPDK_SCSI_TASK_PENDING;
|
|
|
|
static uint32_t g_task_count = 0;
|
2017-01-16 13:18:12 +00:00
|
|
|
|
2018-08-31 21:02:11 +00:00
|
|
|
struct spdk_trace_histories *g_trace_histories;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB_V(_spdk_trace_record,
|
|
|
|
(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
|
|
|
|
uint32_t size, uint64_t object_id, uint64_t arg1));
|
2018-11-29 01:23:07 +00:00
|
|
|
|
2017-06-08 20:45:41 +00:00
|
|
|
static void
|
|
|
|
spdk_lun_ut_cpl_task(struct spdk_scsi_task *task)
|
|
|
|
{
|
2017-08-29 23:32:19 +00:00
|
|
|
SPDK_CU_ASSERT_FATAL(g_task_count > 0);
|
|
|
|
g_task_count--;
|
2017-06-08 20:45:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 19:14:12 +00:00
|
|
|
static void
|
|
|
|
spdk_lun_ut_free_task(struct spdk_scsi_task *task)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
static void
|
|
|
|
ut_init_task(struct spdk_scsi_task *task)
|
2016-07-27 16:32:00 +00:00
|
|
|
{
|
2017-08-29 23:32:19 +00:00
|
|
|
memset(task, 0, sizeof(*task));
|
2017-06-08 20:45:41 +00:00
|
|
|
spdk_scsi_task_construct(task, spdk_lun_ut_cpl_task,
|
2018-01-04 21:03:34 +00:00
|
|
|
spdk_lun_ut_free_task);
|
2017-05-13 00:16:44 +00:00
|
|
|
g_task_count++;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 16:28:45 +00:00
|
|
|
void
|
2016-11-14 19:14:12 +00:00
|
|
|
spdk_bdev_free_io(struct spdk_bdev_io *bdev_io)
|
2016-07-27 16:32:00 +00:00
|
|
|
{
|
2016-11-14 19:14:12 +00:00
|
|
|
CU_ASSERT(0);
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB(spdk_bdev_open, int,
|
|
|
|
(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_cb,
|
|
|
|
void *remove_ctx, struct spdk_bdev_desc **desc),
|
|
|
|
0);
|
2017-01-10 16:54:23 +00:00
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc));
|
2017-01-10 16:54:23 +00:00
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB(spdk_bdev_get_name, const char *,
|
|
|
|
(const struct spdk_bdev *bdev), "test");
|
2017-05-10 20:29:31 +00:00
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB_V(spdk_scsi_dev_queue_mgmt_task,
|
|
|
|
(struct spdk_scsi_dev *dev, struct spdk_scsi_task *task));
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB_V(spdk_scsi_dev_delete_lun,
|
|
|
|
(struct spdk_scsi_dev *dev, struct spdk_scsi_lun *lun));
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-07-09 06:24:26 +00:00
|
|
|
void
|
2018-01-04 22:45:01 +00:00
|
|
|
spdk_bdev_scsi_reset(struct spdk_scsi_task *task)
|
2016-07-27 16:32:00 +00:00
|
|
|
{
|
2018-11-28 00:47:45 +00:00
|
|
|
task->status = SPDK_SCSI_STATUS_GOOD;
|
|
|
|
task->response = SPDK_SCSI_TASK_MGMT_RESP_SUCCESS;
|
|
|
|
|
|
|
|
spdk_scsi_lun_complete_reset_task(task->lun, task);
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-01-04 22:45:01 +00:00
|
|
|
spdk_bdev_scsi_execute(struct spdk_scsi_task *task)
|
2016-07-27 16:32:00 +00:00
|
|
|
{
|
2017-12-07 23:23:48 +00:00
|
|
|
if (g_lun_execute_fail) {
|
2016-07-27 16:32:00 +00:00
|
|
|
return -EINVAL;
|
2017-12-07 23:23:48 +00:00
|
|
|
} else {
|
2017-01-06 16:18:15 +00:00
|
|
|
task->status = SPDK_SCSI_STATUS_GOOD;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (g_lun_execute_status == SPDK_SCSI_TASK_PENDING) {
|
2016-07-27 16:32:00 +00:00
|
|
|
return g_lun_execute_status;
|
2017-12-07 23:23:48 +00:00
|
|
|
} else if (g_lun_execute_status == SPDK_SCSI_TASK_COMPLETE) {
|
2016-07-27 16:32:00 +00:00
|
|
|
return g_lun_execute_status;
|
2017-12-07 23:23:48 +00:00
|
|
|
} else {
|
2016-07-27 16:32:00 +00:00
|
|
|
return 0;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 00:10:56 +00:00
|
|
|
DEFINE_STUB(spdk_bdev_get_io_channel, struct spdk_io_channel *,
|
|
|
|
(struct spdk_bdev_desc *desc), NULL);
|
2016-09-20 19:46:28 +00:00
|
|
|
|
2016-07-27 16:32:00 +00:00
|
|
|
static _spdk_scsi_lun *
|
|
|
|
lun_construct(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
struct spdk_bdev bdev;
|
|
|
|
|
2018-01-10 05:55:53 +00:00
|
|
|
lun = spdk_scsi_lun_construct(&bdev, NULL, NULL);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
SPDK_CU_ASSERT_FATAL(lun != NULL);
|
|
|
|
return lun;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_destruct(struct spdk_scsi_lun *lun)
|
|
|
|
{
|
2018-01-04 20:09:02 +00:00
|
|
|
/* LUN will defer its removal if there are any unfinished tasks */
|
|
|
|
SPDK_CU_ASSERT_FATAL(TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
2016-07-27 16:32:00 +00:00
|
|
|
spdk_scsi_lun_destruct(lun);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_task_mgmt_execute_abort_task_not_supported(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
|
|
|
struct spdk_scsi_task mgmt_task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
struct spdk_scsi_port initiator_port = { 0 };
|
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
uint8_t cdb[6] = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
lun->dev = &dev;
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&mgmt_task);
|
|
|
|
mgmt_task.lun = lun;
|
|
|
|
mgmt_task.initiator_port = &initiator_port;
|
2018-11-26 02:05:21 +00:00
|
|
|
mgmt_task.function = SPDK_SCSI_TASK_FUNC_ABORT_TASK;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
/* Params to add regular task to the lun->tasks */
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.lun = lun;
|
|
|
|
task.cdb = cdb;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-11-29 01:18:50 +00:00
|
|
|
spdk_scsi_lun_append_task(lun, &task);
|
|
|
|
spdk_scsi_lun_execute_tasks(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-04-24 18:14:41 +00:00
|
|
|
/* task should now be on the tasks list */
|
2016-07-27 16:32:00 +00:00
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
spdk_scsi_lun_append_mgmt_task(lun, &mgmt_task);
|
|
|
|
spdk_scsi_lun_execute_mgmt_task(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
/* task abort is not supported */
|
2017-08-29 23:32:19 +00:00
|
|
|
CU_ASSERT(mgmt_task.response == SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
/* task is still on the tasks list */
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 1);
|
2018-01-04 20:09:02 +00:00
|
|
|
|
|
|
|
spdk_scsi_lun_complete_task(lun, &task);
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_task_mgmt_execute_abort_task_all_not_supported(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
|
|
|
struct spdk_scsi_task mgmt_task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
struct spdk_scsi_port initiator_port = { 0 };
|
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
uint8_t cdb[6] = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
lun->dev = &dev;
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&mgmt_task);
|
|
|
|
mgmt_task.lun = lun;
|
|
|
|
mgmt_task.initiator_port = &initiator_port;
|
2018-11-26 02:05:21 +00:00
|
|
|
mgmt_task.function = SPDK_SCSI_TASK_FUNC_ABORT_TASK_SET;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
/* Params to add regular task to the lun->tasks */
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.initiator_port = &initiator_port;
|
|
|
|
task.lun = lun;
|
|
|
|
task.cdb = cdb;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-11-29 01:18:50 +00:00
|
|
|
spdk_scsi_lun_append_task(lun, &task);
|
|
|
|
spdk_scsi_lun_execute_tasks(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-04-24 18:14:41 +00:00
|
|
|
/* task should now be on the tasks list */
|
2016-07-27 16:32:00 +00:00
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
spdk_scsi_lun_append_mgmt_task(lun, &mgmt_task);
|
|
|
|
spdk_scsi_lun_execute_mgmt_task(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
/* task abort is not supported */
|
2017-08-29 23:32:19 +00:00
|
|
|
CU_ASSERT(mgmt_task.response == SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
/* task is still on the tasks list */
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 1);
|
2018-01-04 20:09:02 +00:00
|
|
|
|
|
|
|
spdk_scsi_lun_complete_task(lun, &task);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_task_mgmt_execute_lun_reset(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task mgmt_task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
lun->dev = &dev;
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&mgmt_task);
|
|
|
|
mgmt_task.lun = lun;
|
2018-11-26 02:05:21 +00:00
|
|
|
mgmt_task.function = SPDK_SCSI_TASK_FUNC_LUN_RESET;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
spdk_scsi_lun_append_mgmt_task(lun, &mgmt_task);
|
|
|
|
spdk_scsi_lun_execute_mgmt_task(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
/* Returns success */
|
2018-11-28 00:47:45 +00:00
|
|
|
CU_ASSERT_EQUAL(mgmt_task.status, SPDK_SCSI_STATUS_GOOD);
|
|
|
|
CU_ASSERT_EQUAL(mgmt_task.response, SPDK_SCSI_TASK_MGMT_RESP_SUCCESS);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
lun_destruct(lun);
|
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_task_mgmt_execute_invalid_case(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task mgmt_task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
lun->dev = &dev;
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&mgmt_task);
|
2018-11-26 02:05:21 +00:00
|
|
|
mgmt_task.function = 5;
|
|
|
|
|
2016-07-27 16:32:00 +00:00
|
|
|
/* Pass an invalid value to the switch statement */
|
2018-11-28 00:47:45 +00:00
|
|
|
spdk_scsi_lun_append_mgmt_task(lun, &mgmt_task);
|
|
|
|
spdk_scsi_lun_execute_mgmt_task(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-11-28 00:47:45 +00:00
|
|
|
/* function code is invalid */
|
|
|
|
CU_ASSERT_EQUAL(mgmt_task.response, SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
lun_destruct(lun);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_append_task_null_lun_task_cdb_spc_inquiry(void)
|
|
|
|
{
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
uint8_t cdb[6] = { 0 };
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.cdb = cdb;
|
|
|
|
task.cdb[0] = SPDK_SPC_INQUIRY;
|
2016-07-27 16:32:00 +00:00
|
|
|
/* alloc_len >= 4096 */
|
2017-08-29 23:32:19 +00:00
|
|
|
task.cdb[3] = 0xFF;
|
|
|
|
task.cdb[4] = 0xFF;
|
|
|
|
task.lun = NULL;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
spdk_scsi_task_process_null_lun(&task);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
CU_ASSERT_EQUAL(task.status, SPDK_SCSI_STATUS_GOOD);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-06-06 01:04:43 +00:00
|
|
|
spdk_scsi_task_put(&task);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
/* spdk_scsi_task_process_null_lun() does not call cpl_fn */
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 1);
|
|
|
|
g_task_count = 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_append_task_null_lun_alloc_len_lt_4096(void)
|
|
|
|
{
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
uint8_t cdb[6] = { 0 };
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.cdb = cdb;
|
|
|
|
task.cdb[0] = SPDK_SPC_INQUIRY;
|
2016-07-27 16:32:00 +00:00
|
|
|
/* alloc_len < 4096 */
|
2017-08-29 23:32:19 +00:00
|
|
|
task.cdb[3] = 0;
|
|
|
|
task.cdb[4] = 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
/* alloc_len is set to a minimal value of 4096
|
2017-05-05 20:15:51 +00:00
|
|
|
* Hence, buf of size 4096 is allocated */
|
2017-08-29 23:32:19 +00:00
|
|
|
spdk_scsi_task_process_null_lun(&task);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
CU_ASSERT_EQUAL(task.status, SPDK_SCSI_STATUS_GOOD);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2018-06-06 01:04:43 +00:00
|
|
|
spdk_scsi_task_put(&task);
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
/* spdk_scsi_task_process_null_lun() does not call cpl_fn */
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 1);
|
|
|
|
g_task_count = 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_append_task_null_lun_not_supported(void)
|
|
|
|
{
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
uint8_t cdb[6] = { 0 };
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.cdb = cdb;
|
|
|
|
task.lun = NULL;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
spdk_scsi_task_process_null_lun(&task);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
CU_ASSERT_EQUAL(task.status, SPDK_SCSI_STATUS_CHECK_CONDITION);
|
2016-07-27 16:32:00 +00:00
|
|
|
/* LUN not supported; task's data transferred should be 0 */
|
2017-08-29 23:32:19 +00:00
|
|
|
CU_ASSERT_EQUAL(task.data_transferred, 0);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
/* spdk_scsi_task_process_null_lun() does not call cpl_fn */
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 1);
|
|
|
|
g_task_count = 0;
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_execute_scsi_task_pending(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.lun = lun;
|
2016-07-27 16:32:00 +00:00
|
|
|
lun->dev = &dev;
|
|
|
|
|
|
|
|
g_lun_execute_fail = false;
|
|
|
|
g_lun_execute_status = SPDK_SCSI_TASK_PENDING;
|
|
|
|
|
2018-01-08 11:20:57 +00:00
|
|
|
/* the tasks list should still be empty since it has not been
|
2016-07-27 16:32:00 +00:00
|
|
|
executed yet
|
|
|
|
*/
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
2018-11-29 01:18:50 +00:00
|
|
|
spdk_scsi_lun_append_task(lun, &task);
|
|
|
|
spdk_scsi_lun_execute_tasks(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
/* Assert the task has been successfully added to the tasks queue */
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
/* task is still on the tasks list */
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 1);
|
2018-01-04 20:09:02 +00:00
|
|
|
|
|
|
|
/* Need to complete task so LUN might be removed right now */
|
|
|
|
spdk_scsi_lun_complete_task(lun, &task);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_execute_scsi_task_complete(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
2017-08-29 23:32:19 +00:00
|
|
|
struct spdk_scsi_task task = { 0 };
|
2016-07-27 16:32:00 +00:00
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
|
2017-08-29 23:32:19 +00:00
|
|
|
ut_init_task(&task);
|
|
|
|
task.lun = lun;
|
2016-07-27 16:32:00 +00:00
|
|
|
lun->dev = &dev;
|
|
|
|
|
|
|
|
g_lun_execute_fail = false;
|
|
|
|
g_lun_execute_status = SPDK_SCSI_TASK_COMPLETE;
|
|
|
|
|
2018-01-08 11:20:57 +00:00
|
|
|
/* the tasks list should still be empty since it has not been
|
2016-07-27 16:32:00 +00:00
|
|
|
executed yet
|
|
|
|
*/
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
2018-11-29 01:18:50 +00:00
|
|
|
spdk_scsi_lun_append_task(lun, &task);
|
|
|
|
spdk_scsi_lun_execute_tasks(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
/* Assert the task has not been added to the tasks queue */
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_destruct_success(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
|
2018-01-04 20:09:02 +00:00
|
|
|
spdk_scsi_lun_destruct(lun);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_construct_null_ctx(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
|
2018-01-10 05:55:53 +00:00
|
|
|
lun = spdk_scsi_lun_construct(NULL, NULL, NULL);
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
/* lun should be NULL since we passed NULL for the ctx pointer. */
|
|
|
|
CU_ASSERT(lun == NULL);
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_construct_success(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun = lun_construct();
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
2018-11-29 08:19:56 +00:00
|
|
|
static void
|
|
|
|
lun_reset_task_wait_scsi_task_complete(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
struct spdk_scsi_task task = { 0 };
|
|
|
|
struct spdk_scsi_task mgmt_task = { 0 };
|
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
lun->dev = &dev;
|
|
|
|
|
|
|
|
ut_init_task(&task);
|
|
|
|
task.lun = lun;
|
|
|
|
|
|
|
|
g_lun_execute_fail = false;
|
|
|
|
g_lun_execute_status = SPDK_SCSI_TASK_PENDING;
|
|
|
|
|
|
|
|
ut_init_task(&mgmt_task);
|
|
|
|
mgmt_task.lun = lun;
|
|
|
|
mgmt_task.function = SPDK_SCSI_TASK_FUNC_LUN_RESET;
|
|
|
|
|
|
|
|
/* Append a task to the pending task list. */
|
|
|
|
spdk_scsi_lun_append_task(lun, &task);
|
|
|
|
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->pending_tasks));
|
|
|
|
|
|
|
|
/* Execute the task but it is still in the task list. */
|
|
|
|
spdk_scsi_lun_execute_tasks(lun);
|
|
|
|
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->pending_tasks));
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
|
|
|
/* Append a reset task to the pending mgmt task list. */
|
|
|
|
spdk_scsi_lun_append_mgmt_task(lun, &mgmt_task);
|
|
|
|
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->pending_mgmt_tasks));
|
|
|
|
|
|
|
|
/* Execute the reset task */
|
|
|
|
spdk_scsi_lun_execute_mgmt_task(lun);
|
|
|
|
|
|
|
|
/* The reset task should be still on the submitted mgmt task list and
|
|
|
|
* a poller is created because the task prior to the reset task is pending.
|
|
|
|
*/
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->mgmt_tasks));
|
|
|
|
CU_ASSERT(lun->reset_poller != NULL);
|
|
|
|
|
|
|
|
/* Execute the poller to check if the task prior to the reset task complete. */
|
|
|
|
spdk_scsi_lun_reset_check_outstanding_tasks(&mgmt_task);
|
|
|
|
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->mgmt_tasks));
|
|
|
|
CU_ASSERT(lun->reset_poller != NULL);
|
|
|
|
|
|
|
|
/* Complete the task. */
|
|
|
|
spdk_scsi_lun_complete_task(lun, &task);
|
|
|
|
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
|
|
|
/* Execute the poller to check if the task prior to the reset task complete. */
|
|
|
|
spdk_scsi_lun_reset_check_outstanding_tasks(&mgmt_task);
|
|
|
|
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->mgmt_tasks));
|
|
|
|
CU_ASSERT(lun->reset_poller == NULL);
|
|
|
|
CU_ASSERT_EQUAL(mgmt_task.status, SPDK_SCSI_STATUS_GOOD);
|
|
|
|
CU_ASSERT_EQUAL(mgmt_task.response, SPDK_SCSI_TASK_MGMT_RESP_SUCCESS);
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lun_reset_task_suspend_scsi_task(void)
|
|
|
|
{
|
|
|
|
struct spdk_scsi_lun *lun;
|
|
|
|
struct spdk_scsi_task task = { 0 };
|
|
|
|
struct spdk_scsi_task mgmt_task = { 0 };
|
|
|
|
struct spdk_scsi_dev dev = { 0 };
|
|
|
|
|
|
|
|
lun = lun_construct();
|
|
|
|
lun->dev = &dev;
|
|
|
|
|
|
|
|
ut_init_task(&task);
|
|
|
|
task.lun = lun;
|
|
|
|
|
|
|
|
g_lun_execute_fail = false;
|
|
|
|
g_lun_execute_status = SPDK_SCSI_TASK_COMPLETE;
|
|
|
|
|
|
|
|
ut_init_task(&mgmt_task);
|
|
|
|
mgmt_task.lun = lun;
|
|
|
|
mgmt_task.function = SPDK_SCSI_TASK_FUNC_LUN_RESET;
|
|
|
|
|
|
|
|
/* Append a reset task to the pending mgmt task list. */
|
|
|
|
spdk_scsi_lun_append_mgmt_task(lun, &mgmt_task);
|
|
|
|
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->pending_mgmt_tasks));
|
|
|
|
|
|
|
|
/* Append a task to the pending task list. */
|
|
|
|
spdk_scsi_lun_append_task(lun, &task);
|
|
|
|
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->pending_tasks));
|
|
|
|
|
|
|
|
/* Execute the task but it is still on the pending task list. */
|
|
|
|
spdk_scsi_lun_execute_tasks(lun);
|
|
|
|
|
|
|
|
CU_ASSERT(!TAILQ_EMPTY(&lun->pending_tasks));
|
|
|
|
|
|
|
|
/* Execute the reset task. The task will be executed then. */
|
|
|
|
spdk_scsi_lun_execute_mgmt_task(lun);
|
|
|
|
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->mgmt_tasks));
|
|
|
|
CU_ASSERT(lun->reset_poller == NULL);
|
|
|
|
CU_ASSERT_EQUAL(mgmt_task.status, SPDK_SCSI_STATUS_GOOD);
|
|
|
|
CU_ASSERT_EQUAL(mgmt_task.response, SPDK_SCSI_TASK_MGMT_RESP_SUCCESS);
|
|
|
|
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->pending_tasks));
|
|
|
|
CU_ASSERT(TAILQ_EMPTY(&lun->tasks));
|
|
|
|
|
|
|
|
lun_destruct(lun);
|
|
|
|
|
|
|
|
CU_ASSERT_EQUAL(g_task_count, 0);
|
|
|
|
}
|
|
|
|
|
2016-07-27 16:32:00 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
CU_pSuite suite = NULL;
|
2018-03-02 19:49:36 +00:00
|
|
|
unsigned int num_failures;
|
2016-07-27 16:32:00 +00:00
|
|
|
|
|
|
|
if (CU_initialize_registry() != CUE_SUCCESS) {
|
|
|
|
return CU_get_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
suite = CU_add_suite("lun_suite", NULL, NULL);
|
|
|
|
if (suite == NULL) {
|
|
|
|
CU_cleanup_registry();
|
|
|
|
return CU_get_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2018-11-28 00:47:45 +00:00
|
|
|
CU_add_test(suite, "task management abort task - not supported",
|
|
|
|
lun_task_mgmt_execute_abort_task_not_supported) == NULL
|
2016-07-27 16:32:00 +00:00
|
|
|
|| CU_add_test(suite, "task management abort task set - success",
|
|
|
|
lun_task_mgmt_execute_abort_task_all_not_supported) == NULL
|
|
|
|
|| CU_add_test(suite, "task management - lun reset success",
|
|
|
|
lun_task_mgmt_execute_lun_reset) == NULL
|
|
|
|
|| CU_add_test(suite, "task management - invalid option",
|
|
|
|
lun_task_mgmt_execute_invalid_case) == NULL
|
|
|
|
|| CU_add_test(suite, "append task - null lun SPDK_SPC_INQUIRY",
|
|
|
|
lun_append_task_null_lun_task_cdb_spc_inquiry) == NULL
|
|
|
|
|| CU_add_test(suite, "append task - allocated length less than 4096",
|
|
|
|
lun_append_task_null_lun_alloc_len_lt_4096) == NULL
|
|
|
|
|| CU_add_test(suite, "append task - unsupported lun",
|
|
|
|
lun_append_task_null_lun_not_supported) == NULL
|
|
|
|
|| CU_add_test(suite, "execute task - scsi task pending",
|
|
|
|
lun_execute_scsi_task_pending) == NULL
|
|
|
|
|| CU_add_test(suite, "execute task - scsi task complete",
|
|
|
|
lun_execute_scsi_task_complete) == NULL
|
|
|
|
|| CU_add_test(suite, "destruct task - success", lun_destruct_success) == NULL
|
|
|
|
|| CU_add_test(suite, "construct - null ctx", lun_construct_null_ctx) == NULL
|
|
|
|
|| CU_add_test(suite, "construct - success", lun_construct_success) == NULL
|
2018-11-29 08:19:56 +00:00
|
|
|
|| CU_add_test(suite, "reset task wait for prior task completion",
|
|
|
|
lun_reset_task_wait_scsi_task_complete) == NULL
|
|
|
|
|| CU_add_test(suite, "reset task suspend subsequent scsi task",
|
|
|
|
lun_reset_task_suspend_scsi_task) == NULL
|
2016-07-27 16:32:00 +00:00
|
|
|
) {
|
|
|
|
CU_cleanup_registry();
|
|
|
|
return CU_get_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
CU_basic_set_mode(CU_BRM_VERBOSE);
|
2018-11-12 13:58:15 +00:00
|
|
|
allocate_threads(1);
|
|
|
|
set_thread(0);
|
2016-07-27 16:32:00 +00:00
|
|
|
CU_basic_run_tests();
|
2018-11-12 13:58:15 +00:00
|
|
|
free_threads();
|
2016-07-27 16:32:00 +00:00
|
|
|
num_failures = CU_get_number_of_failures();
|
|
|
|
CU_cleanup_registry();
|
|
|
|
return num_failures;
|
|
|
|
}
|