Commit 70b86ec9 authored by Wojciech Malikowski's avatar Wojciech Malikowski Committed by Ben Walker
Browse files

ftl: Added unit tests for FTL library



This patch implements unit tests for the following modules:
 * band
 * PPA (Physical Page Address) translations
 * write buffer

Change-Id: Ia7292bd3027347e8a3da77dafe71cde2c016bf38
Signed-off-by: default avatarWojciech Malikowski <wojciech.malikowski@intel.com>
Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-on: https://review.gerrithub.io/c/431328


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 05b43152
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ extern "C" {
#include <sys/un.h>
#include <sys/user.h>
#include <sys/wait.h>
#include <regex.h>

/* GNU extension */
#include <getopt.h>
+2 −0
Original line number Diff line number Diff line
@@ -167,7 +167,9 @@ ftl_rwb_batch_init(struct ftl_rwb *rwb, struct ftl_rwb_batch *batch, unsigned in
	return 0;
error:
	free(batch->entries);
	batch->entries = NULL;
	spdk_dma_free(batch->buffer);
	batch->buffer = NULL;
	return -1;
}

+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ DIRS-$(CONFIG_REDUCE) += reduce
ifeq ($(OS),Linux)
DIRS-$(CONFIG_VHOST) += vhost
endif
DIRS-$(CONFIG_FTL) += ftl

.PHONY: all clean $(DIRS-y)

+44 −0
Original line number Diff line number Diff line
#
#  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

DIRS-y = ftl_rwb.c ftl_ppa ftl_band.c

.PHONY: all clean $(DIRS-y)

all: $(DIRS-y)
clean: $(DIRS-y)

include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk
+117 −0
Original line number Diff line number Diff line
/*-
 *   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 "spdk/ftl.h"

static struct spdk_ftl_dev *
test_init_ftl_dev(const struct spdk_ocssd_geometry_data *geo,
		  const struct spdk_ftl_punit_range *range)
{
	struct spdk_ftl_dev *dev;
	unsigned int punit;

	dev = calloc(1, sizeof(*dev));
	SPDK_CU_ASSERT_FATAL(dev != NULL);

	dev->xfer_size = geo->ws_opt;
	dev->geo = *geo;
	dev->range = *range;

	dev->bands = calloc(geo->num_chk, sizeof(*dev->bands));
	SPDK_CU_ASSERT_FATAL(dev->bands != NULL);

	dev->punits = calloc(ftl_dev_num_punits(dev), sizeof(*dev->punits));
	SPDK_CU_ASSERT_FATAL(dev->punits != NULL);

	for (size_t i = 0; i < ftl_dev_num_punits(dev); ++i) {
		punit = range->begin + i;
		dev->punits[i].dev = dev;
		dev->punits[i].start_ppa.grp = punit % geo->num_grp;
		dev->punits[i].start_ppa.pu = punit / geo->num_grp;
	}

	return dev;
}

static struct ftl_band *
test_init_ftl_band(struct spdk_ftl_dev *dev, size_t id)
{
	struct ftl_band *band;
	struct ftl_chunk *chunk;

	SPDK_CU_ASSERT_FATAL(dev != NULL);
	SPDK_CU_ASSERT_FATAL(id < dev->geo.num_chk);

	band = &dev->bands[id];
	band->dev = dev;
	band->id = id;
	CIRCLEQ_INIT(&band->chunks);

	band->md.vld_map = spdk_bit_array_create(ftl_num_band_lbks(dev));
	SPDK_CU_ASSERT_FATAL(band->md.vld_map != NULL);

	band->chunk_buf = calloc(ftl_dev_num_punits(dev), sizeof(*band->chunk_buf));
	SPDK_CU_ASSERT_FATAL(band->chunk_buf != NULL);

	for (size_t i = 0; i < ftl_dev_num_punits(dev); ++i) {
		chunk = &band->chunk_buf[i];
		chunk->pos = i;
		chunk->state = FTL_CHUNK_STATE_CLOSED;
		chunk->punit = &dev->punits[i];
		chunk->start_ppa = dev->punits[i].start_ppa;
		chunk->start_ppa.chk = band->id;
		CIRCLEQ_INSERT_TAIL(&band->chunks, chunk, circleq);
		band->num_chunks++;
	}

	pthread_spin_init(&band->md.lock, PTHREAD_PROCESS_PRIVATE);
	return band;
}

static void
test_free_ftl_dev(struct spdk_ftl_dev *dev)
{
	SPDK_CU_ASSERT_FATAL(dev != NULL);
	free(dev->punits);
	free(dev->bands);
	free(dev);
}

static void
test_free_ftl_band(struct ftl_band *band)
{
	SPDK_CU_ASSERT_FATAL(band != NULL);
	spdk_bit_array_free(&band->md.vld_map);
	free(band->chunk_buf);
	free(band->md.lba_map);
}
Loading