-
|
How should I code my unit testing if the expected result is one clock later? Like how am I going to test for flip flop? What if the output is one clock or two clocks later? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Perhaps You can also use |
Beta Was this translation helpful? Give feedback.
-
|
I see. Thanks for writing the example @chykon! Appreciate it. I wonder if it's possible to merge with dart unit test |
Beta Was this translation helpful? Give feedback.
-
|
Here's an example where you can use import 'dart:async';
import 'package:rohd/rohd.dart';
import 'package:test/test.dart';
void main() {
test('test flop', () async {
final clk = SimpleClockGenerator(10).clk;
final input = Logic(width: 8);
final output = FlipFlop(clk, input).q;
/// Prints the current state of the flop.
void printFlop([String message = '']) {
print('@${Simulator.time}:\t'
' input=${input.value}, output=${output.value}\t$message');
}
// set a max time in case something goes longer than expected
Simulator.setMaxSimTime(100);
// kick off the simulator, but dont wait for it, so we can do other async
// stuff meanwhile.
unawaited(Simulator.run());
await clk.nextPosedge;
input.put(0);
// check after posedge sampling that the value matches expectations
await clk.nextPosedge;
printFlop('After sampling 0');
expect(output.value.toInt(), 0);
// drive a new value onto the flop
input.put(0xa5);
printFlop('After driving 0xa5, before posedge sampling');
await clk.nextPosedge;
printFlop('After driving 0xa5 and posedge sampling');
expect(output.value.toInt(), 0xa5);
// we're done, we can end the simulation
Simulator.endSimulation();
await Simulator.simulationEnded;
});
}The output of this test looks like this: |
Beta Was this translation helpful? Give feedback.
Here's an example where you can use
awaiton the edges of the clock to drive stimulus and check values out of the flop.