Skip to content
Merged
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
26 changes: 19 additions & 7 deletions src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,31 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine;
public class TestEngine : ITestEngine
{
private readonly ITestRuntimeProviderManager _testHostProviderManager;
private ITestExtensionManager _testExtensionManager;
private readonly IProcessHelper _processHelper;
private readonly IEnvironment _environment;

private ITestExtensionManager _testExtensionManager;

public TestEngine() : this(TestRuntimeProviderManager.Instance, new ProcessHelper())
public TestEngine()
: this(TestRuntimeProviderManager.Instance, new ProcessHelper())
{
}

protected internal TestEngine(
TestRuntimeProviderManager testHostProviderManager,
IProcessHelper processHelper) : this((ITestRuntimeProviderManager)testHostProviderManager, processHelper)
IProcessHelper processHelper)
: this(testHostProviderManager, processHelper, new PlatformEnvironment())
{
}

internal TestEngine(
ITestRuntimeProviderManager testHostProviderManager,
IProcessHelper processHelper)
IProcessHelper processHelper,
IEnvironment environment)
{
_testHostProviderManager = testHostProviderManager;
_processHelper = processHelper;
_environment = environment;
}

#region ITestEngine implementation
Expand Down Expand Up @@ -492,15 +498,21 @@ private int VerifyParallelSettingAndCalculateParallelLevel(
// Check the user parallel setting.
int userParallelSetting = RunSettingsUtilities.GetMaxCpuCount(runSettings);
parallelLevelToUse = userParallelSetting == 0
// TODO: use environment helper so we can control this from tests.
? Environment.ProcessorCount
? _environment.ProcessorCount
: userParallelSetting;
var enableParallel = parallelLevelToUse > 1;

EqtTrace.Verbose(
"TestEngine: Initializing Parallel Execution as MaxCpuCount is set to: {0}",
parallelLevelToUse);

// TODO: EXPERIMENTAL FEATURE - will need to be removed or strengthen/tested.
// A negative value is used to indicate that the value should be used as a percentage of the number of cores.
if (parallelLevelToUse < 0)
{
parallelLevelToUse = (int)Math.Max(1, Math.Round((double)-parallelLevelToUse * _environment.ProcessorCount / 100.0, MidpointRounding.AwayFromZero));
}

var enableParallel = parallelLevelToUse > 1;
// Verify if the number of sources is less than user setting of parallel.
// We should use number of sources as the parallel level, if sources count is less
// than parallel level.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public interface IEnvironment
/// </summary>
/// <returns>Returns the thread Id</returns>
int GetCurrentManagedThreadId();

/// <inheritdoc cref="System.Environment.ProcessorCount"/>
int ProcessorCount { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IAssemblyRes
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IAssemblyResolver.AssemblyResolve -> Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.AssemblyResolveEventHandler?
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IEnvironment
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IEnvironment.Architecture.get -> Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformArchitecture
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IEnvironment.ProcessorCount.get -> int
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IEnvironment.Exit(int exitcode) -> void
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IEnvironment.GetCurrentManagedThreadId() -> int
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces.IEnvironment.OperatingSystem.get -> Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformOperatingSystem
Expand Down Expand Up @@ -79,6 +80,7 @@ Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformAssemblyResolve
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformAssemblyResolver.PlatformAssemblyResolver() -> void
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformEnvironment
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformEnvironment.Architecture.get -> Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformArchitecture
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformEnvironment.ProcessorCount.get -> int
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformEnvironment.Exit(int exitcode) -> void
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformEnvironment.GetCurrentManagedThreadId() -> int
Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformEnvironment.OperatingSystem.get -> Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformOperatingSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public PlatformOperatingSystem OperatingSystem
/// <inheritdoc />
public string OperatingSystemVersion => Environment.OSVersion.ToString();

/// <inheritdoc />
public int ProcessorCount => Environment.ProcessorCount;

/// <inheritdoc />
public void Exit(int exitcode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public string OperatingSystemVersion
}
}

/// <inheritdoc />
public int ProcessorCount => Environment.ProcessorCount;

/// <inheritdoc />
public void Exit(int exitcode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public string OperatingSystemVersion
}
}

/// <inheritdoc />
public int ProcessorCount => throw new NotImplementedException();

/// <inheritdoc />
public void Exit(int exitcode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public PlatformOperatingSystem OperatingSystem
/// <inheritdoc />
public string OperatingSystemVersion => RuntimeInformation.OSDescription;

/// <inheritdoc />
public int ProcessorCount => Environment.ProcessorCount;

/// <inheritdoc />
public void Exit(int exitcode)
{
Expand Down
2 changes: 2 additions & 0 deletions test/vstest.ProgrammerTests/Fakes/FakeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal class FakeEnvironment : IEnvironment

public string OperatingSystemVersion => _environment.OperatingSystemVersion;

public int ProcessorCount => _environment.ProcessorCount;

public void Exit(int exitcode) => _environment.Exit(exitcode);

public int GetCurrentManagedThreadId() => _environment.GetCurrentManagedThreadId();
Expand Down
2 changes: 1 addition & 1 deletion test/vstest.ProgrammerTests/Fakes/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ internal TestRequestManagerTestHelper BuildTestRequestManager(
throw new InvalidOperationException("There are runtime providers registered for FakeTestRuntimeProviderManager.");


TestEngine = new TestEngine(TestRuntimeProviderManager, ProcessHelper);
TestEngine = new TestEngine(TestRuntimeProviderManager, ProcessHelper, Environment);
TestPlatform = new TestPlatform(TestEngine, FileHelper, TestRuntimeProviderManager);

TestRunResultAggregator = new TestRunResultAggregator();
Expand Down