Skip to content

Commit 10dfd9b

Browse files
committed
Fix MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException
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.
1 parent 06ae1be commit 10dfd9b

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ private static IntPtr ProcessorAffinityCore
5757
/// </summary>
5858
private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorkingSet)
5959
{
60+
EnsureState(State.HaveNonExitedId);
61+
6062
// We can only do this for the current process on OS X
6163
if (_processId != Environment.ProcessId)
6264
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);
@@ -86,6 +88,8 @@ private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorking
8688
/// <param name="resultingMax">The resulting maximum working set limit after any changes applied.</param>
8789
private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
8890
{
91+
EnsureState(State.HaveNonExitedId);
92+
8993
// We can only do this for the current process on OS X
9094
if (_processId != Environment.ProcessId)
9195
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorking
246246
/// <param name="resultingMin">The resulting minimum working set limit after any changes applied.</param>
247247
/// <param name="resultingMax">The resulting maximum working set limit after any changes applied.</param>
248248
#pragma warning disable IDE0060
249-
private static void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
249+
private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
250250
{
251+
EnsureState(State.HaveNonExitedId);
251252
// RLIMIT_RSS with setrlimit not supported on Linux > 2.4.30.
252253
throw new PlatformNotSupportedException(SR.MinimumWorkingSetNotSupported);
253254
}

src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -603,20 +603,12 @@ public void TestMaxWorkingSet()
603603
}
604604

605605
[Fact]
606-
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
606+
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on iOS, MacCatalyst, and tvOS.")]
607607
public void MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
608608
{
609609
var process = new Process();
610610
Assert.Throws<InvalidOperationException>(() => process.MaxWorkingSet);
611-
}
612-
613-
[Fact]
614-
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
615-
public void MaxValueWorkingSet_GetSetMacos_ThrowsPlatformSupportedException()
616-
{
617-
var process = new Process();
618-
Assert.Throws<PlatformNotSupportedException>(() => process.MaxWorkingSet);
619-
Assert.Throws<PlatformNotSupportedException>(() => process.MaxWorkingSet = (IntPtr)1);
611+
Assert.Throws<InvalidOperationException>(() => process.MaxWorkingSet = (IntPtr)1);
620612
}
621613

622614
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
@@ -659,21 +651,13 @@ public void TestMinWorkingSet()
659651
}
660652

661653
[Fact]
662-
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
654+
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on iOS, MacCatalyst, and tvOS.")]
663655
public void MinWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
664656
{
665657
var process = new Process();
666658
Assert.Throws<InvalidOperationException>(() => process.MinWorkingSet);
667659
}
668660

669-
[Fact]
670-
[PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
671-
public void MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
672-
{
673-
var process = new Process();
674-
Assert.Throws<PlatformNotSupportedException>(() => process.MinWorkingSet);
675-
}
676-
677661
[Fact]
678662
public void TestModules()
679663
{

0 commit comments

Comments
 (0)