1- // Copyright (C) 2022-2023 Intel Corporation
1+ // Copyright (C) 2022-2025 Intel Corporation
22// SPDX-License-Identifier: BSD-3-Clause
33//
44// port_launch.dart
77// 2022 October 27
88// Author: Max Korbel <[email protected] > 99
10- // ignore_for_file: avoid_print
11-
1210import 'dart:async' ;
1311
1412import 'package:args/args.dart' ;
1513import 'package:logging/logging.dart' ;
1614import 'package:rohd/rohd.dart' ;
1715import 'package:rohd_cosim/rohd_cosim.dart' ;
1816
19- void main (List <String > args) async {
17+ Future < void > main (List <String > args) async {
2018 final parser = ArgParser ()
2119 ..addOption ('port' , mandatory: true )
2220 ..addFlag ('fail' )
@@ -28,7 +26,7 @@ void main(List<String> args) async {
2826 final fail = results['fail' ] as bool ;
2927 final failAsync = results['failAsync' ] as bool ;
3028 final hang = results['hang' ] as bool ;
31- await runCosim (port, fail : fail, failAsync: failAsync, hang: hang);
29+ await runCosim (port, dartFail : fail, failAsync: failAsync, hang: hang);
3230}
3331
3432class BottomMod extends ExternalSystemVerilogModule with Cosim {
@@ -50,34 +48,41 @@ class BottomMod extends ExternalSystemVerilogModule with Cosim {
5048const bool enableLogging = true ;
5149
5250Future <void > runCosim (int port,
53- {required bool fail, required bool failAsync, required bool hang}) async {
54- // var portStuffDir = './test/port_stuff/';
55- // var outDirPath = '$portStuffDir/tmp_output/';
56-
51+ {required bool dartFail,
52+ required bool failAsync,
53+ required bool hang,
54+ bool doPrint = true }) async {
5755 void expectEqual (dynamic a, dynamic b) {
5856 if (a != b) {
5957 throw Exception ('$a != $b ' );
6058 }
6159 }
6260
63- print ('Building module...' );
61+ void log (String message) {
62+ if (doPrint) {
63+ // ignore: avoid_print
64+ print (message);
65+ }
66+ }
67+
68+ log ('Building module...' );
6469 final a = Logic ();
6570 final mod = BottomMod (a);
6671 await mod.build ();
6772
6873 if (enableLogging) {
6974 Logger .root.level = Level .ALL ;
70- Logger .root.onRecord.listen (print );
75+ Logger .root.onRecord.listen ((msg) => log (msg. toString ()) );
7176 }
7277
73- print ('Connecting to cosimulation on port $port ...' );
78+ log ('Connecting to cosimulation on port $port ...' );
7479 await Cosim .connectCosimulation (
7580 CosimPortConfig (port, enableLogging: enableLogging));
7681
77- print ('Starting simulation...' );
82+ log ('Starting simulation...' );
7883
7984 mod.aBar.changed.listen ((event) {
80- print ('checking @ ${Simulator .time }' );
85+ log ('checking @ ${Simulator .time }' );
8186 if (Simulator .time == 2 ) {
8287 expectEqual (event.newValue, LogicValue .zero);
8388 } else if (Simulator .time == 4 ) {
@@ -88,44 +93,44 @@ Future<void> runCosim(int port,
8893 });
8994
9095 Simulator .registerAction (2 , () {
91- print ('putting 1' );
96+ log ('putting 1' );
9297 a.put (1 );
9398 });
9499 Simulator .registerAction (4 , () {
95- print ('putting 0' );
100+ log ('putting 0' );
96101 a.put (0 );
97102 });
98103
99- if (fail ) {
100- print ('Setting up to fail on the dart side.' );
104+ if (dartFail ) {
105+ log ('Setting up to fail on the dart side.' );
101106 Simulator .registerAction (3 , () {
102107 throw Exception ('Failure intentionally injected' );
103108 });
104109 }
105110
106111 if (failAsync) {
107- print ('Setting up to async fail on the dart side.' );
112+ log ('Setting up to async fail on the dart side.' );
108113 unawaited (a.changed.first.then (
109114 (value) => throw Exception ('Async failure intentionally injected' )));
110115 }
111116
112117 if (hang) {
113- print ('Setting up to hang on the dart side.' );
118+ log ('Setting up to hang on the dart side.' );
114119 Simulator .registerAction (3 , () async {
115- print ('About to hang...' );
120+ log ('About to hang...' );
116121 Simulator .injectAction (() async {
117122 await Future <void >.delayed (const Duration (seconds: 10 ));
118123 });
119124 });
120125 }
121126
122127 Simulator .registerEndOfSimulationAction (() {
123- print ('End of ROHD Simulation!' );
128+ log ('End of ROHD Simulation!' );
124129 });
125130
126- print ('Done setting up vectors, launching simulation!' );
131+ log ('Done setting up vectors, launching simulation!' );
127132
128133 await Simulator .run ();
129134
130- print ('Simulation has completed!' );
135+ log ('Simulation has completed!' );
131136}
0 commit comments