Skip to content

Commit becc139

Browse files
Nathan Ricciadamsitnik
andauthored
Dont redirect standard input for WASM (#1689)
* Don't redirect standard input with Wasm. * Apply suggestions from code review Co-authored-by: Adam Sitnik <[email protected]>
1 parent 63e28c1 commit becc139

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/BenchmarkDotNet/Loggers/SynchronousProcessOutputLoggerWithDiagnoser.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using BenchmarkDotNet.Diagnosers;
55
using BenchmarkDotNet.Engines;
6+
using BenchmarkDotNet.Environments;
67
using BenchmarkDotNet.Running;
78

89
namespace BenchmarkDotNet.Loggers
@@ -18,7 +19,7 @@ public SynchronousProcessOutputLoggerWithDiagnoser(ILogger logger, Process proce
1819
{
1920
if (!process.StartInfo.RedirectStandardOutput)
2021
throw new NotSupportedException("set RedirectStandardOutput to true first");
21-
if (!process.StartInfo.RedirectStandardInput)
22+
if (!(process.StartInfo.RedirectStandardInput || benchmarkCase.GetRuntime() is WasmRuntime))
2223
throw new NotSupportedException("set RedirectStandardInput to true first");
2324

2425
this.logger = logger;
@@ -54,7 +55,11 @@ internal void ProcessInput()
5455
else if (Engine.Signals.TryGetSignal(line, out var signal))
5556
{
5657
diagnoser?.Handle(signal, diagnoserActionParameters);
57-
process.StandardInput.WriteLine(Engine.Signals.Acknowledgment);
58+
59+
if (process.StartInfo.RedirectStandardInput)
60+
{
61+
process.StandardInput.WriteLine(Engine.Signals.Acknowledgment);
62+
}
5863

5964
if (signal == HostSignal.AfterAll)
6065
{
@@ -70,4 +75,4 @@ internal void ProcessInput()
7075
}
7176
}
7277
}
73-
}
78+
}

src/BenchmarkDotNet/Running/BenchmarkCase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Linq;
33
using BenchmarkDotNet.Configs;
4+
using BenchmarkDotNet.Environments;
45
using BenchmarkDotNet.Jobs;
56
using BenchmarkDotNet.Parameters;
7+
using BenchmarkDotNet.Portability;
68

79
namespace BenchmarkDotNet.Running
810
{
@@ -26,6 +28,10 @@ private BenchmarkCase(Descriptor descriptor, Job job, ParameterInstances paramet
2628
Config = config;
2729
}
2830

31+
public Runtime GetRuntime() => Job.Environment.HasValue(EnvironmentMode.RuntimeCharacteristic)
32+
? Job.Environment.Runtime
33+
: RuntimeInformation.GetCurrentRuntime();
34+
2935
public void Dispose() => Parameters.Dispose();
3036

3137
public int CompareTo(BenchmarkCase other) => string.Compare(FolderInfo, other.FolderInfo, StringComparison.Ordinal);
@@ -37,4 +43,4 @@ private BenchmarkCase(Descriptor descriptor, Job job, ParameterInstances paramet
3743
public static BenchmarkCase Create(Descriptor descriptor, Job job, ParameterInstances parameters, ImmutableConfig config)
3844
=> new BenchmarkCase(descriptor, job.MakeSettingsUserFriendly(descriptor), parameters, config);
3945
}
40-
}
46+
}

src/BenchmarkDotNet/Toolchains/Executor.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ private ProcessStartInfo CreateStartInfo(BenchmarkCase benchmarkCase, ArtifactsP
9898

9999
string exePath = artifactsPaths.ExecutablePath;
100100

101-
var runtime = benchmarkCase.Job.Environment.HasValue(EnvironmentMode.RuntimeCharacteristic)
102-
? benchmarkCase.Job.Environment.Runtime
103-
: RuntimeInformation.GetCurrentRuntime();
101+
var runtime = benchmarkCase.GetRuntime();
104102
// TODO: use resolver
105103

106104
switch (runtime)
@@ -117,6 +115,7 @@ private ProcessStartInfo CreateStartInfo(BenchmarkCase benchmarkCase, ArtifactsP
117115
break;
118116
case WasmRuntime wasm:
119117
start.FileName = wasm.JavaScriptEngine;
118+
start.RedirectStandardInput = false;
120119
start.Arguments = $"{wasm.JavaScriptEngineArguments} runtime.js -- --run {artifactsPaths.ProgramName}.dll {args} ";
121120
start.WorkingDirectory = artifactsPaths.BinariesDirectoryPath;
122121
break;
@@ -151,4 +150,4 @@ private string GetMonoArguments(Job job, string exePath, string args, IResolver
151150
return builder.ToString();
152151
}
153152
}
154-
}
153+
}

0 commit comments

Comments
 (0)