class GloballyOrderedRegion
Defined at line 59 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.h
An MMIO range that responds to a list of pre-determined memory accesses.
GloballyOrderedRegion enforces a global ordering on all accesses to the mocked MMIO
range. This is stricter than Region, which accepts any interleaving of the access
lists specified at the register level. So, GloballyOrderedRegion results in more brittle
mocks, and should only be used when there is a single acceptable access ordering.
Example usage:
constexpr static size_t kMmioRegionSize = 0x4000;
GloballyOrderedRegion region_{kMmioRegionSize, GloballyOrderedRegion::Size::k32};
fdf::MmioBuffer buffer_{region_.GetMmioBuffer()};
// Expect a 32-bit read at 0x1000, the read will return 0x12345678.
region_.Expect({.address = 0x1000, .value = 0x12345678});
// Expect a 32-bit write of 0x87654321 at 0x1002
region_.Expect({.address = 0x1002, .value = 0x87654321, .write = true});
// Test polling for a ready flag at 0x1004.
region_.Expect(GloballyOrderedRegion::AccessList({
{.address = 0x1004, .value = 0x0},
{.address = 0x1004, .value = 0x0},
{.address = 0x1004, .value = 0x0},
{.address = 0x1004, .value = 0x1},
}));
// This could go in TearDown().
region_.CheckAllAccessesReplayed();
The following practices are not required, but are consistent with the
recommendation of keeping testing logic simple:
* Expect() calls should be at the beginning of the test case, before
executing the code that accesses the MMIO region.
* A test's expectations should be grouped in a single Expect() call. In rare
cases, multiple cases and conditional logic may improve readability.
* Expect() should not be called concurrently from multiple threads.
GloballyOrderedRegion instances are 100% thread-safe because all MMIO accesses to the region are
serialized using a mutex.
Public Methods
void Expect (cpp20::span<const Access> accesses)
Appends the given entries to the list of expected memory accesses.
To keep the testing logic simple, all Expect() calls should be performed
before executing the code that uses the MMIO range.
Defined at line 28 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.cc
void CheckAllAccessesReplayed ()
Asserts that the entire memory access list has been replayed.
Defined at line 41 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.cc
fdf::MmioBuffer GetMmioBuffer ()
Constructs and returns a MmioBuffer object with a size that matches GloballyOrderedRegion.
Defined at line 48 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.cc
void GloballyOrderedRegion (size_t region_size, Size default_access_size)
`default_access_size` is used for Access instances whose `size` is
`kUseDefault`.
Defined at line 83 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.h
void ~GloballyOrderedRegion ()
Defined at line 85 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.h
void Expect (const Access & access)
Appends an entry to the list of expected memory accesses.
To keep the testing logic simple, all Expect() calls should be performed
before executing the code that uses the MMIO range.
Defined at line 91 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.h
Enumerations
enum Size
| Name | Value |
|---|---|
| kUseDefault | 0 |
| k8 | 8 |
| k16 | 16 |
| k32 | 32 |
| k64 | 64 |
The supported MMIO access sizes.
Defined at line 62 of file ../../sdk/lib/driver/mock-mmio/cpp/globally-ordered-region.h