test: lmb: add test for lmb_reserve_flags
Add a test to check the management of reserved region with flags. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
358c7789af
commit
7d08a3dd02
@ -723,3 +723,92 @@ static int lib_test_lmb_max_regions(struct unit_test_state *uts)
|
||||
|
||||
DM_TEST(lib_test_lmb_max_regions,
|
||||
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
||||
|
||||
static int lib_test_lmb_flags(struct unit_test_state *uts)
|
||||
{
|
||||
const phys_addr_t ram = 0x40000000;
|
||||
const phys_size_t ram_size = 0x20000000;
|
||||
struct lmb lmb;
|
||||
long ret;
|
||||
|
||||
lmb_init(&lmb);
|
||||
|
||||
ret = lmb_add(&lmb, ram, ram_size);
|
||||
ut_asserteq(ret, 0);
|
||||
|
||||
/* reserve, same flag */
|
||||
ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
/* reserve again, same flag */
|
||||
ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
/* reserve again, new flag */
|
||||
ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, -1);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
|
||||
|
||||
/* merge after */
|
||||
ret = lmb_reserve_flags(&lmb, 0x40020000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 1);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x20000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
/* merge before */
|
||||
ret = lmb_reserve_flags(&lmb, 0x40000000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 1);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40000000, 0x30000,
|
||||
0, 0, 0, 0);
|
||||
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
|
||||
|
||||
ret = lmb_reserve_flags(&lmb, 0x40030000, 0x10000, LMB_NONE);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x30000,
|
||||
0x40030000, 0x10000, 0, 0);
|
||||
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0);
|
||||
|
||||
/* test that old API use LMB_NONE */
|
||||
ret = lmb_reserve(&lmb, 0x40040000, 0x10000);
|
||||
ut_asserteq(ret, 1);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x30000,
|
||||
0x40030000, 0x20000, 0, 0);
|
||||
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0);
|
||||
|
||||
ret = lmb_reserve_flags(&lmb, 0x40070000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 3, 0x40000000, 0x30000,
|
||||
0x40030000, 0x20000, 0x40070000, 0x10000);
|
||||
|
||||
ret = lmb_reserve_flags(&lmb, 0x40050000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 0);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 4, 0x40000000, 0x30000,
|
||||
0x40030000, 0x20000, 0x40050000, 0x10000);
|
||||
|
||||
/* merge with 2 adjacent regions */
|
||||
ret = lmb_reserve_flags(&lmb, 0x40060000, 0x10000, LMB_NOMAP);
|
||||
ut_asserteq(ret, 2);
|
||||
ASSERT_LMB(&lmb, ram, ram_size, 3, 0x40000000, 0x30000,
|
||||
0x40030000, 0x20000, 0x40050000, 0x30000);
|
||||
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0);
|
||||
ut_asserteq(lmb_is_nomap(&lmb.reserved.region[2]), 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DM_TEST(lib_test_lmb_flags,
|
||||
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
||||
|
Loading…
Reference in New Issue
Block a user