From fc1476d9ddbdc02cc16d7c4cf88339fd58ed01fd Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Tue, 3 Oct 2017 11:24:44 +0200 Subject: [PATCH] test: ftl: add test to check if an exact match works for trace_path() --- source/tests/ftl/trace_path.c | 70 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/source/tests/ftl/trace_path.c b/source/tests/ftl/trace_path.c index f0ce27c..438ded2 100644 --- a/source/tests/ftl/trace_path.c +++ b/source/tests/ftl/trace_path.c @@ -31,7 +31,72 @@ static void test_empty_root(void **state) assert_int_equal(ret, -2); } -static void test_trace1(void **state) +static void test_exact_match(void **state) +{ + struct ftl_page_desc descs[] = { + { + .va = 0xdeadbeef, + .subtrees = { + [0] = 19, + [1] = 21, + [2] = 38, + [3] = 81, + [4] = 24, + [5] = 64, + [6] = 25, + [7] = 15, + [8] = 0, + [9] = 73, + [10] = 49, + [11] = 22, + [12] = 85, + [13] = 45, + [14] = 98, + [15] = 7, + [16] = 72, + [17] = 26, + [18] = 92, + [19] = 16, + [20] = 12, + [21] = 57, + [22] = 52, + [23] = 39, + [24] = 28, + [25] = 42, + [26] = 37, + [27] = 87, + [28] = 5, + [29] = 27, + [30] = 30, + [31] = 47, + }, + }, + }; + struct ftl_page_desc ret_page_desc; + struct ftl_map map; + uint32_t page; + int ret; + + (void)state; + + map.log2_page_size = ilog2(4 * KIB); + map.root = 75; + map.flags = 0; + + expect_value(__wrap_read_page_desc, map, &map); + expect_value(__wrap_read_page_desc, upage, 75); + will_return(__wrap_read_page_desc, descs); + will_return(__wrap_read_page_desc, 0); + + ret = __real_trace_path(&map, &ret_page_desc, &page, 0xdeadbeef); + + assert_int_equal(ret, 0); + assert_int_equal(page, 75); + + assert_memory_equal(&ret_page_desc, descs, sizeof ret_page_desc); +} + +static void test_walk(void **state) { struct ftl_page_desc descs[] = { { @@ -127,7 +192,8 @@ int test_trace_path(void) { const struct CMUnitTest tests[] = { { "trace_path: empty root", test_empty_root, NULL, NULL, NULL }, - { "trace_path: successful trace", test_trace1, NULL, NULL, NULL }, + { "trace_path: exact match", test_exact_match, NULL, NULL, NULL }, + { "trace_path: page descriptor walk", test_walk, NULL, NULL, NULL }, }; return cmocka_run_group_tests_name("trace_path", tests, NULL, NULL);