diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 65c397be3d36e8..07e4b88097dfa6 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -36,6 +36,8 @@ public static partial class PlatformDetection public static bool IsNativeAot => IsNotMonoRuntime && !IsReflectionEmitSupported; public static bool IsNotNativeAot => !IsNativeAot; public static bool IsCoreCLR => IsNotMonoRuntime && IsNotNativeAot; + public static bool IsCoreClrInterpreter => GetIsRunningOnCoreClrInterpreter(); + public static bool IsNotCoreClrInterpreter => !IsCoreClrInterpreter; public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")); public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")); public static bool IsAndroid => RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")); @@ -209,6 +211,8 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly() public static bool SupportsSsl3 => GetSsl3Support(); public static bool SupportsSsl2 => IsWindows && !PlatformDetection.IsWindows10Version1607OrGreater; + public static bool SupportsDirtyAccessViolations => !PlatformDetection.IsMonoRuntime && !PlatformDetection.IsCoreClrInterpreter && !PlatformDetection.IsWasm; + #if NET public static bool IsReflectionEmitSupported => RuntimeFeature.IsDynamicCodeSupported; public static bool IsNotReflectionEmitSupported => !IsReflectionEmitSupported; @@ -727,6 +731,26 @@ private static bool GetIsRunningOnMonoInterpreter() #endif } + private static string GetEnvironmentVariableValue(string name, string defaultValue = "0") => + Environment.GetEnvironmentVariable("DOTNET_" + name) ?? Environment.GetEnvironmentVariable("COMPlus_" + name) ?? defaultValue; + + private static bool GetIsRunningOnCoreClrInterpreter() + { + if (IsCoreCLR) + { +#if NET + if (RuntimeFeature.IsDynamicCodeSupported && !RuntimeFeature.IsDynamicCodeCompiled) + return true; +#endif + if (!string.IsNullOrWhiteSpace(GetEnvironmentVariableValue("Interpreter", ""))) + return true; + if (int.TryParse(GetEnvironmentVariableValue("InterpMode", "0"), out int mode) && (mode > 0)) + return true; + } + + return false; + } + private static bool IsEnvironmentVariableTrue(string variableName) { if (!IsBrowser) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.NonNativeAot.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.NonNativeAot.cs index 4495e552342c9b..8d0e0d94dad035 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.NonNativeAot.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.NonNativeAot.cs @@ -22,7 +22,11 @@ public static bool IsDynamicCodeCompiled #if MONO [Intrinsic] // the Mono AOT compiler and Interpreter will change this flag to false for FullAOT and interpreted scenarios, otherwise this code is used #endif +#if CORECLR && (TARGET_WASM || TARGET_IOS || TARGET_TVOS || TARGET_MACCATALYST) + get => false; +#else get => IsDynamicCodeSupported; +#endif } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs index 2d9a9c4977f4c1..7399b3de60a6de 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/ByteTests.cs @@ -131,11 +131,13 @@ public void ReadByte_StructWithReferenceTypes_ReturnsExpected() } [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadByte_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.ReadByte(IntPtr.Zero)); - AssertExtensions.ThrowsAny(() => Marshal.ReadByte(IntPtr.Zero, 2)); + AssertExtensions.Throws(() => Marshal.ReadByte(IntPtr.Zero)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.ReadByte(IntPtr.Zero, 2)); + } } [Fact] @@ -157,15 +159,15 @@ public void ReadByte_NotReadable_ThrowsArgumentException() AssertExtensions.Throws(null, () => Marshal.ReadByte(collectibleObject, 0)); } - [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteByte_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.WriteByte(IntPtr.Zero, 0)); - AssertExtensions.ThrowsAny(() => Marshal.WriteByte(IntPtr.Zero, 2, 0)); + AssertExtensions.Throws(() => Marshal.WriteByte(IntPtr.Zero, 0)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.WriteByte(IntPtr.Zero, 2, 0)); + } } - [Fact] [SkipOnMono("Marshal.WriteByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteByte_NullObject_ThrowsAccessViolationException() diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs index da886307dddd1e..b7629e41878640 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int16Tests.cs @@ -124,15 +124,15 @@ public void ReadInt16_StructWithReferenceTypes_ReturnsExpected() Assert.Equal(100, Marshal.ReadInt16(structure, pointerOffset)); Assert.Equal(3, Marshal.ReadInt16(structure, arrayOffset + sizeof(short) * 2)); } - [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt16_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.ReadInt16(IntPtr.Zero)); - AssertExtensions.ThrowsAny(() => Marshal.ReadInt16(IntPtr.Zero, 2)); + AssertExtensions.Throws(() => Marshal.ReadInt16(IntPtr.Zero)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.ReadInt16(IntPtr.Zero, 2)); + } } - [Fact] [SkipOnMono("Marshal.ReadInt16 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt16_NullObject_ThrowsAccessViolationException() @@ -152,15 +152,15 @@ public void ReadInt16_NotReadable_ThrowsArgumentException() AssertExtensions.Throws(null, () => Marshal.ReadInt16(collectibleObject, 0)); } - [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt16_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.WriteInt16(IntPtr.Zero, 0)); - AssertExtensions.ThrowsAny(() => Marshal.WriteInt16(IntPtr.Zero, 2, 0)); + AssertExtensions.Throws(() => Marshal.WriteInt16(IntPtr.Zero, 0)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.WriteInt16(IntPtr.Zero, 2, 0)); + } } - [Fact] [SkipOnMono("Marshal.WriteInt16 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt16_NullObject_ThrowsAccessViolationException() diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs index 276dca25e110ae..a8300210ca0f33 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int32Tests.cs @@ -128,11 +128,13 @@ public void ReadInt32_StructWithReferenceTypes_ReturnsExpected() } [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt32_ZeroPoint_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.ReadInt32(IntPtr.Zero)); - AssertExtensions.ThrowsAny(() => Marshal.ReadInt32(IntPtr.Zero, 2)); + AssertExtensions.Throws(() => Marshal.ReadInt32(IntPtr.Zero)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.ReadInt32(IntPtr.Zero, 2)); + } } [Fact] @@ -154,15 +156,15 @@ public void ReadInt32_NotReadable_ThrowsArgumentException() AssertExtensions.Throws(null, () => Marshal.ReadInt32(collectibleObject, 0)); } - [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt32_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.WriteInt32(IntPtr.Zero, 0)); - AssertExtensions.ThrowsAny(() => Marshal.WriteInt32(IntPtr.Zero, 2, 0)); + AssertExtensions.Throws(() => Marshal.WriteInt32(IntPtr.Zero, 0)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.WriteInt32(IntPtr.Zero, 2, 0)); + } } - [Fact] [SkipOnMono("Marshal.WriteInt32 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt32_NullObject_ThrowsAccessViolationException() diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs index 47f668270b80e3..6780d7b1670c3c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/Int64Tests.cs @@ -140,11 +140,13 @@ public void ReadInt64_StructWithReferenceTypes_ReturnsExpected() } [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadInt64_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.ReadInt64(IntPtr.Zero)); - AssertExtensions.ThrowsAny(() => Marshal.ReadInt64(IntPtr.Zero, 2)); + AssertExtensions.Throws(() => Marshal.ReadInt64(IntPtr.Zero)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.ReadInt64(IntPtr.Zero, 2)); + } } [Fact] @@ -166,15 +168,15 @@ public void ReadInt64_NotReadable_ThrowsArgumentException() AssertExtensions.Throws(null, () => Marshal.ReadInt64(collectibleObject, 0)); } - [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt64_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.WriteInt64(IntPtr.Zero, 0)); - AssertExtensions.ThrowsAny(() => Marshal.WriteInt64(IntPtr.Zero, 2, 0)); + AssertExtensions.Throws(() => Marshal.WriteInt64(IntPtr.Zero, 0)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.WriteInt64(IntPtr.Zero, 2, 0)); + } } - [Fact] [SkipOnMono("Marshal.WriteInt64 will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteInt64_NullObject_ThrowsAccessViolationException() diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs index e6a21fce1228bd..b43b74d47a6278 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ReadWrite/IntPtrTests.cs @@ -135,11 +135,13 @@ public void ReadIntPtr_StructWithReferenceTypes_ReturnsExpected() } [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void ReadIntPtr_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.ReadIntPtr(IntPtr.Zero)); - AssertExtensions.ThrowsAny(() => Marshal.ReadIntPtr(IntPtr.Zero, 2)); + AssertExtensions.Throws(() => Marshal.ReadIntPtr(IntPtr.Zero)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.ReadIntPtr(IntPtr.Zero, 2)); + } } [Fact] @@ -163,11 +165,13 @@ public void ReadIntPtr_NotReadable_ThrowsArgumentException() } [Fact] - [SkipOnMono("Marshal.ReadByte will not be implemented in Mono, see https://github.com/mono/mono/issues/15085.")] public void WriteIntPtr_ZeroPointer_ThrowsException() { - AssertExtensions.ThrowsAny(() => Marshal.WriteIntPtr(IntPtr.Zero, (IntPtr)0)); - AssertExtensions.ThrowsAny(() => Marshal.WriteIntPtr(IntPtr.Zero, 2, (IntPtr)0)); + AssertExtensions.Throws(() => Marshal.WriteIntPtr(IntPtr.Zero, (IntPtr)0)); + if (PlatformDetection.SupportsDirtyAccessViolations) + { + AssertExtensions.Throws(() => Marshal.WriteIntPtr(IntPtr.Zero, 2, (IntPtr)0)); + } } [Fact] diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs index 818b5606b65e23..4335f71c57f4d2 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/ControlledExecutionTests.cs @@ -73,7 +73,7 @@ void Test() // Tests that an infinite loop may be aborted, that the ThreadAbortException is automatically rethrown, // and that it is eventually translated to an OperationCanceledException. - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] +// [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] public void CancelInTryAndExitCatchNormally() { var cts = new CancellationTokenSource(); @@ -204,7 +204,7 @@ void Test() } // Tests cancellation by the action itself - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] +// [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))] public void CancelItselfOutsideOfTryCatchFinally() { var cts = new CancellationTokenSource(); diff --git a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs index 8ff2506756f869..ee363cdf0b8c7c 100644 --- a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs +++ b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs @@ -103,11 +103,9 @@ public static bool IsCoreClrInterpreter { get { - if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("DOTNET_Interpreter"))) + if (RuntimeFeature.IsDynamicCodeSupported && !RuntimeFeature.IsDynamicCodeCompiled) return true; - if (int.TryParse(Environment.GetEnvironmentVariable("DOTNET_InterpMode") ?? "", out int mode) && (mode > 0)) - return true; - return false; + return CoreClrConfigurationDetection.IsCoreClrInterpreter; } }