Spdk/test/unit/lib/ftl/ftl_md/ftl_md_ut.c
Jim Harris 488570ebd4 Replace most BSD 3-clause license text with SPDX identifier.
Many open source projects have moved to using SPDX identifiers
to specify license information, reducing the amount of
boilerplate code in every source file.  This patch replaces
the bulk of SPDK .c, .cpp and Makefiles with the BSD-3-Clause
identifier.

Almost all of these files share the exact same license text,
and this patch only modifies the files that contain the
most common license text.  There can be slight variations
because the third clause contains company names - most say
"Intel Corporation", but there are instances for Nvidia,
Samsung, Eideticom and even "the copyright holder".

Used a bash script to automate replacement of the license text
with SPDX identifier which is checked into scripts/spdx.sh.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iaa88ab5e92ea471691dc298cfe41ebfb5d169780
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12904
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: <qun.wan@intel.com>
2022-06-09 07:35:12 +00:00

134 lines
3.1 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk/stdinc.h"
#include "spdk_cunit.h"
#include "common/lib/test_env.c"
#include "ftl/ftl_band.c"
#include "../common/utils.c"
#if defined(DEBUG)
DEFINE_STUB(ftl_band_validate_md, bool, (struct ftl_band *band), true);
#endif
DEFINE_STUB_V(ftl_apply_limits, (struct spdk_ftl_dev *dev));
DEFINE_STUB(ftl_io_init_internal, struct ftl_io *,
(const struct ftl_io_init_opts *opts), NULL);
DEFINE_STUB_V(ftl_io_read, (struct ftl_io *io));
DEFINE_STUB_V(ftl_io_write, (struct ftl_io *io));
DEFINE_STUB_V(ftl_reloc_add, (struct ftl_reloc *reloc, struct ftl_band *band, size_t offset,
size_t num_blocks, int prio, bool defrag));
struct base_bdev_geometry g_geo = {
.write_unit_size = 16,
.optimal_open_zones = 12,
.zone_size = 100,
.blockcnt = 1500 * 100 * 12,
};
static void
setup_band(struct ftl_band **band, const struct base_bdev_geometry *geo)
{
int rc;
struct spdk_ftl_dev *dev;
dev = test_init_ftl_dev(&g_geo);
*band = test_init_ftl_band(dev, 0, geo->zone_size);
rc = ftl_band_alloc_lba_map(*band);
SPDK_CU_ASSERT_FATAL(rc == 0);
(*band)->state = FTL_BAND_STATE_PREP;
ftl_band_clear_lba_map(*band);
}
static void
cleanup_band(struct ftl_band *band)
{
struct spdk_ftl_dev *dev = band->dev;
test_free_ftl_band(band);
test_free_ftl_dev(dev);
}
static void
test_md_unpack(void)
{
struct ftl_band *band;
struct ftl_lba_map *lba_map;
setup_band(&band, &g_geo);
lba_map = &band->lba_map;
SPDK_CU_ASSERT_FATAL(lba_map->dma_buf);
ftl_pack_head_md(band);
CU_ASSERT_EQUAL(ftl_unpack_head_md(band), FTL_MD_SUCCESS);
ftl_pack_tail_md(band);
CU_ASSERT_EQUAL(ftl_unpack_tail_md(band), FTL_MD_SUCCESS);
cleanup_band(band);
}
static void
test_md_unpack_fail(void)
{
struct ftl_band *band;
struct ftl_lba_map *lba_map;
struct ftl_md_hdr *hdr;
setup_band(&band, &g_geo);
lba_map = &band->lba_map;
SPDK_CU_ASSERT_FATAL(lba_map->dma_buf);
/* check crc */
ftl_pack_tail_md(band);
/* flip last bit of lba_map */
*((char *)lba_map->dma_buf + ftl_tail_md_num_blocks(band->dev) * FTL_BLOCK_SIZE - 1) ^= 0x1;
CU_ASSERT_EQUAL(ftl_unpack_tail_md(band), FTL_MD_INVALID_CRC);
/* check invalid version */
hdr = lba_map->dma_buf;
ftl_pack_tail_md(band);
hdr->ver++;
CU_ASSERT_EQUAL(ftl_unpack_tail_md(band), FTL_MD_INVALID_VER);
/* check wrong UUID */
ftl_pack_head_md(band);
hdr->uuid.u.raw[0] ^= 0x1;
CU_ASSERT_EQUAL(ftl_unpack_head_md(band), FTL_MD_NO_MD);
/* check invalid size */
ftl_pack_tail_md(band);
g_geo.zone_size--;
CU_ASSERT_EQUAL(ftl_unpack_tail_md(band), FTL_MD_INVALID_SIZE);
cleanup_band(band);
}
int
main(int argc, char **argv)
{
CU_pSuite suite = NULL;
unsigned int num_failures;
CU_set_error_action(CUEA_ABORT);
CU_initialize_registry();
suite = CU_add_suite("ftl_meta_suite", NULL, NULL);
CU_ADD_TEST(suite, test_md_unpack);
CU_ADD_TEST(suite, test_md_unpack_fail);
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
num_failures = CU_get_number_of_failures();
CU_cleanup_registry();
return num_failures;
}