mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
tests: unit test for uniq insert into radix_tree
This commit is contained in:
parent
5b1ebed3fc
commit
0852c3171d
@ -1,5 +1,5 @@
|
|||||||
// Copyright (C) 2018 Red Hat, Inc. All rights reserved.
|
// Copyright (C) 2018 Red Hat, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
// This file is part of LVM2.
|
// This file is part of LVM2.
|
||||||
//
|
//
|
||||||
// This copyrighted material is made available to anyone wishing to use,
|
// This copyrighted material is made available to anyone wishing to use,
|
||||||
@ -9,7 +9,7 @@
|
|||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with this program; if not, write to the Free Software Foundation,
|
// along with this program; if not, write to the Free Software Foundation,
|
||||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
#include "units.h"
|
#include "units.h"
|
||||||
#include "base/data-struct/radix-tree.h"
|
#include "base/data-struct/radix-tree.h"
|
||||||
#include "base/memory/container_of.h"
|
#include "base/memory/container_of.h"
|
||||||
@ -348,7 +348,7 @@ static void test_remove_prefix(void *fixture)
|
|||||||
|
|
||||||
T_ASSERT(radix_tree_is_well_formed(rt));
|
T_ASSERT(radix_tree_is_well_formed(rt));
|
||||||
|
|
||||||
// remove keys in a sub range
|
// remove keys in a sub range
|
||||||
k[0] = 21;
|
k[0] = 21;
|
||||||
T_ASSERT_EQUAL(radix_tree_remove_prefix(rt, k, 1), count);
|
T_ASSERT_EQUAL(radix_tree_remove_prefix(rt, k, 1), count);
|
||||||
T_ASSERT(radix_tree_is_well_formed(rt));
|
T_ASSERT(radix_tree_is_well_formed(rt));
|
||||||
@ -542,7 +542,7 @@ static void test_remove_calls_dtr(void *fixture)
|
|||||||
}
|
}
|
||||||
|
|
||||||
T_ASSERT(radix_tree_is_well_formed(rt));
|
T_ASSERT(radix_tree_is_well_formed(rt));
|
||||||
|
|
||||||
// double check
|
// double check
|
||||||
for (i = 0; i < DTR_COUNT; i++) {
|
for (i = 0; i < DTR_COUNT; i++) {
|
||||||
uint8_t *k = keys + (i * 3);
|
uint8_t *k = keys + (i * 3);
|
||||||
@ -597,7 +597,7 @@ static void test_destroy_calls_dtr(void *fixture)
|
|||||||
|
|
||||||
T_ASSERT(radix_tree_is_well_formed(rt));
|
T_ASSERT(radix_tree_is_well_formed(rt));
|
||||||
}
|
}
|
||||||
|
|
||||||
radix_tree_destroy(rt);
|
radix_tree_destroy(rt);
|
||||||
T_ASSERT(c.c == DTR_COUNT);
|
T_ASSERT(c.c == DTR_COUNT);
|
||||||
for (i = 0; i < DTR_COUNT; i++)
|
for (i = 0; i < DTR_COUNT; i++)
|
||||||
@ -810,6 +810,37 @@ static void test_bcache_scenario3(void *fixture)
|
|||||||
#include "test/unit/rt_case1.c"
|
#include "test/unit/rt_case1.c"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _uniq_visit(struct radix_tree_iterator *it,
|
||||||
|
const void *key, size_t keylen, union radix_value v)
|
||||||
|
{
|
||||||
|
struct visitor *vt = container_of(it, struct visitor, it);
|
||||||
|
T_ASSERT_EQUAL(v.n, 2); // always expecting value == 2
|
||||||
|
vt->count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_uniq_insert(void *fixture)
|
||||||
|
{
|
||||||
|
struct radix_tree *rt = fixture;
|
||||||
|
struct visitor vt = { .it.visit = _uniq_visit };
|
||||||
|
uint8_t k[6] = "test1";
|
||||||
|
uint8_t l[6] = "test2";
|
||||||
|
union radix_value v1 = { .n = 1 };
|
||||||
|
union radix_value v2 = { .n = 2 };
|
||||||
|
|
||||||
|
T_ASSERT(radix_tree_insert(rt, k, sizeof(k), v1));
|
||||||
|
T_ASSERT(radix_tree_insert(rt, k, sizeof(k), v1));
|
||||||
|
T_ASSERT_EQUAL(radix_tree_uniq_insert(rt, k, sizeof(k), v2), -1);
|
||||||
|
|
||||||
|
T_ASSERT(radix_tree_uniq_insert(rt, l, sizeof(l), v1));
|
||||||
|
T_ASSERT_EQUAL(radix_tree_uniq_insert(rt, l, sizeof(l), v2), -1);
|
||||||
|
|
||||||
|
T_ASSERT(radix_tree_is_well_formed(rt));
|
||||||
|
|
||||||
|
radix_tree_iterate(rt, NULL, 0, &vt.it);
|
||||||
|
T_ASSERT_EQUAL(radix_tree_size(rt), vt.count);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
#define T(path, desc, fn) register_test(ts, "/base/data-struct/radix-tree/" path, desc, fn)
|
#define T(path, desc, fn) register_test(ts, "/base/data-struct/radix-tree/" path, desc, fn)
|
||||||
|
|
||||||
@ -846,6 +877,7 @@ void radix_tree_tests(struct dm_list *all_tests)
|
|||||||
T("bcache-scenario", "A specific series of keys from a bcache scenario", test_bcache_scenario);
|
T("bcache-scenario", "A specific series of keys from a bcache scenario", test_bcache_scenario);
|
||||||
T("bcache-scenario-2", "A second series of keys from a bcache scenario", test_bcache_scenario2);
|
T("bcache-scenario-2", "A second series of keys from a bcache scenario", test_bcache_scenario2);
|
||||||
T("bcache-scenario-3", "A third series of keys from a bcache scenario", test_bcache_scenario3);
|
T("bcache-scenario-3", "A third series of keys from a bcache scenario", test_bcache_scenario3);
|
||||||
|
T("uniq-insert", "Test insert with test for uniq key", test_uniq_insert);
|
||||||
|
|
||||||
dm_list_add(all_tests, &ts->list);
|
dm_list_add(all_tests, &ts->list);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user