1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

tests: unit test for uniq insert into radix_tree

This commit is contained in:
Zdenek Kabelac 2024-10-24 14:08:51 +02:00
parent 5b1ebed3fc
commit 0852c3171d

View File

@ -810,6 +810,37 @@ static void test_bcache_scenario3(void *fixture)
#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)
@ -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-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("uniq-insert", "Test insert with test for uniq key", test_uniq_insert);
dm_list_add(all_tests, &ts->list);
}