Skip to content

Commit 7a320f3

Browse files
Kyle ZhangHarley Zhang
authored andcommitted
Merged PR 5416282: Need to detect current OS, as PTF is cross-platform now.
Need to detect current OS, as PTF is cross-platform now. Related work items: #30498306
2 parents 6bf76b4 + 780178c commit 7a320f3

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/TestFramework/Core/Adapters/ShellAdapterProxy.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Diagnostics;
99
using System.Text;
1010
using System.Data;
11+
using System.Runtime.InteropServices;
1112

1213
namespace Microsoft.Protocols.TestTools
1314
{
@@ -210,7 +211,7 @@ private string LookupScript(string methodname)
210211
}
211212
}
212213

213-
private string BuildScriptArguments()
214+
private string BuildScriptArguments()
214215
{
215216
StringBuilder arguments = new StringBuilder();
216217
arguments.Append(BuildInArguments());
@@ -253,24 +254,32 @@ private int InvokeScript(string path, string arguments)
253254
{
254255
using (Process proc = new Process())
255256
{
257+
// For Linux/macOS, use the shell on current system
256258
string wslPath = "/bin/bash";
257-
string winDir = Environment.GetEnvironmentVariable("WINDIR");
258-
if(!string.IsNullOrEmpty(winDir))
259-
{
260-
if (Environment.Is64BitProcess)
261-
{
262-
wslPath = string.Format(@"{0}\System32\bash.exe", winDir);
263-
}
264-
else
265-
{
266-
wslPath = string.Format(@"{0}\Sysnative\bash.exe", winDir);
267-
}
268259

269-
if (!File.Exists(wslPath))
260+
// Detect current OS
261+
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
262+
if (isWindows)
263+
{
264+
// For Windows, WSL is needed
265+
string winDir = Environment.GetEnvironmentVariable("WINDIR");
266+
if (!string.IsNullOrEmpty(winDir))
270267
{
271-
TestSite.Assume.Fail("Windows Subsystem for Linux (WSL) is not installed.");
268+
if (Environment.Is64BitProcess)
269+
{
270+
wslPath = string.Format(@"{0}\System32\bash.exe", winDir);
271+
}
272+
else
273+
{
274+
wslPath = string.Format(@"{0}\Sysnative\bash.exe", winDir);
275+
}
276+
277+
if (!File.Exists(wslPath))
278+
{
279+
TestSite.Assume.Fail("Windows Subsystem for Linux (WSL) is not installed.");
280+
}
272281
}
273-
}
282+
}
274283

275284
proc.StartInfo.FileName = wslPath;
276285
proc.StartInfo.Arguments = String.Format("{0} {1}", path, arguments);

0 commit comments

Comments
 (0)