Skip to content

Commit

Permalink
[unit-test/radix-tree] Add a huge test case
Browse files Browse the repository at this point in the history
Derived from the logs that dct gave me.
  • Loading branch information
jthornber committed Sep 20, 2018
1 parent bb17302 commit ba6d8a3
Show file tree
Hide file tree
Showing 3 changed files with 1,731 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ UNIT_SOURCE=\
test/unit/string_t.c \
test/unit/vdo_t.c

test/unit/radix_tree_t.o: test/unit/rt_case1.c

UNIT_DEPENDS=$(subst .c,.d,$(UNIT_SOURCE))
UNIT_OBJECTS=$(UNIT_SOURCE:%.c=%.o)
CLEAN_TARGETS+=$(UNIT_DEPENDS) $(UNIT_OBJECTS)
Expand Down
60 changes: 60 additions & 0 deletions test/unit/radix_tree_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,65 @@ static void test_bcache_scenario2(void *fixture)

//----------------------------------------------------------------

struct key_parts {
uint32_t fd;
uint64_t b;
} __attribute__ ((packed));

union key {
struct key_parts parts;
uint8_t bytes[12];
};

static void __lookup_matches(struct radix_tree *rt, int fd, uint64_t b, uint64_t expected)
{
union key k;
union radix_value v;

k.parts.fd = fd;
k.parts.b = b;
T_ASSERT(radix_tree_lookup(rt, k.bytes, k.bytes + sizeof(k.bytes), &v));
T_ASSERT(v.n == expected);
}

static void __lookup_fails(struct radix_tree *rt, int fd, uint64_t b)
{
union key k;
union radix_value v;

k.parts.fd = fd;
k.parts.b = b;
T_ASSERT(!radix_tree_lookup(rt, k.bytes, k.bytes + sizeof(k.bytes), &v));
}

static void __insert(struct radix_tree *rt, int fd, uint64_t b, uint64_t n)
{
union key k;
union radix_value v;

k.parts.fd = fd;
k.parts.b = b;
v.n = n;
T_ASSERT(radix_tree_insert(rt, k.bytes, k.bytes + sizeof(k.bytes), v));
}

static void __invalidate(struct radix_tree *rt, int fd)
{
union key k;

k.parts.fd = fd;
radix_tree_remove_prefix(rt, k.bytes, k.bytes + sizeof(k.parts.fd));
radix_tree_is_well_formed(rt);
}

static void test_bcache_scenario3(void *fixture)
{
struct radix_tree *rt = fixture;

#include "test/unit/rt_case1.c"
}

//----------------------------------------------------------------
#define T(path, desc, fn) register_test(ts, "/base/data-struct/radix-tree/" path, desc, fn)

void radix_tree_tests(struct dm_list *all_tests)
Expand Down Expand Up @@ -784,6 +843,7 @@ void radix_tree_tests(struct dm_list *all_tests)
T("destroy-calls-dtr", "destroy should call the dtr for all values", test_destroy_calls_dtr);
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);

dm_list_add(all_tests, &ts->list);
}
Expand Down
Loading

0 comments on commit ba6d8a3

Please sign in to comment.