Assertions reference#
All assertion classes live in the Avr8Sharp.TestKit.Assertions namespace and are
available via .Should() extension methods after using FluentAssertions.
CPU assertions — sim.Cpu.Should()#
Obtained from any AvrTestSimulation via sim.Cpu.Should().
Registers and state#
Assertion |
What it checks |
|---|---|
|
General-purpose register |
|
Program counter at |
|
Stack pointer equals |
|
Cycle counter exactly |
SREG raw value#
Assertion |
What it checks |
|---|---|
|
SREG byte equals the given value exactly |
SREG bit constants (defined in test base class and usable as arguments):
Constant |
Bit |
Flag |
|---|---|---|
|
0 |
Carry |
|
1 |
Zero |
|
2 |
Negative |
|
3 |
Overflow |
|
4 |
Sign (N ⊕ V) |
|
5 |
Half-carry |
|
6 |
Bit-copy (T) |
|
7 |
Global interrupt enable |
SREG individual flags#
Each flag assertion accepts an optional bool expected argument (default true).
Pass false to assert the flag is clear.
Assertion |
Flag |
|---|---|
|
C (bit 0) |
|
Z (bit 1) |
|
N (bit 2) |
|
V (bit 3) |
|
S (bit 4) |
|
H (bit 5) |
|
T (bit 6) |
|
I (bit 7) |
Examples:
sim.Cpu.Should().HaveRegister(16, 0xAB);
sim.Cpu.Should().HavePC(0x0040);
sim.Cpu.Should().HaveSreg(SREG_Z | SREG_C);
sim.Cpu.Should().HaveZeroFlag();
sim.Cpu.Should().HaveCarryFlag(false);
sim.Cpu.Should().HaveInterruptsEnabled();
GPIO assertions — port.Should()#
Obtained from any AvrIoPort via port.Should().
Assertion |
What it checks |
|---|---|
|
Pin |
|
Pin |
|
Pin |
|
Pin |
|
Pin |
|
All listed pins are high |
|
All listed pins are low |
|
The PORT register value equals |
Pin states:
using AVR8Sharp.Core.Peripherals;
uno.PortB.Should().HavePinHigh(5); // LED_BUILTIN on
uno.PortD.Should().HavePinLow(2); // INT0 driven low
uno.PortC.Should().HavePinInputPullup(4); // A4/SDA as pulled-up input
uno.PortB.Should().HavePinsHigh(1, 2, 3); // multiple pins
uno.PortA.Should().HaveOutputValue(0b00001111); // lower nibble high
Memory assertions — sim.Memory.Should()#
Obtained from sim.Memory (an AvrMemoryView over the full _ram array).
Assertion |
What it checks |
|---|---|
|
|
|
16-bit little-endian word at |
|
16-bit big-endian word at |
|
Byte sequence at |
Note
Addresses are in the AVR unified data space: registers at 0x0000–0x001F,
I/O space at 0x0020–0x005F (plus extended I/O on ATmega2560), SRAM at 0x0100+ (ATmega328P)
or 0x0200+ (ATmega2560). The sim.Data[n] shortcut gives the same array.
Examples:
sim.Memory.Should().HaveByteAt(0x0100, 0x42);
sim.Memory.Should().HaveWordAt(0x0100, 0x1234); // little-endian
sim.Memory.Should().HaveBytesAt(0x0200, new byte[] { 0xDE, 0xAD, 0xBE, 0xEF });
// Read directly without assertion
byte val = sim.Data[0x0100];
Serial probe assertions — serial.Should()#
Obtained from any SerialProbe via serial.Should().
Text content#
Assertion |
What it checks |
|---|---|
|
Captured text is exactly |
|
Captured text contains |
|
Captured text does not contain |
|
Captured text starts with |
|
Captured text ends with |
|
Nothing transmitted yet |
Line-level#
Assertion |
What it checks |
|---|---|
|
Output split by |
|
At least one line equals |
Binary / byte-level#
Assertion |
What it checks |
|---|---|
|
Raw byte stream contains |
|
Raw byte stream is exactly |
|
Bytes starting at |
Examples:
uno.Serial.Should().ContainLine("count=0");
uno.Serial.Should().HaveLineCount(3);
uno.Serial.Should().StartWith("boot");
uno.Serial.Should().NotContain("ERROR");
// Binary protocol
serial.Should().HaveBytes(new byte[] { 0x02, 0x41, 0x03 });
serial.Should().HaveBytesAt(1, new byte[] { 0x41 }); // 'A' at position 1
Chaining assertions#
All assertions return AndConstraint<T>, so you can chain:
sim.Cpu.Should().HaveZeroFlag().And.HaveCarryFlag(false);
uno.Serial.Should().Contain("ready").And.NotContain("error");