Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
40 changes: 40 additions & 0 deletions src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Console</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:System.Resources.ResourceManager.BaseNameField</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:System.Resources.ResourceSet.Reader</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.String.Trim(System.ReadOnlySpan{System.Char})</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.String.TrimEnd(System.ReadOnlySpan{System.Char})</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.String.TrimStart(System.ReadOnlySpan{System.Char})</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Diagnostics.Debug.GetProvider</Target>
<Left>ref/net10.0/System.Private.CoreLib.dll</Left>
<Right>lib/net10.0/System.Private.CoreLib.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0008</DiagnosticId>
<Target>T:System.Collections.BitArray</Target>
<Left>ref/net10.0/System.Private.CoreLib.dll</Left>
<Right>lib/net10.0/System.Private.CoreLib.dll</Right>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public virtual void WriteLine(string? message) { }
}
public static partial class Debug
{
public static System.Diagnostics.DebugProvider GetProvider() { throw null; }
public static System.Diagnostics.DebugProvider SetProvider(System.Diagnostics.DebugProvider provider) { throw null; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
T:System.Runtime.Serialization.DeserializationToken
M:System.Runtime.Serialization.SerializationInfo.StartDeserialization
T:System.Diagnostics.DebugProvider
M:System.Diagnostics.Debug.GetProvider
M:System.Diagnostics.Debug.SetProvider(System.Diagnostics.DebugProvider)
M:System.Threading.Thread.AssureBlockingPossible
F:System.Threading.Thread.ThrowOnBlockingWaitOnJSInteropThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static partial class Debug
{
private static volatile DebugProvider s_provider = new DebugProvider();

public static DebugProvider GetProvider() => s_provider;

public static DebugProvider SetProvider(DebugProvider provider)
{
ArgumentNullException.ThrowIfNull(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,63 @@
// The .NET Foundation licenses this file to you under the MIT license.
#define DEBUG
using System.Reflection;
using System.Runtime.CompilerServices;
using Xunit;

namespace System.Diagnostics.Tests
{
public abstract class DebugTests
{
private const string DebugTypeName = "System.Diagnostics.Debug, System.Private.CoreLib";
private const string DebugProviderTypeName = "System.Diagnostics.DebugProvider, System.Private.CoreLib";

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[return: UnsafeAccessorType(DebugProviderTypeName)]
private static extern object GetProvider([UnsafeAccessorType(DebugTypeName)] object? _);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[return: UnsafeAccessorType(DebugProviderTypeName)]
private static extern object SetProvider([UnsafeAccessorType(DebugTypeName)] object? _, [UnsafeAccessorType(DebugProviderTypeName)] object provider);

[UnsafeAccessor(UnsafeAccessorKind.StaticField, Name = "s_WriteCore")]
private static extern ref Action<string>? GetWriteCore([UnsafeAccessorType(DebugProviderTypeName)] object _);

[UnsafeAccessor(UnsafeAccessorKind.StaticField, Name = "s_FailCore")]
private static extern ref Action<string, string?, string?, string>? GetFailCore([UnsafeAccessorType(DebugProviderTypeName)] object _);

protected abstract bool DebugUsesTraceListeners { get; }
protected static readonly DebugProvider _debugOnlyProvider;
protected static readonly DebugProvider _debugTraceProvider;
protected static readonly object _debugOnlyProvider;
protected static readonly object _debugTraceProvider;

static DebugTests()
{
FieldInfo fieldInfo = typeof(Debug).GetField("s_provider", BindingFlags.Static | BindingFlags.NonPublic);
_debugOnlyProvider = (DebugProvider)fieldInfo.GetValue(null);
_debugOnlyProvider = GetProvider(null);
// Triggers code to wire up TraceListeners with Debug
Assert.Equal(1, Trace.Listeners.Count);
_debugTraceProvider = (DebugProvider)fieldInfo.GetValue(null);
_debugTraceProvider = GetProvider(null);
Assert.NotEqual(_debugOnlyProvider.GetType(), _debugTraceProvider.GetType());
}

public DebugTests()
{
if (DebugUsesTraceListeners)
{
Debug.SetProvider(_debugTraceProvider);
SetProvider(null, _debugTraceProvider);
}
else
{
Debug.SetProvider(_debugOnlyProvider);
SetProvider(null, _debugOnlyProvider);
}
}

protected void VerifyLogged(Action test, string expectedOutput)
{
FieldInfo writeCoreHook = typeof(DebugProvider).GetField("s_WriteCore", BindingFlags.Static | BindingFlags.NonPublic);
ref Action<string>? writeCoreHook = ref GetWriteCore(null);

// First use our test logger to verify the output
var originalWriteCoreHook = writeCoreHook.GetValue(null);
writeCoreHook.SetValue(null, new Action<string>(WriteLogger.s_instance.WriteCore));
var originalWriteCoreHook = writeCoreHook;
writeCoreHook = WriteLogger.s_instance.WriteCore;

try
{
Expand All @@ -50,7 +68,7 @@ protected void VerifyLogged(Action test, string expectedOutput)
}
finally
{
writeCoreHook.SetValue(null, originalWriteCoreHook);
writeCoreHook = originalWriteCoreHook;
}

// Then also use the actual logger for this platform, just to verify
Expand All @@ -60,13 +78,13 @@ protected void VerifyLogged(Action test, string expectedOutput)

protected void VerifyAssert(Action test, params string[] expectedOutputStrings)
{
FieldInfo writeCoreHook = typeof(DebugProvider).GetField("s_WriteCore", BindingFlags.Static | BindingFlags.NonPublic);
var originalWriteCoreHook = writeCoreHook.GetValue(null);
writeCoreHook.SetValue(null, new Action<string>(WriteLogger.s_instance.WriteCore));
ref Action<string>? writeCoreHook = ref GetWriteCore(null);
var originalWriteCoreHook = writeCoreHook;
writeCoreHook = WriteLogger.s_instance.WriteCore;

FieldInfo failCoreHook = typeof(DebugProvider).GetField("s_FailCore", BindingFlags.Static | BindingFlags.NonPublic);
var originalFailCoreHook = failCoreHook.GetValue(null);
failCoreHook.SetValue(null, new Action<string, string, string, string>(WriteLogger.s_instance.FailCore));
ref Action<string, string?, string?, string>? failCoreHook = ref GetFailCore(null);
var originalFailCoreHook = failCoreHook;
failCoreHook = WriteLogger.s_instance.FailCore;

try
{
Expand All @@ -81,8 +99,8 @@ protected void VerifyAssert(Action test, params string[] expectedOutputStrings)
}
finally
{
writeCoreHook.SetValue(null, originalWriteCoreHook);
failCoreHook.SetValue(null, originalFailCoreHook);
writeCoreHook = originalWriteCoreHook;
failCoreHook = originalFailCoreHook;
}
}

Expand Down
Loading