Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Microsoft.TestPlatform.ObjectModel/Architecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum Architecture
X86,
X64,
ARM,
AnyCPU
AnyCPU,
ARM64
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public static RunConfiguration FromXml(XmlReader reader)
try
{
archType = (Architecture)Enum.Parse(typeof(Architecture), value, true);
if (archType != Architecture.X64 && archType != Architecture.X86 && archType != Architecture.ARM)
if (archType != Architecture.X64 && archType != Architecture.X86 && archType != Architecture.ARM && archType != Architecture.ARM64)
{
throw new SettingsException(
string.Format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ public static ObjectModel.Architecture OSArchitecture
{
get
{
#if !NETSTANDARD1_4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this come from the PlatformEnvironment ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No due to backwards compat reasons this API normally lies about the OS architecture, so this is the way to do it.

try
{
// use the new IsWow64Process2 to detect ARM64 as well.
var processHandle = System.Diagnostics.Process.GetCurrentProcess().Handle;
if (IsWow64Process2(processHandle, out ImageFileMachine pProcessMachinem, out ImageFileMachine pNativeMachine))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the m at the end of pProcessMachinem a typo?

Copy link
Contributor Author

@dotMorten dotMorten Jul 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted this PR almost a year and a half ago, so honestly I have no clue but probably? 🤷‍♂️. To be honest, I don't even remember submitting this PR.
Feel free to take what I have and work with it, but with such a delay in response and in the mean time I found other means for testing on ARM64, I don't see myself picking this PR up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will most likely pick this up, when we get ARM64 hardware.

{
switch (pNativeMachine)
{
case ImageFileMachine.AMD64:
case ImageFileMachine.IA64:
return Architecture.X64;
Comment on lines +39 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IA64 (Itanium) should not be mapped to X64.

case ImageFileMachine.X86:
return Architecture.X86;
case ImageFileMachine.ARM:
return Architecture.ARM;
case ImageFileMachine.ARM64:
return Architecture.ARM64;
}
}
}
catch { }
#endif
var arch = new PlatformEnvironment().Architecture;

switch (arch)
Expand All @@ -34,11 +57,25 @@ public static ObjectModel.Architecture OSArchitecture
return ObjectModel.Architecture.X64;
case PlatformArchitecture.X86:
return ObjectModel.Architecture.X86;
case PlatformArchitecture.ARM64:
return ObjectModel.Architecture.ARM64;
default:
return ObjectModel.Architecture.ARM;
}
}
}
#if !NETSTANDARD1_4
private enum ImageFileMachine : ushort
{
X86 = 0x014c,
ARM = 0x01c0,
IA64 = 0x0200,
AMD64 = 0x8664,
ARM64 = 0xAA64
}
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern bool IsWow64Process2([System.Runtime.InteropServices.In] IntPtr processHandle, [System.Runtime.InteropServices.Out] out ImageFileMachine pProcessMachinem, [System.Runtime.InteropServices.Out] out ImageFileMachine pNativeMachine);
#endif

/// <summary>
/// Gets the settings to be used while creating XmlReader for runsettings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ private static void VerifyCompatibilityWithOSArchitecture(Architecture architect
{
var osArchitecture = XmlRunSettingsUtilities.OSArchitecture;

if (architecture == Architecture.X86 && osArchitecture == Architecture.X64)
if (architecture == Architecture.X86 && (osArchitecture == Architecture.X64 || osArchitecture == Architecture.ARM64))
{
return;
}
if ((architecture == Architecture.ARM || architecture == Architecture.X86) && osArchitecture == Architecture.ARM64)
Comment on lines +519 to +523
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The combination architecture == Architecture.X86 && osArchitecture == Architecture.ARM64 is checked twice. Using IsWow64GuestMachineSupported may be more appropriate here.

{
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/vstest.console/CommandLine/AssemblyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Architecture GetArchitectureForSource(string imagePath)
const int IMAGE_FILE_MACHINE_ARM = 0x01c0; // ARM Little-Endian
const int IMAGE_FILE_MACHINE_THUMB = 0x01c2; // ARM Thumb/Thumb-2 Little-Endian
const int IMAGE_FILE_MACHINE_ARMNT = 0x01c4; // ARM Thumb-2 Little-Endian

const int IMAGE_FILE_MACHINE_ARM64 = 0xAA64; // ARM64 Little-Endian

try
{
Expand Down Expand Up @@ -235,6 +235,9 @@ public Architecture GetArchitectureForSource(string imagePath)
case IMAGE_FILE_MACHINE_ARMNT:
archType = Architecture.ARM;
break;
case IMAGE_FILE_MACHINE_ARM64:
archType = Architecture.ARM64;
break;
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/vstest.console/Processors/PlatformArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void Initialize(string argument)
var validPlatform = Enum.TryParse(argument, true, out platform);
if (validPlatform)
{
validPlatform = platform == Architecture.X86 || platform == Architecture.X64 || platform == Architecture.ARM;
validPlatform = platform == Architecture.X86 || platform == Architecture.X64 || platform == Architecture.ARM || platform == Architecture.ARM64;
}

if (validPlatform)
Expand Down
2 changes: 1 addition & 1 deletion src/vstest.console/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
<value>The --ParentProcessId|/ParentProcessId argument requires the process id which is an integer. Specify the process id of the parent process that launched this process.</value>
</data>
<data name="InvalidPlatformType" xml:space="preserve">
<value>Invalid platform type:{0}. Valid platform types are x86, x64 and Arm.</value>
<value>Invalid platform type:{0}. Valid platform types are x86, x64, Arm and Arm64.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize ARM and ARM64 in messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! This is the correct capitalization

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use lower case only as in C# compiler usage help. In any case the two lists below should be consistent, and they are not (@nohwnd):

X86,
X64,
ARM,
AnyCPU,
ARM64,
S390x
Valid values are x86, x64 and ARM.</value>

</data>
<data name="InvalidPortArgument" xml:space="preserve">
<value>The --Port|/Port argument requires the port number which is an integer. Specify the port for socket connection and receiving the event messages.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void InitializeShouldThrowIfArgumentIsNotAnArchitecture()
{
ExceptionUtilities.ThrowsException<CommandLineException>(
() => this.executor.Initialize("foo"),
"Invalid platform type:{0}. Valid platform types are x86, x64 and Arm.",
"Invalid platform type:{0}. Valid platform types are x86, x64, Arm and Arm64.",
"foo");
}

Expand All @@ -95,7 +95,7 @@ public void InitializeShouldThrowIfArgumentIsNotASupportedArchitecture()
{
ExceptionUtilities.ThrowsException<CommandLineException>(
() => this.executor.Initialize("AnyCPU"),
"Invalid platform type:{0}. Valid platform types are x86, x64 and Arm.",
"Invalid platform type:{0}. Valid platform types are x86, x64, Arm and Arm64.",
"AnyCPU");
}

Expand Down