Skip to content

Commit

Permalink
Fix FifoChecker sampling bugs (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 authored Jan 8, 2024
1 parent 4de3cca commit c319f0f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/src/fifo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,37 +266,38 @@ class FifoChecker extends Component {
.where((e) => !e.name.contains('Data'));

fifo._clk.posedge.listen((event) {
if (!fifo._reset.value.isValid) {
if (!fifo._reset.previousValue!.isValid) {
// reset is invalid, bad state
hasReset = false;
return;
} else if (fifo._reset.value.toBool()) {
} else if (fifo._reset.previousValue!.toBool()) {
// reset is high, track that and move on
hasReset = true;
return;
} else if (hasReset) {
// reset is low, and we've previously reset, should be good to check

if (!fifoPortSignals
.map((e) => e.value.isValid)
.map((e) => e.previousValue!.isValid)
.reduce((a, b) => a && b)) {
final portValuesMap = Map.fromEntries(
fifoPortSignals.map((e) => MapEntry(e.name, e.value)));
fifoPortSignals.map((e) => MapEntry(e.name, e.previousValue!)));
logger.severe('Fifo control port has an invalid value after reset.'
' Port values: $portValuesMap');
return;
}

if (fifo.full.value.toBool() &&
fifo._writeEnable.value.toBool() &&
!fifo._readEnable.value.toBool()) {
if (fifo.full.previousValue!.toBool() &&
fifo._writeEnable.previousValue!.toBool() &&
!fifo._readEnable.previousValue!.toBool()) {
if (enableOverflowCheck) {
logger
.severe('Fifo $fifo received a write that caused an overflow.');
}
} else if (fifo.empty.value.toBool() &&
fifo._readEnable.value.toBool()) {
if (!(fifo.generateBypass && fifo._writeEnable.value.toBool())) {
} else if (fifo.empty.previousValue!.toBool() &&
fifo._readEnable.previousValue!.toBool()) {
if (!(fifo.generateBypass &&
fifo._writeEnable.previousValue!.toBool())) {
if (enableUnderflowCheck) {
logger.severe(
'Fifo $fifo received a read that caused an underflow.');
Expand All @@ -309,8 +310,10 @@ class FifoChecker extends Component {

@override
void check() {
if (!fifo.empty.value.toBool()) {
if (enableEndOfTestEmptyCheck) {
if (enableEndOfTestEmptyCheck) {
if (!fifo.empty.value.isValid) {
logger.severe('Fifo empty signal has invalid value at end of test.');
} else if (!fifo.empty.value.toBool()) {
logger.severe('Fifo $fifo is not empty at the end of the test.');
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/fifo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,30 @@ void main() {
});
});

test('sampling time', () async {
final fifoTest = FifoTest((clk, reset, wrEn, wrData, rdEn, rdData) async {
wrEn.inject(1);
wrData.inject(0x111);

await clk.nextPosedge;
await clk.nextPosedge;
wrEn.inject(0);
rdEn.inject(1);
await clk.nextPosedge;
await clk.nextPosedge;
rdEn.inject(0);
await clk.nextPosedge;
await clk.nextPosedge;
});

FifoChecker(fifoTest.fifo, parent: fifoTest);

fifoTest.printLevel = Level.OFF;

await fifoTest.start();
expect(fifoTest.failureDetected, false);
});

test('fifo logger', () async {
final fifoTest = FifoTest((clk, reset, wrEn, wrData, rdEn, rdData) async {
wrEn.put(1);
Expand Down

0 comments on commit c319f0f

Please sign in to comment.