mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2026-08-27 00:26:02 -04:00
gdb: add unit test for blockvector::lookup of non-contiguous blocks
This commit add a new unit test that tests block lookup when blocks are non-contiguous.
This commit is contained in:
parent
fc59e2a17d
commit
ec23174dc4
1 changed files with 74 additions and 0 deletions
|
|
@ -20,6 +20,7 @@
|
|||
#include "gdbsupport/selftest.h"
|
||||
#include "block.h"
|
||||
#include "addrmap.h"
|
||||
#include "obstack.h"
|
||||
|
||||
|
||||
namespace selftests {
|
||||
|
|
@ -81,6 +82,76 @@ test_blockvector_lookup_contains ()
|
|||
SELF_CHECK (bv->contains (0x4000) == false);
|
||||
}
|
||||
|
||||
/* Create and return struct blockranges* from 2 ranges. */
|
||||
static struct blockranges *
|
||||
make_blockranges_2 (struct obstack &ob, CORE_ADDR start0,
|
||||
CORE_ADDR end0, CORE_ADDR start1,
|
||||
CORE_ADDR end1)
|
||||
{
|
||||
struct blockranges *ranges = (struct blockranges *) obstack_alloc
|
||||
(&ob, sizeof (struct blockranges) + (2 - 1) * sizeof (struct blockrange));
|
||||
|
||||
ranges->nranges = 2;
|
||||
ranges->range[0].set_start (start0);
|
||||
ranges->range[0].set_end (end0);
|
||||
ranges->range[1].set_start (start1);
|
||||
ranges->range[1].set_end (end1);
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
static void
|
||||
test_blockvector_lookup_non_continuguous ()
|
||||
{
|
||||
/* Create blockvector with following blocks:
|
||||
|
||||
B0 0x1000 - 0x8000 (global block)
|
||||
B1 0x1000 - 0x8000 (static block)
|
||||
B2 0x1000 - 0x2000 (B2's range 1)
|
||||
B3 0x2000 - 0x3000 (B3's range 1)
|
||||
(hole 1)
|
||||
B4 0x5000 - 0x5500
|
||||
(hole 2)
|
||||
(B2) 0x6000 - 0x7000 (B2's range 2)
|
||||
(B3) 0x7000 - 0x8000 (B3's range 2)
|
||||
|
||||
Blocks B2 and B3 are non-continguous (consist of two
|
||||
disjoint ranges) and interleaved.
|
||||
*/
|
||||
auto_obstack ob;
|
||||
blockvector_up bv = std::make_unique<struct blockvector> (0);
|
||||
|
||||
auto global_block = make_block (*bv.get (), ob, 0x1000, 0x8000);
|
||||
auto static_block = make_block (*bv.get (), ob, 0x1000, 0x8000,
|
||||
global_block);
|
||||
auto b2 = make_block (*bv.get (), ob, 0x1000, 0x7000, static_block);
|
||||
b2->set_ranges (make_blockranges_2 (ob, 0x1000, 0x2000, 0x6000, 0x7000));
|
||||
auto b3 = make_block (*bv.get (), ob, 0x2000, 0x8000, static_block);
|
||||
b3->set_ranges (make_blockranges_2 (ob, 0x2000, 0x3000, 0x7000, 0x8000));
|
||||
auto b4 = make_block (*bv.get (), ob, 0x5000, 0x5500, static_block);
|
||||
|
||||
/* Test address falling into range 1 of B2. */
|
||||
SELF_CHECK (bv->lookup (0x1500) == b2);
|
||||
|
||||
/* Test address falling into range 2 of B2. */
|
||||
SELF_CHECK (bv->lookup (0x6000) == b2);
|
||||
|
||||
/* Test address falling into range 1 of B3. */
|
||||
SELF_CHECK (bv->lookup (0x2500) == b3);
|
||||
|
||||
/* Test address falling into range 2 of B3. */
|
||||
SELF_CHECK (bv->lookup (0x7999) == b3);
|
||||
|
||||
/* Test address falling into B4. */
|
||||
SELF_CHECK (bv->lookup (0x5250) == b4);
|
||||
|
||||
/* Test address falling into hole 1. */
|
||||
SELF_CHECK (bv->lookup (0x4000) == static_block);
|
||||
|
||||
/* Test address falling into hole 2. */
|
||||
SELF_CHECK (bv->lookup (0x5750) == static_block);
|
||||
}
|
||||
|
||||
} /* namespace selftests */
|
||||
|
||||
|
||||
|
|
@ -88,4 +159,7 @@ INIT_GDB_FILE (block_selftest)
|
|||
{
|
||||
selftests::register_test ("blockvector-lookup-contains",
|
||||
selftests::test_blockvector_lookup_contains);
|
||||
selftests::register_test
|
||||
("blockvector-lookup-non-contiguous",
|
||||
selftests::test_blockvector_lookup_non_continuguous);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue