Skip to content

Commit fd67f99

Browse files
CopilotMalcolmnixon
andcommitted
Fix deadlock risks in RunProgram/Runner; add const for ActiveHDL dir; fix VivadoSimulator comment
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent 0e27b63 commit fd67f99

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

src/DEMAConsulting.VHDLTest/Run/RunProgram.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ public static int Run(
5959
using var p = new Process { StartInfo = startInfo };
6060
p.Start();
6161

62-
// Collect all output
63-
output = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd();
62+
// Read both streams asynchronously to prevent deadlock if either buffer fills
63+
var stdoutTask = p.StandardOutput.ReadToEndAsync();
64+
var stderrTask = p.StandardError.ReadToEndAsync();
6465
p.WaitForExit();
6566

67+
// Collect all output
68+
output = stdoutTask.GetAwaiter().GetResult() + stderrTask.GetAwaiter().GetResult();
69+
6670
// Return the output
6771
return p.ExitCode;
6872
}

src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public sealed class ActiveHdlSimulator : Simulator
3434
/// </summary>
3535
private const string SimApp = "vsimsa";
3636

37+
/// <summary>
38+
/// Library output directory path (relative to working directory)
39+
/// </summary>
40+
private const string LibDirPath = "VHDLTest.out/ActiveHDL";
41+
3742
/// <summary>
3843
/// Compile processor
3944
/// </summary>
@@ -88,7 +93,7 @@ public override RunResults Compile(Context context, Options options)
8893
context.WriteVerboseLine($" Simulator Path: {simPath}");
8994

9095
// Create the library directory
91-
var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL");
96+
var libDir = Path.Combine(options.WorkingDirectory, LibDirPath);
9297
context.WriteVerboseLine($" Library Directory: {libDir}");
9398
if (!Directory.Exists(libDir))
9499
{
@@ -98,7 +103,7 @@ public override RunResults Compile(Context context, Options options)
98103
// Build the batch file
99104
var writer = new StringBuilder();
100105
writer.AppendLine("onerror {exit -code 1}");
101-
writer.AppendLine("alib work VHDLTest.out/ActiveHDL");
106+
writer.AppendLine($"alib work {LibDirPath}");
102107
writer.AppendLine("set worklib work");
103108
foreach (var file in options.Config.Files)
104109
{
@@ -113,12 +118,12 @@ public override RunResults Compile(Context context, Options options)
113118
// Run the ActiveHDL compiler
114119
var application = Path.Combine(simPath, SimApp);
115120
context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}");
116-
context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/compile.do");
121+
context.WriteVerboseLine($" Run Command: {application} -do {LibDirPath}/compile.do");
117122
return CompileProcessor.Execute(
118123
application,
119124
options.WorkingDirectory,
120125
"-do",
121-
"VHDLTest.out/ActiveHDL/compile.do");
126+
$"{LibDirPath}/compile.do");
122127
}
123128

124129
/// <inheritdoc />
@@ -133,7 +138,7 @@ public override TestResult Test(Context context, Options options, string test)
133138
context.WriteVerboseLine($" Simulator Path: {simPath}");
134139

135140
// Get the library directory
136-
var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL");
141+
var libDir = Path.Combine(options.WorkingDirectory, LibDirPath);
137142
context.WriteVerboseLine($" Library Directory: {libDir}");
138143

139144
// Build the batch file
@@ -153,12 +158,12 @@ public override TestResult Test(Context context, Options options, string test)
153158
// Run the test
154159
var application = Path.Combine(simPath, SimApp);
155160
context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}");
156-
context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/test.do");
161+
context.WriteVerboseLine($" Run Command: {application} -do {LibDirPath}/test.do");
157162
var testRunResults = TestProcessor.Execute(
158163
Path.Combine(simPath, SimApp),
159164
options.WorkingDirectory,
160165
"-do",
161-
"VHDLTest.out/ActiveHDL/test.do");
166+
$"{LibDirPath}/test.do");
162167

163168
// Return the test results
164169
return new TestResult(

src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override RunResults Compile(Context context, Options options)
9696
context.WriteVerboseLine($" Script File: {script}");
9797
File.WriteAllText(script, writer.ToString());
9898

99-
// Run the ModelSim compiler
99+
// Run the Vivado compiler
100100
var application = Path.Combine(simPath, "xvhdl");
101101
context.WriteVerboseLine($" Run Directory: {libDir}");
102102
context.WriteVerboseLine($" Run Command: cmd /c {application} -file compile.do");

test/DEMAConsulting.VHDLTest.Tests/Runner.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ public static int Run(out string output, string program, params string[] argumen
5656
var process = Process.Start(startInfo) ??
5757
throw new InvalidOperationException("Failed to start process");
5858

59+
// Read both streams asynchronously to prevent deadlock if either buffer fills
60+
var stdoutTask = process.StandardOutput.ReadToEndAsync();
61+
var stderrTask = process.StandardError.ReadToEndAsync();
62+
5963
// Wait for the process to exit
6064
process.WaitForExit();
6165

6266
// Save the output and return the exit code
63-
output = process.StandardOutput.ReadToEnd();
67+
output = stdoutTask.GetAwaiter().GetResult() + stderrTask.GetAwaiter().GetResult();
6468
return process.ExitCode;
6569
}
6670
}

0 commit comments

Comments
 (0)