Skip to content

Commit

Permalink
Fix MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException
Browse files Browse the repository at this point in the history
Fixes issue #105422

On MacOS, FreeBSD, SunOS (the ports that share ProcessBSD.c)
the get/set WorkingSet methods only work on the current process.
Skip the parts of tests that operate on other processes.

Remove now redundant MacOS-speicifc tests.
  • Loading branch information
gwr committed Jul 29, 2024
1 parent 4072e73 commit cf89c00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private static IntPtr ProcessorAffinityCore
/// </summary>
private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorkingSet)
{
EnsureState(State.HaveNonExitedId);

// We can only do this for the current process on OS X
if (_processId != Environment.ProcessId)
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);
Expand Down Expand Up @@ -86,6 +88,8 @@ private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorking
/// <param name="resultingMax">The resulting maximum working set limit after any changes applied.</param>
private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
{
EnsureState(State.HaveNonExitedId);

// We can only do this for the current process on OS X
if (_processId != Environment.ProcessId)
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);
Expand Down
22 changes: 3 additions & 19 deletions src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,20 +602,12 @@ public void TestMaxWorkingSet()
}

[Fact]
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
public void MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
Assert.Throws<InvalidOperationException>(() => process.MaxWorkingSet);
}

[Fact]
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
public void MaxValueWorkingSet_GetSetMacos_ThrowsPlatformSupportedException()
{
var process = new Process();
Assert.Throws<PlatformNotSupportedException>(() => process.MaxWorkingSet);
Assert.Throws<PlatformNotSupportedException>(() => process.MaxWorkingSet = (IntPtr)1);
Assert.Throws<InvalidOperationException>(() => process.MaxWorkingSet = (IntPtr)1);
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -657,21 +649,13 @@ public void TestMinWorkingSet()
}

[Fact]
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
public void MinWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
Assert.Throws<InvalidOperationException>(() => process.MinWorkingSet);
}

[Fact]
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
public void MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
{
var process = new Process();
Assert.Throws<PlatformNotSupportedException>(() => process.MinWorkingSet);
}

[Fact]
public void TestModules()
{
Expand Down

0 comments on commit cf89c00

Please sign in to comment.