runtime: add tests for addrRanges.findSucc

This change adds a test suite for addrRanges.findSucc so we can change
the implementation more safely.

For #40191.

Change-Id: I14a834b6d54836cbc676eb0edb292ba6176705cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/242678
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Michael Anthony Knyszek 2020-07-14 21:39:52 +00:00 committed by Michael Knyszek
parent 9db7db54b0
commit e01a1c01f8
2 changed files with 196 additions and 0 deletions

View file

@ -785,6 +785,30 @@ func (a AddrRange) Equals(b AddrRange) bool {
return a == b
}
// AddrRanges is a wrapper around addrRanges for testing.
type AddrRanges struct {
addrRanges
}
// MakeAddrRanges creates a new addrRanges populated with
// the ranges in a.
func MakeAddrRanges(a ...AddrRange) AddrRanges {
// Methods that manipulate the backing store of addrRanges.ranges should
// not be used on the result from this function (e.g. add) since they may
// trigger reallocation.
ranges := make([]addrRange, 0, len(a))
for _, r := range a {
ranges = append(ranges, r.addrRange)
}
return AddrRanges{addrRanges{ranges: ranges, sysStat: new(uint64)}}
}
// FindSucc returns the successor to base. See addrRanges.findSucc
// for more details.
func (a *AddrRanges) FindSucc(base uintptr) int {
return a.findSucc(base)
}
// BitRange represents a range over a bitmap.
type BitRange struct {
I, N uint // bit index and length in bits