Spdk/test/unit/lib/blobfs/tree.c/tree_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

123 lines
3.6 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk_cunit.h"
#include "blobfs/tree.c"
void
cache_buffer_free(struct cache_buffer *cache_buffer)
{
free(cache_buffer);
}
static void
blobfs_tree_op_test(void)
{
struct cache_tree *tree;
struct cache_buffer *buffer[5];
struct cache_buffer *tmp_buffer;
int i;
for (i = 0; i < 5; i ++) {
buffer[i] = calloc(1, sizeof(struct cache_buffer));
SPDK_CU_ASSERT_FATAL(buffer[i]);
}
tree = calloc(1, sizeof(*tree));
SPDK_CU_ASSERT_FATAL(tree != NULL);
/* insert buffer[0] */
buffer[0]->offset = 0;
tree = tree_insert_buffer(tree, buffer[0]);
SPDK_CU_ASSERT_FATAL(tree != NULL);
CU_ASSERT(tree->level == 0);
tmp_buffer = tree_find_buffer(tree, buffer[0]->offset);
CU_ASSERT(tmp_buffer == buffer[0]);
/* insert buffer[1] */
buffer[1]->offset = CACHE_BUFFER_SIZE;
/* set the bytes_filled equal = bytes_filled with same non zero value, e.g., 32 */
buffer[1]->bytes_filled = buffer[1]->bytes_flushed = 32;
tree = tree_insert_buffer(tree, buffer[1]);
SPDK_CU_ASSERT_FATAL(tree != NULL);
CU_ASSERT(tree->level == 0);
tmp_buffer = tree_find_filled_buffer(tree, buffer[1]->offset);
CU_ASSERT(tmp_buffer == buffer[1]);
/* insert buffer[2] */
buffer[2]->offset = (CACHE_TREE_WIDTH - 1) * CACHE_BUFFER_SIZE;
tree = tree_insert_buffer(tree, buffer[2]);
SPDK_CU_ASSERT_FATAL(tree != NULL);
CU_ASSERT(tree->level == 0);
tmp_buffer = tree_find_buffer(tree, buffer[2]->offset);
CU_ASSERT(tmp_buffer == buffer[2]);
tmp_buffer = tree_find_filled_buffer(tree, buffer[2]->offset);
CU_ASSERT(tmp_buffer == NULL);
/* insert buffer[3], set an offset which can not be fit level 0 */
buffer[3]->offset = CACHE_TREE_LEVEL_SIZE(1);
tree = tree_insert_buffer(tree, buffer[3]);
SPDK_CU_ASSERT_FATAL(tree != NULL);
CU_ASSERT(tree->level == 1);
tmp_buffer = tree_find_buffer(tree, buffer[3]->offset);
CU_ASSERT(tmp_buffer == buffer[3]);
/* insert buffer[4], set an offset which can not be fit level 1 */
buffer[4]->offset = CACHE_TREE_LEVEL_SIZE(2);
tree = tree_insert_buffer(tree, buffer[4]);
SPDK_CU_ASSERT_FATAL(tree != NULL);
CU_ASSERT(tree->level == 2);
tmp_buffer = tree_find_buffer(tree, buffer[4]->offset);
CU_ASSERT(tmp_buffer == buffer[4]);
/* delete buffer[0] */
tree_remove_buffer(tree, buffer[0]);
/* check whether buffer[0] is still existed or not */
tmp_buffer = tree_find_buffer(tree, 0);
CU_ASSERT(tmp_buffer == NULL);
/* delete buffer[3] */
tree_remove_buffer(tree, buffer[3]);
/* check whether buffer[3] is still existed or not */
tmp_buffer = tree_find_buffer(tree, CACHE_TREE_LEVEL_SIZE(1));
CU_ASSERT(tmp_buffer == NULL);
/* free all buffers in the tree */
tree_free_buffers(tree);
/* check whether buffer[1] is still existed or not */
tmp_buffer = tree_find_buffer(tree, CACHE_BUFFER_SIZE);
CU_ASSERT(tmp_buffer == NULL);
/* check whether buffer[2] is still existed or not */
tmp_buffer = tree_find_buffer(tree, (CACHE_TREE_WIDTH - 1) * CACHE_BUFFER_SIZE);
CU_ASSERT(tmp_buffer == NULL);
/* check whether buffer[4] is still existed or not */
tmp_buffer = tree_find_buffer(tree, CACHE_TREE_LEVEL_SIZE(2));
CU_ASSERT(tmp_buffer == NULL);
/* According to tree_free_buffers, root will not be freed */
free(tree);
}
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("tree", NULL, NULL);
CU_ADD_TEST(suite, blobfs_tree_op_test);
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
num_failures = CU_get_number_of_failures();
CU_cleanup_registry();
return num_failures;
}