Skip to content

Commit

Permalink
Added test for changed triggers on injection from changed (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 authored Dec 22, 2022
1 parent 447a7cf commit fda9de6
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/changed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,51 @@ void main() {
a <= Const(0);
expect(b.value, equals(LogicValue.one));
});

test('injection on edge happens on same edge', () async {
final clk = SimpleClockGenerator(200).clk;

// faster clk just to add more events to the Simulator
SimpleClockGenerator(17).clk;

final posedgeChangingSignal = Logic()..put(0);
final negedgeChangingSignal = Logic()..put(0);

void posedgeExpect() {
if (Simulator.time > 50) {
expect((Simulator.time + 100) % 200, equals(0));
}
}

void negedgeExpect() {
if (Simulator.time > 50) {
expect(Simulator.time % 200, equals(0));
}
}

clk.posedge.listen((event) {
posedgeExpect();
posedgeChangingSignal.inject(~posedgeChangingSignal.value);
});
clk.negedge.listen((event) {
negedgeChangingSignal.inject(~negedgeChangingSignal.value);
});

posedgeChangingSignal.glitch.listen((args) {
posedgeExpect();
});
negedgeChangingSignal.glitch.listen((args) {
negedgeExpect();
});

posedgeChangingSignal.changed.listen((args) {
posedgeExpect();
});
negedgeChangingSignal.changed.listen((args) {
negedgeExpect();
});

Simulator.setMaxSimTime(5000);
await Simulator.run();
});
}

0 comments on commit fda9de6

Please sign in to comment.