Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.DotnetHostHelper.GetMuxerArchitectureByPEHeaderOnWin
DotnetHostHelper.cs
Source: DotnetHostHelper.cs
...296 EqtTrace.Error($"DotnetHostHelper.GetMuxerFromGlobalRegistrationOnUnix: Exception during '{installLocation}' muxer resolution.\n{ex}");297 }298 return null;299 }300 private PlatformArchitecture? GetMuxerArchitectureByPEHeaderOnWin(string path)301 {302 try303 {304 using Stream stream = _fileHelper.GetStream(path, FileMode.Open, FileAccess.Read);305 using PEReader peReader = new(stream);306 switch (peReader.PEHeaders.CoffHeader.Machine)307 {308 case Machine.Amd64:309 return PlatformArchitecture.X64;310 case Machine.IA64:311 return PlatformArchitecture.X64;312 case Machine.Arm64:313 return PlatformArchitecture.ARM64;314 case Machine.Arm:315 return PlatformArchitecture.ARM;316 case Machine.I386:317 return PlatformArchitecture.X86;318 default:319 break;320 }321 }322 catch (Exception ex)323 {324 EqtTrace.Error($"DotnetHostHelper.GetMuxerArchitectureByPEHeaderOnWin: Failed to get architecture from PEHeader for '{path}'\n{ex}");325 }326 return null;327 }328 // See https://opensource.apple.com/source/xnu/xnu-2050.18.24/EXTERNAL_HEADERS/mach-o/loader.h329 // https://opensource.apple.com/source/xnu/xnu-4570.41.2/osfmk/mach/machine.h.auto.html330 private PlatformArchitecture? GetMuxerArchitectureByMachoOnMac(string path)331 {332 try333 {334 using var headerReader = _fileHelper.GetStream(path, FileMode.Open, FileAccess.Read);335 var magicBytes = new byte[4];336 var cpuInfoBytes = new byte[4];337 headerReader.Read(magicBytes, 0, magicBytes.Length);338 headerReader.Read(cpuInfoBytes, 0, cpuInfoBytes.Length);339 var magic = BitConverter.ToUInt32(magicBytes, 0);340 var cpuInfo = BitConverter.ToUInt32(cpuInfoBytes, 0);341 PlatformArchitecture? architecture = (MacOsCpuType)cpuInfo switch342 {343 MacOsCpuType.Arm64Magic or MacOsCpuType.Arm64Cigam => PlatformArchitecture.ARM64,344 MacOsCpuType.X64Magic or MacOsCpuType.X64Cigam => PlatformArchitecture.X64,345 MacOsCpuType.X86Magic or MacOsCpuType.X86Cigam => PlatformArchitecture.X86,346 _ => null,347 };348 return architecture;349 }350 catch (Exception ex)351 {352 // In case of failure during header reading we must fallback to the next place(default installation path)353 EqtTrace.Error($"DotnetHostHelper.GetMuxerArchitectureByMachoOnMac: Failed to get architecture from Mach-O for '{path}'\n{ex}");354 }355 return null;356 }357 internal enum MacOsCpuType : uint358 {359 Arm64Magic = 0x0100000c,360 Arm64Cigam = 0x0c000001,361 X64Magic = 0x01000007,362 X64Cigam = 0x07000001,363 X86Magic = 0x00000007,364 X86Cigam = 0x07000000365 }366 private bool IsValidArchitectureMuxer(PlatformArchitecture targetArchitecture, string path)367 {368 PlatformArchitecture? muxerPlatform = null;369 if (_environment.OperatingSystem == PlatformOperatingSystem.Windows)370 {371 muxerPlatform = GetMuxerArchitectureByPEHeaderOnWin(path);372 }373 else if (_environment.OperatingSystem == PlatformOperatingSystem.OSX)374 {375 muxerPlatform = GetMuxerArchitectureByMachoOnMac(path);376 }377 if (targetArchitecture != muxerPlatform)378 {379 EqtTrace.Verbose($"DotnetHostHelper.IsValidArchitectureMuxer: Incompatible architecture muxer, target architecture '{targetArchitecture}', actual '{muxerPlatform}'");380 return false;381 }382 EqtTrace.Verbose($"DotnetHostHelper.IsValidArchitectureMuxer: Compatible architecture muxer, target architecture '{targetArchitecture}', actual '{muxerPlatform}'");383 return true;384 }385}...
Check out the latest blogs from LambdaTest on this topic:
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
Sometimes, in our test code, we need to handle actions that apparently could not be done automatically. For example, some mouse actions such as context click, double click, drag and drop, mouse movements, and some special key down and key up actions. These specific actions could be crucial depending on the project context.
Traditional software testers must step up if they want to remain relevant in the Agile environment. Agile will most probably continue to be the leading form of the software development process in the coming years.
The events over the past few years have allowed the world to break the barriers of traditional ways of working. This has led to the emergence of a huge adoption of remote working and companies diversifying their workforce to a global reach. Even prior to this many organizations had already had operations and teams geographically dispersed.
Howdy testers! June has ended, and it’s time to give you a refresher on everything that happened at LambdaTest over the last month. We are thrilled to share that we are live with Cypress testing and that our very own LT Browser is free for all LambdaTest users. That’s not all, folks! We have also added a whole new range of browsers, devices & features to make testing more effortless than ever.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!