Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJackson Schuster <36744439+jtschuster@users.noreply.github.com>2022-05-06 22:08:07 +0300
committerGitHub <noreply@github.com>2022-05-06 22:08:07 +0300
commiteb6144b2406e2d7afe18afb6a152dcb71c23a724 (patch)
tree2fbdf0d3de06d61c59b08121de764e3adc4c7608 /test
parent00e9a154efeb6369b1345bdafeebb686c0163841 (diff)
Revert static interface trimming (#2784)
* Revert "Trim static interfaces (#2741)" This reverts commit a073a68561a7f45a2dba0976083ee3e9873bf423. * Revert "Don't remove MethodImpl if overridden method is not in a link assembly (#2771)" This reverts commit 44610681fb096cc2b38a18689e954af24049d390. * Revert "Fix NullReferenceException when sweeping unused static interface (#2783)" This reverts commit 00e9a154efeb6369b1345bdafeebb686c0163841.
Diffstat (limited to 'test')
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs27
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs25
-rw-r--r--test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs16
-rw-r--r--test/Mono.Linker.Tests.Cases/Libraries/Dependencies/CopyLibrary.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/Libraries/Dependencies/SkipLibrary.cs10
-rw-r--r--test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs15
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs41
7 files changed, 18 insertions, 117 deletions
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs
deleted file mode 100644
index 62bfd0c15..000000000
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptOverrideAttribute.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-
-namespace Mono.Linker.Tests.Cases.Expectations.Assertions
-{
- /// <summary>
- /// Used to ensure that a method should keep an 'override' annotation for a method in the supplied base type.
- /// The absence of this attribute does not enforce that the override is removed -- this is different from other Kept attributes
- /// To enforce the removal of an override, use <see cref="RemovedOverrideAttribute"/>.
- /// Fails in tests if the method doesn't have the override method in the original or linked assembly.
- /// </summary>
- /// <seealso cref="RemovedOverrideAttribute" />
- [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
- public class KeptOverrideAttribute : KeptAttribute
- {
- public Type TypeWithOverriddenMethodDeclaration;
-
- public KeptOverrideAttribute (Type typeWithOverriddenMethod)
- {
- if (typeWithOverriddenMethod == null)
- throw new ArgumentNullException (nameof (typeWithOverriddenMethod));
- TypeWithOverriddenMethodDeclaration = typeWithOverriddenMethod;
- }
- }
-} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs
deleted file mode 100644
index c15cf9a9e..000000000
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RemovedOverrideAttribute.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-
-namespace Mono.Linker.Tests.Cases.Expectations.Assertions
-{
- /// <Summary>
- /// Used to ensure that a method should remove an 'override' annotation for a method in the supplied base type.
- /// Fails in tests if the method has the override method in the linked assembly,
- /// or if the override is not found in the original assembly
- /// </Summary>
- /// <seealso cref="KeptOverrideAttribute" />
- [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
- public class RemovedOverrideAttribute : BaseInAssemblyAttribute
- {
- public Type TypeWithOverriddenMethodDeclaration;
- public RemovedOverrideAttribute (Type typeWithOverriddenMethod)
- {
- if (typeWithOverriddenMethod == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (typeWithOverriddenMethod));
- TypeWithOverriddenMethodDeclaration = typeWithOverriddenMethod;
- }
- }
-} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs
index de7f5a537..bb43569b6 100644
--- a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs
+++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/InterfaceVariants.cs
@@ -45,7 +45,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces
internal class InterfaceMethodUsedThroughInterface : IStaticInterfaceUsed
{
[Kept]
- [KeptOverride (typeof (IStaticInterfaceUsed))]
public static void StaticMethodUsedThroughInterface ()
{
}
@@ -57,7 +56,6 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces
internal class InterfaceMethodUnused : IStaticInterfaceUsed
{
[Kept]
- [KeptOverride (typeof (IStaticInterfaceUsed))]
public static void StaticMethodUsedThroughInterface ()
{
}
@@ -73,33 +71,41 @@ namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces
// The interface methods themselves are not used, but the implementation of these methods is
internal interface IStaticInterfaceMethodUnused
{
+ // Can be removed with Static Interface trimming optimization
+ [Kept]
static abstract void InterfaceUsedMethodNot ();
}
- // The interface methods themselves are not used, but the implementation of these methods is
+ // Can be removed with Static Interface Trimming
+ [Kept]
internal interface IStaticInterfaceUnused
{
+ // Can be removed with Static Interface Trimming
+ [Kept]
static abstract void InterfaceAndMethodNoUsed ();
}
[Kept]
+ [KeptInterface (typeof (IStaticInterfaceUnused))]
+ [KeptInterface (typeof (IStaticInterfaceMethodUnused))]
internal class InterfaceMethodUsedThroughImplementation : IStaticInterfaceMethodUnused, IStaticInterfaceUnused
{
[Kept]
- [RemovedOverride (typeof (IStaticInterfaceMethodUnused))]
public static void InterfaceUsedMethodNot () { }
[Kept]
- [RemovedOverride (typeof (IStaticInterfaceUnused))]
public static void InterfaceAndMethodNoUsed () { }
}
[Kept]
[KeptInterface (typeof (IStaticInterfaceMethodUnused))]
+ [KeptInterface (typeof (IStaticInterfaceUnused))]
internal class InterfaceMethodUnused : IStaticInterfaceMethodUnused, IStaticInterfaceUnused
{
+ [Kept]
public static void InterfaceUsedMethodNot () { }
+ [Kept]
public static void InterfaceAndMethodNoUsed () { }
}
diff --git a/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/CopyLibrary.cs b/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/CopyLibrary.cs
index 792f869fb..0f31e8277 100644
--- a/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/CopyLibrary.cs
+++ b/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/CopyLibrary.cs
@@ -13,6 +13,5 @@ namespace Mono.Linker.Tests.Cases.Libraries.Dependencies
{
static abstract void CopyLibraryStaticInterfaceMethod ();
static abstract void CopyLibraryExplicitImplementationStaticInterfaceMethod ();
- public static abstract void PublicStaticInterfaceMethod ();
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/SkipLibrary.cs b/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/SkipLibrary.cs
deleted file mode 100644
index 20f59e090..000000000
--- a/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/SkipLibrary.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-namespace Mono.Linker.Tests.Cases.Libraries.Dependencies
-{
- public interface ISkipLibraryStaticInterface
- {
- static abstract void StaticInterfaceMethod ();
- }
-}
diff --git a/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs b/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs
index 03cf665de..1534573ea 100644
--- a/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs
+++ b/test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs
@@ -12,9 +12,7 @@ using Mono.Linker.Tests.Cases.Libraries.Dependencies;
namespace Mono.Linker.Tests.Cases.Libraries
{
[SetupCompileBefore ("copylibrary.dll", new[] { "Dependencies/CopyLibrary.cs" })]
- [SetupCompileBefore ("skiplibrary.dll", new[] { "Dependencies/SkipLibrary.cs" })]
[SetupLinkerAction ("copy", "copylibrary")]
- [SetupLinkerAction ("skip", "skiplibrary")]
[SetupLinkerArgument ("-a", "test.exe", "library")]
[SetupLinkerArgument ("--enable-opt", "ipconstprop")]
[VerifyMetadataNames]
@@ -190,7 +188,6 @@ namespace Mono.Linker.Tests.Cases.Libraries
[KeptInterface (typeof (IInternalStaticInterface))]
[KeptInterface (typeof (ICopyLibraryInterface))]
[KeptInterface (typeof (ICopyLibraryStaticInterface))]
- [KeptInterface (typeof (ISkipLibraryStaticInterface))]
public class UninstantiatedPublicClassWithInterface :
IPublicInterface,
IPublicStaticInterface,
@@ -198,8 +195,7 @@ namespace Mono.Linker.Tests.Cases.Libraries
IInternalStaticInterface,
IEnumerator,
ICopyLibraryInterface,
- ICopyLibraryStaticInterface,
- ISkipLibraryStaticInterface
+ ICopyLibraryStaticInterface
{
internal UninstantiatedPublicClassWithInterface () { }
@@ -221,7 +217,6 @@ namespace Mono.Linker.Tests.Cases.Libraries
void IInternalInterface.ExplicitImplementationInternalInterfaceMethod () { }
[Kept]
- [RemovedOverride (typeof (IInternalStaticInterface))]
public static void InternalStaticInterfaceMethod () { }
static void IInternalStaticInterface.ExplicitImplementationInternalStaticInterfaceMethod () { }
@@ -245,12 +240,7 @@ namespace Mono.Linker.Tests.Cases.Libraries
public static void CopyLibraryStaticInterfaceMethod () { }
[Kept]
- [KeptOverride (typeof (ICopyLibraryStaticInterface))]
static void ICopyLibraryStaticInterface.CopyLibraryExplicitImplementationStaticInterfaceMethod () { }
-
- [Kept]
- [KeptOverride (typeof (ISkipLibraryStaticInterface))]
- static void ISkipLibraryStaticInterface.StaticInterfaceMethod () { }
}
[Kept]
@@ -310,7 +300,6 @@ namespace Mono.Linker.Tests.Cases.Libraries
void IInternalInterface.ExplicitImplementationInternalInterfaceMethod () { }
[Kept]
- [RemovedOverride (typeof (IInternalStaticInterface))]
public static void InternalStaticInterfaceMethod () { }
static void IInternalStaticInterface.ExplicitImplementationInternalStaticInterfaceMethod () { }
@@ -334,7 +323,6 @@ namespace Mono.Linker.Tests.Cases.Libraries
public static void CopyLibraryStaticInterfaceMethod () { }
[Kept]
- [KeptOverride (typeof (ICopyLibraryStaticInterface))]
static void ICopyLibraryStaticInterface.CopyLibraryExplicitImplementationStaticInterfaceMethod () { }
}
@@ -378,6 +366,7 @@ namespace Mono.Linker.Tests.Cases.Libraries
[Kept]
internal interface IInternalStaticInterface
{
+ [Kept] // https://github.com/dotnet/linker/issues/2733
static abstract void InternalStaticInterfaceMethod ();
static abstract void ExplicitImplementationInternalStaticInterfaceMethod ();
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
index ccd92ca5f..aa346b38a 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs
@@ -172,13 +172,12 @@ namespace Mono.Linker.Tests.TestCasesRunner
linkedMembers.Remove (f.FullName);
}
- foreach (var originalMethod in original.Methods) {
- if (verifiedEventMethods.Contains (originalMethod.FullName))
+ foreach (var m in original.Methods) {
+ if (verifiedEventMethods.Contains (m.FullName))
continue;
- var methodSignature = originalMethod.GetSignature ();
- var linkedMethod = linked?.Methods.FirstOrDefault (l => methodSignature == l.GetSignature ());
- VerifyMethod (originalMethod, linkedMethod);
- linkedMembers.Remove (originalMethod.FullName);
+ var msign = m.GetSignature ();
+ VerifyMethod (m, linked?.Methods.FirstOrDefault (l => msign == l.GetSignature ()));
+ linkedMembers.Remove (m.FullName);
}
}
@@ -213,35 +212,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
}
}
- void VerifyOverrides (MethodDefinition original, MethodDefinition linked)
- {
- if (linked is null)
- return;
- var expectedBaseTypesOverridden = new HashSet<string> (original.CustomAttributes
- .Where (ca => ca.AttributeType.Name == nameof (KeptOverrideAttribute))
- .Select (ca => (ca.ConstructorArguments[0].Value as TypeReference).FullName));
- var originalBaseTypesOverridden = new HashSet<string> (original.Overrides.Select (ov => ov.DeclaringType.FullName));
- var linkedBaseTypesOverridden = new HashSet<string> (linked.Overrides.Select (ov => ov.DeclaringType.FullName));
- foreach (var expectedBaseType in expectedBaseTypesOverridden) {
- Assert.IsTrue (originalBaseTypesOverridden.Contains (expectedBaseType),
- $"Method {linked.FullName} was expected to keep override {expectedBaseType}::{linked.Name}, " +
- "but it wasn't in the unlinked assembly");
- Assert.IsTrue (linkedBaseTypesOverridden.Contains (expectedBaseType),
- $"Method {linked.FullName} was expected to override {expectedBaseType}::{linked.Name}");
- }
-
- var expectedBaseTypesNotOverridden = new HashSet<string> (original.CustomAttributes
- .Where (ca => ca.AttributeType.Name == nameof (RemovedOverrideAttribute))
- .Select (ca => (ca.ConstructorArguments[0].Value as TypeReference).FullName));
- foreach (var expectedRemovedBaseType in expectedBaseTypesNotOverridden) {
- Assert.IsTrue (originalBaseTypesOverridden.Contains (expectedRemovedBaseType),
- $"Method {linked.FullName} was expected to remove override {expectedRemovedBaseType}::{linked.Name}, " +
- $"but it wasn't in the unlinked assembly");
- Assert.IsFalse (linkedBaseTypesOverridden.Contains (expectedRemovedBaseType),
- $"Method {linked.FullName} was expected to not override {expectedRemovedBaseType}::{linked.Name}");
- }
- }
-
static string FormatBaseOrInterfaceAttributeValue (CustomAttribute attr)
{
if (attr.ConstructorArguments.Count == 1)
@@ -403,7 +373,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
VerifySecurityAttributes (src, linked);
VerifyArrayInitializers (src, linked);
VerifyMethodBody (src, linked);
- VerifyOverrides (src, linked);
}
protected virtual void VerifyMethodBody (MethodDefinition src, MethodDefinition linked)