FTL: Add mempool tests
Signed-off-by: Kozlowski Mateusz <mateusz.kozlowski@intel.com> Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Change-Id: I21bc22b53e4bb43077220e4ec21891758d94cbfa Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13304 Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
b431640409
commit
0da057a424
@ -6,7 +6,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
DIRS-y = ftl_mngt
|
||||
DIRS-y = ftl_mempool.c ftl_mngt
|
||||
|
||||
.PHONY: all clean $(DIRS-y)
|
||||
|
||||
|
1
test/unit/lib/ftl/ftl_mempool.c/.gitignore
vendored
Normal file
1
test/unit/lib/ftl/ftl_mempool.c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
ftl_mempool_ut
|
10
test/unit/lib/ftl/ftl_mempool.c/Makefile
Normal file
10
test/unit/lib/ftl/ftl_mempool.c/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||
|
||||
TEST_FILE = ftl_mempool_ut.c
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk
|
95
test/unit/lib/ftl/ftl_mempool.c/ftl_mempool_ut.c
Normal file
95
test/unit/lib/ftl/ftl_mempool.c/ftl_mempool_ut.c
Normal file
@ -0,0 +1,95 @@
|
||||
/* 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/utils/ftl_mempool.c"
|
||||
|
||||
#define COUNT 16
|
||||
#define ALIGNMENT 64
|
||||
#define SIZE (ALIGNMENT * 2)
|
||||
#define SOCKET_ID_ANY -1
|
||||
|
||||
static struct ftl_mempool *g_mpool;
|
||||
|
||||
static void
|
||||
test_ftl_mempool_create(void)
|
||||
{
|
||||
struct ftl_mempool *mpool;
|
||||
|
||||
/* improper value of alignment */
|
||||
mpool = ftl_mempool_create(COUNT, SIZE, ALIGNMENT + 1, SOCKET_ID_ANY);
|
||||
CU_ASSERT_EQUAL(mpool, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_ftl_mempool_get_put(void)
|
||||
{
|
||||
void *elem[COUNT];
|
||||
void *elem_empty;
|
||||
void *elem_first = SLIST_FIRST(&g_mpool->list);
|
||||
struct ftl_mempool_element *ftl_elem;
|
||||
int i;
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
elem[i] = ftl_mempool_get(g_mpool);
|
||||
ftl_elem = elem[i];
|
||||
CU_ASSERT_EQUAL(ftl_elem->entry.sle_next, SLIST_FIRST(&g_mpool->list));
|
||||
}
|
||||
|
||||
CU_ASSERT(SLIST_EMPTY(&g_mpool->list));
|
||||
|
||||
elem_empty = ftl_mempool_get(g_mpool);
|
||||
CU_ASSERT_EQUAL(elem_empty, NULL);
|
||||
|
||||
for (i = COUNT - 1; i >= 0; i--) {
|
||||
ftl_mempool_put(g_mpool, elem[i]);
|
||||
CU_ASSERT_EQUAL(SLIST_FIRST(&g_mpool->list), elem[i]);
|
||||
}
|
||||
|
||||
CU_ASSERT_EQUAL(SLIST_FIRST(&g_mpool->list), elem_first);
|
||||
}
|
||||
|
||||
static int
|
||||
test_setup(void)
|
||||
{
|
||||
g_mpool = ftl_mempool_create(COUNT, SIZE, ALIGNMENT, SOCKET_ID_ANY);
|
||||
if (!g_mpool) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_cleanup(void)
|
||||
{
|
||||
ftl_mempool_destroy(g_mpool);
|
||||
g_mpool = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_mempool", test_setup, test_cleanup);
|
||||
CU_ADD_TEST(suite, test_ftl_mempool_create);
|
||||
CU_ADD_TEST(suite, test_ftl_mempool_get_put);
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
num_failures = CU_get_number_of_failures();
|
||||
CU_cleanup_registry();
|
||||
|
||||
return num_failures;
|
||||
}
|
@ -46,6 +46,7 @@ function unittest_event() {
|
||||
|
||||
function unittest_ftl() {
|
||||
$valgrind $testdir/lib/ftl/ftl_mngt/ftl_mngt_ut
|
||||
$valgrind $testdir/lib/ftl/ftl_mempool.c/ftl_mempool_ut
|
||||
}
|
||||
|
||||
function unittest_iscsi() {
|
||||
|
Loading…
Reference in New Issue
Block a user