run method
- Phase phase
override
Executes this Component's activities related to running the test.
Overrides of run must call super.run in an unawaited fashion.
For example:
@override
Future<void> run(Phase phase) async {
unawaited(super.run(phase));
// New code goes here!
}
Implementation
@override
Future<void> run(Phase phase) async {
unawaited(super.run(phase));
var cycle = 0;
while (!Simulator.simulationHasEnded) {
await clk.nextPosedge;
if (Simulator.simulationHasEnded) {
return;
}
final resetValue = reset.previousValue;
final debitValue = debit.previousValue;
final creditReturnValue = creditReturn.previousValue;
if (resetValue == null ||
debitValue == null ||
creditReturnValue == null) {
cycle++;
continue;
}
final inReset = (resetValue.isValid && resetValue.toBool()) ||
reinitializationResets.any((reset) {
final value = reset.previousValue;
return value != null && value.isValid && value.toBool();
});
if (inReset) {
_credits.setAll(0, configuration.initialCredits);
_sharedCredits = configuration.sharedInitialCredits ??
_credits.fold(0, (sum, credits) => sum + credits);
} else if (!debitValue.isValid || !creditReturnValue.isValid) {
_report(
'credit.controls_known',
cycle,
'Debit and credit-return controls must be known after reset.',
{'debit': debitValue, 'creditReturn': creditReturnValue});
} else {
final debitedPools = [
for (var pool = 0; pool < debit.width; pool++)
if (debitValue[pool].toBool()) pool
];
if (debitedPools.length > 1) {
_report(
'credit.debit_one_hot',
cycle,
'At most one credit pool may be debited in a cycle.',
{'debit': debitValue, 'pools': debitedPools});
}
if (configuration.sharedMaximumCredits != null) {
_checkSharedCredits(debitedPools, creditReturnValue, cycle);
} else {
for (final pool in debitedPools) {
if (_credits[pool] == 0) {
_report(
'credit.no_credit',
cycle,
'A send consumed a credit from an empty pool.',
{'pool': pool, 'credits': _credits[pool]});
} else {
_credits[pool]--;
}
}
for (var pool = 0; pool < creditReturn.width; pool++) {
if (creditReturnValue[pool].toBool()) {
if (_credits[pool] == configuration.maximumCredits[pool]) {
_report('credit.overflow', cycle,
'A credit return exceeded the configured pool capacity.', {
'pool': pool,
'credits': _credits[pool],
'maximumCredits': configuration.maximumCredits[pool]
});
} else {
_credits[pool]++;
}
}
}
}
}
cycle++;
}
}