Commit 64c30c0f authored by Wojciech Malikowski's avatar Wojciech Malikowski Committed by Jim Harris
Browse files

test/unit/ftl: Add module unit tests for relocate



Change-Id: Iabe45ecc7dc52d45b792a1a5b1e42bb511c13a89
Signed-off-by: default avatarWojciech Malikowski <wojciech.malikowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443238


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
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 467debe3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

DIRS-y = ftl_rwb.c ftl_ppa ftl_band.c
DIRS-y = ftl_rwb.c ftl_ppa ftl_band.c ftl_reloc.c

.PHONY: all clean $(DIRS-y)

+14 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
 */

#include "spdk/ftl.h"
#include "ftl/ftl_core.h"

static struct spdk_ftl_dev *
test_init_ftl_dev(const struct spdk_ocssd_geometry_data *geo,
@@ -115,3 +116,16 @@ test_free_ftl_band(struct ftl_band *band)
	free(band->chunk_buf);
	free(band->md.lba_map);
}

static uint64_t
test_offset_from_ppa(struct ftl_ppa ppa, struct ftl_band *band)
{
	struct spdk_ftl_dev *dev = band->dev;
	unsigned int punit;

	/* TODO: ftl_ppa_flatten_punit should return uint32_t */
	punit = ftl_ppa_flatten_punit(dev, ppa);
	CU_ASSERT_EQUAL(ppa.chk, band->id);

	return punit * ftl_dev_lbks_in_chunk(dev) + ppa.lbk;
}
+7 −20
Original line number Diff line number Diff line
@@ -88,19 +88,6 @@ ppa_from_punit(uint64_t punit)
	return ppa;
}

static uint64_t
offset_from_ppa(struct ftl_ppa ppa, struct ftl_band *band)
{
	struct spdk_ftl_dev *dev = band->dev;
	unsigned int punit;

	/* TODO: ftl_ppa_flatten_punit should return uint32_t */
	punit = ftl_ppa_flatten_punit(dev, ppa);
	CU_ASSERT_EQUAL(ppa.chk, band->id);

	return punit * ftl_dev_lbks_in_chunk(dev) + ppa.lbk;
}

static void
test_band_lbkoff_from_ppa_base(void)
{
@@ -134,7 +121,7 @@ test_band_lbkoff_from_ppa_lbk(void)

			offset = ftl_band_lbkoff_from_ppa(g_band, ppa);

			expect = offset_from_ppa(ppa, g_band);
			expect = test_offset_from_ppa(ppa, g_band);
			CU_ASSERT_EQUAL(offset, expect);
		}
	}
@@ -177,7 +164,7 @@ test_band_set_addr(void)

	CU_ASSERT_EQUAL(md->num_vld, 0);

	offset = offset_from_ppa(ppa, g_band);
	offset = test_offset_from_ppa(ppa, g_band);

	ftl_band_set_addr(g_band, TEST_LBA, ppa);
	CU_ASSERT_EQUAL(md->num_vld, 1);
@@ -185,13 +172,13 @@ test_band_set_addr(void)
	CU_ASSERT_TRUE(spdk_bit_array_get(md->vld_map, offset));

	ppa.pu++;
	offset = offset_from_ppa(ppa, g_band);
	offset = test_offset_from_ppa(ppa, g_band);
	ftl_band_set_addr(g_band, TEST_LBA + 1, ppa);
	CU_ASSERT_EQUAL(md->num_vld, 2);
	CU_ASSERT_EQUAL(md->lba_map[offset], TEST_LBA + 1);
	CU_ASSERT_TRUE(spdk_bit_array_get(md->vld_map, offset));
	ppa.pu--;
	offset = offset_from_ppa(ppa, g_band);
	offset = test_offset_from_ppa(ppa, g_band);
	CU_ASSERT_TRUE(spdk_bit_array_get(md->vld_map, offset));
	cleanup_band();
}
@@ -207,7 +194,7 @@ test_invalidate_addr(void)
	md = &g_band->md;
	ppa = ppa_from_punit(g_range.begin);
	ppa.chk = TEST_BAND_IDX;
	offset[0] = offset_from_ppa(ppa, g_band);
	offset[0] = test_offset_from_ppa(ppa, g_band);

	ftl_band_set_addr(g_band, TEST_LBA, ppa);
	CU_ASSERT_EQUAL(md->num_vld, 1);
@@ -216,10 +203,10 @@ test_invalidate_addr(void)
	CU_ASSERT_EQUAL(md->num_vld, 0);
	CU_ASSERT_FALSE(spdk_bit_array_get(md->vld_map, offset[0]));

	offset[0] = offset_from_ppa(ppa, g_band);
	offset[0] = test_offset_from_ppa(ppa, g_band);
	ftl_band_set_addr(g_band, TEST_LBA, ppa);
	ppa.pu++;
	offset[1] = offset_from_ppa(ppa, g_band);
	offset[1] = test_offset_from_ppa(ppa, g_band);
	ftl_band_set_addr(g_band, TEST_LBA + 1, ppa);
	CU_ASSERT_EQUAL(md->num_vld, 2);
	CU_ASSERT_TRUE(spdk_bit_array_get(md->vld_map, offset[0]));
+1 −0
Original line number Diff line number Diff line
ftl_reloc_ut
+38 −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)/../../../../..)

TEST_FILE = ftl_reloc_ut.c

include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk
Loading