diff --git a/README.md b/README.md index 6c88fb1a3..f657176e4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/doc/tutorials/chapter_7/answers/exercise_1_d_flip_flop.dart b/doc/tutorials/chapter_7/answers/exercise_1_d_flip_flop.dart index f7c9d1b3b..15395d7ec 100644 --- a/doc/tutorials/chapter_7/answers/exercise_1_d_flip_flop.dart +++ b/doc/tutorials/chapter_7/answers/exercise_1_d_flip_flop.dart @@ -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 @@ -80,6 +80,6 @@ Future main() async { printFlop('Third tick, end simulation.'); expect(dff.q.value.toInt(), equals(0)); - Simulator.endSimulation(); + await Simulator.simulationEnded; }); } diff --git a/doc/tutorials/chapter_7/shift_register.dart b/doc/tutorials/chapter_7/shift_register.dart index 38f1bece8..1dc98c4f1 100644 --- a/doc/tutorials/chapter_7/shift_register.dart +++ b/doc/tutorials/chapter_7/shift_register.dart @@ -1,4 +1,4 @@ -// Copyright (C) 2023 Intel Corporation +// Copyright (C) 2023-2024 Intel Corporation // SPDX-License-Identifier: BSD-3-Clause // // shift_register.dart @@ -167,7 +167,5 @@ void main() async { Simulator.setMaxSimTime(100); await Simulator.run(); - - Simulator.endSimulation(); }); } diff --git a/doc/user_guide/_docs/A01-sample-example.md b/doc/user_guide/_docs/A01-sample-example.md index ff97f6d22..ac6d26024 100644 --- a/doc/user_guide/_docs/A01-sample-example.md +++ b/doc/user_guide/_docs/A01-sample-example.md @@ -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 --- diff --git a/doc/user_guide/_docs/B02-comparisons-with-alternatives.md b/doc/user_guide/_docs/B02-comparisons-with-alternatives.md index ca98fd2eb..1af3d0619 100644 --- a/doc/user_guide/_docs/B02-comparisons-with-alternatives.md +++ b/doc/user_guide/_docs/B02-comparisons-with-alternatives.md @@ -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 --- diff --git a/doc/user_guide/_get-started/01-overview.md b/doc/user_guide/_get-started/01-overview.md index 0481708e5..7b84a1fbb 100644 --- a/doc/user_guide/_get-started/01-overview.md +++ b/doc/user_guide/_get-started/01-overview.md @@ -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 --- diff --git a/lib/src/finite_state_machine.dart b/lib/src/finite_state_machine.dart index 0f5387784..9847b288b 100644 --- a/lib/src/finite_state_machine.dart +++ b/lib/src/finite_state_machine.dart @@ -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 diff --git a/lib/src/simulator.dart b/lib/src/simulator.dart index 638b0d545..0cd8c2532 100644 --- a/lib/src/simulator.dart +++ b/lib/src/simulator.dart @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2023 Intel Corporation +// Copyright (C) 2021-2024 Intel Corporation // SPDX-License-Identifier: BSD-3-Clause // // simulator.dart @@ -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 endSimulation() async { _simulationEndRequested = true; + + // wait for the simulation to actually end + await simulationEnded; } /// Collects an [exception] and associated [stackTrace] triggered diff --git a/test/fsm_test.dart b/test/fsm_test.dart index c906b093c..ca173c564 100644 --- a/test/fsm_test.dart +++ b/test/fsm_test.dart @@ -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 diff --git a/test/simulator_test.dart b/test/simulator_test.dart index bcbdbbe14..65c1adc34 100644 --- a/test/simulator_test.dart +++ b/test/simulator_test.dart @@ -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 @@ -43,7 +43,8 @@ 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)); @@ -51,7 +52,7 @@ void main() { }); 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()); }); @@ -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);