Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Simulator.endSimulation return a Future #455

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ ROHD is under active development. If you're interested in contributing, have fe

----------------

Copyright (C) 2021-2023 Intel Corporation
Copyright (C) 2021-2024 Intel Corporation
SPDX-License-Identifier: BSD-3-Clause
4 changes: 2 additions & 2 deletions doc/tutorials/chapter_7/answers/exercise_1_d_flip_flop.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023 Intel Corporation
// Copyright (C) 2023-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// exercise_1_d_flip_flop.dart
Expand Down Expand Up @@ -80,6 +80,6 @@ Future<void> main() async {
printFlop('Third tick, end simulation.');
expect(dff.q.value.toInt(), equals(0));

Simulator.endSimulation();
await Simulator.simulationEnded;
});
}
4 changes: 1 addition & 3 deletions doc/tutorials/chapter_7/shift_register.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023 Intel Corporation
// Copyright (C) 2023-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// shift_register.dart
Expand Down Expand Up @@ -167,7 +167,5 @@ void main() async {

Simulator.setMaxSimTime(100);
await Simulator.run();

Simulator.endSimulation();
});
}
2 changes: 1 addition & 1 deletion doc/user_guide/_docs/A01-sample-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "ROHD Example"
permalink: /docs/sample-example/
excerpt: "Sample example of using ROHD."
last_modified_at: 2022-12-21
last_modified_at: 2024-01-04
toc: true
---

Expand Down
2 changes: 1 addition & 1 deletion doc/user_guide/_docs/B02-comparisons-with-alternatives.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Comparison with Alternatives"
permalink: /docs/comparison-with-alternatives/
excerpt: "Comparison with Alternatives"
last_modified_at: 2023-6-19
last_modified_at: 2024-01-04
toc: true
---

Expand Down
2 changes: 1 addition & 1 deletion doc/user_guide/_get-started/01-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Overview"
permalink: /get-started/overview/
excerpt: "Overview of ROHD framework."
last_modified_at: 2022-12-05
last_modified_at: 2024-01-04
toc: true
---

Expand Down
2 changes: 1 addition & 1 deletion lib/src/finite_state_machine.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022-2023 Intel Corporation
// Copyright (C) 2022-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// finite_state_machine.dart
Expand Down
10 changes: 8 additions & 2 deletions lib/src/simulator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021-2023 Intel Corporation
// Copyright (C) 2021-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// simulator.dart
Expand Down Expand Up @@ -270,8 +270,14 @@ abstract class Simulator {

/// Halts the simulation. Allows the current [tick] to finish, if there
/// is one.
static void endSimulation() {
///
/// The [Future] returned is equivalent to [simulationEnded] and completes
/// once the simulation has actually ended.
static Future<void> endSimulation() async {
_simulationEndRequested = true;

// wait for the simulation to actually end
await simulationEnded;
}

/// Collects an [exception] and associated [stackTrace] triggered
Expand Down
2 changes: 1 addition & 1 deletion test/fsm_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022-2023 Intel Corporation
// Copyright (C) 2022-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// fsm_test.dart
Expand Down
18 changes: 15 additions & 3 deletions test/simulator_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021-2023 Intel Corporation
// Copyright (C) 2021-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// simulator_test.dart
Expand Down Expand Up @@ -43,15 +43,16 @@ void main() {
const haltTime = 650;
Simulator.registerAction(100, () => farEnough = true);
Simulator.registerAction(1000, () => tooFar = true);
Simulator.registerAction(haltTime, Simulator.endSimulation);
Simulator.registerAction(
haltTime, () => unawaited(Simulator.endSimulation()));
await Simulator.run();
expect(Simulator.time, equals(haltTime));
expect(tooFar, equals(false));
expect(farEnough, equals(true));
});

test('simulator reset waits for simulation to complete', () async {
Simulator.registerAction(100, Simulator.endSimulation);
Simulator.registerAction(100, () => unawaited(Simulator.endSimulation()));
Simulator.registerAction(100, () {
unawaited(Simulator.reset());
});
Expand Down Expand Up @@ -80,6 +81,17 @@ void main() {
expect(endOfSimActionExecuted, isTrue);
});

test('simulator end simulation waits for simulation to end', () async {
final signal = Logic()..put(0);
Simulator.setMaxSimTime(1000);
Simulator.registerAction(100, () => signal.inject(1));
unawaited(Simulator.run());
await signal.nextPosedge;
await Simulator.endSimulation();
expect(Simulator.simulationHasEnded, isTrue);
expect(Simulator.time, 100);
});

test('simulator waits for async registered actions to complete', () async {
var registeredActionExecuted = false;
Simulator.registerAction(100, () => true);
Expand Down