Skip to content

Commit

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

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

There are tests that verify the old (less correct) behavior of
the get/set WorkingSet methods from before this fix.
Comment out those tests for now and add notes.

Needs testing on the affected platforms and then either
update those commented out tests or just remove them.
  • Loading branch information
gwr committed Jul 27, 2024
1 parent 214a376 commit e1cf1ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 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
42 changes: 25 additions & 17 deletions src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,22 +601,26 @@ public void TestMaxWorkingSet()
}
}

// XXX No longer skip: OSX, FreeBSD
[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);
}
// XXX This appears to be testing for incorrect behavoir which has been fixed.
// XXX See https://github.com/dotnet/runtime/issues/105422
// The correct exception for a new process is: InvalidOperationException
// [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);
// }

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void TestMinWorkingSet()
Expand Down Expand Up @@ -656,21 +660,25 @@ public void TestMinWorkingSet()
}
}

// XXX No longer skip: OSX, FreeBSD
[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);
}
// XXX This appears to be testing for incorrect behavoir which has been fixed.
// XXX See https://github.com/dotnet/runtime/issues/105422
// The correct exception for a new process is: InvalidOperationException
// [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 e1cf1ad

Please sign in to comment.