diff options
author | Patrick Delaunay <patrick.delaunay@foss.st.com> | 2021-03-10 10:16:30 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-04-22 14:09:45 -0400 |
commit | a57b596e8b3eb3b24af31ce91b2fd6a57d8df0ba (patch) | |
tree | 2c242e92438fa5908eb7880d9407665d95af4950 /test/lib | |
parent | cb1e619824f0c942ccd9b230b5f41caaf7cd91b4 (diff) | |
download | u-boot-a57b596e8b3eb3b24af31ce91b2fd6a57d8df0ba.zip u-boot-a57b596e8b3eb3b24af31ce91b2fd6a57d8df0ba.tar.gz u-boot-a57b596e8b3eb3b24af31ce91b2fd6a57d8df0ba.tar.bz2 |
test: lmb: add test for overflow protection in lmb_add_region
Add test for max number of memory regions and in reserved regions.
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/lmb.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 644ee78..0d8963f 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -659,3 +659,67 @@ static int lib_test_lmb_get_free_size(struct unit_test_state *uts) DM_TEST(lib_test_lmb_get_free_size, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +static int lib_test_lmb_max_regions(struct unit_test_state *uts) +{ + const phys_addr_t ram = 0x00000000; + const phys_size_t ram_size = 0x8000000; + const phys_size_t blk_size = 0x10000; + phys_addr_t offset; + struct lmb lmb; + int ret, i; + + lmb_init(&lmb); + + ut_asserteq(lmb.memory.cnt, 0); + ut_asserteq(lmb.memory.max, 8); + ut_asserteq(lmb.reserved.cnt, 0); + ut_asserteq(lmb.reserved.max, 8); + + /* Add 8 memory regions */ + for (i = 0; i < 8; i++) { + offset = ram + 2 * i * ram_size; + ret = lmb_add(&lmb, offset, ram_size); + ut_asserteq(ret, 0); + } + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 0); + + /* error for the 9th memory regions */ + offset = ram + 2 * 8 * ram_size; + ret = lmb_add(&lmb, offset, ram_size); + ut_asserteq(ret, -1); + + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 0); + + /* reserve 8 regions */ + for (i = 0; i < 8; i++) { + offset = ram + 2 * i * blk_size; + ret = lmb_reserve(&lmb, offset, blk_size); + ut_asserteq(ret, 0); + } + + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 8); + + /* error for the 9th reserved blocks */ + offset = ram + 2 * 8 * blk_size; + ret = lmb_reserve(&lmb, offset, blk_size); + ut_asserteq(ret, -1); + + ut_asserteq(lmb.memory.cnt, 8); + ut_asserteq(lmb.reserved.cnt, 8); + + /* check each regions */ + for (i = 0; i < 8; i++) + ut_asserteq(lmb.memory.region[i].base, ram + 2 * i * ram_size); + + for (i = 0; i < 8; i++) + ut_asserteq(lmb.reserved.region[i].base, ram + 2 * i * blk_size); + + return 0; +} + +DM_TEST(lib_test_lmb_max_regions, + UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |