#include #include #include #include #include #include #include #include #include #include int find_root(struct ftl_map *map, uint32_t group); static void test_group0_upage0(void **state) { struct ftl_map map; struct ftl_page_desc page_desc; int ret; (void)state; map.log2_pages_per_group = ilog2(16); map.log2_groups_per_block = ilog2(1); map.nblocks = 4; expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 0); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, -1); ret = find_root(&map, 0); assert_int_equal(ret, -1); } static void test_group0_upage5(void **state) { struct ftl_map map; struct ftl_page_desc page_desc; int ret; (void)state; map.log2_pages_per_group = ilog2(16); map.log2_groups_per_block = ilog2(1); map.nblocks = 4; expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 0); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 1); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 2); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 3); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 4); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 5); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 6); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, -1); ret = find_root(&map, 0); assert_int_equal(ret, 0); assert_int_equal(map.root, 5); } static void test_group1_upage5(void **state) { struct ftl_map map; struct ftl_page_desc page_desc; int ret; (void)state; map.log2_pages_per_group = ilog2(16); map.log2_groups_per_block = ilog2(1); map.nblocks = 4; expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16 + 1); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16 + 2); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16 + 3); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16 + 4); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16 + 5); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, 0); expect_value(__wrap_read_page_desc, map, &map); expect_value(__wrap_read_page_desc, upage, 16 + 6); will_return(__wrap_read_page_desc, &page_desc); will_return(__wrap_read_page_desc, -1); ret = find_root(&map, 1); assert_int_equal(ret, 0); assert_int_equal(map.root, 16 + 5); } int test_find_root(void) { const struct CMUnitTest tests[] = { { "find_root: group=0, upage=0 (no root)", test_group0_upage0, NULL, NULL, NULL }, { "find_root: group=0, upage=5", test_group0_upage5, NULL, NULL, NULL }, { "find_root: group=1, upage=5", test_group1_upage5, NULL, NULL, NULL }, }; return cmocka_run_group_tests_name("find_root", tests, NULL, NULL); }