diff options
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
558 files changed, 14981 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/Advanced/DeadCodeElimination1.cs b/test/Mono.Linker.Tests.Cases/Advanced/DeadCodeElimination1.cs new file mode 100644 index 000000000..339d223b6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Advanced/DeadCodeElimination1.cs @@ -0,0 +1,19 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Advanced { + [IgnoreTestCase ("We cannot do this yet")] + class DeadCodeElimination1 { + public static void Main () + { + object o = null; + if (o is B) + ((B) o).Method (); + } + + class B { + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Advanced/FieldThatOnlyGetsSetIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Advanced/FieldThatOnlyGetsSetIsRemoved.cs new file mode 100644 index 000000000..8c4933ad2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Advanced/FieldThatOnlyGetsSetIsRemoved.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Advanced { + [IgnoreTestCase ("We cannot do this yet")] + class FieldThatOnlyGetsSetIsRemoved { + public static void Main () + { + new B ().Method (); + } + + [KeptMember (".ctor()")] + class B { + public int _unused = 3; + + [Kept] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs new file mode 100644 index 000000000..795570cf6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", Target = typeof (DebuggerDisplayAttributeOnAssemblyUsingTarget.Foo))] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_Target(System.Type)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTarget { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + public class Foo { + [Kept] + [KeptBackingField] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs new file mode 100644 index 000000000..2b4c6ab50 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs @@ -0,0 +1,25 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: DebuggerDisplay ("{Property}", Target = typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.Foo))] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType { + public static void Main () + { + } + + public class Foo { + public int Property { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs new file mode 100644 index 000000000..61db04028 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs @@ -0,0 +1,29 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", TargetTypeName = "Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies.DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib, library")] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + [SetupCompileBefore ("library.dll", new [] { typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib) })] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")] + + [RemovedMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib), "get_Property()")] + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib), "set_Property(System.Int32)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly { + public static void Main () + { + var foo = new DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib (); + foo.Property = 1; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs new file mode 100644 index 000000000..e52ec9e48 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnType.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + public class DebuggerDisplayAttributeOnType { + public static void Main () + { + var foo = new Foo (); + var bar = new Bar(); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] + [DebuggerDisplay ("{Property}")] + class Foo { + public int Property { get; set; } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] + [DebuggerDisplay ("{Method()}")] + class Bar { + public int Method () + { + return 1; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs new file mode 100644 index 000000000..894d5adbb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs @@ -0,0 +1,21 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class DebuggerDisplayAttributeOnTypeThatIsNotUsed { + public static void Main () + { + } + + [DebuggerDisplay ("{Property}")] + class Foo { + public int Property { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs new file mode 100644 index 000000000..be03fde14 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs @@ -0,0 +1,43 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute(typeof(DebuggerTypeProxyAttribute))] +[assembly: DebuggerTypeProxy (typeof(DebuggerTypeProxyAttributeOnAssemblyUsingTarget.Foo.FooDebugView), Target = typeof (DebuggerTypeProxyAttributeOnAssemblyUsingTarget.Foo))] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerTypeProxyAttribute), ".ctor(System.Type)")] + public class DebuggerTypeProxyAttributeOnAssemblyUsingTarget { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + public class Foo { + [Kept] + [KeptBackingField] + public int Property { get; [Kept] set; } + + [Kept] + internal class FooDebugView + { + private Foo _foo; + + public FooDebugView(Foo foo) + { + _foo = foo; + } + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerTypeProxyAttributeOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerTypeProxyAttributeOnType.cs new file mode 100644 index 000000000..a9db20ae7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerTypeProxyAttributeOnType.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("false")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerTypeProxyAttribute), ".ctor(System.Type)")] + public class DebuggerTypeProxyAttributeOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerTypeProxyAttribute))] + [DebuggerTypeProxy (typeof (FooDebugView))] + class Foo { + } + + [Kept] + class FooDebugView { + public FooDebugView (Foo foo) + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs new file mode 100644 index 000000000..4af869817 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs @@ -0,0 +1,13 @@ +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies { + public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib { + public int Property { get; set; } + + public class NestedType { + public int NestedProperty { get; set; } + } + + public class GenericType<T> { + public T PropertyOnGenericType { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs new file mode 100644 index 000000000..e099dbf89 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTarget.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", Target = typeof (DebuggerDisplayAttributeOnAssemblyUsingTarget.Foo))] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_Target(System.Type)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTarget { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + public class Foo { + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs new file mode 100644 index 000000000..df9ede7b2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs @@ -0,0 +1,25 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: DebuggerDisplay ("{Property}", Target = typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.Foo))] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType { + public static void Main () + { + } + + public class Foo { + public int Property { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs new file mode 100644 index 000000000..b21c02d12 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs @@ -0,0 +1,30 @@ + +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", TargetTypeName = "Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies.DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib, library")] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + [SetupCompileBefore ("library.dll", new [] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")] + + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib), "get_Property()")] + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib), "set_Property(System.Int32)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly { + public static void Main () + { + var foo = new DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib (); + foo.Property = 1; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly.cs new file mode 100644 index 000000000..4b0841ba9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly.cs @@ -0,0 +1,32 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", TargetTypeName = "Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers.DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly+Foo")] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + public class Foo { + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfGenericTypeInOtherAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfGenericTypeInOtherAssembly.cs new file mode 100644 index 000000000..9dc27eec8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfGenericTypeInOtherAssembly.cs @@ -0,0 +1,29 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", TargetTypeName = "Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies.DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib+GenericType`1, library")] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + [SetupCompileBefore ("library.dll", new [] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")] + + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.GenericType<>), "get_PropertyOnGenericType()")] + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.GenericType<>), "set_PropertyOnGenericType(T)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfGenericTypeInOtherAssembly { + public static void Main () + { + var foo = new DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.GenericType<int> (); + foo.PropertyOnGenericType = 1; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfNestedTypeInOtherAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfNestedTypeInOtherAssembly.cs new file mode 100644 index 000000000..44242011d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfNestedTypeInOtherAssembly.cs @@ -0,0 +1,29 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] +[assembly: DebuggerDisplay ("{Property}", TargetTypeName = "Mono.Linker.Tests.Cases.Attributes.Debugger.Dependencies.DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib+NestedType, library")] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + [SetupCompileBefore ("library.dll", new [] { "../Dependencies/DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" })] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), "set_TargetTypeName(System.String)")] + + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.NestedType), "get_NestedProperty()")] + [KeptMemberInAssembly ("library.dll", typeof (DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.NestedType), "set_NestedProperty(System.Int32)")] + public class DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfNestedTypeInOtherAssembly { + public static void Main () + { + var foo = new DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.NestedType (); + foo.NestedProperty = 1; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs new file mode 100644 index 000000000..a68cf7e5d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnType.cs @@ -0,0 +1,42 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerDisplayAttribute), ".ctor(System.String)")] + public class DebuggerDisplayAttributeOnType { + public static void Main () + { + var foo = new Foo (); + var bar = new Bar(); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] + [DebuggerDisplay ("{Property}")] + class Foo { + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } + + [Kept] + [KeptMember(".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerDisplayAttribute))] + [DebuggerDisplay ("{Method()}")] + class Bar { + [Kept] + public int Method () + { + return 1; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs new file mode 100644 index 000000000..de51c012b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs @@ -0,0 +1,21 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class DebuggerDisplayAttributeOnTypeThatIsNotUsed { + public static void Main () + { + } + + [DebuggerDisplay ("{Property}")] + class Foo { + public int Property { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs new file mode 100644 index 000000000..4324bdbc7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs @@ -0,0 +1,46 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (DebuggerTypeProxyAttribute))] +[assembly: DebuggerTypeProxy (typeof(DebuggerTypeProxyAttributeOnAssemblyUsingTarget.Foo.FooDebugView), Target = typeof (DebuggerTypeProxyAttributeOnAssemblyUsingTarget.Foo))] + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerTypeProxyAttribute), ".ctor(System.Type)")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerTypeProxyAttribute), "set_Target(System.Type)")] + public class DebuggerTypeProxyAttributeOnAssemblyUsingTarget { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + public class Foo { + [Kept] + [KeptBackingField] + public int Property { get; [Kept] set; } + + [Kept] + internal class FooDebugView + { + [Kept] + private Foo _foo; + + [Kept] + public FooDebugView(Foo foo) + { + _foo = foo; + } + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerTypeProxyAttributeOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerTypeProxyAttributeOnType.cs new file mode 100644 index 000000000..70351534f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.Debugger/KeepDebugMembers/DebuggerTypeProxyAttributeOnType.cs @@ -0,0 +1,34 @@ +using System.Diagnostics; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Debugger.KeepDebugMembers { + [SetupLinkerCoreAction ("link")] + [SetupLinkerKeepDebugMembers ("true")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (DebuggerTypeProxyAttribute), ".ctor(System.Type)")] + public class DebuggerTypeProxyAttributeOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (DebuggerTypeProxyAttribute))] + [DebuggerTypeProxy (typeof (FooDebugView))] + class Foo { + } + + [Kept] + class FooDebugView { + [Kept] + public FooDebugView (Foo foo) + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/AutoClass.cs b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/AutoClass.cs new file mode 100644 index 000000000..be4085bad --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/AutoClass.cs @@ -0,0 +1,23 @@ +using System; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes.StructLayout +{ + [StructLayout (LayoutKind.Auto)] + [KeptMember (".ctor()")] + class AutoClassData { + public int never_used; + [Kept] + public int used; + } + + public class AutoClass + { + public static void Main () + { + var c = new AutoClassData (); + c.used = 1; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/ExplicitClass.cs b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/ExplicitClass.cs new file mode 100644 index 000000000..dc9f60013 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/ExplicitClass.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes.StructLayout { + [StructLayout (LayoutKind.Explicit)] + [KeptMember (".ctor()")] + class ExplicitClassData { + [FieldOffset (0)] + [Kept] // the linker could remove this + public int never_used; + [FieldOffset (4)] + [Kept] + public int used; + [FieldOffset (8)] + [Kept] + public int never_ever_used; + } + + public class ExplicitClass + { + public static void Main () + { + var c = new ExplicitClassData (); + c.used = 1; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/SequentialClass.cs b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/SequentialClass.cs new file mode 100644 index 000000000..dd8a8b659 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/SequentialClass.cs @@ -0,0 +1,27 @@ +using System; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes.StructLayout +{ + [StructLayout (LayoutKind.Sequential)] + [KeptMember (".ctor()")] + class SequentialClassData + { + [Kept] + public int never_used; + [Kept] + public int used; + } + + public class SequentialClass + { + public static void Main () + { + var c = new SequentialClassData (); + c.used = 1; + if (Marshal.SizeOf (c) != 8) + throw new ApplicationException (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/UnusedTypeWithSequentialLayoutIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/UnusedTypeWithSequentialLayoutIsRemoved.cs new file mode 100644 index 000000000..d3cb2c30f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes.StructLayout/UnusedTypeWithSequentialLayoutIsRemoved.cs @@ -0,0 +1,16 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes.StructLayout +{ + class UnusedTypeWithSequentialLayoutIsRemoved { + static void Main () + { + } + + [StructLayout (LayoutKind.Sequential)] + class B { + int a; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly.cs new file mode 100644 index 000000000..1e74f81c2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly.cs @@ -0,0 +1,16 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: AttributeInReference] + +namespace Mono.Linker.Tests.Cases.Attributes { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly_Lib.cs" })] + [RemovedAssembly ("library.dll")] + class AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly { + static void Main () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeKeptInComplexCase.cs b/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeKeptInComplexCase.cs new file mode 100644 index 000000000..9373f9bde --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AssemblyAttributeKeptInComplexCase.cs @@ -0,0 +1,41 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +// This attribute is defined in this assembly so it will be kept +[assembly: AssemblyAttributeKeptInComplexCase.Foo] + +// This attribute is not going to get marked on the first pass because the reference +// it is defined in will not have been marked yet. +// The catch is, Foo's ctor() will mark a method in `library`, at which point we now expect this +// attribute to be kept +[assembly: AssemblyAttributeKeptInComplexCase_Lib.OtherAssembly] + +[assembly: KeptAttributeAttribute (typeof (AssemblyAttributeKeptInComplexCase.FooAttribute))] +[assembly: KeptAttributeAttribute (typeof (AssemblyAttributeKeptInComplexCase_Lib.OtherAssemblyAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyAttributeKeptInComplexCase_Lib.cs" })] + [KeptAssembly ("library.dll")] + [KeptMemberInAssembly ("library.dll", typeof (AssemblyAttributeKeptInComplexCase_Lib.OtherAssemblyAttribute), ".ctor()")] + [KeptMemberInAssembly ("library.dll", typeof (AssemblyAttributeKeptInComplexCase_Lib), "MethodThatWillBeUsed()")] + public class AssemblyAttributeKeptInComplexCase { + static void Main () + { + } + + [Kept] + [KeptBaseType (typeof (Attribute))] + public class FooAttribute : Attribute { + [Kept] + public FooAttribute () + { + // This ctor will be marked late after processing the queue + // This method we call will be the first marked in the referenced library + AssemblyAttributeKeptInComplexCase_Lib.MethodThatWillBeUsed (); + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnAssemblyIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnAssemblyIsKept.cs new file mode 100644 index 000000000..b42d3ff2f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnAssemblyIsKept.cs @@ -0,0 +1,22 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +[assembly: AttributeOnAssemblyIsKept.Foo] +[assembly: KeptAttributeAttribute (typeof (AttributeOnAssemblyIsKept.FooAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes { + class AttributeOnAssemblyIsKept { + static void Main () + { + } + + [KeptBaseType (typeof (System.Attribute))] + public class FooAttribute : Attribute { + [Kept] + public FooAttribute () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnParameterInUsedMethodIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnParameterInUsedMethodIsKept.cs new file mode 100644 index 000000000..01cdad565 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnParameterInUsedMethodIsKept.cs @@ -0,0 +1,22 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + class AttributeOnParameterInUsedMethodIsKept { + static void Main () + { + Method ("Bar"); + } + + [Kept] + static void Method ([Foo] [KeptAttributeAttribute (typeof (FooAttribute))] string arg) + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof(Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeIsKept.cs new file mode 100644 index 000000000..1cd0cdc23 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeIsKept.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + [Foo] + [KeptAttributeAttribute (typeof (FooAttribute))] + class AttributeOnPreservedTypeIsKept { + public static void Main () + { + } + + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + [Kept] + public FooAttribute () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInConstructorIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInConstructorIsKept.cs new file mode 100644 index 000000000..aa6600837 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInConstructorIsKept.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + [Foo (typeof (A))] + [KeptAttributeAttribute (typeof (FooAttribute))] + class AttributeOnPreservedTypeWithTypeUsedInConstructorIsKept { + public static void Main () + { + } + + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + [Kept] + public FooAttribute (Type val) + { + } + } + + [Kept] + class A { + public A () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept.cs new file mode 100644 index 000000000..976ac6d26 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept.cs @@ -0,0 +1,33 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace NamespaceForAttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept { + [Kept] + class A { + public A () + { + } + } +} + +namespace Mono.Linker.Tests.Cases.Attributes { + [Foo (typeof (NamespaceForAttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept.A))] + [KeptAttributeAttribute (typeof (FooAttribute))] + class AttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept { + public static void Main () + { + } + + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + [Kept] + public FooAttribute (Type val) + { + } + } + + // This A is not used and should be removed + class A { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInFieldIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInFieldIsKept.cs new file mode 100644 index 000000000..e038333e9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInFieldIsKept.cs @@ -0,0 +1,26 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + [Foo (Val = typeof (A))] + [KeptAttributeAttribute (typeof (FooAttribute))] + class AttributeOnPreservedTypeWithTypeUsedInFieldIsKept { + public static void Main () + { + } + + [KeptMember(".ctor()")] + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + [Kept] + public Type Val; + } + + [Kept] + class A { + public A () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInPropertySetterIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInPropertySetterIsKept.cs new file mode 100644 index 000000000..8bc4dd523 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithTypeUsedInPropertySetterIsKept.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + [Foo (Val = typeof (A))] + [KeptAttributeAttribute (typeof (FooAttribute))] + class AttributeOnPreservedTypeWithTypeUsedInPropertySetterIsKept { + public static void Main () + { + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + [Kept] + [KeptBackingField] + public Type Val { get; [Kept] set; } + } + + [Kept] + class A { + public A () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithUsedSetter.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithUsedSetter.cs new file mode 100644 index 000000000..957de91e1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnPreservedTypeWithUsedSetter.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + [Foo (Val = 1)] + [KeptAttributeAttribute (typeof (FooAttribute))] + class AttributeOnPreservedTypeWithUsedSetter { + public static void Main () + { + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + [Kept] + [KeptBackingField] + public int Val { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedFieldIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedFieldIsKept.cs new file mode 100644 index 000000000..834c446ac --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedFieldIsKept.cs @@ -0,0 +1,25 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + class AttributeOnUsedFieldIsKept { + public static void Main () + { + var val = new A ().field; + } + + [KeptMember (".ctor()")] + class A { + [Kept] + [KeptAttributeAttribute (typeof (FooAttribute))] + [Foo] + public int field; + } + + [Kept] + [KeptMember(".ctor()")] + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedMethodIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedMethodIsKept.cs new file mode 100644 index 000000000..0f99a1ca9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedMethodIsKept.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + class AttributeOnUsedMethodIsKept { + public static void Main () + { + new A ().Method (); + } + + [KeptMember (".ctor()")] + class A { + [Foo] + [Kept] + [KeptAttributeAttribute (typeof (FooAttribute))] + public void Method () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedPropertyIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedPropertyIsKept.cs new file mode 100644 index 000000000..8e61c12c1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/AttributeOnUsedPropertyIsKept.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Attributes { + class AttributeOnUsedPropertyIsKept { + public static void Main () + { + var val = new A ().Field; + } + + [KeptMember (".ctor()")] + [KeptMember ("get_Field()")] + class A { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (FooAttribute))] + [Foo] + public int Field { get; set; } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (System.Attribute))] + class FooAttribute : Attribute { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/CoreLibraryAssemblyAttributesAreKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/CoreLibraryAssemblyAttributesAreKept.cs new file mode 100644 index 000000000..9ec53e48a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/CoreLibraryAssemblyAttributesAreKept.cs @@ -0,0 +1,21 @@ +using System.Reflection; +using System.Timers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes { + [Reference ("System.dll")] + [SetupLinkerCoreAction ("link")] + [KeptAttributeInAssembly ("mscorlib.dll", typeof (AssemblyDescriptionAttribute))] + [KeptAttributeInAssembly ("mscorlib.dll", typeof (AssemblyCompanyAttribute))] + [KeptAttributeInAssembly ("System.dll", typeof (AssemblyDescriptionAttribute))] + [KeptAttributeInAssembly ("System.dll", typeof (AssemblyCompanyAttribute))] + [SkipPeVerify] + public class CoreLibraryAssemblyAttributesAreKept { + public static void Main () + { + // Use something from System so that the entire reference isn't linked away + var system = new Timer (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs new file mode 100644 index 000000000..f19ffcf4d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType1.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithType2.dll", new [] { typeof(TypeDefinedInReference2) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType1.dll", typeof (TypeDefinedInReference))] + [KeptTypeInAssembly ("LibraryWithType2.dll", typeof (TypeDefinedInReference2))] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type[])")] + public class OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType { + public static void Main() + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (new [] { typeof (TypeDefinedInReference), typeof (TypeDefinedInReference2) })] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs new file mode 100644 index 000000000..62c1fd568 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs @@ -0,0 +1,23 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] +[assembly: AttributeDefinedInReference (typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// In the case of attributes on assemblies, we expect both assemblies to be removed because we don't keep assembly level attributes + /// when that is the only type marked in the assembly + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [RemovedAssembly ("LibraryWithType.dll")] + [RemovedAssembly ("LibraryWithAttribute.dll")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly { + public static void Main() + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs new file mode 100644 index 000000000..65da28788 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] +[assembly: KeptAttributeAttribute (typeof (AttributeDefinedInReference))] +[assembly: AttributeDefinedInReference (typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof (AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + [KeptTypeInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference_OtherType))] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed { + public static void Main () + { + // Use something in the attribute assembly so that the special behavior of not preserving a reference if the only thing that is marked + // are attributes is not trigged + AttributeDefinedInReference_OtherType.Method(); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs new file mode 100644 index 000000000..42b28839a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs @@ -0,0 +1,44 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + [KeptDelegateCacheField ("0")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent { + public static void Main () + { + var foo = new Foo (); + foo.MyEvent += FooOnMyEvent; + } + + [Kept] + private static void FooOnMyEvent (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Foo + { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptAttributeAttribute (typeof( AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public event EventHandler MyEvent; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs new file mode 100644 index 000000000..a5b52a3de --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof (TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof (AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod { + public static void Main () + { + var foo = new Foo (); + foo.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs new file mode 100644 index 000000000..a6f0869b1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs new file mode 100644 index 000000000..3be888774 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof (TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof (AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType { + public static void Main() + { + var foo = new Foo(); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + class Foo + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs new file mode 100644 index 000000000..b385f1919 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] +[assembly: AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// In the case of attributes on assemblies, we expect both assemblies to be removed because we don't keep assembly level attributes + /// when that is the only type marked in the assembly + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [RemovedAssembly ("LibraryWithType.dll")] + [RemovedAssembly ("LibraryWithAttribute.dll")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly + { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs new file mode 100644 index 000000000..bba7fc8c0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs @@ -0,0 +1,44 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + [KeptDelegateCacheField ("0")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent { + public static void Main () + { + var foo = new Foo (); + foo.MyEvent += FooOnMyEvent; + } + + [Kept] + private static void FooOnMyEvent (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + public event EventHandler MyEvent; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs new file mode 100644 index 000000000..b8aa33f92 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs @@ -0,0 +1,37 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod + { + public static void Main () + { + var foo = new Foo (); + foo.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof(TypeDefinedInReference))] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs new file mode 100644 index 000000000..cfbefbcea --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs new file mode 100644 index 000000000..64da808bc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs new file mode 100644 index 000000000..0ed2c3d81 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs @@ -0,0 +1,23 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] +[assembly: AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// In the case of attributes on assemblies, we expect both assemblies to be removed because we don't keep assembly level attributes + /// when that is the only type marked in the assembly + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [RemovedAssembly ("LibraryWithType.dll")] + [RemovedAssembly ("LibraryWithAttribute.dll")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs new file mode 100644 index 000000000..b19923228 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs @@ -0,0 +1,44 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + [KeptDelegateCacheField ("0")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent { + public static void Main () + { + var foo = new Foo (); + foo.MyEvent += FooOnMyEvent; + } + + [Kept] + private static void FooOnMyEvent (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + public event EventHandler MyEvent; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs new file mode 100644 index 000000000..9683563f9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs @@ -0,0 +1,36 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod { + public static void Main () + { + var foo = new Foo (); + foo.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs new file mode 100644 index 000000000..c9ebe388e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs new file mode 100644 index 000000000..d67bd9177 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs new file mode 100644 index 000000000..ed284479a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Csc/OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs @@ -0,0 +1,33 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.Csc { + /// <summary> + /// This explicit csc test exists to ensure that csc adds references in this scenario + /// </summary> + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithTypeAndReference.dll", new [] { typeof(TypeDefinedInReferenceWithReference) }, new [] { "LibraryWithType.dll", "LibraryWithAttribute.dll" }, compilerToUse: "csc")] + [KeptTypeInAssembly ("LibraryWithTypeAndReference.dll", typeof (TypeDefinedInReferenceWithReference))] + [RemovedMemberInAssembly ("LibraryWithTypeAndReference.dll", typeof (TypeDefinedInReferenceWithReference), "Unused()")] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReferenceWithReference))] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly_Lib.cs b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly_Lib.cs new file mode 100644 index 000000000..b52782cd8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly_Lib.cs @@ -0,0 +1,6 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Attributes.Dependencies { + public class AttributeInReferenceAttribute : Attribute { + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AssemblyAttributeKeptInComplexCase_Lib.cs b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AssemblyAttributeKeptInComplexCase_Lib.cs new file mode 100644 index 000000000..914361f07 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AssemblyAttributeKeptInComplexCase_Lib.cs @@ -0,0 +1,12 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Attributes.Dependencies { + public class AssemblyAttributeKeptInComplexCase_Lib { + public class OtherAssemblyAttribute : Attribute { + } + + public static void MethodThatWillBeUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AttributeDefinedInReference.cs b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AttributeDefinedInReference.cs new file mode 100644 index 000000000..cc6d8d928 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/AttributeDefinedInReference.cs @@ -0,0 +1,28 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Attributes.Dependencies { + [AttributeUsage (AttributeTargets.All, AllowMultiple = true)] + public class AttributeDefinedInReference : Attribute { + public Type FieldType; + + public AttributeDefinedInReference () + { + } + + public AttributeDefinedInReference (Type t) + { + } + + public AttributeDefinedInReference (Type[] t) + { + } + + public Type PropertyType { get; set; } + } + + public class AttributeDefinedInReference_OtherType { + public static void Method () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReference.cs b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReference.cs new file mode 100644 index 000000000..76c32933b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReference.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.Attributes.Dependencies { + public class TypeDefinedInReference { + public static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReference2.cs b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReference2.cs new file mode 100644 index 000000000..b306dcea5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReference2.cs @@ -0,0 +1,4 @@ +namespace Mono.Linker.Tests.Cases.Attributes.Dependencies { + public class TypeDefinedInReference2 { + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReferenceWithReference.cs b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReferenceWithReference.cs new file mode 100644 index 000000000..2f60f4763 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Dependencies/TypeDefinedInReferenceWithReference.cs @@ -0,0 +1,8 @@ +namespace Mono.Linker.Tests.Cases.Attributes.Dependencies { + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public class TypeDefinedInReferenceWithReference { + public static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/FixedLengthArrayAttributesArePreserved.cs b/test/Mono.Linker.Tests.Cases/Attributes/FixedLengthArrayAttributesArePreserved.cs new file mode 100644 index 000000000..3c65d0204 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/FixedLengthArrayAttributesArePreserved.cs @@ -0,0 +1,41 @@ +using System.Runtime.CompilerServices; +using System.Security; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes { + /// <summary> + /// The purpose of this test is mainly to provide coverage on the `KeptAttributeOnFixedBufferType` attribute + /// </summary> + [SetupCompileArgument ("/unsafe")] + // Can't verify because the test contains unsafe code + [SkipPeVerify] + public class FixedLengthArrayAttributesArePreserved { + public static void Main () + { + Helper (); + } + + [Kept] + static unsafe void Helper () + { + var tmp = new WithFixedArrayField (); + var v = tmp.Values; + AMethodToUseTheReturnValue (v); + } + + [Kept] + static unsafe void AMethodToUseTheReturnValue (int* ptr) + { + } + + [Kept] + public unsafe struct WithFixedArrayField { + [Kept] + [KeptFixedBuffer] + [KeptAttributeOnFixedBufferType (typeof (UnsafeValueTypeAttribute))] + [KeptAttributeAttribute (typeof (FixedBufferAttribute))] + public fixed int Values [10]; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs new file mode 100644 index 000000000..4f06ea861 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType1.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithType2.dll", new [] { typeof(TypeDefinedInReference2) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType1.dll", typeof (TypeDefinedInReference))] + [KeptTypeInAssembly ("LibraryWithType2.dll", typeof (TypeDefinedInReference2))] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type[])")] + public class OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType { + public static void Main() + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (new [] { typeof (TypeDefinedInReference), typeof (TypeDefinedInReference2) })] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs new file mode 100644 index 000000000..18734fff7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs @@ -0,0 +1,22 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: AttributeDefinedInReference (typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// In the case of attributes on assemblies, we expect both assemblies to be removed because we don't keep assembly level attributes + /// when that is the only type marked in the assembly + /// </summary> + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [RemovedAssembly ("LibraryWithType.dll")] + [RemovedAssembly ("LibraryWithAttribute.dll")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly { + public static void Main() + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs new file mode 100644 index 000000000..c3a62bed0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (AttributeDefinedInReference))] +[assembly: AttributeDefinedInReference (typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof (AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + [KeptTypeInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference_OtherType))] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed { + public static void Main () + { + // Use something in the attribute assembly so that the special behavior of not preserving a reference if the only thing that is marked + // are attributes is not trigged + AttributeDefinedInReference_OtherType.Method(); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs new file mode 100644 index 000000000..0df1c12e5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs @@ -0,0 +1,43 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + [KeptDelegateCacheField ("0")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent { + public static void Main () + { + var foo = new Foo (); + foo.MyEvent += FooOnMyEvent; + } + + [Kept] + private static void FooOnMyEvent (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Foo + { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptAttributeAttribute (typeof( AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public event EventHandler MyEvent; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs new file mode 100644 index 000000000..0d191d7f4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof (TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof (AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod { + public static void Main () + { + var foo = new Foo (); + foo.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs new file mode 100644 index 000000000..ec52d0556 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs @@ -0,0 +1,33 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs new file mode 100644 index 000000000..1708be4a4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof (TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof (AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType { + public static void Main() + { + var foo = new Foo(); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReference))] + class Foo + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs new file mode 100644 index 000000000..00394f906 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs @@ -0,0 +1,23 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// In the case of attributes on assemblies, we expect both assemblies to be removed because we don't keep assembly level attributes + /// when that is the only type marked in the assembly + /// </summary> + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [RemovedAssembly ("LibraryWithType.dll")] + [RemovedAssembly ("LibraryWithAttribute.dll")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly + { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs new file mode 100644 index 000000000..ad376f852 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs @@ -0,0 +1,43 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + [KeptDelegateCacheField ("0")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent { + public static void Main () + { + var foo = new Foo (); + foo.MyEvent += FooOnMyEvent; + } + + [Kept] + private static void FooOnMyEvent (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + public event EventHandler MyEvent; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs new file mode 100644 index 000000000..26574eb8a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs @@ -0,0 +1,36 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod + { + public static void Main () + { + var foo = new Foo (); + foo.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof(TypeDefinedInReference))] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs new file mode 100644 index 000000000..87b1853eb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs new file mode 100644 index 000000000..cd62f5b3d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "FieldType")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (FieldType = typeof (TypeDefinedInReference))] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs new file mode 100644 index 000000000..54dc92639 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs @@ -0,0 +1,22 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// In the case of attributes on assemblies, we expect both assemblies to be removed because we don't keep assembly level attributes + /// when that is the only type marked in the assembly + /// </summary> + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [RemovedAssembly ("LibraryWithType.dll")] + [RemovedAssembly ("LibraryWithAttribute.dll")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs new file mode 100644 index 000000000..3c479943d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs @@ -0,0 +1,43 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + [KeptDelegateCacheField ("0")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent { + public static void Main () + { + var foo = new Foo (); + foo.MyEvent += FooOnMyEvent; + } + + [Kept] + private static void FooOnMyEvent (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + public event EventHandler MyEvent; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs new file mode 100644 index 000000000..41d1c803e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod { + public static void Main () + { + var foo = new Foo (); + foo.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs new file mode 100644 index 000000000..66d1a04af --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty { + public static void Main () + { + var foo = new Foo (); + foo.Property = 1; + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + public int Property { get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs new file mode 100644 index 000000000..668f8a9ab --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), "set_PropertyType(System.Type)")] + public class OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (PropertyType = typeof (TypeDefinedInReference))] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs new file mode 100644 index 000000000..22a34cffb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/Mcs/OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs @@ -0,0 +1,32 @@ +using Mono.Linker.Tests.Cases.Attributes.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.Mcs { + /// <summary> + /// This explicit mcs test exists because mcs did not add a reference prior to https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5 + /// </summary> + [IgnoreTestCase ("Can be enabled once the mcs contains https://github.com/mono/mono/commit/f71b208ca7b41a2a97ca70b955df0c4c411ce8e5")] + [SetupCSharpCompilerToUse ("mcs")] + [SetupCompileBefore ("LibraryWithAttribute.dll", new [] { typeof(AttributeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithType.dll", new [] { typeof(TypeDefinedInReference) })] + [SetupCompileBefore ("LibraryWithTypeAndReference.dll", new [] { typeof(TypeDefinedInReferenceWithReference) }, new [] { "LibraryWithType.dll", "LibraryWithAttribute.dll" }, compilerToUse: "mcs")] + [KeptTypeInAssembly ("LibraryWithTypeAndReference.dll", typeof (TypeDefinedInReferenceWithReference))] + [RemovedMemberInAssembly ("LibraryWithTypeAndReference.dll", typeof (TypeDefinedInReferenceWithReference), "Unused()")] + [KeptTypeInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference))] + [RemovedMemberInAssembly ("LibraryWithType.dll", typeof (TypeDefinedInReference), "Unused()")] + [KeptMemberInAssembly ("LibraryWithAttribute.dll", typeof (AttributeDefinedInReference), ".ctor(System.Type)")] + public class OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType { + public static void Main () + { + var foo = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (AttributeDefinedInReference))] + [AttributeDefinedInReference (typeof (TypeDefinedInReferenceWithReference))] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs new file mode 100644 index 000000000..153fe9469 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/CoreLibrarySecurityAttributeTypesAreRemoved.cs @@ -0,0 +1,43 @@ +using System.Diagnostics; +using System.Security; +using System.Security.Permissions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.NoSecurity { + [SetupLinkerCoreAction ("link")] + [SetupLinkerArgument ("--strip-security", "true")] + [Reference ("System.dll")] + // Attributes from System.Security.Permissions + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecurityPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (PermissionSetAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (ReflectionPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (RegistryPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (StrongNameIdentityPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (CodeAccessSecurityAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (EnvironmentPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (FileIOPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (HostProtectionAttribute))] + + // "Special" attributes from System.Security namespace that we seem to need to remove in order to set HasSecurity = false and not have + // pe verify complain + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecurityCriticalAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecuritySafeCriticalAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SuppressUnmanagedCodeSecurityAttribute))] + + // Fails with `Runtime critical type System.Reflection.CustomAttributeData not found` which is a known short coming + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + [SkipPeVerify ("System.dll")] + + // System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code + // detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked. + // PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output + [SkipPeVerify ("System.Core.dll")] + public class CoreLibrarySecurityAttributeTypesAreRemoved { + public static void Main () + { + // Use something that has security attributes to make this test more meaningful + var process = new Process (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/SecurityAttributesOnUsedMethodAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/SecurityAttributesOnUsedMethodAreRemoved.cs new file mode 100644 index 000000000..eba5ba81f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/SecurityAttributesOnUsedMethodAreRemoved.cs @@ -0,0 +1,24 @@ +using System.Security.Permissions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.NoSecurity { + [SetupLinkerArgument ("--strip-security", "true")] + public class SecurityAttributesOnUsedMethodAreRemoved { + static void Main () + { + new Foo ().Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [SecurityPermission (SecurityAction.LinkDemand)] + [Kept] + [RemovedPseudoAttribute (16384)] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/SecurityAttributesOnUsedTypeAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/SecurityAttributesOnUsedTypeAreRemoved.cs new file mode 100644 index 000000000..a5b251400 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/NoSecurity/SecurityAttributesOnUsedTypeAreRemoved.cs @@ -0,0 +1,20 @@ +using System.Security.Permissions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.NoSecurity { + [SetupLinkerArgument ("--strip-security", "true")] + public class SecurityAttributesOnUsedTypeAreRemoved { + static void Main () + { + new Foo (); + } + + [SecurityPermission (SecurityAction.LinkDemand)] + [Kept] + [KeptMember (".ctor()")] + [RemovedPseudoAttribute (262144u)] + class Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/AttributeDefinedAndUsedInOtherAssemblyIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/AttributeDefinedAndUsedInOtherAssemblyIsKept.cs new file mode 100644 index 000000000..826ad0011 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/AttributeDefinedAndUsedInOtherAssemblyIsKept.cs @@ -0,0 +1,24 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.cs" })] + [KeptMemberInAssembly ("library.dll", typeof (AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.FooAttribute), ".ctor()")] + class AttributeDefinedAndUsedInOtherAssemblyIsKept { + static void Main () + { + Method (); + } + + [AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.Foo] + [Kept] + [KeptAttributeAttribute (typeof (AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.FooAttribute))] + static void Method () + { + AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.UseTheAttributeType (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/AttributeUsedByAttributeIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/AttributeUsedByAttributeIsKept.cs new file mode 100644 index 000000000..3c7c0d292 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/AttributeUsedByAttributeIsKept.cs @@ -0,0 +1,102 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class AttributeUsedByAttributeIsKept { + static void Main () + { + var jar = new Jar (); + jar.SomeMethod (); + } + + [Foo] + [Bar] + [Kar] + [NotUsed] + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof(FooAttribute))] + [KeptAttributeAttribute (typeof(BarAttribute))] + [KeptAttributeAttribute (typeof(KarAttribute))] + class Jar { + [Kept] + public void SomeMethod () + { + var attr = typeof (Jar).GetCustomAttributes (typeof (FooAttribute), false) [0]; + var asFooAttr = (FooAttribute) attr; + asFooAttr.MethodWeWillCall (); + } + } + + [Kept] + [KeptBaseType (typeof(Attribute))] + class FooAttribute : Attribute { + [Kept] + public FooAttribute () + { + // This ctor should be marked lazy. So let's use another attribute type here which should then trigger that attribute + // to be marked + var str = typeof (BarAttribute).ToString (); + MethodsUsedFromLateMarking.Method1 (); + } + + [Foo] + [Bar] + [Kar] + [NotUsed] + [Kept] + [KeptAttributeAttribute (typeof (FooAttribute))] + [KeptAttributeAttribute (typeof (BarAttribute))] + [KeptAttributeAttribute (typeof (KarAttribute))] + public void MethodWeWillCall () + { + } + } + + [Kept] + [KeptBaseType (typeof(Attribute))] + class BarAttribute : Attribute { + [Kept] + public BarAttribute () + { + // Let's do this one more time to make sure we catch everything + var str = typeof (KarAttribute).ToString (); + MethodsUsedFromLateMarking.Method2 (); + } + } + + [Kept] + [KeptBaseType (typeof (Attribute))] + class KarAttribute : Attribute { + [Kept] + public KarAttribute () + { + MethodsUsedFromLateMarking.Method3 (); + } + } + + class NotUsedAttribute : Attribute { + } + + [Kept] + static class MethodsUsedFromLateMarking { + [Kept] + public static void Method1 () + { + } + + [Kept] + public static void Method2 () + { + } + + [Kept] + public static void Method3 () + { + } + } + + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CanLinkCoreLibrariesWithOnlyKeepUsedAttributes.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CanLinkCoreLibrariesWithOnlyKeepUsedAttributes.cs new file mode 100644 index 000000000..6599677e4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CanLinkCoreLibrariesWithOnlyKeepUsedAttributes.cs @@ -0,0 +1,23 @@ +using System; +using System.Timers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerCoreAction ("link")] + [SetupLinkerArgument ("--used-attrs-only", "true")] + [Reference ("System.dll")] + // System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code + // detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked. + // PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output + [SkipPeVerify ("System.Core.dll")] + // Fails with `Runtime critical type System.Reflection.CustomAttributeData not found` + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + class CanLinkCoreLibrariesWithOnlyKeepUsedAttributes { + static void Main () + { + // Use something from System so that the entire reference isn't linked away + var system = new Timer (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesArePreserved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesArePreserved.cs new file mode 100644 index 000000000..8c34640d1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesArePreserved.cs @@ -0,0 +1,31 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + /// <summary> + /// COM related attributes are required at runtime + /// </summary> + [SetupLinkerArgument ("--used-attrs-only", "true")] + public class ComAttributesArePreserved { + public static void Main () + { + var tmp = ReturnValueUsedToMarkType (); + } + + [Kept] + static A ReturnValueUsedToMarkType () + { + return null; + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [KeptAttributeAttribute (typeof (InterfaceTypeAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)] + interface A { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs new file mode 100644 index 000000000..ca83503d4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ComAttributesAreRemovedWhenFeatureExcluded.cs @@ -0,0 +1,28 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + [SetupLinkerArgument ("--exclude-feature", "com")] + public class ComAttributesAreRemovedWhenFeatureExcluded { + public static void Main () + { + var tmp = ReturnValueUsedToMarkType (); + } + + [Kept] + static A ReturnValueUsedToMarkType () + { + return null; + } + + [Kept] + [RemovedPseudoAttribute (0x00001000u)] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)] + interface A { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ContextStaticIsPreservedOnField.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ContextStaticIsPreservedOnField.cs new file mode 100644 index 000000000..39fecc123 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ContextStaticIsPreservedOnField.cs @@ -0,0 +1,21 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + /// <summary> + /// [ContextStatic] is required by the mono runtime + /// </summary> + [SetupLinkerArgument ("--used-attrs-only", "true")] + public class ContextStaticIsPreservedOnField { + [ContextStatic] + [Kept] + [KeptAttributeAttribute (typeof (ContextStaticAttribute))] + public static int UsedField; + + public static void Main () + { + UsedField = 0; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CoreLibraryUnusedAssemblyAttributesAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CoreLibraryUnusedAssemblyAttributesAreRemoved.cs new file mode 100644 index 000000000..476f279c1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CoreLibraryUnusedAssemblyAttributesAreRemoved.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Timers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [Reference ("System.dll")] + [SetupLinkerCoreAction ("link")] + [SetupLinkerArgument ("--used-attrs-only", "true")] + [RemovedAttributeInAssembly ("mscorlib.dll", typeof (AssemblyDescriptionAttribute))] + [RemovedAttributeInAssembly ("System.dll", typeof (AssemblyDescriptionAttribute))] + [SkipPeVerify] + public class CoreLibraryUnusedAssemblyAttributesAreRemoved { + public static void Main () + { + // Use something from System so that the entire reference isn't linked away + var system = new Timer (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CoreLibraryUsedAssemblyAttributesAreKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CoreLibraryUsedAssemblyAttributesAreKept.cs new file mode 100644 index 000000000..46cb2f1f3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/CoreLibraryUsedAssemblyAttributesAreKept.cs @@ -0,0 +1,23 @@ +using System.Reflection; +using System.Timers; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [Reference ("System.dll")] + [SetupLinkerCoreAction ("link")] + [SetupLinkerArgument ("--used-attrs-only", "true")] + [KeptAttributeInAssembly ("mscorlib.dll", typeof (AssemblyDescriptionAttribute))] + [KeptAttributeInAssembly ("System.dll", typeof (AssemblyDescriptionAttribute))] + [SkipPeVerify] + public class CoreLibraryUsedAssemblyAttributesAreKept { + public static void Main () + { + // Use something from System so that the entire reference isn't linked away + var system = new Timer (); + + // use one of the attribute types so that it is marked + var tmp = typeof (AssemblyDescriptionAttribute).ToString (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/AssemblyWithUnusedAttributeOnReturnParameterDefinition.il b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/AssemblyWithUnusedAttributeOnReturnParameterDefinition.il new file mode 100644 index 000000000..90b51a91a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/AssemblyWithUnusedAttributeOnReturnParameterDefinition.il @@ -0,0 +1,54 @@ +.assembly extern mscorlib +{ +} +.assembly 'library' +{ + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module library.dll + + +.namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies +{ + .class public auto ansi beforefieldinit AssemblyWithUnusedAttributeOnReturnParameterDefinition + extends [mscorlib]System.Object + { + + .method public hidebysig specialname rtspecialname + instance default void '.ctor' () cil managed + { + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void object::'.ctor'() + IL_0006: ret + } + + .method public hidebysig + instance default int32 Method (int32 arg) cil managed + { + .param [0] + .custom instance void class Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies.AssemblyWithUnusedAttributeOnReturnParameterDefinition/FooAttribute::'.ctor'() = (01 00 00 00 ) // .... + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + .class nested private auto ansi beforefieldinit FooAttribute + extends [mscorlib]System.Attribute + { + + .method public hidebysig specialname rtspecialname + instance default void '.ctor' () cil managed + { + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [mscorlib]System.Attribute::'.ctor'() + IL_0006: ret + } + + } + } +} + diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.cs new file mode 100644 index 000000000..c94d85ba0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies { + public class AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib { + public static void UseTheAttributeType () + { + var str = typeof (FooAttribute).ToString (); + } + + public class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Forwarder.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Forwarder.cs new file mode 100644 index 000000000..9bea6c499 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Forwarder.cs @@ -0,0 +1,6 @@ +using System; +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies; + +[assembly: TypeForwardedTo (typeof (UnusedAttributeWithTypeForwarderIsRemoved_LibAttribute))] +[assembly: TypeForwardedTo (typeof (UnusedAttributeWithTypeForwarderIsRemoved_OtherUsedClass))] diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Lib.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Lib.cs new file mode 100644 index 000000000..b22c07be9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Lib.cs @@ -0,0 +1,15 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies { + public class UnusedAttributeWithTypeForwarderIsRemoved_LibAttribute : Attribute { + public UnusedAttributeWithTypeForwarderIsRemoved_LibAttribute (string arg) + { + } + } + + public class UnusedAttributeWithTypeForwarderIsRemoved_OtherUsedClass { + public static void UsedMethod () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/FixedLengthArrayAttributesArePreserved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/FixedLengthArrayAttributesArePreserved.cs new file mode 100644 index 000000000..3e33c8584 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/FixedLengthArrayAttributesArePreserved.cs @@ -0,0 +1,38 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + [SetupCompileArgument ("/unsafe")] + + // Can't verify because the test contains unsafe code + [SkipPeVerify] + public class FixedLengthArrayAttributesArePreserved { + public static void Main () + { + Helper (); + } + + [Kept] + static unsafe void Helper () + { + var tmp = new WithFixedArrayField (); + var v = tmp.Values; + AMethodToUseTheReturnValue (v); + } + + [Kept] + static unsafe void AMethodToUseTheReturnValue (int* ptr) + { + } + + [Kept] + public unsafe struct WithFixedArrayField { + [Kept] + [KeptFixedBuffer] + [KeptAttributeAttribute (typeof (FixedBufferAttribute))] + public fixed int Values [10]; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ThreadStaticIsPreservedOnField.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ThreadStaticIsPreservedOnField.cs new file mode 100644 index 000000000..35ed32fc1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/ThreadStaticIsPreservedOnField.cs @@ -0,0 +1,21 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + /// <summary> + /// [ThreadStatic] is required by the mono runtime + /// </summary> + [SetupLinkerArgument ("--used-attrs-only", "true")] + public class ThreadStaticIsPreservedOnField { + [ThreadStatic] + [Kept] + [KeptAttributeAttribute (typeof (ThreadStaticAttribute))] + public static int UsedField; + + public static void Main () + { + UsedField = 0; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeOnReturnTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeOnReturnTypeIsRemoved.cs new file mode 100644 index 000000000..62d1b368d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeOnReturnTypeIsRemoved.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + [Define ("IL_ASSEMBLY_AVAILABLE")] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyWithUnusedAttributeOnReturnParameterDefinition.il" })] + [RemovedTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies.AssemblyWithUnusedAttributeOnReturnParameterDefinition/FooAttribute")] + public class UnusedAttributeOnReturnTypeIsRemoved { + static void Main () + { +#if IL_ASSEMBLY_AVAILABLE + var tmp = new Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies.AssemblyWithUnusedAttributeOnReturnParameterDefinition ().Method (1); +#endif + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributePreservedViaLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributePreservedViaLinkXmlIsKept.cs new file mode 100644 index 000000000..c7273e993 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributePreservedViaLinkXmlIsKept.cs @@ -0,0 +1,33 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UnusedAttributePreservedViaLinkXmlIsKept { + static void Main () + { + var tmp = new Bar (); + tmp.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (FooAttribute))] + [Foo] + class Bar { + [Kept] + [KeptAttributeAttribute (typeof (FooAttribute))] + [Foo] + public void Method () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributePreservedViaLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributePreservedViaLinkXmlIsKept.xml new file mode 100644 index 000000000..02a75666f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributePreservedViaLinkXmlIsKept.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.UnusedAttributePreservedViaLinkXmlIsKept/FooAttribute" preserve="all"> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnAssemblyIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnAssemblyIsRemoved.cs new file mode 100644 index 000000000..bbe066f6f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnAssemblyIsRemoved.cs @@ -0,0 +1,17 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: UnusedAttributeTypeOnAssemblyIsRemoved.Foo] + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UnusedAttributeTypeOnAssemblyIsRemoved { + static void Main () + { + } + + public class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnEventIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnEventIsRemoved.cs new file mode 100644 index 000000000..9f0a5271c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnEventIsRemoved.cs @@ -0,0 +1,33 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + [KeptDelegateCacheField ("0")] + class UnusedAttributeTypeOnEventIsRemoved { + static void Main () + { + var tmp = new Bar (); + tmp.Something += Tmp_Something; + } + + [Kept] + private static void Tmp_Something (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Foo] + [Kept] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler<EventArgs> Something { [Foo] add { } [Foo] remove { } } + } + + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnMethodIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnMethodIsRemoved.cs new file mode 100644 index 000000000..2804e2ff4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnMethodIsRemoved.cs @@ -0,0 +1,30 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + // System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code + // detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked. + // PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output + [SkipPeVerify ("System.Core.dll")] + class UnusedAttributeTypeOnMethodIsRemoved { + static void Main () + { + new Bar ().Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Foo] + [Kept] + public void Method () + { + } + } + + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnModuleIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnModuleIsRemoved.cs new file mode 100644 index 000000000..90619679c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnModuleIsRemoved.cs @@ -0,0 +1,17 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[module: UnusedAttributeTypeOnModuleIsRemoved.Foo] + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UnusedAttributeTypeOnModuleIsRemoved { + static void Main () + { + } + + public class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnParameterIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnParameterIsRemoved.cs new file mode 100644 index 000000000..c74e4f6c0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnParameterIsRemoved.cs @@ -0,0 +1,25 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UnusedAttributeTypeOnParameterIsRemoved { + static void Main () + { + new Bar ().Method ("Hello"); + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Kept] + public void Method ([Foo] string arg) + { + } + } + + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnPropertyIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnPropertyIsRemoved.cs new file mode 100644 index 000000000..7144700ff --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnPropertyIsRemoved.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UnusedAttributeTypeOnPropertyIsRemoved { + static void Main () + { + var bar = new Bar (); + bar.Value = "Hello"; + var tmp = bar.Value; + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Foo] + [Kept] + [KeptBackingField] + public string Value { [Foo] [Kept] get; [Foo] [Kept] set; } + } + + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnTypeIsRemoved.cs new file mode 100644 index 000000000..03aba0d14 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeTypeOnTypeIsRemoved.cs @@ -0,0 +1,22 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UnusedAttributeTypeOnTypeIsRemoved { + static void Main () + { + new Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [Foo] + class Bar { + } + + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeWithTypeForwarderIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeWithTypeForwarderIsRemoved.cs new file mode 100644 index 000000000..49167f6a7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UnusedAttributeWithTypeForwarderIsRemoved.cs @@ -0,0 +1,28 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [KeepTypeForwarderOnlyAssemblies ("true")] + [SetupLinkerArgument ("--used-attrs-only", "true")] + [SetupCompileBefore ("library.dll", new[] { "Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Lib.cs" })] + [SetupCompileAfter ("implementation.dll", new[] { "Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Lib.cs" })] + [SetupCompileAfter ("library.dll", new[] { "Dependencies/UnusedAttributeWithTypeForwarderIsRemoved_Forwarder.cs" }, new[] { "implementation.dll" })] + + [RemovedTypeInAssembly ("library.dll", typeof(UnusedAttributeWithTypeForwarderIsRemoved_LibAttribute))] + [RemovedTypeInAssembly ("implementation.dll", typeof (UnusedAttributeWithTypeForwarderIsRemoved_LibAttribute))] + class UnusedAttributeWithTypeForwarderIsRemoved { + static void Main () + { + Method (null); + } + + [Kept] + + static void Method ([UnusedAttributeWithTypeForwarderIsRemoved_Lib ("")] string arg) + { + UnusedAttributeWithTypeForwarderIsRemoved_OtherUsedClass.UsedMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnAssemblyIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnAssemblyIsKept.cs new file mode 100644 index 000000000..3f84fddbb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnAssemblyIsKept.cs @@ -0,0 +1,23 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +[assembly: UsedAttributeTypeOnAssemblyIsKept.Foo] +[assembly: KeptAttributeAttribute (typeof (UsedAttributeTypeOnAssemblyIsKept.FooAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument("--used-attrs-only", "true")] + class UsedAttributeTypeOnAssemblyIsKept { + static void Main () + { + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Attribute))] + public class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnEventIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnEventIsKept.cs new file mode 100644 index 000000000..72fb256dc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnEventIsKept.cs @@ -0,0 +1,38 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + [KeptDelegateCacheField ("0")] + class UsedAttributeTypeOnEventIsKept { + static void Main () + { + var tmp = new Bar (); + tmp.Something += Tmp_Something; + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + private static void Tmp_Something (object sender, EventArgs e) + { + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Foo] + [Kept] + [KeptAttributeAttribute (typeof (FooAttribute))] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler<EventArgs> Something { [Foo] [KeptAttributeAttribute (typeof (FooAttribute))] add { } [Foo] [KeptAttributeAttribute (typeof (FooAttribute))] remove { } } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof(Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnMethodIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnMethodIsKept.cs new file mode 100644 index 000000000..fc8516f87 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnMethodIsKept.cs @@ -0,0 +1,32 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UsedAttributeTypeOnMethodIsKept { + static void Main () + { + new Bar ().Method (); + var tmp = new Bar (); + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Foo] + [Kept] + [KeptAttributeAttribute (typeof (FooAttribute))] + public void Method () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof(Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnModuleIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnModuleIsKept.cs new file mode 100644 index 000000000..72e9906df --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnModuleIsKept.cs @@ -0,0 +1,23 @@ +using System; +using Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[module: UsedAttributeTypeOnModuleIsKept.Foo] +[module: KeptAttributeAttribute (typeof (UsedAttributeTypeOnModuleIsKept.FooAttribute))] + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UsedAttributeTypeOnModuleIsKept { + static void Main () + { + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Attribute))] + public class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnParameterIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnParameterIsKept.cs new file mode 100644 index 000000000..4fb4b134b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnParameterIsKept.cs @@ -0,0 +1,29 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UsedAttributeTypeOnParameterIsKept { + static void Main () + { + new Bar ().Method ("Hello"); + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Kept] + public void Method ([Foo] [KeptAttributeAttribute (typeof (FooAttribute))] string arg) + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof(Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnPropertyIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnPropertyIsKept.cs new file mode 100644 index 000000000..8932d7252 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnPropertyIsKept.cs @@ -0,0 +1,32 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UsedAttributeTypeOnPropertyIsKept { + static void Main () + { + var bar = new Bar (); + bar.Value = "Hello"; + var tmp = bar.Value; + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + [Foo] + [Kept] + [KeptBackingField] + [KeptAttributeAttribute (typeof (FooAttribute))] + public string Value { [Foo] [Kept] [KeptAttributeAttribute (typeof (FooAttribute))] get; [Foo] [Kept] [KeptAttributeAttribute (typeof (FooAttribute))]set; } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof(Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnTypeIsKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnTypeIsKept.cs new file mode 100644 index 000000000..04dba4d26 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/OnlyKeepUsed/UsedAttributeTypeOnTypeIsKept.cs @@ -0,0 +1,28 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed { + + [SetupLinkerArgument ("--used-attrs-only", "true")] + class UsedAttributeTypeOnTypeIsKept { + static void Main () + { + var tmp = new Bar (); + var str = typeof (FooAttribute).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (FooAttribute))] + [Foo] + class Bar { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Attribute))] + class FooAttribute : Attribute { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/SecurityAttributesOnUsedMethodAreKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/SecurityAttributesOnUsedMethodAreKept.cs new file mode 100644 index 000000000..6ffa3845a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/SecurityAttributesOnUsedMethodAreKept.cs @@ -0,0 +1,25 @@ +using System; +using System.Security.Permissions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes { + [SetupLinkerArgument ("--strip-security", "false")] + class SecurityAttributesOnUsedMethodAreKept { + static void Main () + { + new Foo ().Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [SecurityPermission (SecurityAction.LinkDemand)] + [Kept] + [KeptSecurity (typeof (SecurityPermissionAttribute))] + public void Method () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Attributes/SecurityAttributesOnUsedTypeAreKept.cs b/test/Mono.Linker.Tests.Cases/Attributes/SecurityAttributesOnUsedTypeAreKept.cs new file mode 100644 index 000000000..080fe2096 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Attributes/SecurityAttributesOnUsedTypeAreKept.cs @@ -0,0 +1,21 @@ +using System; +using System.Security.Permissions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Attributes { + [SetupLinkerArgument("--strip-security", "false")] + class SecurityAttributesOnUsedTypeAreKept { + static void Main () + { + new Foo (); + } + + [SecurityPermission (SecurityAction.LinkDemand)] + [Kept] + [KeptMember (".ctor()")] + [KeptSecurity (typeof (SecurityPermissionAttribute))] + class Foo { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs new file mode 100644 index 000000000..d63d45a7c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/BaseRemovedEventSource.cs @@ -0,0 +1,81 @@ +using System; +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { + [SetupLinkerArgument ("--exclude-feature", "etw")] + public class BaseRemovedEventSource { + public static void Main () + { + var b = CustomCtorEventSource.Log.IsEnabled (); + if (b) + CustomCtorEventSource.Log.SomeMethod (); + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptMember (".ctor()")] + [KeptMember (".cctor()")] + [EventSource (Name = "MyCompany")] + class CustomCtorEventSource : EventSource { + public class Keywords { + public const EventKeywords Page = (EventKeywords)1; + + public int Unused; + } + + [Kept] + public static CustomCtorEventSource Log = new MyEventSourceBasedOnCustomCtorEventSource (1); + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldarg.0", + "call", + "ret", + })] + public CustomCtorEventSource (int value) + { + Removed (); + } + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + protected override void OnEventCommand (EventCommandEventArgs command) + { + } + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + [Event (8)] + public void SomeMethod () + { + Removed (); + } + + public void Removed () + { + } + } + + [Kept] + [KeptBaseType (typeof (CustomCtorEventSource))] + class MyEventSourceBasedOnCustomCtorEventSource : CustomCtorEventSource { + [Kept] + public MyEventSourceBasedOnCustomCtorEventSource (int value) : base (value) + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/CustomEventSource.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/CustomEventSource.cs new file mode 100644 index 000000000..8286f22c5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/CustomEventSource.cs @@ -0,0 +1,47 @@ +using System; +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { + public class CustomEventSource { + public static void Main () + { + var b = MyCompanyEventSource.Log.IsEnabled (); + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptAttributeAttribute (typeof (EventSourceAttribute))] + [KeptMember (".ctor()")] + [KeptMember (".cctor()")] + + [EventSource (Name = "MyCompany")] + class MyCompanyEventSource : EventSource + { + [Kept] + public class Keywords + { + [Kept] + public const EventKeywords Page = (EventKeywords)1; + + public int Unused; + } + + [Kept] + public class Tasks + { + [Kept] + public const EventTask Page = (EventTask)1; + + public int Unused; + } + + class NotMatching + { + } + + [Kept] + public static MyCompanyEventSource Log = new MyCompanyEventSource (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs new file mode 100644 index 000000000..575a7dec0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/Excluded.cs @@ -0,0 +1,63 @@ +using System; +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { + [SetupLinkerArgument ("--exclude-feature", "etw")] + // Used to avoid different compilers generating different IL which can mess up the instruction asserts + [SetupCompileArgument ("/optimize+")] + public class Excluded + { + public static void Main () + { + var b = RemovedEventSource.Log.IsEnabled (); + if (b) + RemovedEventSource.Log.SomeMethod (); + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptMember (".ctor()")] + [KeptMember (".cctor()")] + [EventSource (Name = "MyCompany")] + class RemovedEventSource : EventSource { + public class Keywords { + public const EventKeywords Page = (EventKeywords)1; + + public int Unused; + } + + [Kept] + public static RemovedEventSource Log = new RemovedEventSource (); + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + protected override void OnEventCommand (EventCommandEventArgs command) + { + } + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + [Event (8)] + public void SomeMethod () + { + Removed (); + } + + public void Removed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs new file mode 100644 index 000000000..1a5b1cb80 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/LocalsOfModifiedMethodAreRemoved.cs @@ -0,0 +1,65 @@ +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { + [SetupLinkerArgument ("--exclude-feature", "etw")] + // Used to avoid different compilers generating different IL which can mess up the instruction asserts + [SetupCompileArgument ("/optimize+")] + public class LocalsOfModifiedMethodAreRemoved { + public static void Main () + { + var b = LocalsAreCleared_RemovedEventSource.Log.IsEnabled (); + if (b) + LocalsAreCleared_RemovedEventSource.Log.SomeMethod (); + } + + public class ClassForLocal { + } + + public static void CallsToForceALocal (int arg1, int arg2, int arg3) + { + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptMember (".ctor()")] + [KeptMember (".cctor()")] + [EventSource (Name = "MyCompany")] + class LocalsAreCleared_RemovedEventSource : EventSource { + public class Keywords { + public const EventKeywords Page = (EventKeywords)1; + + public int Unused; + } + + [Kept] + public static LocalsAreCleared_RemovedEventSource Log = new LocalsAreCleared_RemovedEventSource (); + + [Kept] + [ExpectBodyModified] + [ExpectedLocalsSequence (new string[0])] + protected override void OnEventCommand (EventCommandEventArgs command) + { + // Do some extra stuff to be extra certain the compiler introduced a local instead of using `dup` + var tmp = new LocalsOfModifiedMethodAreRemoved.ClassForLocal (); + LocalsOfModifiedMethodAreRemoved.CallsToForceALocal (1, 3, 4); + LocalsOfModifiedMethodAreRemoved.CallsToForceALocal (1, 4, 4); + var hashcode = tmp.GetHashCode (); + LocalsOfModifiedMethodAreRemoved.CallsToForceALocal(1, hashcode, 3); + } + + [Kept] + [Event (8)] + [ExpectBodyModified] + public void SomeMethod () + { + Removed (); + } + + public void Removed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs new file mode 100644 index 000000000..5b0b82f18 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/NonEventWithLog.cs @@ -0,0 +1,51 @@ +using System; +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { + [SetupLinkerArgument ("--exclude-feature", "etw")] + // Used to avoid different compilers generating different IL which can mess up the instruction asserts + [SetupCompileArgument ("/optimize+")] + public class NonEventWithLog { + public static void Main () + { + var n = new NonEventWithLogSource (); + n.Test1 (); + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptMember (".ctor()")] + + [EventSource (Name = "MyCompany")] + class NonEventWithLogSource : EventSource { + + [NonEvent] + [Kept] + internal void Test1 () + { + if (IsEnabled ()) + Test2 (); + } + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + private void Test2 () + { + Console.WriteLine (); + } + + [NonEvent] + private void Test3 () + { + Console.WriteLine (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs new file mode 100644 index 000000000..e3f76779f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/StubbedMethodWithExceptionHandlers.cs @@ -0,0 +1,74 @@ +using System; +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW { + [SetupLinkerArgument ("--exclude-feature", "etw")] + // Used to avoid different compilers generating different IL which can mess up the instruction asserts + [SetupCompileArgument ("/optimize+")] + public class StubbedMethodWithExceptionHandlers { + public static void Main () + { + var b = StubbedMethodWithExceptionHandlers_RemovedEventSource.Log.IsEnabled (); + if (b) + StubbedMethodWithExceptionHandlers_RemovedEventSource.Log.SomeMethod (); + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptMember (".ctor()")] + [KeptMember (".cctor()")] + [EventSource (Name = "MyCompany")] + class StubbedMethodWithExceptionHandlers_RemovedEventSource : EventSource { + public class Keywords { + public const EventKeywords Page = (EventKeywords)1; + + public int Unused; + } + + [Kept] + public static StubbedMethodWithExceptionHandlers_RemovedEventSource Log = new StubbedMethodWithExceptionHandlers_RemovedEventSource (); + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + [ExpectedExceptionHandlerSequence (new string[0])] + protected override void OnEventCommand (EventCommandEventArgs command) + { + try { + Removed (); + } catch { + try { + Removed (); + } catch { + Removed (); + throw; + } + throw; + } + } + + [Kept] + [ExpectedInstructionSequence (new [] + { + "ldstr", + "newobj", + "throw", + })] + [Event (8)] + public void SomeMethod () + { + Removed (); + } + + public void Removed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/ComplexNestedClassesHasUnusedRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/ComplexNestedClassesHasUnusedRemoved.cs new file mode 100644 index 000000000..fbdbee204 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/ComplexNestedClassesHasUnusedRemoved.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class ComplexNestedClassesHasUnusedRemoved { + public static void Main () + { + new A.AB.ABD (); + } + + [Kept] + public class A { + [Kept] + public class AB { + public class ABC { + } + + [Kept] + [KeptMember(".ctor()")] + public class ABD { + public class ABDE { + } + } + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/InitializerForArrayIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/InitializerForArrayIsKept.cs new file mode 100644 index 000000000..7d461c741 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/InitializerForArrayIsKept.cs @@ -0,0 +1,40 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + public class InitializerForArrayIsKept { + public static void Main () + { + Method1 (); + Method2 (); + Method3 (); + } + + [Kept] + [KeptInitializerData] + static void Method1 () + { + Helper (new [] {1, 2, 3}); + Helper (new [] {1, 2, 3, 4}); + Helper (new [] {3, 4, 5}); + } + + [Kept] + [KeptInitializerData] + static void Method2 () + { + Helper (new [] {10, 11, 12}); + } + + [Kept] + [KeptInitializerData] + static void Method3 () + { + Helper (new [] {10, 11, 12}); + } + + [Kept] + static void Helper<T> (T [] arr) + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/InstantiatedTypeWithOverridesFromObject.cs b/test/Mono.Linker.Tests.Cases/Basic/InstantiatedTypeWithOverridesFromObject.cs new file mode 100644 index 000000000..aca4cf892 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/InstantiatedTypeWithOverridesFromObject.cs @@ -0,0 +1,44 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + public class InstantiatedTypeWithOverridesFromObject { + public static void Main () + { + var f = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + ~Foo () + { + // Finalize shouldn't be empty + DoCleanupStuff (); + } + + [Kept] + void DoCleanupStuff () + { + } + + [Kept] + public override bool Equals (object obj) + { + return false; + } + + [Kept] + public override string ToString () + { + return null; + } + + [Kept] + public override int GetHashCode () + { + return 0; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/InterfaceMethodImplementedOnBaseClassDoesNotGetStripped.cs b/test/Mono.Linker.Tests.Cases/Basic/InterfaceMethodImplementedOnBaseClassDoesNotGetStripped.cs new file mode 100644 index 000000000..fa0b762a8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/InterfaceMethodImplementedOnBaseClassDoesNotGetStripped.cs @@ -0,0 +1,37 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class InterfaceMethodImplementedOnBaseClassDoesNotGetStripped { + public static void Main () + { + I1 i1 = new Derived (); + i1.Used (); + } + + public interface I1 { + void Unused (); + + [Kept] + void Used (); + } + + [KeptMember (".ctor()")] + public class Base { + public void Unused () + { + } + + [Kept] + public void Used () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + [KeptInterface (typeof (I1))] + public class Derived : Base, I1 { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/MultiLevelNestedClassesAllRemovedWhenNonUsed.cs b/test/Mono.Linker.Tests.Cases/Basic/MultiLevelNestedClassesAllRemovedWhenNonUsed.cs new file mode 100644 index 000000000..dd5f8628e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/MultiLevelNestedClassesAllRemovedWhenNonUsed.cs @@ -0,0 +1,19 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class MultiLevelNestedClassesAllRemovedWhenNonUsed { + public static void Main () + { + } + + public class A { + public class AB { + public class ABC { + } + + public class ABD { + } + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/NestedDelegateInvokeMethodsPreserved.cs b/test/Mono.Linker.Tests.Cases/Basic/NestedDelegateInvokeMethodsPreserved.cs new file mode 100644 index 000000000..c3e231781 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/NestedDelegateInvokeMethodsPreserved.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class NestedDelegateInvokeMethodsPreserved { + [Kept] + static B.Delegate @delegate; + + static void Main () + { + System.GC.KeepAlive (@delegate); + } + + [Kept] + public class B { + [Kept] + [KeptMember ("Invoke()")] + [KeptMember ("BeginInvoke(System.AsyncCallback,System.Object)")] + [KeptMember ("EndInvoke(System.IAsyncResult)")] + [KeptMember (".ctor(System.Object,System.IntPtr)")] + [KeptBaseType (typeof (System.MulticastDelegate))] + public delegate void Delegate (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/NeverInstantiatedTypeWithOverridesFromObject.cs b/test/Mono.Linker.Tests.Cases/Basic/NeverInstantiatedTypeWithOverridesFromObject.cs new file mode 100644 index 000000000..5303fe69f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/NeverInstantiatedTypeWithOverridesFromObject.cs @@ -0,0 +1,38 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + public class NeverInstantiatedTypeWithOverridesFromObject { + public static void Main () + { + typeof (Foo).ToString (); + } + + [Kept] + class Foo { + ~Foo () + { + // Finalize shouldn't be empty + DoCleanupStuff (); + } + + void DoCleanupStuff () + { + } + + public override bool Equals (object obj) + { + return false; + } + + public override string ToString () + { + return null; + } + + public override int GetHashCode () + { + return 0; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UninvokedInterfaceMemberGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UninvokedInterfaceMemberGetsRemoved.cs new file mode 100644 index 000000000..fb03b0f6d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UninvokedInterfaceMemberGetsRemoved.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UninvokedInterfaceMemberGetsRemoved { + public static void Main () + { + I i = new B (); + var tmp = i.ToString (); + } + + [Kept] + interface I { + void Method (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (I))] + class B : I { + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedClassGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedClassGetsRemoved.cs new file mode 100644 index 000000000..85d60e33d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedClassGetsRemoved.cs @@ -0,0 +1,10 @@ +namespace Mono.Linker.Tests.Cases.Basic { + public class UnusedClassGetsRemoved { + public static void Main () + { + } + } + + class Unused { + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedDelegateGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedDelegateGetsRemoved.cs new file mode 100644 index 000000000..d366e718e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedDelegateGetsRemoved.cs @@ -0,0 +1,11 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedDelegateGetsRemoved { + static void Main () + { + } + + public delegate void Foo (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedEnumGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedEnumGetsRemoved.cs new file mode 100644 index 000000000..e646cfe63 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedEnumGetsRemoved.cs @@ -0,0 +1,15 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedEnumGetsRemoved { + static void Main () + { + } + + enum Unused { + One, + Two, + Three + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedEventGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedEventGetsRemoved.cs new file mode 100644 index 000000000..ed9279d08 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedEventGetsRemoved.cs @@ -0,0 +1,19 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedEventGetsRemoved { + public static void Main () + { + var tmp = new Foo (); + } + + [KeptMember (".ctor()")] + public class Foo + { + public delegate void CustomDelegate (); + + public event CustomDelegate Bar; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedFieldGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedFieldGetsRemoved.cs new file mode 100644 index 000000000..6edcf5729 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedFieldGetsRemoved.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedFieldGetsRemoved { + public static void Main () + { + new B ().Method (); + } + + [KeptMember (".ctor()")] + class B { + public int _unused; + + [Kept] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedFieldsOfStructsAreKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedFieldsOfStructsAreKept.cs new file mode 100644 index 000000000..a4443a7ff --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedFieldsOfStructsAreKept.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + public class UnusedFieldsOfStructsAreKept { + public static void Main () + { + A a = new A (); + PreventCompilerOptimization (a); + } + + [Kept] + static void PreventCompilerOptimization (A a) + { + } + + [Kept] + struct A { + [Kept] + private int UnusedField1; + [Kept] + private int UnusedField2; + + public void UnusedMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedMethodGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedMethodGetsRemoved.cs new file mode 100644 index 000000000..eaded4de5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedMethodGetsRemoved.cs @@ -0,0 +1,22 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedMethodGetsRemoved { + public static void Main () + { + new UnusedMethodGetsRemoved.B ().Method (); + } + + [KeptMember (".ctor()")] + class B { + public void Unused () + { + } + + [Kept] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedNestedClassGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedNestedClassGetsRemoved.cs new file mode 100644 index 000000000..7ff2fc3a6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedNestedClassGetsRemoved.cs @@ -0,0 +1,11 @@ + +namespace Mono.Linker.Tests.Cases.Basic { + public class UnusedNestedClassGetsRemoved { + public static void Main () + { + } + + class Unused { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedPropertyGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedPropertyGetsRemoved.cs new file mode 100644 index 000000000..63d82842e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedPropertyGetsRemoved.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedPropertyGetsRemoved { + public static void Main () + { + new UnusedPropertyGetsRemoved.B ().Method (); + } + + [KeptMember(".ctor()")] + class B { + public int Unused { get; set; } + + [Kept] + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UnusedPropertySetterRemoved.cs b/test/Mono.Linker.Tests.Cases/Basic/UnusedPropertySetterRemoved.cs new file mode 100644 index 000000000..9bf680e77 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UnusedPropertySetterRemoved.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UnusedPropertySetterRemoved { + public static void Main () + { + var val = new UnusedPropertySetterRemoved.B ().PartiallyUsed; + } + + [KeptMember (".ctor()")] + class B { + [Kept] // FIXME: Should be removed + [KeptBackingField] + public int PartiallyUsed { [Kept] get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedEnumIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedEnumIsKept.cs new file mode 100644 index 000000000..5320ce63d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedEnumIsKept.cs @@ -0,0 +1,39 @@ +using System; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UsedEnumIsKept { + static void Main () + { + // Use all of the values in case we implement a feature in the future that removes unused values + HelperAsEnum (Used.One); + HelperAsEnum (Used.Two); + HelperAsObject (Used.Three); + } + + [Kept] + static void HelperAsEnum (Used arg) + { + } + + [Kept] + static void HelperAsObject (object arg) + { + } + + [Kept] + [KeptMember ("value__")] + [KeptBaseType (typeof(Enum))] + enum Used { + [Kept] + One, + + [Kept] + Two, + + [Kept] + Three + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedEventIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedEventIsKept.cs new file mode 100644 index 000000000..0ff3cd573 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedEventIsKept.cs @@ -0,0 +1,45 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + [KeptDelegateCacheField ("0")] + [KeptDelegateCacheField ("1")] + class UsedEventIsKept { + public static void Main () + { + var tmp = new Foo (); + + tmp.Bar += Tmp_Bar; + tmp.Fire (); + tmp.Bar -= Tmp_Bar; + } + + [Kept] + private static void Tmp_Bar () + { + } + + [KeptMember (".ctor()")] + public class Foo { + [Kept] + [KeptBaseType (typeof(MulticastDelegate))] + [KeptMember (".ctor(System.Object,System.IntPtr)")] + [KeptMember ("Invoke()")] + [KeptMember ("BeginInvoke(System.AsyncCallback,System.Object)")] + [KeptMember ("EndInvoke(System.IAsyncResult)")] + public delegate void CustomDelegate (); + + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event CustomDelegate Bar; + + [Kept] + public void Fire () + { + Bar (); + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedEventOnInterfaceIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedEventOnInterfaceIsKept.cs new file mode 100644 index 000000000..828a76dac --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedEventOnInterfaceIsKept.cs @@ -0,0 +1,48 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + [KeptDelegateCacheField ("0")] + class UsedEventOnInterfaceIsKept { + static void Main () + { + IFoo bar = new Bar (); + IFoo jar = new Jar (); + + bar.Ping += Bar_Ping; + } + + [Kept] + private static void Bar_Ping (object sender, EventArgs e) + { + } + + [Kept] + interface IFoo { + [Kept] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + event EventHandler Ping; + } + + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class Bar : IFoo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler Ping; + } + + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class Jar : IFoo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler Ping; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedEventOnInterfaceIsRemovedWhenUsedFromClass.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedEventOnInterfaceIsRemovedWhenUsedFromClass.cs new file mode 100644 index 000000000..edff204d6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedEventOnInterfaceIsRemovedWhenUsedFromClass.cs @@ -0,0 +1,38 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + [KeptDelegateCacheField ("0")] + class UsedEventOnInterfaceIsRemovedWhenUsedFromClass { + static void Main () + { + var bar = new Bar (); + var jar = new Jar (); + + bar.Ping += Bar_Ping; + } + + [Kept] + private static void Bar_Ping (object sender, EventArgs e) + { + } + + interface IFoo { + event EventHandler Ping; + } + + [KeptMember (".ctor()")] + class Bar : IFoo { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler Ping; + } + + [KeptMember (".ctor()")] + class Jar : IFoo { + public event EventHandler Ping; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedInterfaceIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedInterfaceIsKept.cs new file mode 100644 index 000000000..e399d2c9b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedInterfaceIsKept.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic +{ + class UsedInterfaceIsKept + { + public static void Main () + { + A a = new A (); + var t = typeof (I).ToString(); + } + + [Kept] + [KeptInterface (typeof (I))] + [KeptMember (".ctor()")] + class A : I + { + } + + [Kept] + interface I + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedPropertyIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedPropertyIsKept.cs new file mode 100644 index 000000000..8adc71f27 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedPropertyIsKept.cs @@ -0,0 +1,19 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic { + class UsedPropertyIsKept { + public static void Main () + { + var obj = new B (); + obj.Prop = 1; + var val = obj.Prop; + } + + [KeptMember (".ctor()")] + class B { + [Kept] + [KeptBackingField] + public int Prop { [Kept] get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Basic/UsedStructIsKept.cs b/test/Mono.Linker.Tests.Cases/Basic/UsedStructIsKept.cs new file mode 100644 index 000000000..4af518fed --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Basic/UsedStructIsKept.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Basic +{ + class UsedStructIsKept { + public static void Main() + { + A a; + a.MethodVerifiedByKeptMember (); + } + + [Kept] + // This KeptMember is here to make sure the test framework's support of KeptMember on value types is working correctly + [KeptMember ("MethodVerifiedByKeptMember()")] + struct A { + public void MethodVerifiedByKeptMember () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/CommandLine/Dependencies/ResponseFilesWork.rsp b/test/Mono.Linker.Tests.Cases/CommandLine/Dependencies/ResponseFilesWork.rsp new file mode 100644 index 000000000..e4a075582 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CommandLine/Dependencies/ResponseFilesWork.rsp @@ -0,0 +1 @@ +--used-attrs-only true
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CommandLine/ResponseFilesWork.cs b/test/Mono.Linker.Tests.Cases/CommandLine/ResponseFilesWork.cs new file mode 100644 index 000000000..6f65a2d52 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CommandLine/ResponseFilesWork.cs @@ -0,0 +1,25 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CommandLine { + /// <summary> + /// This test will use only keep used attributes, which is disabled by default, to infer that the rsp file worked + /// </summary> + [SetupLinkerResponseFileAttribute ("Dependencies/ResponseFilesWork.rsp")] + public class ResponseFilesWork { + public static void Main () + { + new Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [Foo] + class Bar { + } + + class FooAttribute : Attribute { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/CanIncludeI18nAssemblies.cs b/test/Mono.Linker.Tests.Cases/CoreLink/CanIncludeI18nAssemblies.cs new file mode 100644 index 000000000..28223435e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/CanIncludeI18nAssemblies.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink { + [SetupLinkerCoreAction ("link")] + [Il8n ("all")] + + // i18n assemblies should only be included when processing mono class libs. By forcing this test to use mcs, + // we can ensure the test will be ignored when the test runs against .net fw assemblies. + [SetupCSharpCompilerToUse ("mcs")] + + [KeptAssembly ("I18N.dll")] + [KeptAssembly ("I18N.CJK.dll")] + [KeptAssembly ("I18N.MidEast.dll")] + [KeptAssembly ("I18N.Other.dll")] + [KeptAssembly ("I18N.Rare.dll")] + [KeptAssembly ("I18N.West.dll")] + + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class CanIncludeI18nAssemblies { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/CopyOfCoreLibrariesKeepsUnusedTypes.cs b/test/Mono.Linker.Tests.Cases/CoreLink/CopyOfCoreLibrariesKeepsUnusedTypes.cs new file mode 100644 index 000000000..bc1fd3681 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/CopyOfCoreLibrariesKeepsUnusedTypes.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink +{ + [SetupLinkerCoreAction ("copy")] + + [KeptAssembly ("mscorlib.dll")] + [KeptAllTypesAndMembersInAssembly ("mscorlib.dll")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + class CopyOfCoreLibrariesKeepsUnusedTypes + { + public static void Main() + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs b/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs new file mode 100644 index 000000000..22419a6d6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/DelegateAndMulticastDelegateKeepInstantiatedReqs.cs @@ -0,0 +1,35 @@ +using System; +using System.Runtime.Serialization; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink { + /// <summary> + /// Delegate and is created from + /// </summary> + [SetupLinkerCoreAction ("link")] + [KeptBaseOnTypeInAssembly ("mscorlib.dll", typeof (MulticastDelegate), "mscorlib.dll", typeof (Delegate))] + + // Check a couple override methods to verify they were not removed + [KeptMemberInAssembly ("mscorlib.dll", typeof (MulticastDelegate), "GetHashCode()")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (MulticastDelegate), "Equals(System.Object)")] + + [KeptMemberInAssembly ("mscorlib.dll", typeof (Delegate), "GetHashCode()")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (Delegate), "Equals(System.Object)")] + [KeptInterfaceOnTypeInAssembly("mscorlib.dll", typeof (Delegate), "mscorlib.dll", typeof (ICloneable))] + [KeptInterfaceOnTypeInAssembly("mscorlib.dll", typeof (Delegate), "mscorlib.dll", typeof (ISerializable))] + + // Fails due to Runtime critical type System.Reflection.CustomAttributeData not found. + [SkipPeVerify(SkipPeVerifyForToolchian.Pedump)] + public class DelegateAndMulticastDelegateKeepInstantiatedReqs { + public static void Main () + { + typeof (MulticastDelegate).ToString (); + + // Cause the interfaces to be marked in order to eliminate the possibility of them being removed + // due to no code path marking the interface type + typeof (ISerializable).ToString (); + typeof (ICloneable).ToString(); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/InstantiatedTypeWithOverridesFromObject.cs b/test/Mono.Linker.Tests.Cases/CoreLink/InstantiatedTypeWithOverridesFromObject.cs new file mode 100644 index 000000000..0af5194e8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/InstantiatedTypeWithOverridesFromObject.cs @@ -0,0 +1,48 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink { + [SetupLinkerCoreAction ("link")] + // Need to skip due to `Runtime critical type System.Reflection.CustomAttributeData not found` failure + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class InstantiatedTypeWithOverridesFromObject { + public static void Main () + { + var f = new Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + ~Foo () + { + // Finalize shouldn't be empty + DoCleanupStuff (); + } + + [Kept] + void DoCleanupStuff () + { + } + + [Kept] + public override bool Equals (object obj) + { + return false; + } + + [Kept] + public override string ToString () + { + return null; + } + + [Kept] + public override int GetHashCode () + { + return 0; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs new file mode 100644 index 000000000..5a39b04aa --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedMethods.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections; +using System.IO; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink +{ + [SetupLinkerCoreAction ("link")] + + [KeptAssembly ("mscorlib.dll")] + [KeptMemberInAssembly ("mscorlib.dll", typeof (Stack), ".ctor(System.Int32)", "Pop()", "Push(System.Object)")] + // We can't check everything that should be removed, but we should be able to check a few niche things that + // we known should be removed which will at least verify that the core library was processed + [RemovedMemberInAssembly ("mscorlib.dll", typeof (Stack), ".ctor(System.Collections.ICollection)")] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + class LinkingOfCoreLibrariesRemovesUnusedMethods { + public static void Main() + { + Stack stack = new Stack (2); + stack.Push (1); + var val = stack.Pop (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs new file mode 100644 index 000000000..2ccbea396 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/LinkingOfCoreLibrariesRemovesUnusedTypes.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink { + [SetupLinkerCoreAction ("link")] + [Reference("System.dll")] + + [KeptAssembly ("mscorlib.dll")] + [KeptAssembly("System.dll")] + // We can't check everything that should be removed, but we should be able to check a few niche things that + // we known should be removed which will at least verify that the core library was processed + [KeptTypeInAssembly ("mscorlib.dll", typeof (System.Collections.Generic.IEnumerable<>))] + [KeptTypeInAssembly ("System.dll", typeof (System.Collections.Generic.SortedList<,>))] + + [RemovedTypeInAssembly ("mscorlib.dll", typeof (System.Resources.ResourceWriter))] + [RemovedTypeInAssembly ("System.dll", typeof (System.Collections.Generic.SortedDictionary<,>))] + + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + + // All sorts of stuff is flagged as invalid even in the original System.dll and System.Configuration.dll for mono class libraries + [SkipPeVerify("System.dll")] + [SkipPeVerify("System.Configuration.dll")] + // System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code + // detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked. + // PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output + [SkipPeVerify ("System.Core.dll")] + class LinkingOfCoreLibrariesRemovesUnusedTypes { + public static void Main () + { + // Use something from system that would normally be removed if we didn't use it + OtherMethods2 (new SortedList<string, string>()); + } + + [Kept] + static void OtherMethods2 (SortedList<string, string> list) + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/NeverInstantiatedTypeWithOverridesFromObject.cs b/test/Mono.Linker.Tests.Cases/CoreLink/NeverInstantiatedTypeWithOverridesFromObject.cs new file mode 100644 index 000000000..9d1627aff --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/NeverInstantiatedTypeWithOverridesFromObject.cs @@ -0,0 +1,42 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink { + [SetupLinkerCoreAction ("link")] + // Need to skip due to `Runtime critical type System.Reflection.CustomAttributeData not found` failure + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class NeverInstantiatedTypeWithOverridesFromObject { + public static void Main () + { + typeof (Foo).ToString (); + } + + [Kept] + class Foo { + ~Foo () + { + // Finalize shouldn't be empty + DoCleanupStuff (); + } + + void DoCleanupStuff () + { + } + + public override bool Equals (object obj) + { + return false; + } + + public override string ToString () + { + return null; + } + + public override int GetHashCode () + { + return 0; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs b/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs new file mode 100644 index 000000000..cc6757e6e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/CoreLink/NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs @@ -0,0 +1,41 @@ +using System.Diagnostics; +using System.Security; +using System.Security.Permissions; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.CoreLink { + [SetupLinkerCoreAction ("link")] + [SetupLinkerArgument ("--strip-security", "true")] + [SetupLinkerArgument ("--used-attrs-only", "true")] + [Reference ("System.dll")] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecurityPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (PermissionSetAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (ReflectionPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (RegistryPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (StrongNameIdentityPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (CodeAccessSecurityAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (EnvironmentPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (FileIOPermissionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (HostProtectionAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecurityCriticalAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecuritySafeCriticalAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SuppressUnmanagedCodeSecurityAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (SecurityRulesAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (AllowPartiallyTrustedCallersAttribute))] + [RemovedTypeInAssembly ("mscorlib.dll", typeof (UnverifiableCodeAttribute))] + // Fails with `Runtime critical type System.Reflection.CustomAttributeData not found` which is a known short coming + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + [SkipPeVerify ("System.dll")] + // System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code + // detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked. + // PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output + [SkipPeVerify ("System.Core.dll")] + public class NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries { + public static void Main () + { + // Use something that has security attributes to make this test more meaningful + var process = new Process (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/CorrectOverloadedMethodGetsStrippedInGenericClass.cs b/test/Mono.Linker.Tests.Cases/Generics/CorrectOverloadedMethodGetsStrippedInGenericClass.cs new file mode 100644 index 000000000..362c3bb3d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/CorrectOverloadedMethodGetsStrippedInGenericClass.cs @@ -0,0 +1,37 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class CorrectOverloadedMethodGetsStrippedInGenericClass { + public static void Main () + { + // Call overloaded method through the abstract base class + GenericClassWithTwoOverloadedAbstractMethods<float> item = new SpecializedClassWithTwoOverloadedVirtualMethods (); + item.OverloadedMethod (5); + } + + [KeptMember (".ctor()")] + public abstract class GenericClassWithTwoOverloadedAbstractMethods<T> { + public abstract string OverloadedMethod (T thing); // Don't call this one, it should be stripped + + [Kept] + public abstract string OverloadedMethod (int thing); // Call to this should preserve the overriden one + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (GenericClassWithTwoOverloadedAbstractMethods<System.Single>))] + public class SpecializedClassWithTwoOverloadedVirtualMethods : GenericClassWithTwoOverloadedAbstractMethods<float> { + // Don't call this one, it should be stripped + public override string OverloadedMethod (float thing) + { + return "first"; + } + + // Don't call this one, but it shouldn't be stripped because the method it overrides is invoked + [Kept] + public override string OverloadedMethod (int thing) + { + return "second"; + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Generics/DerivedClassWithMethodOfSameNameAsBaseButDifferentNumberOfGenericParametersUnusedBaseWillGetStripped.cs b/test/Mono.Linker.Tests.Cases/Generics/DerivedClassWithMethodOfSameNameAsBaseButDifferentNumberOfGenericParametersUnusedBaseWillGetStripped.cs new file mode 100644 index 000000000..b13f8267e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/DerivedClassWithMethodOfSameNameAsBaseButDifferentNumberOfGenericParametersUnusedBaseWillGetStripped.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class DerivedClassWithMethodOfSameNameAsBaseButDifferentNumberOfGenericParametersUnusedBaseWillGetStripped { + public static void Main (string [] args) + { + MyDerived obj = new MyDerived (); + obj.Method<int, int> (1); + } + + [Kept] + [KeptMember (".ctor()")] + class MyBase { + public virtual T Method<T> (T arg1) + { + return arg1; + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (MyBase))] + class MyDerived : MyBase { + [Kept] + public virtual T Method<T, K> (T arg1) + { + return arg1; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/GenericInstanceInterfaceMethodImplementedWithDifferentGenericArgumentNameDoesNotGetStripped.cs b/test/Mono.Linker.Tests.Cases/Generics/GenericInstanceInterfaceMethodImplementedWithDifferentGenericArgumentNameDoesNotGetStripped.cs new file mode 100644 index 000000000..4a912d678 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/GenericInstanceInterfaceMethodImplementedWithDifferentGenericArgumentNameDoesNotGetStripped.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class GenericInstanceInterfaceMethodImplementedWithDifferentGenericArgumentNameDoesNotGetStripped { + public static void Main () + { + ISomething it = new Concrete (); + it.ShouldNotGetStripped<int> (); + } + + [Kept] + public class GenericType<T> { + } + + public interface ISomething { + [Kept] + GenericType<TInInterface> ShouldNotGetStripped<TInInterface> (); + } + + [KeptMember (".ctor()")] + [KeptInterface (typeof (ISomething))] + public class Concrete : ISomething { + [Kept] + public GenericType<TInConcrete> ShouldNotGetStripped<TInConcrete> () + { + throw new System.Exception (); + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameter.cs b/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameter.cs new file mode 100644 index 000000000..5f8a4389e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameter.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameter { + public static void Main (string [] args) + { + Derived<int, int> tmp = new Derived<int, int> (); + tmp.Method<int> (null); + } + + [KeptMember (".ctor()")] + public abstract class Base<TSource> { + [Kept] + public abstract TResult1 Method<TResult1> (IDictionary<TSource, TResult1> arg); + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base<>), "TResult1")] + public class Derived<TSource, TResult1> : Base<TResult1> { + [Kept] + public override TResult2 Method<TResult2> (IDictionary<TResult1, TResult2> arg) + { + return default (TResult2); + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase.cs b/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase.cs new file mode 100644 index 000000000..37d1305dc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase { + public static void Main (string [] args) + { + Derived<int, int> tmp = new Derived<int, int> (); + tmp.Method<int> (null); + } + + [Kept] + public class Base<TSource> { + + [KeptMember (".ctor()")] + public abstract class Nested { + [Kept] + public abstract TResult1 Method<TResult1> (IDictionary<TSource, TResult1> arg); + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base<>.Nested), "TResult1")] + public class Derived<TSource, TResult1> : Base<TResult1>.Nested { + [Kept] + public override TResult2 Method<TResult2> (IDictionary<TResult1, TResult2> arg) + { + return default (TResult2); + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase2.cs b/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase2.cs new file mode 100644 index 000000000..f6e1370a3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase2.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase2 { + public static void Main (string [] args) + { + Derived<int, int> tmp = new Derived<int, int> (); + tmp.Method<int> (null); + } + + [Kept] + public class Base<TSource> { + + [KeptMember (".ctor()")] + public abstract class Nested<T1, T2, T3> { + [Kept] + public abstract TResult1 Method<TResult1> (IDictionary<TSource, TResult1> arg); + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base<>.Nested<,,>), "TResult1", typeof (int), typeof (int), typeof (string))] + public class Derived<TSource, TResult1> : Base<TResult1>.Nested<int, int, string> { + [Kept] + public override TResult2 Method<TResult2> (IDictionary<TResult1, TResult2> arg) + { + return default (TResult2); + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/NewConstraintOnClass.cs b/test/Mono.Linker.Tests.Cases/Generics/NewConstraintOnClass.cs new file mode 100644 index 000000000..2d644e5c3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/NewConstraintOnClass.cs @@ -0,0 +1,37 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics +{ + public class NewConstraintOnClass + { + public static void Main () + { + var g1 = new G1<G1Ctor> (); + } + + class G1Ctor + { + static readonly int field = 1; + + [Kept] + public G1Ctor () + { + } + + public G1Ctor (int a) + { + } + + public void Foo () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + class G1<T> where T : G1Ctor, new () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Generics/OverrideWithAnotherVirtualMethodOfSameNameWithDifferentParameterType.cs b/test/Mono.Linker.Tests.Cases/Generics/OverrideWithAnotherVirtualMethodOfSameNameWithDifferentParameterType.cs new file mode 100644 index 000000000..ba81282b8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/OverrideWithAnotherVirtualMethodOfSameNameWithDifferentParameterType.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + class OverrideWithAnotherVirtualMethodOfSameNameWithDifferentParameterType { + public static void Main (string [] args) + { + new Derived<double, int> ().Method (1.0); + } + + [KeptMember (".ctor()")] + public class Base<S> { + [Kept] + public virtual S Method (S arg) + { + return arg; + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base<>), "K")] + public class Derived<K, S> : Base<K> { + [Kept] + public override K Method (K arg) + { + return arg; + } + + public virtual S Method (S arg) + { + return arg; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodInGenericClassIsNotStripped.cs b/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodInGenericClassIsNotStripped.cs new file mode 100644 index 000000000..908e0d50d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodInGenericClassIsNotStripped.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + public class UsedOverloadedGenericMethodInGenericClassIsNotStripped { + public static void Main () + { + B<int>.Method (true); + } + + class B<TBase> { + [Kept] + public static void Method<T> (T value) + { + } + + public static void Method (TBase value) + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodInstanceInGenericClassIsNotStripped.cs b/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodInstanceInGenericClassIsNotStripped.cs new file mode 100644 index 000000000..a565d4cf5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodInstanceInGenericClassIsNotStripped.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + public class UsedOverloadedGenericMethodInstanceInGenericClassIsNotStripped { + public static void Main () + { + B<int>.Method (1); + } + + class B<TBase> { + public static void Method<T> (T value) + { + } + + [Kept] + public static void Method (TBase value) + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodWithNoParametersIsNotStripped.cs b/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodWithNoParametersIsNotStripped.cs new file mode 100644 index 000000000..52e1ff7b2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Generics/UsedOverloadedGenericMethodWithNoParametersIsNotStripped.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Generics { + public class UsedOverloadedGenericMethodWithNoParametersIsNotStripped { + public static void Main () + { + B.Call<string, int> (); + } + + public class B { + public static void Method<T> () + { + } + + [Kept] + public static void Method<TKey, TValue> () + { + } + + [Kept] + public static void Call<TKey, TValue> () + { + B.Method<TKey, TValue> (); + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKept.cs new file mode 100644 index 000000000..9cbb14504 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKept.cs @@ -0,0 +1,42 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class OverrideOfAbstractIsKept { + public static void Main () + { + Base b = HelperToMarkFooAndRequireBase (); + b.Method (); + } + + [Kept] + static Foo HelperToMarkFooAndRequireBase () + { + return null; + } + + [Kept] + abstract class Base { + [Kept] + public abstract void Method (); + } + + [Kept] + [KeptBaseType (typeof(Base))] + abstract class Base2 : Base { + } + + [Kept] + [KeptBaseType (typeof (Base2))] + abstract class Base3 : Base2 { + } + + [Kept] + [KeptBaseType (typeof (Base3))] + class Foo : Base3 { + [Kept] + public override void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved.cs new file mode 100644 index 000000000..6277e8338 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved.cs @@ -0,0 +1,33 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class OverrideOfVirtualCanBeRemoved { + public static void Main () + { + Base b = HelperToMarkFooAndRequireBase (); + b.Method (); + } + + [Kept] + static Foo HelperToMarkFooAndRequireBase () + { + return null; + } + + [Kept] + class Base { + [Kept] + public virtual void Method () + { + } + } + + [Kept] + [KeptBaseType (typeof (Base))] + class Foo : Base { + public override void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved2.cs new file mode 100644 index 000000000..4bb4df93c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved2.cs @@ -0,0 +1,46 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class OverrideOfVirtualCanBeRemoved2 { + public static void Main () + { + Base b = HelperToMarkFooAndRequireBase (); + b.Method (); + } + + [Kept] + static Foo HelperToMarkFooAndRequireBase () + { + return null; + } + + [Kept] + abstract class Base { + [Kept] + public abstract void Method (); + } + + [Kept] + [KeptBaseType (typeof (Base))] + abstract class Base2 : Base + { + } + + [Kept] + [KeptBaseType (typeof (Base2))] + class Base3 : Base2 { + [Kept] + public override void Method () + { + } + } + + [Kept] + [KeptBaseType (typeof (Base3))] + class Foo : Base3 { + public override void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved3.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved3.cs new file mode 100644 index 000000000..1f376e05c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfVirtualCanBeRemoved3.cs @@ -0,0 +1,45 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class OverrideOfVirtualCanBeRemoved3 { + public static void Main () + { + HelperToMarkFoo2AndRequireBase(); + Base b = HelperToMarkFooAndRequireBase (); + b.Method (); + } + + [Kept] + static Foo HelperToMarkFooAndRequireBase () + { + return null; + } + + [Kept] + static Foo2 HelperToMarkFoo2AndRequireBase () + { + return null; + } + + [Kept] + class Base { + [Kept] + public virtual void Method () + { + } + } + + [Kept] + [KeptBaseType (typeof (Base))] + class Foo : Base { + public override void Method () + { + } + } + + [Kept] + [KeptBaseType (typeof (Foo))] + class Foo2 : Foo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideThatAlsoFulfilsInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideThatAlsoFulfilsInterface.cs new file mode 100644 index 000000000..428310dad --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideThatAlsoFulfilsInterface.cs @@ -0,0 +1,59 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class OverrideThatAlsoFulfilsInterface { + public static void Main () + { + Base b = HelperToMarkFooAndRequireBase (); + b.Method (); + + MethodToUseTheInterface (); + } + + [Kept] + static void MethodToUseTheInterface () + { + // Now use the interface method so that it is kept + IFoo f = new Bar (); + f.Method (); + } + + [Kept] + static Foo HelperToMarkFooAndRequireBase () + { + return null; + } + + [Kept] + class Base { + [Kept] + public virtual void Method () + { + } + } + + [Kept] + interface IFoo { + [Kept] + void Method (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class Bar : IFoo { + [Kept] + public void Method () + { + } + } + + [Kept] + [KeptBaseType (typeof (Base))] + class Foo : Base, IFoo { + public override void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.cs new file mode 100644 index 000000000..d21678797 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.cs @@ -0,0 +1,51 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved { + public static void Main () + { + Base j = new Jar (); + j.One (); + } + + [Kept] + [KeptMember (".ctor()")] + abstract class Base { + [Kept] + public abstract void Foo (); + + [Kept] + public virtual void One () + { + } + } + + [Kept] + [KeptBaseType (typeof (Base))] + class Bar : Base { + [Kept] + public override void Foo () + { + } + + public override void One () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class Jar : Base { + [Kept] + public override void Foo () + { + } + + [Kept] + public override void One () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.xml b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.xml new file mode 100644 index 000000000..932f34d59 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved/Bar"> + <method name="Foo"/> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.cs new file mode 100644 index 000000000..a1ddd7c30 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.cs @@ -0,0 +1,60 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval { + public class PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2 { + public static void Main () + { + Base j = new Jar (); + j.One (); + } + + [Kept] + [KeptMember (".ctor()")] + abstract class Base { + [Kept] + public abstract void Foo (); + + [Kept] + public abstract void One (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + abstract class Base2 : Base + { + [Kept] + public override void One () + { + } + } + + [Kept] + [KeptBaseType (typeof (Base2))] + class Bar : Base2 { + [Kept] + public override void Foo () + { + } + + public override void One () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base2))] + class Jar : Base2 { + [Kept] + public override void Foo () + { + } + + [Kept] + public override void One () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.xml b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.xml new file mode 100644 index 000000000..1395ed53f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2/Bar"> + <method name="Foo"/> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UnusedAbstractMethodRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UnusedAbstractMethodRemoved.cs new file mode 100644 index 000000000..452493a97 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UnusedAbstractMethodRemoved.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses { + public class UnusedAbstractMethodRemoved { + public static void Main () + { + var tmp = new B (); + } + + [KeptMember (".ctor()")] + abstract class Base { + public abstract void Call (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UnusedVirtualMethodRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UnusedVirtualMethodRemoved.cs new file mode 100644 index 000000000..82f5d6729 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UnusedVirtualMethodRemoved.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses { + public class UnusedVirtualMethodRemoved { + public static void Main () + { + var tmp = new B (); + } + + [KeptMember (".ctor()")] + abstract class Base { + public virtual void Call () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UsedOverrideOfAbstractMethodIsKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UsedOverrideOfAbstractMethodIsKept.cs new file mode 100644 index 000000000..f2362aef6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UsedOverrideOfAbstractMethodIsKept.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses { + public class UsedOverrideOfAbstractMethodIsKept { + public static void Main () + { + var tmp = new B (); + tmp.Call (); + } + + [KeptMember (".ctor()")] + abstract class Base { + [Kept] + public abstract void Call (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + [Kept] + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UsedOverrideOfVirtualMethodIsKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UsedOverrideOfVirtualMethodIsKept.cs new file mode 100644 index 000000000..e27049e36 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/UsedOverrideOfVirtualMethodIsKept.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses { + public class UsedOverrideOfVirtualMethodIsKept { + public static void Main () + { + var tmp = new B (); + tmp.Call (); + } + + [KeptMember (".ctor()")] + abstract class Base { + [Kept] + public virtual void Call () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + [Kept] + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.cs new file mode 100644 index 000000000..72d30becd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.cs @@ -0,0 +1,13 @@ +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies { + public class InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy { + public static void ToKeepReferenceAtCompileTime () + { + } + + public class A : InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.IFoo { + void InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.IFoo.Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.cs new file mode 100644 index 000000000..cf093a8d7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies { + public class InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link { + public interface IFoo { + void Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.cs new file mode 100644 index 000000000..62eb61d3a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.cs @@ -0,0 +1,13 @@ +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies { + public class InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy { + public static void ToKeepReferenceAtCompileTime () + { + } + + public class A : InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.IFoo { + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.cs new file mode 100644 index 000000000..a03e2708f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies { + public class InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link { + public interface IFoo { + void Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.cs new file mode 100644 index 000000000..e4ca903cb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/Dependencies/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.cs @@ -0,0 +1,10 @@ +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies +{ + public class InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib + { + public interface IFoo + { + bool ExplicitMethod(); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplementingInterfaceMethodsNested.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplementingInterfaceMethodsNested.cs new file mode 100644 index 000000000..3a4b3b197 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplementingInterfaceMethodsNested.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class ClassImplementingInterfaceMethodsNested { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar : IFoo { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IBar { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplementingInterfaceMethodsNested2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplementingInterfaceMethodsNested2.cs new file mode 100644 index 000000000..aba1ed062 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplementingInterfaceMethodsNested2.cs @@ -0,0 +1,39 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class ClassImplementingInterfaceMethodsNested2 { + public static void Main () + { + IBar b = new A (); + IFoo f = b; + f.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + interface IBar : IFoo { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IBar))] + [KeptInterface (typeof (IFoo))] + class A : IBar { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass2.cs new file mode 100644 index 000000000..0d7f9353e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass2.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + class ClassImplemtingInterfaceMethodsThroughBaseClass2 { + public static void Main () + { + new B (); + IFoo i = null; + i.Foo (); + } + + interface IFoo { + [Kept] + void Foo (); + } + + [KeptMember (".ctor()")] + class B { + [Kept] // FIXME: Should be removed + public void Foo () + { + } + } + + class A : B, IFoo { + //my IFoo.Foo() is actually implemented by B which doesn't know about it. + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass3.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass3.cs new file mode 100644 index 000000000..1154be592 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass3.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + class ClassImplemtingInterfaceMethodsThroughBaseClass3 { + public static void Main () + { + new B ().Foo (); + } + + interface IFoo { + void Foo (); + } + + [KeptMember (".ctor()")] + class B { + [Kept] + public void Foo () + { + } + } + + class A : B, IFoo { + //my IFoo.Foo() is actually implemented by B which doesn't know about it. + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass4.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass4.cs new file mode 100644 index 000000000..7a01c07ac --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass4.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + class ClassImplemtingInterfaceMethodsThroughBaseClass4 { + public static void Main () + { + new A ().Foo (); + } + + interface IFoo { + void Foo (); + } + + [KeptMember (".ctor()")] + class B { + [Kept] + public void Foo () + { + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (B))] + class A : B, IFoo { + //my IFoo.Foo() is actually implemented by B which doesn't know about it. + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass5.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass5.cs new file mode 100644 index 000000000..f7ebfda35 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass5.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + class ClassImplemtingInterfaceMethodsThroughBaseClass5 { + public static void Main () + { + new A (); + } + + interface IFoo { + void Foo (); + } + + [KeptMember (".ctor()")] + class B { + public void Foo () + { + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (B))] + class A : B, IFoo { + //my IFoo.Foo() is actually implemented by B which doesn't know about it. + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass6.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass6.cs new file mode 100644 index 000000000..1f43d756f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassImplemtingInterfaceMethodsThroughBaseClass6.cs @@ -0,0 +1,38 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + class ClassImplemtingInterfaceMethodsThroughBaseClass6 { + public static void Main () + { + B tmp = new B (); + IFoo i = new C (); + i.Foo (); + } + + interface IFoo { + [Kept] + void Foo (); + } + + [KeptMember (".ctor()")] + class B { + [Kept] // FIXME: Needs to be removed + public void Foo () + { + } + } + + class A : B, IFoo { + //my IFoo.Foo() is actually implemented by B which doesn't know about it. + } + + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class C : IFoo { + [Kept] + public void Foo () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromConcreteTypeHasInterfaceMethodRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromConcreteTypeHasInterfaceMethodRemoved.cs new file mode 100644 index 000000000..8c9212981 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromConcreteTypeHasInterfaceMethodRemoved.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType +{ + class ClassUsedFromConcreteTypeHasInterfaceMethodRemoved { + public static void Main () + { + A a = new A (); + a.Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + class A : IFoo { + [Kept] + public void Foo () + { + } + } + + public interface IFoo { + void Foo (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs new file mode 100644 index 000000000..f754047ca --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class ClassUsedFromConcreteTypeHasInterfaceMethodRemoved2 { + public static void Main () + { + A a = new A (); + a.Foo (); + + // If IFoo is marked for any reason then all of a sudden we do need to keep IFoo on A + var tmp = typeof (IFoo).ToString (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IFoo { + [Kept] + public void Foo () + { + } + } + + [Kept] + public interface IFoo { + void Foo (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromInterfaceHasInterfaceMethodKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromInterfaceHasInterfaceMethodKept.cs new file mode 100644 index 000000000..a04dcb72c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ClassUsedFromInterfaceHasInterfaceMethodKept.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType +{ + class ClassUsedFromInterfaceHasInterfaceMethodKept { + public static void Main () + { + IFoo a = new A (); + a.Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IFoo { + [Kept] + public void Foo () + { + } + } + + [Kept] + public interface IFoo { + [Kept] + void Foo (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ExplicitInterfaceMethodWhichCreatesInstanceOfParentType.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ExplicitInterfaceMethodWhichCreatesInstanceOfParentType.cs new file mode 100644 index 000000000..a9f3729d0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ExplicitInterfaceMethodWhichCreatesInstanceOfParentType.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class ExplicitInterfaceMethodWhichCreatesInstanceOfParentType { + public static void Main () + { + IFoo b = new B (); + b.Method (); + } + + [Kept] + interface IFoo { + [Kept] + void Method (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class B : IFoo { + [Kept] + public void Method () + { + } + } + + class C : IFoo { + void IFoo.Method () { new C (); } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter.cs new file mode 100644 index 000000000..6a2597c8c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter.cs @@ -0,0 +1,136 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class InterfaceMarkOrderingDoesNotMatter { + public static void Main () + { + CauseAToBeMarked ().AMethod (); + CauseZToBeMarked ().ZMethod (); + + MMarked m = new MMarked (); + + B b = m; + Y y = m; + Nested.F f = m; + + b.BMethod (); + y.YMethod (); + f.FMethod (); + } + + [Kept] + static A CauseAToBeMarked () + { + return null; + } + + [Kept] + static Z CauseZToBeMarked () + { + return null; + } + + [Kept] + interface A { + [Kept] + void AMethod (); + } + + [Kept] + interface Z { + [Kept] + void ZMethod (); + } + + [Kept] + interface C { + [Kept] + void CMethod (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (A))] + [KeptInterface (typeof (B))] + [KeptInterface (typeof (C))] + [KeptInterface (typeof (D))] + [KeptInterface (typeof (Nested.F))] + [KeptInterface (typeof (Y))] + [KeptInterface (typeof (Z))] + [KeptInterface (typeof (E))] + class MMarked : A, B, Y, Z, C, D, Nested.F, E { + [Kept] + public void AMethod() + { + } + + [Kept] + public void BMethod () + { + } + + [Kept] + public void YMethod () + { + } + + [Kept] + public void ZMethod () + { + } + + [Kept] + public void CMethod () + { + } + + [Kept] + public void DMethod () + { + } + + [Kept] + public void FMethod () + { + } + + [Kept] + public void EMethod () + { + } + } + + [Kept] + public static class Nested { + [Kept] + public interface F { + [Kept] + void FMethod (); + } + } + + [Kept] + interface B { + [Kept] + void BMethod (); + } + + [Kept] + interface Y { + [Kept] + void YMethod (); + } + + [Kept] + interface D { + [Kept] + void DMethod (); + } + + [Kept] + interface E { + [Kept] + void EMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter.xml new file mode 100644 index 000000000..3acce8472 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter.xml @@ -0,0 +1,11 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter/C"> + <method name="CMethod"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter/D"> + <method name="DMethod"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter/E" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter2.cs new file mode 100644 index 000000000..1831dcd57 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter2.cs @@ -0,0 +1,144 @@ + +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType +{ + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.A))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.B))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.C))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.D))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.Nested.F))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.Y))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.Z))] + [KeptInterface (typeof (InterfaceMarkOrderingDoesNotMatter2_Z.E))] + class InterfaceMarkOrderingDoesNotMatter2_A : InterfaceMarkOrderingDoesNotMatter2_Z.A, InterfaceMarkOrderingDoesNotMatter2_Z.B, InterfaceMarkOrderingDoesNotMatter2_Z.Y, + InterfaceMarkOrderingDoesNotMatter2_Z.Z, InterfaceMarkOrderingDoesNotMatter2_Z.C, InterfaceMarkOrderingDoesNotMatter2_Z.D, + InterfaceMarkOrderingDoesNotMatter2_Z.Nested.F, InterfaceMarkOrderingDoesNotMatter2_Z.E { + [Kept] + public void AMethod() + { + } + + [Kept] + public void BMethod () + { + } + + [Kept] + public void YMethod () + { + } + + [Kept] + public void ZMethod () + { + } + + [Kept] + public void CMethod () + { + } + + [Kept] + public void DMethod () + { + } + + [Kept] + public void FMethod () + { + } + + [Kept] + public void EMethod () + { + } + } + + public class InterfaceMarkOrderingDoesNotMatter2 + { + public static void Main() + { + CauseAToBeMarked().AMethod(); + CauseZToBeMarked().ZMethod(); + + InterfaceMarkOrderingDoesNotMatter2_A mUsedInCode = new InterfaceMarkOrderingDoesNotMatter2_A(); + + InterfaceMarkOrderingDoesNotMatter2_Z.B b = mUsedInCode; + InterfaceMarkOrderingDoesNotMatter2_Z.Y y = mUsedInCode; + InterfaceMarkOrderingDoesNotMatter2_Z.Nested.F f = mUsedInCode; + + b.BMethod(); + y.YMethod(); + f.FMethod(); + } + + [Kept] + static InterfaceMarkOrderingDoesNotMatter2_Z.A CauseAToBeMarked () + { + return null; + } + + [Kept] + static InterfaceMarkOrderingDoesNotMatter2_Z.Z CauseZToBeMarked () + { + return null; + } + } + + [Kept] + public class InterfaceMarkOrderingDoesNotMatter2_Z { + [Kept] + public interface A { + [Kept] + void AMethod (); + } + + [Kept] + public interface Z { + [Kept] + void ZMethod (); + } + + [Kept] + public interface C { + [Kept] + void CMethod (); + } + + [Kept] + public static class Nested { + [Kept] + public interface F { + [Kept] + void FMethod (); + } + } + + [Kept] + public interface B { + [Kept] + void BMethod (); + } + + [Kept] + public interface Y { + [Kept] + void YMethod (); + } + + [Kept] + public interface D { + [Kept] + void DMethod (); + } + + [Kept] + public interface E { + [Kept] + void EMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter2.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter2.xml new file mode 100644 index 000000000..da1a70f25 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter2.xml @@ -0,0 +1,11 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter2_Z/C"> + <method name="CMethod"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter2_Z/D"> + <method name="DMethod"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter2_Z/E" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter3.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter3.cs new file mode 100644 index 000000000..5c658dedc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter3.cs @@ -0,0 +1,144 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class InterfaceMarkOrderingDoesNotMatter3 { + public static void Main () + { + CauseAToBeMarked ().AMethod (); + CauseZToBeMarked ().ZMethod (); + CauseBToBeMarked ().BMethod (); + CauseYToBeMarked ().YMethod (); + CauseFToBeMarked ().FMethod (); + var c = CauseCToBeMarked(); + } + + [Kept] + static A CauseAToBeMarked () + { + return null; + } + + [Kept] + static Z CauseZToBeMarked () + { + return null; + } + + [Kept] + static B CauseBToBeMarked () + { + return null; + } + + [Kept] + static Y CauseYToBeMarked () + { + return null; + } + + [Kept] + static Nested.F CauseFToBeMarked () + { + return null; + } + + [Kept] + static C CauseCToBeMarked () + { + return null; + } + + [Kept] + interface A { + [Kept] + void AMethod (); + } + + [Kept] + interface Z { + [Kept] + void ZMethod (); + } + + [Kept] + interface C { + void CMethod (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (A))] + [KeptInterface (typeof (B))] + [KeptInterface (typeof (C))] + [KeptInterface (typeof (Nested.F))] + [KeptInterface (typeof (Y))] + [KeptInterface (typeof (Z))] + class MMarked : A, B, Y, Z, C, D, Nested.F, E { + [Kept] + public void AMethod() + { + } + + [Kept] + public void BMethod () + { + } + + [Kept] + public void YMethod () + { + } + + [Kept] + public void ZMethod () + { + } + + public void CMethod () + { + } + + public void DMethod () + { + } + + [Kept] + public void FMethod () + { + } + + public void EMethod () + { + } + } + + [Kept] + public static class Nested { + [Kept] + public interface F { + [Kept] + void FMethod (); + } + } + + [Kept] + interface B { + [Kept] + void BMethod (); + } + + [Kept] + interface Y { + [Kept] + void YMethod (); + } + + interface D { + void DMethod (); + } + + interface E { + void EMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter3.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter3.xml new file mode 100644 index 000000000..7b6a3c763 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceMarkOrderingDoesNotMatter3.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter3/MMarked"> + <method name=".ctor"/> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeInOtherUsedOnlyByCopiedAssembly.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeInOtherUsedOnlyByCopiedAssembly.cs new file mode 100644 index 000000000..ba22206b3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeInOtherUsedOnlyByCopiedAssembly.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + [SetupCompileBefore ("linked.dll", new [] {typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link)})] + [SetupCompileBefore ("copy.dll", new [] {typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy)}, new [] {"linked.dll"})] + + [SetupLinkerAction ("copy", "copy")] + [SetupLinkerArgument ("-a", "copy")] + + [KeptTypeInAssembly ("linked.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.IFoo))] + [KeptMemberInAssembly ("copy.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.A), "Method()")] + [KeptInterfaceOnTypeInAssembly ("copy.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.A), "linked.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.IFoo))] + public class InterfaceTypeInOtherUsedOnlyByCopiedAssembly { + public static void Main () + { + InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.ToKeepReferenceAtCompileTime (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit.cs new file mode 100644 index 000000000..df3936a70 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + [SetupCompileBefore ("linked.dll", new [] {typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link)})] + [SetupCompileBefore ("copy.dll", new [] {typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy)}, new [] {"linked.dll"})] + + [SetupLinkerAction ("copy", "copy")] + [SetupLinkerArgument ("-a", "copy")] + + [KeptMemberInAssembly ("linked.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.IFoo), "Method()")] + [KeptMemberInAssembly ("copy.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.A), "Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies.InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.IFoo.Method()")] + [KeptInterfaceOnTypeInAssembly ("copy.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.A), "linked.dll", typeof (InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.IFoo))] + public class InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit { + public static void Main () + { + InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.ToKeepReferenceAtCompileTime (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeOnlyUsedHasInterfacesRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeOnlyUsedHasInterfacesRemoved.cs new file mode 100644 index 000000000..2a444ac3d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceTypeOnlyUsedHasInterfacesRemoved.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class InterfaceTypeOnlyUsedHasInterfacesRemoved { + public static void Main () + { + var tmp = typeof (IUsed).ToString (); + } + + interface IRemovable1 { + } + + interface IRemovable2 { + } + + [Kept] + interface IUsed : IRemovable1, IRemovable2 { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceUsedOnlyAsConstraintIsKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceUsedOnlyAsConstraintIsKept.cs new file mode 100644 index 000000000..b5fe34bd5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceUsedOnlyAsConstraintIsKept.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class InterfaceUsedOnlyAsConstraintIsKept { + public static void Main () + { + var a = new A (); + Helper (a); + } + + [Kept] + static void Helper<T> (T arg) where T : IFoo + { + } + + [Kept] + interface IFoo { + void Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IFoo { + public void Foo () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed.cs new file mode 100644 index 000000000..5a7ff36f2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Inheritance.Interfaces.Dependencies; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + [SetupCompileBefore("library.dll", new []{"../Dependencies/InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.cs"})] + public class InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed { + public static void Main () + { + Helper (null); + } + + [Kept] + static void Helper (IBar obj) + { + var result = ((InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.IFoo) obj).ExplicitMethod (); + } + + [Kept] + [KeptInterface (typeof(InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.IFoo))] + interface IBar : InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.IFoo + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il new file mode 100644 index 000000000..1d9ebade5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il @@ -0,0 +1,68 @@ +.assembly extern mscorlib +{ +} +.assembly 'library' +{ + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module 'library.dll' + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib + extends [mscorlib]System.Object +{ + .class interface abstract auto ansi nested public IFoo + { + .method public hidebysig newslot abstract virtual + instance void Foo() cil managed + { + } // end of method IFoo::Foo + + } // end of class IFoo + + .class interface abstract auto ansi nested public IBar + { + .method public hidebysig newslot abstract virtual + instance void Bar() cil managed + { + } // end of method IBar::Bar + + } // end of class IBar + + .class auto ansi nested private beforefieldinit A + extends [mscorlib]System.Object + implements Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar, + Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo + { + .method public hidebysig newslot virtual final + instance void Foo() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method A::Foo + + .method public hidebysig newslot virtual final + instance void Bar() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method A::Bar + + } // end of class A + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } + +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndAssemblyPreserveAll.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndAssemblyPreserveAll.cs new file mode 100644 index 000000000..2b4dfd2e8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndAssemblyPreserveAll.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor +{ + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + [KeptInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [KeptInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Foo()")] + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Bar()")] + public class NoInstanceCtorAndAssemblyPreserveAll + { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndAssemblyPreserveAll.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndAssemblyPreserveAll.xml new file mode 100644 index 000000000..82bd1ac97 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndAssemblyPreserveAll.xml @@ -0,0 +1,3 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all"/> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveAll.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveAll.cs new file mode 100644 index 000000000..32bbe139f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveAll.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + [KeptInterfaceOnTypeInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [KeptInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Foo()")] + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Bar()")] + public class NoInstanceCtorAndTypePreserveAll { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveAll.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveAll.xml new file mode 100644 index 000000000..b6a27cfed --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveAll.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A" preserve="all"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFields.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFields.cs new file mode 100644 index 000000000..22b2bed90 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFields.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + + // The interfaces should be removed because the interface types are not marked + [RemovedInterfaceOnTypeInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [RemovedInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + + [RemovedMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Foo()")] + [RemovedMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Bar()")] + + // pedump reports this is valid with the following error. + // + // Assertion at metadata.c:1073, condition `index < meta->heap_blob.size' not met + // + // Not worried about it since this is already a niche edge case. Let's just skip verify for pedump + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class NoInstanceCtorAndTypePreserveFields { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFields.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFields.xml new file mode 100644 index 000000000..94b681a9d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFields.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A" preserve="fields"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.cs new file mode 100644 index 000000000..6bcaaa651 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.cs @@ -0,0 +1,41 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor { + [Define("IL_ASSEMBLY_COMPILED")] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + + // Interfaces should be removed because preserve fields would not normally cause an instance ctor to be marked. This means that no instance ctor + // sweeping logic should kick in and remove interfaces + [RemovedInterfaceOnTypeInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [RemovedInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + + // Methods are removed because we only preserved fields + [RemovedMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Foo()")] + [RemovedMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Bar()")] + + // pedump reports this is valid with the following error. + // + // Assertion at metadata.c:1073, condition `index < meta->heap_blob.size' not met + // + // Not worried about it since this is already a niche edge case. Let's just skip verify for pedump + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked { + public static void Main () + { +#if IL_ASSEMBLY_COMPILED + var tmp = typeof (Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib.IFoo).ToString (); +#endif + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.xml new file mode 100644 index 000000000..674b3ca86 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A" preserve="fields"/> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar" preserve="none"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethods.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethods.cs new file mode 100644 index 000000000..045aa2dcb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethods.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + + // The interfaces should be removed because the interface types are not marked + [RemovedInterfaceOnTypeInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [RemovedInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + + // Methods should be kept because of the preserve methods + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Foo()")] + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Bar()")] + public class NoInstanceCtorAndTypePreserveMethods { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethods.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethods.xml new file mode 100644 index 000000000..00a06f0c9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethods.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.cs new file mode 100644 index 000000000..419eae41c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor { + [Define("IL_ASSEMBLY_COMPILED")] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + + // Interfaces will be removed because there is no instance ctor that is marked. + [RemovedInterfaceOnTypeInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [RemovedInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + + // Methods should be kept because of the preserve methods + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Foo()")] + [KeptMemberInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "Bar()")] + public class NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked + { + public static void Main() + { + // We'll mark one interface in code and one via xml, the end result should be the same +#if IL_ASSEMBLY_COMPILED + var tmp = typeof (Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib.IFoo).ToString (); +#endif + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.xml new file mode 100644 index 000000000..95d6579de --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A" preserve="methods"/> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar" preserve="none"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveNone.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveNone.cs new file mode 100644 index 000000000..670d45e43 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveNone.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/NoInstanceCtorAndAssemblyPreserveAll_Lib.il" })] + [RemovedInterfaceOnTypeInAssembly ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IFoo")] + [RemovedInterfaceOnTypeInAssemblyAttribute ("library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A", + "library", + "Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/IBar")] + // pedump reports this is valid with the following error. + // + // Assertion at metadata.c:1073, condition `index < meta->heap_blob.size' not met + // + // Not worried about it since this is already a niche edge case. Let's just skip verify for pedump + [SkipPeVerify (SkipPeVerifyForToolchian.Pedump)] + public class NoInstanceCtorAndTypePreserveNone { + public static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveNone.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveNone.xml new file mode 100644 index 000000000..079694287 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoInstanceCtor/NoInstanceCtorAndTypePreserveNone.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.Dependencies.NoInstanceCtorAndAssemblyPreserveAll_Lib/A" preserve="none"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ComInterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ComInterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs new file mode 100644 index 000000000..62da67caf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ComInterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs @@ -0,0 +1,29 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class ComInterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod { + public static void Main () + { + StaticMethodOnlyUsed.StaticMethod (); + } + + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + interface IUnusedInterface { + void Foo (); + } + + [Kept] + class StaticMethodOnlyUsed : IUnusedInterface { + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ExplicitInterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ExplicitInterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs new file mode 100644 index 000000000..f3bb78c8f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ExplicitInterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs @@ -0,0 +1,40 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class ExplicitInterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + class StaticMethodOnlyUsed : IUsedInterface { + void IUsedInterface.Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/GenericType.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/GenericType.cs new file mode 100644 index 000000000..b6dff2fde --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/GenericType.cs @@ -0,0 +1,22 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class GenericType { + public static void Main () + { + object o = new Bar<Foo> (); + } + + [Kept] + [KeptMember(".ctor()")] + class Bar<T> { + } + + [Kept] + class Foo : IFoo { + } + + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/GenericWithConstraintDoesNotCauseOtherTypesToKeepInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/GenericWithConstraintDoesNotCauseOtherTypesToKeepInterface.cs new file mode 100644 index 000000000..7255cac2c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/GenericWithConstraintDoesNotCauseOtherTypesToKeepInterface.cs @@ -0,0 +1,41 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class GenericWithConstraintDoesNotCauseOtherTypesToKeepInterface { + public static void Main () + { + Foo f = null; + Helper (f); + OtherMethodToDoStuff (); + } + + [Kept] + static void Helper<T> (T f) where T : IFoo + { + } + + [Kept] + static void OtherMethodToDoStuff () + { + HelperToUseFoo2 (null); + } + + [Kept] + static void HelperToUseFoo2 (Foo2 f) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + class Foo2 : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs new file mode 100644 index 000000000..bddacb9d5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs @@ -0,0 +1,40 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + class StaticMethodOnlyUsed : IUsedInterface { + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs new file mode 100644 index 000000000..9d79e5e0b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs @@ -0,0 +1,51 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + class StaticMethodOnlyUsed : IUsedInterface { + [Kept] + static StaticMethodOnlyUsed () + { + UsedByStaticCctor (); + } + + [Kept] + static void UsedByStaticCctor () + { + } + + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceFromCopiedAssemblyCanBeRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceFromCopiedAssemblyCanBeRemoved.cs new file mode 100644 index 000000000..b8001883e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceFromCopiedAssemblyCanBeRemoved.cs @@ -0,0 +1,24 @@ +using System.Collections; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class InterfaceFromCopiedAssemblyCanBeRemoved { + public static void Main () + { + Foo.StaticMethod (); + } + + [Kept] + class Foo : IComparer { + public int Compare (object x, object y) + { + throw new System.NotImplementedException (); + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs new file mode 100644 index 000000000..828376342 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod { + public static void Main () + { + StaticMethodOnlyUsed.StaticMethod (); + } + + interface IUnusedInterface { + void Foo (); + } + + [Kept] + class StaticMethodOnlyUsed : IUnusedInterface { + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs new file mode 100644 index 000000000..fea5b9954 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs @@ -0,0 +1,53 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + + // We are testing removing interfaces when no instance is created, we need to mark the interface types + // so that we don't end up testing unused interface types being swept + var tmp = typeof (IRemovable1).ToString (); + tmp = typeof (IRemovable2).ToString (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] + interface IRemovable1 { + } + + [Kept] + interface IRemovable2 { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + class StaticMethodOnlyUsed : IUsedInterface, IRemovable1, IRemovable2 { + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/LocalDowncastDoesNotCuaseOtherTypesToKeepInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/LocalDowncastDoesNotCuaseOtherTypesToKeepInterface.cs new file mode 100644 index 000000000..00ad89fd2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/LocalDowncastDoesNotCuaseOtherTypesToKeepInterface.cs @@ -0,0 +1,47 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class LocalDowncastDoesNotCuaseOtherTypesToKeepInterface { + public static void Main () + { + Foo f = null; + IFoo i = f; + i.Method (); + DoOtherStuff (); + } + + [Kept] + static void DoOtherStuff () + { + HelperToUseBar (null); + } + + [Kept] + static void HelperToUseBar (Bar arg) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + [Kept] // TODO : It should be safe to stub this. It can't actually be called because no instance of Foo ever exists + public void Method () + { + } + } + + [Kept] + interface IFoo { + [Kept] + void Method (); + } + + [Kept] + class Bar : IFoo + { + public void Method () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ObjectHardCastedToInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ObjectHardCastedToInterface.cs new file mode 100644 index 000000000..84b9b6c16 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/ObjectHardCastedToInterface.cs @@ -0,0 +1,40 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class ObjectHardCastedToInterface { + public static void Main () + { + object o = GetAnObject (); + IFoo i = (IFoo)o; + UseAnIFoo (i); + + // Here to mark Foo so that we can verify the interface is removed + Foo.Helper (); + } + + [Kept] + static object GetAnObject () + { + return null; + } + + [Kept] + static void UseAnIFoo (IFoo arg) + { + } + + [Kept] + class Foo : IFoo + { + [Kept] + public static void Helper () + { + } + } + + [Kept] + interface IFoo + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/PreserveDependencyPreservesInterfaceMethod.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/PreserveDependencyPreservesInterfaceMethod.cs new file mode 100644 index 000000000..a9b0bc1d6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/PreserveDependencyPreservesInterfaceMethod.cs @@ -0,0 +1,32 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + /// <summary> + /// The interface can still be removed in this case because PreserveDependency is just preserving Foo() on the current type + /// </summary> + public class PreserveDependencyPreservesInterfaceMethod { + public static void Main () + { + StaticMethodOnlyUsed.StaticMethod (); + } + + interface IUnusedInterface { + void Foo (); + } + + [Kept] + class StaticMethodOnlyUsed : IUnusedInterface { + [Kept] + public void Foo () + { + } + + [Kept] + [PreserveDependency ("Foo")] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.cs new file mode 100644 index 000000000..fef505898 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class UnusedTypeHasExplicitInterfaceMethodPreservedViaXml { + public static void Main () + { + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class A : IBar, IFoo { + + // Because an explicit interface method was preserved via xml, we need to now mark the interface implementation + [Kept] + void IFoo.Foo () + { + } + + void IBar.Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.xml new file mode 100644 index 000000000..608579eab --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasExplicitInterfaceMethodPreservedViaXml/A"> + <method signature="System.Void Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.IFoo.Foo()"/> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.cs new file mode 100644 index 000000000..191928690 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class UnusedTypeHasExplicitInterfacePropertyPreservedViaXml { + public static void Main () + { + } + + [Kept] + interface IFoo { + [Kept] + int Foo { [Kept] get; [Kept] set; } + } + + interface IBar { + int Bar { get; set; } + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class A : IBar, IFoo { + [Kept] + [KeptBackingField] + int IFoo.Foo { [Kept] get; [Kept] set; } + + int IBar.Bar { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.xml new file mode 100644 index 000000000..f821a3d88 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasExplicitInterfacePropertyPreservedViaXml/A"> + <property signature="System.Int32 Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.IFoo.Foo"/> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasInterfaceMethodPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasInterfaceMethodPreservedViaXml.cs new file mode 100644 index 000000000..eef586956 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasInterfaceMethodPreservedViaXml.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class UnusedTypeHasInterfaceMethodPreservedViaXml { + public static void Main () + { + } + + interface IFoo { + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + class A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasInterfaceMethodPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasInterfaceMethodPreservedViaXml.xml new file mode 100644 index 000000000..2abd15c89 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeHasInterfaceMethodPreservedViaXml.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasInterfaceMethodPreservedViaXml/A"> + <method signature="System.Void Foo()"/> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveFields.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveFields.cs new file mode 100644 index 000000000..7c7b3b49a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveFields.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class UnusedTypeWithPreserveFields { + public static void Main () + { + } + + interface IFoo { + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + class A : IBar, IFoo { + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveFields.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveFields.xml new file mode 100644 index 000000000..9106c06bd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveFields.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeWithPreserveFields/A" preserve="fields"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethods.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethods.cs new file mode 100644 index 000000000..d729f60df --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethods.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class UnusedTypeWithPreserveMethods { + public static void Main () + { + } + + interface IFoo { + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + class A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + [Kept] + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethods.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethods.xml new file mode 100644 index 000000000..f75f875b7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethods.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeWithPreserveMethods/A" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.cs new file mode 100644 index 000000000..183bac795 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.cs @@ -0,0 +1,37 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor { + public class UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked { + public static void Main () + { + // We'll mark one interface in code and one via xml, the end result should be the same + var tmp = typeof (IFoo).ToString (); + } + + [Kept] + interface IFoo { + void Foo (); + } + + [Kept] + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + [KeptInterface (typeof (IBar))] + class A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + [Kept] + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.xml new file mode 100644 index 000000000..7a61853c9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtor/UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked/A" preserve="methods"/> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked/IBar" preserve="none"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ArrayPassedAsParameter.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ArrayPassedAsParameter.cs new file mode 100644 index 000000000..0a9aacc0c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ArrayPassedAsParameter.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class LocalArrayPassedAsParameter { + public static void Main () + { + Foo [] arr = null; + Helper (arr); + } + + [Kept] + static void Helper (IFoo[] f) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ArrayWithIndexAssignedToReturnValue.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ArrayWithIndexAssignedToReturnValue.cs new file mode 100644 index 000000000..179b7577b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ArrayWithIndexAssignedToReturnValue.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class ArrayWithIndexAssignedToReturnValue { + public static void Main () + { + IFoo [] arr = new IFoo [5]; + arr [0] = GetAFoo (); + } + + [Kept] + static Foo GetAFoo () + { + return null; + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/FieldDowncastedToInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/FieldDowncastedToInterface.cs new file mode 100644 index 000000000..84ff1a1c7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/FieldDowncastedToInterface.cs @@ -0,0 +1,32 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class FieldDowncastedToInterface { + [Kept] + private static Foo f; + [Kept] + private static IFoo i; + + public static void Main () + { + f = null; + i = f; + i.Method (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + [Kept] // TODO : It should be safe to stub this. It can't actually be called because no instance of Foo ever exists + public void Method () + { + } + } + + [Kept] + interface IFoo { + [Kept] + void Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericType.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericType.cs new file mode 100644 index 000000000..7e8e8ffa9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericType.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class GenericType { + public static void Main () + { + Foo f = null; + Bar<IFoo> o = new Bar<IFoo> (); + o.Method (f); + } + + [Kept] + [KeptMember(".ctor()")] + class Bar<T> { + [Kept] + public void Method (T arg) + { + } + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint.cs new file mode 100644 index 000000000..48051732a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class GenericTypeWithConstraint { + public static void Main () + { + object o = new Bar<Foo> (); + } + + [Kept] + [KeptMember(".ctor()")] + class Bar<T> where T : IFoo { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint2.cs new file mode 100644 index 000000000..0fb889ae8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint2.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class GenericTypeWithConstraint2 { + public static void Main () + { + Foo f = null; + Bar<Foo>.Helper (f); + } + + [Kept] + static class Bar<T> where T : IFoo { + [Kept] + public static void Helper (T arg) + { + } + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint3.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint3.cs new file mode 100644 index 000000000..bc170287e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/GenericTypeWithConstraint3.cs @@ -0,0 +1,58 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class GenericTypeWithConstraint3 { + public static void Main () + { + Foo f = null; + Bar b = null; + Bar<BaseFoo2, BaseBar2>.Helper (f, b); + } + + [Kept] + static class Bar<T, K> where T : IFoo where K : IBar { + [Kept] + public static void Helper (T arg, K arg2) + { + } + } + + [Kept] + [KeptInterface (typeof (IFoo))] + abstract class BaseFoo : IFoo { + } + + [Kept] + [KeptBaseType (typeof (BaseFoo))] + abstract class BaseFoo2 : BaseFoo { + } + + [Kept] + [KeptInterface (typeof (IBar))] + abstract class BaseBar : IBar { + } + + [Kept] + [KeptBaseType (typeof (BaseBar))] + abstract class BaseBar2 : BaseBar { + } + + [Kept] + [KeptBaseType (typeof (BaseFoo2))] + class Foo : BaseFoo2 { + } + + [Kept] + [KeptBaseType (typeof (BaseBar2))] + class Bar : BaseBar2 { + } + + [Kept] + interface IFoo { + } + + [Kept] + interface IBar { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/InterfaceOnMultipleBases.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/InterfaceOnMultipleBases.cs new file mode 100644 index 000000000..6b303e24f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/InterfaceOnMultipleBases.cs @@ -0,0 +1,42 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class InterfaceOnMultipleBases { + public static void Main () + { + Foo f = null; + Helper (f); + } + + [Kept] + static void Helper (IFoo f) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Base : IFoo { + } + + [Kept] + [KeptBaseType (typeof (Base))] + [KeptInterface (typeof (IFoo))] + class Base2 : Base, IFoo { + } + + [Kept] + [KeptBaseType (typeof (Base2))] + class Base3 : Base2 { + } + + [Kept] + [KeptBaseType (typeof (Base3))] + [KeptInterface (typeof (IFoo))] + class Foo : Base3, IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalDowncastedToInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalDowncastedToInterface.cs new file mode 100644 index 000000000..dc63d99a3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalDowncastedToInterface.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class LocalDowncastedToInterface { + public static void Main () + { + Foo f = null; + IFoo i = f; + i.Method (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + [Kept] // TODO : It should be safe to stub this. It can't actually be called because no instance of Foo ever exists + public void Method () + { + } + } + + [Kept] + interface IFoo { + [Kept] + void Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameter.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameter.cs new file mode 100644 index 000000000..5338cc6ba --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameter.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class LocalPassedAsParameter { + public static void Main () + { + Foo f = null; + Helper (f); + } + + [Kept] + static void Helper (IFoo f) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGeneric.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGeneric.cs new file mode 100644 index 000000000..475ac098a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGeneric.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class LocalPassedAsParameterToGeneric { + public static void Main () + { + Foo f = null; + Helper<IFoo>(f); + } + + [Kept] + static void Helper <T> (T f) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGenericWithConstraint.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGenericWithConstraint.cs new file mode 100644 index 000000000..e00229264 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGenericWithConstraint.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class LocalPassedAsParameterToGenericWithConstraint { + public static void Main () + { + Foo f = null; + Helper (f); + } + + [Kept] + static void Helper<T> (T f) where T : IFoo + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGenericWithConstraint2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGenericWithConstraint2.cs new file mode 100644 index 000000000..cecf742e4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/LocalPassedAsParameterToGenericWithConstraint2.cs @@ -0,0 +1,32 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class LocalPassedAsParameterToGenericWithConstraint2 { + public static void Main () + { + Foo f = null; + Foo2 f2 = null; + Helper (f, f2); + } + + [Kept] + static void Helper<T> (T f, Foo2 arg2) where T : IFoo + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + [KeptInterface (typeof (IFoo))] // technically this can be removed, but it would require more complex knowledge of the stack to do so + class Foo2 : IFoo { + } + + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ReturnValueDowncastedToInterface.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ReturnValueDowncastedToInterface.cs new file mode 100644 index 000000000..0aef967a5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/NoKeptCtorButInterfaceNeeded/ReturnValueDowncastedToInterface.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded { + public class ReturnValueDowncastedToInterface { + public static void Main () + { + UseAnIFoo (GetAFoo ()); + } + + [Kept] + static Foo GetAFoo () + { + return null; + } + + [Kept] + static void UseAnIFoo (IFoo arg) + { + } + + [Kept] + [KeptInterface (typeof (IFoo))] + class Foo : IFoo { + } + + [Kept] + interface IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ObjectCastedToSecondInterfaceHasMemberRemovedButInterfaceKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ObjectCastedToSecondInterfaceHasMemberRemovedButInterfaceKept.cs new file mode 100644 index 000000000..95fd8b266 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/ObjectCastedToSecondInterfaceHasMemberRemovedButInterfaceKept.cs @@ -0,0 +1,38 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class ObjectCastedToSecondInterfaceHasMemberRemovedButInterfaceKept { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + var b = (IBar) i; + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + [Kept] + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + [KeptInterface (typeof (IBar))] + class A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/TypeGetsMarkedThatImplementsAlreadyMarkedInterfaceMethod.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/TypeGetsMarkedThatImplementsAlreadyMarkedInterfaceMethod.cs new file mode 100644 index 000000000..85f1c855a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/TypeGetsMarkedThatImplementsAlreadyMarkedInterfaceMethod.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + class TypeGetsMarkedThatImplementsAlreadyMarkedInterfaceMethod { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + interface IFoo { + [Kept] + void Foo (); + } + + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class B : IFoo { + [Kept] + public void Foo () + { + } + } + + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IFoo { + [Kept] + public void Foo () + { + new B (); /*this will cause us to mark B, but will we be smart enough to realize B.Foo implements the already marked IFoo.Foo?*/ + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsKept.cs new file mode 100644 index 000000000..4e7212bef --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsKept.cs @@ -0,0 +1,38 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + /// <summary> + /// It's much harder to know if a com interface will be needed since so much can be on the native side. + /// As a precaution we will not apply the unused interface rules to com interfaces + /// </summary> + public class UnusedComInterfaceIsKept { + public static void Main () + { + var i = new A (); + i.Foo (); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IBar))] + class A : IBar { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs new file mode 100644 index 000000000..de8908678 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs @@ -0,0 +1,33 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + [SetupLinkerArgument ("--exclude-feature", "com")] + public class UnusedComInterfaceIsRemovedWhenComFeatureExcluded { + public static void Main () + { + var i = new A (); + i.Foo (); + } + + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + class A : IBar { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceHasMethodPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceHasMethodPreservedViaXml.cs new file mode 100644 index 000000000..1a97b7836 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceHasMethodPreservedViaXml.cs @@ -0,0 +1,39 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class UnusedExplicitInterfaceHasMethodPreservedViaXml { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + [Kept] + interface IBar { + [Kept] + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + [KeptInterface (typeof (IBar))] + class A : IBar, IFoo { + [Kept] + void IFoo.Foo () + { + } + + [Kept] + void IBar.Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceHasMethodPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceHasMethodPreservedViaXml.xml new file mode 100644 index 000000000..8a6a8d28e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceHasMethodPreservedViaXml.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.UnusedExplicitInterfaceHasMethodPreservedViaXml/A" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceIsRemoved.cs new file mode 100644 index 000000000..7afcd6056 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedExplicitInterfaceIsRemoved.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class UnusedExplicitInterfaceIsRemoved { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IBar, IFoo { + [Kept] + void IFoo.Foo () + { + } + + void IBar.Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceHasMethodPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceHasMethodPreservedViaXml.cs new file mode 100644 index 000000000..2b5e7ea2f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceHasMethodPreservedViaXml.cs @@ -0,0 +1,36 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class UnusedInterfaceHasMethodPreservedViaXml { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + [Kept] + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceHasMethodPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceHasMethodPreservedViaXml.xml new file mode 100644 index 000000000..0db48c0df --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceHasMethodPreservedViaXml.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType.UnusedInterfaceHasMethodPreservedViaXml/A" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceTypeIsRemoved.cs new file mode 100644 index 000000000..69e55bead --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnReferenceType/UnusedInterfaceTypeIsRemoved.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnReferenceType { + public class UnusedInterfaceTypeIsRemoved { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs new file mode 100644 index 000000000..260dcb92e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs @@ -0,0 +1,42 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType.NoKeptCtor { + public class InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + [KeptInterface (typeof (IUsedInterface))] // Could be removed in the future with improved handling of value types + struct StaticMethodOnlyUsed : IUsedInterface { + [Kept] // Could be removed in the future with improved handling of value types + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs new file mode 100644 index 000000000..0ce19620b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs @@ -0,0 +1,53 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType.NoKeptCtor { + public class InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + [KeptInterface (typeof (IUsedInterface))] // Could be removed in the future with improved handling of value types + struct StaticMethodOnlyUsed : IUsedInterface { + [Kept] + static StaticMethodOnlyUsed () + { + UsedByStaticCctor (); + } + + [Kept] + static void UsedByStaticCctor () + { + } + + [Kept] // Could be removed in the future with improved handling of value types + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs new file mode 100644 index 000000000..54680898a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs @@ -0,0 +1,32 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType.NoKeptCtor { + public class InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod { + public static void Main () + { + StaticMethodOnlyUsed.StaticMethod (); + + // We are testing removing interfaces when no instance is created, we need to mark the interface types + // so that we don't end up testing unused interface types being swept + var tmp = typeof (IUsedInterface).ToString (); + } + + [Kept] // Could be removed in the future with improved handling of value types + interface IUsedInterface { + void Foo (); + } + + [Kept] + [KeptInterface (typeof (IUsedInterface))] // Could be removed in the future with improved handling of value types + struct StaticMethodOnlyUsed : IUsedInterface { + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs new file mode 100644 index 000000000..a6eadcabf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/NoKeptCtor/InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs @@ -0,0 +1,57 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType.NoKeptCtor { + public class InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple { + public static void Main () + { + IUsedInterface p = new UsedClass (); + StaticMethodOnlyUsed.StaticMethod (); + p.Foo (); + + // We are testing removing interfaces when no instance is created, we need to mark the interface types + // so that we don't end up testing unused interface types being swept + var tmp = typeof (IRemovable1).ToString (); + tmp = typeof (IRemovable2).ToString (); + } + + [Kept] + interface IUsedInterface { + [Kept] + void Foo (); + } + + [Kept] // Could be removed in the future with improved handling of value types + interface IRemovable1 { + } + + [Kept] // Could be removed in the future with improved handling of value types + interface IRemovable2 { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IUsedInterface))] + class UsedClass : IUsedInterface { + [Kept] + public void Foo () + { + } + } + + [Kept] + [KeptInterface (typeof (IUsedInterface))] // Could be removed in the future with improved handling of value types + [KeptInterface (typeof (IRemovable1))] // Could be removed in the future with improved handling of value types + [KeptInterface (typeof (IRemovable2))] // Could be removed in the future with improved handling of value types + struct StaticMethodOnlyUsed : IUsedInterface, IRemovable1, IRemovable2 { + [Kept] // Could be removed in the future with improved handling of value types + public void Foo () + { + } + + [Kept] + public static void StaticMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructImplementingInterfaceMethodsNested.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructImplementingInterfaceMethodsNested.cs new file mode 100644 index 000000000..1108175bf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructImplementingInterfaceMethodsNested.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class StructImplementingInterfaceMethodsNested { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar : IFoo { + void Bar (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + struct A : IBar { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructImplementingInterfaceMethodsNested2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructImplementingInterfaceMethodsNested2.cs new file mode 100644 index 000000000..f7a701dc1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructImplementingInterfaceMethodsNested2.cs @@ -0,0 +1,38 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class StructImplementingInterfaceMethodsNested2 { + public static void Main () + { + IBar b = new A (); + IFoo f = b; + f.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + interface IBar : IFoo { + void Bar (); + } + + [Kept] + [KeptInterface (typeof (IBar))] + [KeptInterface (typeof (IFoo))] + struct A : IBar { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromConcreteTypeHasInterfaceMethodRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromConcreteTypeHasInterfaceMethodRemoved.cs new file mode 100644 index 000000000..a1996be28 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromConcreteTypeHasInterfaceMethodRemoved.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType +{ + class StructUsedFromConcreteTypeHasInterfaceMethodRemoved { + public static void Main () + { + A a = new A (); + a.Foo (); + } + + [Kept] + struct A : IFoo { + [Kept] + public void Foo () + { + } + } + + public interface IFoo { + void Foo (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs new file mode 100644 index 000000000..246f682a8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class StructUsedFromConcreteTypeHasInterfaceMethodRemoved2 { + public static void Main () + { + A a = new A (); + a.Foo (); + + // If IFoo is marked for any reason then all of a sudden we do need to keep IFoo on A + var tmp = typeof (IFoo).ToString (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + struct A : IFoo { + [Kept] + public void Foo () + { + } + } + + [Kept] + public interface IFoo { + void Foo (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromInterfaceHasInterfaceMethodKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromInterfaceHasInterfaceMethodKept.cs new file mode 100644 index 000000000..83935642d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/StructUsedFromInterfaceHasInterfaceMethodKept.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType +{ + class StructUsedFromInterfaceHasInterfaceMethodKept { + public static void Main () + { + IFoo a = new A (); + a.Foo (); + } + + [Kept] + [KeptInterface (typeof (IFoo))] + struct A : IFoo { + [Kept] + public void Foo () + { + } + } + + [Kept] + public interface IFoo { + [Kept] + void Foo (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceHasMethodPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceHasMethodPreservedViaXml.cs new file mode 100644 index 000000000..4e76aa1a5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceHasMethodPreservedViaXml.cs @@ -0,0 +1,39 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class UnusedExplicitInterfaceHasMethodPreservedViaXml { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + [Kept] + interface IBar { + [Kept] + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + [KeptInterface (typeof (IBar))] + struct A : IBar, IFoo { + [Kept] + void IFoo.Foo () + { + } + + [Kept] + void IBar.Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceHasMethodPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceHasMethodPreservedViaXml.xml new file mode 100644 index 000000000..988ac904d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceHasMethodPreservedViaXml.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType.UnusedExplicitInterfaceHasMethodPreservedViaXml/A" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceIsRemoved.cs new file mode 100644 index 000000000..f731e3bdc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedExplicitInterfaceIsRemoved.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class UnusedExplicitInterfaceIsRemoved { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + struct A : IBar, IFoo { + [Kept] + void IFoo.Foo () + { + } + + void IBar.Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceHasMethodPreservedViaXml.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceHasMethodPreservedViaXml.cs new file mode 100644 index 000000000..89cf4d264 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceHasMethodPreservedViaXml.cs @@ -0,0 +1,36 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class UnusedInterfaceHasMethodPreservedViaXml { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + struct A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + [Kept] + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceHasMethodPreservedViaXml.xml b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceHasMethodPreservedViaXml.xml new file mode 100644 index 000000000..1788f88b8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceHasMethodPreservedViaXml.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType.UnusedInterfaceHasMethodPreservedViaXml/A" preserve="methods"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceTypeIsRemoved.cs new file mode 100644 index 000000000..82ececac1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.Interfaces/OnValueType/UnusedInterfaceTypeIsRemoved.cs @@ -0,0 +1,35 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.Interfaces.OnValueType { + public class UnusedInterfaceTypeIsRemoved { + public static void Main () + { + IFoo i = new A (); + i.Foo (); + } + + [Kept] + interface IFoo { + [Kept] + void Foo (); + } + + interface IBar { + void Bar (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + struct A : IBar, IFoo { + [Kept] + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/HarderToDetectUnusedVirtualMethodGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/HarderToDetectUnusedVirtualMethodGetsRemoved.cs new file mode 100644 index 000000000..8348dbd09 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/HarderToDetectUnusedVirtualMethodGetsRemoved.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + class HarderToDetectUnusedVirtualMethodGetsRemoved { + public static void Main () + { + new Base ().Call (); + } + + static void DeadCode () + { + new B (); + } + + [Kept] + [KeptMember (".ctor()")] + class Base { + [Kept] + public virtual void Call () + { + } + } + + class B : Base { + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UnusedTypeWithOverrideOfVirtualMethodIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UnusedTypeWithOverrideOfVirtualMethodIsRemoved.cs new file mode 100644 index 000000000..57e84bca1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UnusedTypeWithOverrideOfVirtualMethodIsRemoved.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + class UnusedTypeWithOverrideOfVirtualMethodIsRemoved { + public static void Main () + { + new Base ().Call (); + } + + [KeptMember (".ctor()")] + class Base { + [Kept] + public virtual void Call () + { + } + } + + class B : Base { + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UnusedVirtualMethodRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UnusedVirtualMethodRemoved.cs new file mode 100644 index 000000000..88bd1f8ec --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UnusedVirtualMethodRemoved.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + public class UnusedVirtualMethodRemoved { + public static void Main () + { + var tmp = new B (); + } + + [KeptMember (".ctor()")] + class Base { + public virtual void Call () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UsedOverrideOfVirtualMethodIsKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UsedOverrideOfVirtualMethodIsKept.cs new file mode 100644 index 000000000..27b3c90dd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UsedOverrideOfVirtualMethodIsKept.cs @@ -0,0 +1,29 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + public class UsedOverrideOfVirtualMethodIsKept { + public static void Main () + { + var tmp = new B (); + tmp.Call (); + } + + [KeptMember (".ctor()")] + class Base { + [Kept] + public virtual void Call () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + [Kept] + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UsedTypeWithOverrideOfVirtualMethodHasOverrideKept.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UsedTypeWithOverrideOfVirtualMethodHasOverrideKept.cs new file mode 100644 index 000000000..2474d8dfa --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/UsedTypeWithOverrideOfVirtualMethodHasOverrideKept.cs @@ -0,0 +1,29 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + public class UsedTypeWithOverrideOfVirtualMethodHasOverrideKept { + public static void Main () + { + new B (); + new Base ().Call (); + } + + [KeptMember (".ctor()")] + class Base { + [Kept] + public virtual void Call () + { + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (Base))] + class B : Base { + [Kept] + public override void Call () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsPerservedIfBaseMethodGetsInvoked.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsPerservedIfBaseMethodGetsInvoked.cs new file mode 100644 index 000000000..0b1d75d75 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsPerservedIfBaseMethodGetsInvoked.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + class VirtualMethodGetsPerservedIfBaseMethodGetsInvoked { + public static void Main () + { + new A (); + new B ().Foo (); + } + + [KeptMember (".ctor()")] + class B { + [Kept] + public virtual void Foo () + { + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (B))] + class A : B { + [Kept] + public override void Foo () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsStrippedIfImplementingMethodGetsInvokedDirectly.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsStrippedIfImplementingMethodGetsInvokedDirectly.cs new file mode 100644 index 000000000..d6b4969fe --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/VirtualMethodGetsStrippedIfImplementingMethodGetsInvokedDirectly.cs @@ -0,0 +1,27 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods { + class VirtualMethodGetsStrippedIfImplementingMethodGetsInvokedDirectly { + public static void Main () + { + new A ().Foo (); + } + + [KeptMember (".ctor()")] + class B { + [Kept] // TODO: Would be nice to be removed + public virtual void Foo () + { + } + } + + [KeptMember (".ctor()")] + [KeptBaseType (typeof (B))] + class A : B { + [Kept] + public override void Foo () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/DefaultConstructorOfParameterIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/DefaultConstructorOfParameterIsRemoved.cs new file mode 100644 index 000000000..304a78553 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/DefaultConstructorOfParameterIsRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls.Com { + class DefaultConstructorOfParameterIsRemoved { + public static void Main () + { + SomeMethod (null); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (A val); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/DefaultConstructorOfReturnTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/DefaultConstructorOfReturnTypeIsRemoved.cs new file mode 100644 index 000000000..f9b3fc51d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/DefaultConstructorOfReturnTypeIsRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls.Com { + class DefaultConstructorOfReturnTypeIsRemoved { + public static void Main () + { + var a = SomeMethod (); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern A SomeMethod (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfParameterAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfParameterAreRemoved.cs new file mode 100644 index 000000000..287b00c78 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfParameterAreRemoved.cs @@ -0,0 +1,24 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls.Com { + class FieldsOfParameterAreRemoved { + public static void Main () + { + SomeMethod (null); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + private int field; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (A val); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfReturnTypeAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfReturnTypeAreRemoved.cs new file mode 100644 index 000000000..d1c0a7ecf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfReturnTypeAreRemoved.cs @@ -0,0 +1,24 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls.Com { + class FieldsOfReturnTypeAreRemoved { + public static void Main () + { + var a = SomeMethod (); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + private int field; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern A SomeMethod (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfThisAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfThisAreRemoved.cs new file mode 100644 index 000000000..ad4918318 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/Com/FieldsOfThisAreRemoved.cs @@ -0,0 +1,25 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls.Com { + class FieldsOfThisAreRemoved { + public static void Main () + { + new A ().SomeMethod (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + private int field; + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + public extern void SomeMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs new file mode 100644 index 000000000..ecfe75123 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/DefaultConstructorOfReturnTypeIsNotRemoved.cs @@ -0,0 +1,22 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls { + class DefaultConstructorOfReturnTypeIsNotRemoved { + public static void Main () + { + var a = SomeMethod (); + } + + class A { + [Kept] + public A () + { + } + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern A SomeMethod (); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs new file mode 100644 index 000000000..ab21994f0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorIsRemoved.cs @@ -0,0 +1,27 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls { + class UnusedDefaultConstructorIsRemoved { + public static void Main () + { + var a = new A (1); + SomeMethod (a); + } + + class A { + public A () + { + } + + [Kept] + public A (int other) + { + } + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs new file mode 100644 index 000000000..d181ecd0a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs @@ -0,0 +1,28 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls { + class UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved { + public static void Main () + { + var a = new A (1); + SomeMethod (ref a); + } + + class A { + [Kept] + public A () + { + } + + [Kept] + public A (int other) + { + } + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (ref A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs new file mode 100644 index 000000000..09809a60e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesAreNotRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls { + class UnusedFieldsOfTypesAreNotRemoved { + public static void Main () + { + var a = new A (); + SomeMethod (a); + } + + [KeptMember (".ctor()")] + class A { + [Kept] private int field1; + + [Kept] private int field2; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs new file mode 100644 index 000000000..d4f3c3779 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls { + class UnusedFieldsOfTypesPassedByRefAreNotRemoved { + public static void Main () + { + var a = new A (); + SomeMethod (ref a); + } + + [KeptMember (".ctor()")] + class A { + [Kept] private int field1; + + [Kept] private int field2; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (ref A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs new file mode 100644 index 000000000..df77357d6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/InternalCalls/UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs @@ -0,0 +1,21 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.InternalCalls { + class UnusedFieldsOfTypesWhenHasThisAreNotRemoved { + public static void Main () + { + A a = new A (); + a.SomeMethod (); + } + + [KeptMember (".ctor()")] + class A { + [Kept] private int field1; + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + public extern void SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/DefaultConstructorOfParameterIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/DefaultConstructorOfParameterIsRemoved.cs new file mode 100644 index 000000000..df3d3b552 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/DefaultConstructorOfParameterIsRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Com { + class DefaultConstructorOfParameterIsRemoved { + public static void Main () + { + SomeMethod (null); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (A val); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/DefaultConstructorOfReturnTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/DefaultConstructorOfReturnTypeIsRemoved.cs new file mode 100644 index 000000000..3cc7df5db --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/DefaultConstructorOfReturnTypeIsRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Com { + class DefaultConstructorOfReturnTypeIsRemoved { + public static void Main () + { + var a = SomeMethod (); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern A SomeMethod (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfParameterAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfParameterAreRemoved.cs new file mode 100644 index 000000000..73a66b576 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfParameterAreRemoved.cs @@ -0,0 +1,24 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Com { + class FieldsOfParameterAreRemoved { + public static void Main () + { + SomeMethod (null); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + private int field; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern void SomeMethod (A val); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfReturnTypeAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfReturnTypeAreRemoved.cs new file mode 100644 index 000000000..7551d8687 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfReturnTypeAreRemoved.cs @@ -0,0 +1,24 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Com { + class FieldsOfReturnTypeAreRemoved { + public static void Main () + { + var a = SomeMethod (); + } + + [Kept] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + private int field; + } + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + static extern A SomeMethod (); + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfThisAreRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfThisAreRemoved.cs new file mode 100644 index 000000000..4c7402063 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Com/FieldsOfThisAreRemoved.cs @@ -0,0 +1,25 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Com { + class FieldsOfThisAreRemoved { + public static void Main () + { + new A ().SomeMethod (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof (GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A { + private int field; + + [Kept] + [MethodImpl (MethodImplOptions.InternalCall)] + public extern void SomeMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/DefaultConstructorOfReturnTypeIsNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/DefaultConstructorOfReturnTypeIsNotRemoved.cs new file mode 100644 index 000000000..d714d0d95 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/DefaultConstructorOfReturnTypeIsNotRemoved.cs @@ -0,0 +1,22 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke { + class DefaultConstructorOfReturnTypeIsNotRemoved { + public static void Main () + { + var a = SomeMethod (); + } + + class A { + [Kept] + public A () + { + } + } + + [Kept] + [DllImport ("Unused")] + private static extern A SomeMethod (); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedDefaultConstructorIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedDefaultConstructorIsRemoved.cs new file mode 100644 index 000000000..041cc9c98 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedDefaultConstructorIsRemoved.cs @@ -0,0 +1,27 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke { + class UnusedDefaultConstructorIsRemoved { + public static void Main () + { + var a = new A (1); + SomeMethod (a); + } + + class A { + public A () + { + } + + [Kept] + public A (int other) + { + } + } + + [Kept] + [DllImport ("Unused")] + private static extern void SomeMethod (A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs new file mode 100644 index 000000000..db2514a4a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs @@ -0,0 +1,28 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke { + class UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved { + public static void Main () + { + var a = new A (1); + SomeMethod (ref a); + } + + class A { + [Kept] + public A () + { + } + + [Kept] + public A (int other) + { + } + } + + [Kept] + [DllImport ("Unused")] + private static extern void SomeMethod (ref A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedFieldsOfTypesAreNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedFieldsOfTypesAreNotRemoved.cs new file mode 100644 index 000000000..a34c4d6bb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedFieldsOfTypesAreNotRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke { + class UnusedFieldsOfTypesAreNotRemoved { + public static void Main () + { + var a = new A (); + SomeMethod (a); + } + + [KeptMember (".ctor()")] + class A { + [Kept] private int field1; + + [Kept] private int field2; + } + + [Kept] + [DllImport ("Unused")] + private static extern void SomeMethod (A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs new file mode 100644 index 000000000..50ae45fe3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs @@ -0,0 +1,23 @@ +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Interop.PInvoke { + class UnusedFieldsOfTypesPassedByRefAreNotRemoved { + public static void Main () + { + var a = new A (); + SomeMethod (ref a); + } + + [KeptMember (".ctor()")] + class A { + [Kept] private int field1; + + [Kept] private int field2; + } + + [Kept] + [DllImport ("Unused")] + private static extern void SomeMethod (ref A a); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Libraries/CanLinkPublicApisOfLibrary.cs b/test/Mono.Linker.Tests.Cases/Libraries/CanLinkPublicApisOfLibrary.cs new file mode 100644 index 000000000..1bcd525dd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Libraries/CanLinkPublicApisOfLibrary.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Libraries { + [SetupLinkerLinkPublicAndFamily] + [SetupCompileAsLibrary] + [Kept] + [KeptMember (".ctor()")] + public class CanLinkPublicApisOfLibrary { + // Kept because by default libraries their action set to copy + [Kept] + public static void Main () + { + // Main is needed for the test collector to find and treat as a test + } + + [Kept] + public void UnusedPublicMethod () + { + } + + private void UnusedPrivateMethod () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs b/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs new file mode 100644 index 000000000..5c1e9aba4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Libraries/DefaultLibraryLinkBehavior.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Libraries { + [SetupCompileAsLibrary] + [Kept] + [KeptMember (".ctor()")] + public class DefaultLibraryLinkBehavior { + // Kept because by default libraries their action set to copy + [Kept] + public static void Main () + { + // Main is needed for the test collector to find and treat as a test + } + + [Kept] + public void UnusedPublicMethod () + { + } + + [Kept] + private void UnusedPrivateMethod () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/UserAssemblyActionWorks_Lib.cs b/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/UserAssemblyActionWorks_Lib.cs new file mode 100644 index 000000000..b9b9e5863 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Libraries/Dependencies/UserAssemblyActionWorks_Lib.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Libraries.Dependencies { + public class UserAssemblyActionWorks_Lib { + public static void Used () + { + } + + public static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Libraries/UserAssemblyActionWorks.cs b/test/Mono.Linker.Tests.Cases/Libraries/UserAssemblyActionWorks.cs new file mode 100644 index 000000000..1337ce066 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Libraries/UserAssemblyActionWorks.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Libraries.Dependencies; + +namespace Mono.Linker.Tests.Cases.Libraries { + /// <summary> + /// We have to check another assembly because the test exe is included with -a and that will cause it to be linked + /// </summary> + [SetupLinkerUserAction ("copy")] + [SetupCompileBefore ("lib.dll", new[] { "Dependencies/UserAssemblyActionWorks_Lib.cs" })] + [KeptAllTypesAndMembersInAssembly ("lib.dll")] + public class UserAssemblyActionWorks { + public static void Main () + { + UserAssemblyActionWorks_Lib.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/AssemblyWithPreserveAll.cs b/test/Mono.Linker.Tests.Cases/LinkXml/AssemblyWithPreserveAll.cs new file mode 100644 index 000000000..f02913bc5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/AssemblyWithPreserveAll.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + [KeptMember (".ctor()")] + public class AssemblyWithPreserveAll { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class UnusedType { + [Kept] + public int UnusedField; + + [Kept] + [KeptBackingField] + public int UnusedProperty { [Kept] get; [Kept] set; } + + [Kept] + public void UnusedMethod () + { + } + + [Kept] + [KeptMember (".ctor()")] + class UnusedNestedType { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/AssemblyWithPreserveAll.xml b/test/Mono.Linker.Tests.Cases/LinkXml/AssemblyWithPreserveAll.xml new file mode 100644 index 000000000..a1a96721e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/AssemblyWithPreserveAll.xml @@ -0,0 +1,4 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all"> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveAnExportedType.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveAnExportedType.cs new file mode 100644 index 000000000..bbf26c1d4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveAnExportedType.cs @@ -0,0 +1,19 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.LinkXml.Dependencies; + +namespace Mono.Linker.Tests.Cases.LinkXml +{ + [KeepTypeForwarderOnlyAssemblies ("false")] + [SetupCompileBefore ("Library.dll", new[] { "Dependencies/CanPreserveAnExportedType_Library.cs" })] + // Add another assembly in that uses the forwarder just to make things a little more complex + [SetupCompileBefore ("Forwarder.dll", new[] { "Dependencies/CanPreserveAnExportedType_Forwarder.cs" }, references: new[] { "Library.dll" })] + + [RemovedAssembly ("Forwarder.dll")] + [KeptMemberInAssembly ("Library.dll", typeof (CanPreserveAnExportedType_Library), "Field1", "Method()", ".ctor()")] + class CanPreserveAnExportedType { + public static void Main () { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveAnExportedType.xml b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveAnExportedType.xml new file mode 100644 index 000000000..f469bb982 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveAnExportedType.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="Forwarder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.Dependencies.CanPreserveAnExportedType_Library" preserve="all"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs new file mode 100644 index 000000000..0016d7272 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml { + [SetupLinkerArgument ("--exclude-feature", "com")] + public class CanPreserveExcludedFeatureCom { + public static void Main() + { + var a = new A (); + } + } + + [Kept] + [KeptMember (".ctor()")] + [KeptAttributeAttribute (typeof(GuidAttribute))] + [ComImport] + [Guid ("D7BB1889-3AB7-4681-A115-60CA9158FECA")] + class A + { + private int field; + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.xml b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.xml new file mode 100644 index 000000000..bcd942aaf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExcludedFeatureCom.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="mscorlib"> + <type fullname="System.Runtime.InteropServices.GuidAttribute" preserve="all"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExportedTypesUsingRegex.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExportedTypesUsingRegex.cs new file mode 100644 index 000000000..d122d98f3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExportedTypesUsingRegex.cs @@ -0,0 +1,19 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.LinkXml.Dependencies; + +namespace Mono.Linker.Tests.Cases.LinkXml +{ + [KeepTypeForwarderOnlyAssemblies ("false")] + [SetupCompileBefore ("Library.dll", new [] { "Dependencies/CanPreserveAnExportedType_Library.cs" })] + // Add another assembly in that uses the forwarder just to make things a little more complex + [SetupCompileBefore ("Forwarder.dll", new [] { "Dependencies/CanPreserveAnExportedType_Forwarder.cs" }, references: new [] { "Library.dll" })] + + [RemovedAssembly ("Forwarder.dll")] + [KeptMemberInAssembly ("Library.dll", typeof (CanPreserveAnExportedType_Library), "Field1", "Method()", ".ctor()")] + class CanPreserveExportedTypesUsingRegex { + public static void Main () { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExportedTypesUsingRegex.xml b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExportedTypesUsingRegex.xml new file mode 100644 index 000000000..b5827e265 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveExportedTypesUsingRegex.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="Forwarder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Can*" preserve="all"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs new file mode 100644 index 000000000..0eb9542d2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.cs @@ -0,0 +1,32 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml +{ + [KeptMember (".ctor()")] + class CanPreserveTypesUsingRegex { + public static void Main () { + } + + [Kept] + void UnusedHelper () { + } + + [Kept] + [KeptMember (".ctor()")] + class Bar { + } + } +} + +namespace Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace { + [Kept] + [KeptMember (".ctor()")] + class Type1 { + } + + [Kept] + [KeptMember (".ctor()")] + class Type2 { + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.xml b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.xml new file mode 100644 index 000000000..12f870c04 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/CanPreserveTypesUsingRegex.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Can*" /> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.PreserveNamespace*" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/CanPreserveAnExportedType_Forwarder.cs b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/CanPreserveAnExportedType_Forwarder.cs new file mode 100644 index 000000000..cb6f81e48 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/CanPreserveAnExportedType_Forwarder.cs @@ -0,0 +1,3 @@ +using System; + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo (typeof (Mono.Linker.Tests.Cases.LinkXml.Dependencies.CanPreserveAnExportedType_Library))] diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/CanPreserveAnExportedType_Library.cs b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/CanPreserveAnExportedType_Library.cs new file mode 100644 index 000000000..38814d986 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/CanPreserveAnExportedType_Library.cs @@ -0,0 +1,11 @@ +using System; + +namespace Mono.Linker.Tests.Cases.LinkXml.Dependencies +{ + public class CanPreserveAnExportedType_Library { + public int Field1; + + public void Method () { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Base.cs b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Base.cs new file mode 100644 index 000000000..d9803fada --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Base.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod { + public class Base { + public virtual void VirtualMethodFromBase () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.cs b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.cs new file mode 100644 index 000000000..3c1158922 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.cs @@ -0,0 +1,17 @@ +namespace Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod { + public class Library1 : Base { + public override void VirtualMethodFromBase () + { + } + } + + /// <summary> + /// This is here to confirm that derived types in the same assembly as the embedded resource are correctly taken into + /// consideration + /// </summary> + public class Library1Secondary : Base { + public override void VirtualMethodFromBase () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.xml b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.xml new file mode 100644 index 000000000..58f90df91 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.xml @@ -0,0 +1,14 @@ +<linker> + <assembly fullname="Library1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.Library1Secondary" preserve="nothing"> + <!-- Need to preserve a ctor so that an instance of the type is possible--> + <method name=".ctor"/> + </type> + </assembly> + <assembly fullname="Library2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.Library2" preserve="nothing"> + <!-- Need to preserve a ctor so that an instance of the type is possible--> + <method name=".ctor"/> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library2.cs b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library2.cs new file mode 100644 index 000000000..b977a5834 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library2.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod { + public class Library2 : Base { + public override void VirtualMethodFromBase () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs b/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs new file mode 100644 index 000000000..6111bc713 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod; + +namespace Mono.Linker.Tests.Cases.LinkXml { + [SetupCompileBefore ("Base.dll", + new []{"Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Base.cs"})] + [SetupCompileBefore ("Library1.dll", + new [] { "Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.cs"}, + new [] { "Base.dll"}, + resources: new [] { "Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library1.xml"})] + [SetupCompileBefore("Library2.dll", + new [] {"Dependencies/EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod/Library2.cs"}, + new [] {"Base.dll"}, + addAsReference: false)] + [IncludeBlacklistStep (true)] + + [KeptMemberInAssembly ("Library1.dll", typeof (Library1), "VirtualMethodFromBase()")] + [KeptMemberInAssembly ("Library1.dll", typeof (Library1Secondary), "VirtualMethodFromBase()")] + + // Library1's embedded link xml will preserve the Library2 type. Because Library2 shares a base class with Library1 + // Library2's override should be kept as well + [KeptMemberInAssembly ("Library2.dll", "Mono.Linker.Tests.Cases.LinkXml.Dependencies.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.Library2", "VirtualMethodFromBase()")] + public class EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod { + public static void Main () + { + var tmp = new Library1 (); + tmp.VirtualMethodFromBase (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/Dependencies/OnAssembly_Lib1.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/Dependencies/OnAssembly_Lib1.cs new file mode 100644 index 000000000..1e0c0a738 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/Dependencies/OnAssembly_Lib1.cs @@ -0,0 +1,10 @@ +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.Dependencies { + public class OnAssembly_Lib1 { + public static void UsedSoCompilerDoesntRemoveReference () + { + } + + public class FeatureOneClass { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/Dependencies/OnAssembly_Lib2.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/Dependencies/OnAssembly_Lib2.cs new file mode 100644 index 000000000..0a7731e79 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/Dependencies/OnAssembly_Lib2.cs @@ -0,0 +1,10 @@ +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.Dependencies { + public class OnAssembly_Lib2 { + public static void UsedSoCompilerDoesntRemoveReference () + { + } + + public class FeatureTwoClass { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs new file mode 100644 index 000000000..cbdfb5509 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.Dependencies; + +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { + [SetupLinkerArgument ("--exclude-feature", "one")] + [SetupCompileBefore ("library1.dll", new[] {typeof (OnAssembly_Lib1)})] + [SetupCompileBefore ("library2.dll", new[] {typeof (OnAssembly_Lib2)})] + [RemovedTypeInAssembly ("library1.dll", typeof (OnAssembly_Lib1.FeatureOneClass))] + [KeptTypeInAssembly ("library2.dll", typeof (OnAssembly_Lib2.FeatureTwoClass))] + public class OnAssembly { + public static void Main () + { + OnAssembly_Lib1.UsedSoCompilerDoesntRemoveReference (); + OnAssembly_Lib2.UsedSoCompilerDoesntRemoveReference (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.xml b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.xml new file mode 100644 index 000000000..9583b20ee --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnAssembly.xml @@ -0,0 +1,8 @@ +<linker> + <assembly fullname="library1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" feature="one"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.Dependencies.OnAssembly_Lib1/FeatureOneClass"/> + </assembly> + <assembly fullname="library2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" feature="two"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.Dependencies.OnAssembly_Lib2/FeatureTwoClass"/> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs new file mode 100644 index 000000000..e733ab2d1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.cs @@ -0,0 +1,17 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { + [SetupLinkerArgument ("--exclude-feature", "one")] + public class OnEvent { + public static void Main () + { + } + + public event EventHandler<EventArgs> FeatureOne; + + [Kept] + public event EventHandler<EventArgs> FeatureTwo {[Kept] add {}[Kept] remove {} } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.xml b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.xml new file mode 100644 index 000000000..d0fdc860d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnEvent.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnEvent"> + <event signature="System.EventHandler`1<System.EventArgs> FeatureOne" feature="one"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnEvent"> + <event signature="System.EventHandler`1<System.EventArgs> FeatureTwo" feature="two"/> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs new file mode 100644 index 000000000..93a61f0ab --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.cs @@ -0,0 +1,16 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { + [SetupLinkerArgument ("--exclude-feature", "one")] + public class OnField { + public static void Main () + { + } + + private int _featureOne; + + [Kept] + private int _featureTwo; + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.xml b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.xml new file mode 100644 index 000000000..b7a251bf8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnField.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnField"> + <field signature="System.Int32 _featureOne" feature="one"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnField"> + <field signature="System.Int32 _featureTwo" feature="two"/> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs new file mode 100644 index 000000000..11feb7a6a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { + [SetupLinkerArgument ("--exclude-feature", "one")] + public class OnMethod { + public static void Main () + { + } + + public void FeatureOne () + { + } + + [Kept] + public void FeatureTwo () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.xml b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.xml new file mode 100644 index 000000000..5aaf4c06f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnMethod.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnMethod"> + <method signature="System.Void FeatureOne()" feature="one"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnMethod"> + <method signature="System.Void FeatureTwo()" feature="two"/> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs new file mode 100644 index 000000000..b6e78b255 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { + [SetupLinkerArgument ("--exclude-feature", "one")] + public class OnProperty { + public static void Main () + { + } + + public int FeatureOne { get; set; } + + [Kept] + [KeptBackingField] + public int FeatureTwo {[Kept] get; [Kept] set; } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.xml b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.xml new file mode 100644 index 000000000..3b2ee6fcb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnProperty.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnProperty"> + <property signature="System.Int32 FeatureOne" accessors="all" feature="one"/> + </type> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnProperty"> + <property signature="System.Int32 FeatureTwo" accessors="all" feature="two"/> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs new file mode 100644 index 000000000..368812fcc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.LinkXml.FeatureExclude { + [SetupLinkerArgument ("--exclude-feature", "one")] + public class OnType { + public static void Main () + { + } + + class FeatureOneClass + { + } + + [Kept] + [KeptMember(".ctor()")] + class FeatureTwoClass { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.xml b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.xml new file mode 100644 index 000000000..a2e91e062 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/FeatureExclude/OnType.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnType/FeatureOneClass" feature="one"/> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.FeatureExclude.OnType/FeatureTwoClass" feature="two"/> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/PreserveBackingFieldWhenPropertyIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/PreserveBackingFieldWhenPropertyIsKept.cs new file mode 100644 index 000000000..c319c1442 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/PreserveBackingFieldWhenPropertyIsKept.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml +{ + abstract class PreserveBackingFieldWhenPropertyIsKept + { + public static void Main () + { + Prop = 1; + } + + public abstract int Base { set; } + + [Kept] + [KeptBackingField] + public static int Prop { get; [Kept] set; } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/PreserveBackingFieldWhenPropertyIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/PreserveBackingFieldWhenPropertyIsKept.xml new file mode 100644 index 000000000..256f50a84 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/PreserveBackingFieldWhenPropertyIsKept.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.PreserveBackingFieldWhenPropertyIsKept" preserve="fields"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.cs new file mode 100644 index 000000000..623ee17ca --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.cs @@ -0,0 +1,61 @@ + + +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml +{ + class TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved { + public static void Main () { + } + + [Kept] + class Unused : IFoo<int>, IFoo<string>, IFoo<Cat>, IFoo2<int>, IFoo3<int, string, char>, IDog, IFoo<IFoo<int>> { + [Kept] + public int Field1; + + [Kept] + public IFoo<int> Field2; + + public IFoo<int> Property1 { get; set; } + + string IDog.Name { get; set; } + + int IFoo<int>.Bar { get; set; } + + int IFoo<string>.Bar { get; set; } + + int IFoo<Cat>.Bar { get; set; } + + int Bar2 { get; set; } + + int IFoo2<int>.Bar2 { get; set; } + + int Bar3 { get; set; } + + int IFoo3<int, string, char>.Bar3 { get; set; } + + int IFoo<IFoo<int>>.Bar { get; set; } + } + + interface IDog { + string Name { get; set; } + } + + [Kept] + interface IFoo<T> { + + int Bar { get; set; } + } + + interface IFoo2<T> { + int Bar2 { get; set; } + } + + interface IFoo3<T, K, J> { + int Bar3 { get; set; } + } + + class Cat { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.xml new file mode 100644 index 000000000..338ee7f76 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved/Unused" preserve="fields"> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.cs new file mode 100644 index 000000000..fb8536a2f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.cs @@ -0,0 +1,15 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + [KeptMember (".ctor()")] + public class UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.xml new file mode 100644 index 000000000..ca7da2c44 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.xml @@ -0,0 +1,4 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedEventPreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedEventPreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..594b5bd87 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedEventPreservedByLinkXmlIsKept.cs @@ -0,0 +1,37 @@ +using System; + +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedEventPreservedByLinkXmlIsKept { + public static void Main () + { + } + + [Kept] + class Unused { + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler<EventArgs> Preserved; + + [Kept] + public event EventHandler<EventArgs> Preserved1 { [Kept] add { } [Kept] remove { } } + + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler Preserved2; + + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + public event EventHandler Preserved3; + + public event EventHandler<EventArgs> NotPreserved; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedEventPreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedEventPreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..027cc59d1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedEventPreservedByLinkXmlIsKept.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedEventPreservedByLinkXmlIsKept/Unused"> + <event signature="System.EventHandler`1<System.EventArgs> Preserved" /> + <event signature="System.EventHandler`1<System.EventArgs> Preserved1" /> + <event signature="System.EventHandler Preserved2" /> + <event name="Preserved3" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedFieldPreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedFieldPreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..d41e23716 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedFieldPreservedByLinkXmlIsKept.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedFieldPreservedByLinkXmlIsKept { + public static void Main () + { + } + + [Kept] + class Unused { + [Kept] + private int _preserved; + + [Kept] + private int _preserved2; + + [Kept] + private List<int> _preserved3; + + private int _notPreserved; + } + + [Kept] + class UnusedWithGenerics<T> { + [Kept] + private List<T> _preserved1; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedFieldPreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedFieldPreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..82daa710c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedFieldPreservedByLinkXmlIsKept.xml @@ -0,0 +1,12 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedFieldPreservedByLinkXmlIsKept/Unused"> + <field signature="System.Int32 _preserved" /> + <field name="_preserved2" /> + <field signature="System.Collections.Generic.List`1<System.Int32> _preserved3" /> + </type> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedFieldPreservedByLinkXmlIsKept/UnusedWithGenerics`1"> + <field signature="System.Collections.Generic.List`1<T> _preserved1" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.cs new file mode 100644 index 000000000..659d4c5d1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.cs @@ -0,0 +1,85 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + public class UnusedGenericTypeWithPreserveAllHasAllMembersPreserved { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused<T1, T2, T3> { + [Kept] + public int Field1; + + [Kept] + private int Field2; + + [Kept] + internal int Field3; + + [Kept] + public static int Field4; + + [Kept] + private static int Field5; + + [Kept] + internal static int Field6; + + [Kept] + [KeptBackingField] + public string Property1 { [Kept] get; [Kept] set;} + + [Kept] + [KeptBackingField] + private string Property2 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal string Property3 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public static string Property4 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + private static string Property5 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal static string Property6 { [Kept] get; [Kept] set; } + + [Kept] + public void Method1 () + { + } + + [Kept] + private void Method2 () + { + } + + [Kept] + internal void Method3 () + { + } + + [Kept] + public static void Method4 () + { + } + + [Kept] + private static void Method5 () + { + } + + [Kept] + internal static void Method6 () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.xml new file mode 100644 index 000000000..b2da72420 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedGenericTypeWithPreserveAllHasAllMembersPreserved/Unused`3" preserve="all" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.cs new file mode 100644 index 000000000..8e362a4d8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.cs @@ -0,0 +1,19 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + public class UnusedInterfaceTypeOnTypeWithPreserveAllIsKept { + public static void Main () + { + } + + [Kept] + interface IFoo { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptInterface (typeof (IFoo))] + class Bar : IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.xml new file mode 100644 index 000000000..48d80c17d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedInterfaceTypeOnTypeWithPreserveAllIsKept/Bar" preserve="all"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.cs new file mode 100644 index 000000000..968d0d1e6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.cs @@ -0,0 +1,16 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + public class UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved { + public static void Main () + { + } + + interface IFoo { + } + + [Kept] + class Bar : IFoo { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.xml new file mode 100644 index 000000000..0cd063a84 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved/Bar" preserve="nothing"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..9fe2b353b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedMethodPreservedByLinkXmlIsKept { + public static void Main () + { + } + + [Kept] + class Unused { + [Kept] + private void PreservedMethod () + { + } + + [Kept] + private void PreservedMethod2 (int arg1, string arg2) + { + } + + [Kept] + private void PreservedMethod3 () + { + } + + [Kept] + private void PreservedMethod4 (List<int> arg1) + { + } + + private void NotPreservedMethod () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..d5af5b146 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedMethodPreservedByLinkXmlIsKept.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedMethodPreservedByLinkXmlIsKept/Unused"> + <method signature="System.Void PreservedMethod()" /> + <method signature="System.Void PreservedMethod2(System.Int32,System.String)" /> + <method name="PreservedMethod3" /> + <method signature="System.Void PreservedMethod4(System.Collections.Generic.List`1<System.Int32>)" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNestedTypePreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNestedTypePreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..5e319acfd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNestedTypePreservedByLinkXmlIsKept.cs @@ -0,0 +1,14 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedNestedTypePreservedByLinkXmlIsKept { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNestedTypePreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNestedTypePreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..7990e8fec --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNestedTypePreservedByLinkXmlIsKept.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedNestedTypePreservedByLinkXmlIsKept/Unused" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNonRequiredTypeIsRemoved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNonRequiredTypeIsRemoved.cs new file mode 100644 index 000000000..8175ee32e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNonRequiredTypeIsRemoved.cs @@ -0,0 +1,10 @@ +namespace Mono.Linker.Tests.Cases.LinkXml { + public class UnusedNonRequiredTypeIsRemoved { + public static void Main () + { + } + + class Unused { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNonRequiredTypeIsRemoved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNonRequiredTypeIsRemoved.xml new file mode 100644 index 000000000..168b5aa2c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedNonRequiredTypeIsRemoved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedNonRequiredTypeIsRemoved/Unused" preserve="all" required="0"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedPropertyPreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedPropertyPreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..6f21e7b55 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedPropertyPreservedByLinkXmlIsKept.cs @@ -0,0 +1,46 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedPropertyPreservedByLinkXmlIsKept { + public static void Main () + { + } + + [Kept] + class Unused { + [Kept] + [KeptBackingField] + public int PreservedProperty1 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty2 { [Kept] get; set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty3 { get; [Kept] set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty4 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty5 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty6 { [Kept] get; set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty7 { get; [Kept] set; } + + [Kept] + [KeptBackingField] + public int PreservedProperty8 { [Kept] get; [Kept] set; } + + public int NotPreservedProperty { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedPropertyPreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedPropertyPreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..c606c5445 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedPropertyPreservedByLinkXmlIsKept.xml @@ -0,0 +1,17 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedPropertyPreservedByLinkXmlIsKept/Unused"> + <method signature="System.Int32 get_PreservedProperty1()" /> + <method signature="System.Void set_PreservedProperty1(System.Int32)" /> + <method signature="System.Int32 get_PreservedProperty2()" /> + <method signature="System.Void set_PreservedProperty3(System.Int32)" /> + + <property signature="System.Int32 PreservedProperty4" /> + <property signature="System.Int32 PreservedProperty5" accessors="all" /> + <property signature="System.Int32 PreservedProperty6" accessors="get" /> + <property signature="System.Int32 PreservedProperty7" accessors="set" /> + + <property name="PreservedProperty8" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeDeclarationPreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeDeclarationPreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..bd2b15ba3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeDeclarationPreservedByLinkXmlIsKept.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + public class UnusedTypeDeclarationPreservedByLinkXmlIsKept { + public static void Main () + { + } + } + + [Kept] + [KeptBaseType (typeof (UnusedTypeDeclarationPreservedByLinkXmlIsKeptUnusedTypeBase))] + class UnusedTypeDeclarationPreservedByLinkXmlIsKeptUnusedType : UnusedTypeDeclarationPreservedByLinkXmlIsKeptUnusedTypeBase + { + int field; + static void Method () + { + } + + string Prop { get; set; } + } + + [Kept] + class UnusedTypeDeclarationPreservedByLinkXmlIsKeptUnusedTypeBase + { + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeDeclarationPreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeDeclarationPreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..c99f6b46b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeDeclarationPreservedByLinkXmlIsKept.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeDeclarationPreservedByLinkXmlIsKeptUnusedType" preserve="nothing" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.cs new file mode 100644 index 000000000..246c80af6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + + [KeptMember(".ctor()")] + class UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused { + [Kept] + void Foo () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.xml new file mode 100644 index 000000000..7ecdb6c22 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.xml @@ -0,0 +1,3 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all" /> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlIsKept.cs new file mode 100644 index 000000000..edaff63eb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlIsKept.cs @@ -0,0 +1,14 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypePreservedByLinkXmlIsKept { + public static void Main () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + class UnusedTypePreservedByLinkXmlIsKeptUnusedType { + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlIsKept.xml new file mode 100644 index 000000000..ffb652e1e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlIsKept.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypePreservedByLinkXmlIsKeptUnusedType" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlWithCommentIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlWithCommentIsKept.cs new file mode 100644 index 000000000..fe077d530 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlWithCommentIsKept.cs @@ -0,0 +1,15 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypePreservedByLinkXmlWithCommentIsKept { + public static void Main () + { + } + } + + [Kept] + [KeptMember (".ctor()")] + class UnusedTypePreservedByLinkXmlWithCommentIsKeptUnusedType + { + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlWithCommentIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlWithCommentIsKept.xml new file mode 100644 index 000000000..a6e5643a2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypePreservedByLinkXmlWithCommentIsKept.xml @@ -0,0 +1,6 @@ +<!-- this is a comment --> +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypePreservedByLinkXmlWithCommentIsKeptUnusedType" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.cs new file mode 100644 index 000000000..840d7f474 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.cs @@ -0,0 +1,86 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved + { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused { + [Kept] + public int Field1; + + [Kept] + private int Field2; + + [Kept] + internal int Field3; + + [Kept] + public static int Field4; + + [Kept] + private static int Field5; + + [Kept] + internal static int Field6; + + [Kept] + [KeptBackingField] + public string Property1 { [Kept] get; [Kept] set;} + + [Kept] + [KeptBackingField] + private string Property2 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal string Property3 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public static string Property4 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + private static string Property5 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal static string Property6 { [Kept] get; [Kept] set; } + + [Kept] + public void Method1 () + { + } + + [Kept] + private void Method2 () + { + } + + [Kept] + internal void Method3 () + { + } + + [Kept] + public static void Method4 () + { + } + + [Kept] + private static void Method5 () + { + } + + [Kept] + internal static void Method6 () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.xml new file mode 100644 index 000000000..d84df95e0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved/Unused" /> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveAllHasAllMembersPreserved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveAllHasAllMembersPreserved.cs new file mode 100644 index 000000000..02fb956f2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveAllHasAllMembersPreserved.cs @@ -0,0 +1,85 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypeWithPreserveAllHasAllMembersPreserved { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused { + [Kept] + public int Field1; + + [Kept] + private int Field2; + + [Kept] + internal int Field3; + + [Kept] + public static int Field4; + + [Kept] + private static int Field5; + + [Kept] + internal static int Field6; + + [Kept] + [KeptBackingField] + public string Property1 { [Kept] get; [Kept] set;} + + [Kept] + [KeptBackingField] + private string Property2 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal string Property3 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public static string Property4 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + private static string Property5 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal static string Property6 { [Kept] get; [Kept] set; } + + [Kept] + public void Method1 () + { + } + + [Kept] + private void Method2 () + { + } + + [Kept] + internal void Method3 () + { + } + + [Kept] + public static void Method4 () + { + } + + [Kept] + private static void Method5 () + { + } + + [Kept] + internal static void Method6 () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveAllHasAllMembersPreserved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveAllHasAllMembersPreserved.xml new file mode 100644 index 000000000..7987a7765 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveAllHasAllMembersPreserved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeWithPreserveAllHasAllMembersPreserved/Unused" preserve="all" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveFieldsHasMethodsRemoved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveFieldsHasMethodsRemoved.cs new file mode 100644 index 000000000..1af6f4530 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveFieldsHasMethodsRemoved.cs @@ -0,0 +1,66 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypeWithPreserveFieldsHasMethodsRemoved { + public static void Main () + { + } + + [Kept] + class Unused { + [Kept] + public int Field1; + + [Kept] + private int Field2; + + [Kept] + internal int Field3; + + [Kept] + public static int Field4; + + [Kept] + private static int Field5; + + [Kept] + internal static int Field6; + + public string Property1 { get; set; } + private string Property2 { get; set; } + internal string Property3 { get; set; } + public static string Property4 { get; set; } + private static string Property5 { get; set; } + internal static string Property6 { get; set; } + + [Kept] + public void PreservedMethod () + { + } + + public void Method1 () + { + } + + private void Method2 () + { + } + + internal void Method3 () + { + } + + public static void Method4 () + { + } + + private static void Method5 () + { + } + + internal static void Method6 () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveFieldsHasMethodsRemoved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveFieldsHasMethodsRemoved.xml new file mode 100644 index 000000000..619a8db26 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveFieldsHasMethodsRemoved.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeWithPreserveFieldsHasMethodsRemoved/Unused" preserve="fields"> + <method signature="System.Void PreservedMethod()" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveMethodsHasFieldsRemoved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveMethodsHasFieldsRemoved.cs new file mode 100644 index 000000000..8a79d2d2b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveMethodsHasFieldsRemoved.cs @@ -0,0 +1,74 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypeWithPreserveMethodsHasFieldsRemoved { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + class Unused { + public int Field1; + private int Field2; + internal int Field3; + public static int Field4; + private static int Field5; + internal static int Field6; + + [Kept] + [KeptBackingField] + public string Property1 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + private string Property2 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal string Property3 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + public static string Property4 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + private static string Property5 { [Kept] get; [Kept] set; } + + [Kept] + [KeptBackingField] + internal static string Property6 { [Kept] get; [Kept] set; } + + [Kept] + public void Method1 () + { + } + + [Kept] + private void Method2 () + { + } + + [Kept] + internal void Method3 () + { + } + + [Kept] + public static void Method4 () + { + } + + [Kept] + private static void Method5 () + { + } + + [Kept] + internal static void Method6 () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveMethodsHasFieldsRemoved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveMethodsHasFieldsRemoved.xml new file mode 100644 index 000000000..20723f8ed --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveMethodsHasFieldsRemoved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeWithPreserveMethodsHasFieldsRemoved/Unused" preserve="methods" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingAndPreserveMembers.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingAndPreserveMembers.cs new file mode 100644 index 000000000..b9d404f22 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingAndPreserveMembers.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypeWithPreserveNothingAndPreserveMembers { + public static void Main () + { + } + + [Kept] + class Unused { + [Kept] + public int Field1; + + private int Field2; + + [Kept] + public void Method1 () + { + } + + private void Method2 () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingAndPreserveMembers.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingAndPreserveMembers.xml new file mode 100644 index 000000000..d672e9e09 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingAndPreserveMembers.xml @@ -0,0 +1,8 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeWithPreserveNothingAndPreserveMembers/Unused" preserve="nothing"> + <field signature="System.Int32 Field1" /> + <method signature="System.Void Method1()" /> + </type> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingHasMembersRemoved.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingHasMembersRemoved.cs new file mode 100644 index 000000000..d6ea29b89 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingHasMembersRemoved.cs @@ -0,0 +1,50 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + class UnusedTypeWithPreserveNothingHasMembersRemoved { + public static void Main () + { + } + + [Kept] + class Unused { + public int Field1; + private int Field2; + internal int Field3; + public static int Field4; + private static int Field5; + internal static int Field6; + + public string Property1 { get; set; } + private string Property2 { get; set; } + internal string Property3 { get; set; } + public static string Property4 { get; set; } + private static string Property5 { get; set; } + internal static string Property6 { get; set; } + + public void Method1 () + { + } + + private void Method2 () + { + } + + internal void Method3 () + { + } + + public static void Method4 () + { + } + + private static void Method5 () + { + } + + internal static void Method6 () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingHasMembersRemoved.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingHasMembersRemoved.xml new file mode 100644 index 000000000..f76df307a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UnusedTypeWithPreserveNothingHasMembersRemoved.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UnusedTypeWithPreserveNothingHasMembersRemoved/Unused" preserve="nothing" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UsedNonRequiredTypeIsKept.cs b/test/Mono.Linker.Tests.Cases/LinkXml/UsedNonRequiredTypeIsKept.cs new file mode 100644 index 000000000..37cce219c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UsedNonRequiredTypeIsKept.cs @@ -0,0 +1,52 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.LinkXml { + public class UsedNonRequiredTypeIsKept { + public static void Main () + { + var tmp = typeof (Used1).ToString (); + tmp = typeof (Used2).ToString (); + tmp = typeof (Used3).ToString (); + } + + class Used1 { + [Kept] + public int field; + + public void Method () + { + } + + public int Property { get; set; } + } + + [KeptMember (".ctor()")] + class Used2 { + public int field; + + [Kept] + public void Method () + { + } + + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } + + [KeptMember (".ctor()")] + class Used3 { + [Kept] + public int field; + + [Kept] + public void Method () + { + } + + [Kept] + [KeptBackingField] + public int Property { [Kept] get; [Kept] set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/LinkXml/UsedNonRequiredTypeIsKept.xml b/test/Mono.Linker.Tests.Cases/LinkXml/UsedNonRequiredTypeIsKept.xml new file mode 100644 index 000000000..2294c4f4f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/LinkXml/UsedNonRequiredTypeIsKept.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UsedNonRequiredTypeIsKept/Used1" preserve="fields" required="0"/> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UsedNonRequiredTypeIsKept/Used2" preserve="methods" required="0"/> + <type fullname="Mono.Linker.Tests.Cases.LinkXml.UsedNonRequiredTypeIsKept/Used3" preserve="all" required="0"/> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj b/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj new file mode 100644 index 000000000..27c913108 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Mono.Linker.Tests.Cases.csproj @@ -0,0 +1,621 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{B6BEE6AA-ADA0-4E1D-9A17-FBF2936F82B5}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Mono.Linker.Tests.Cases</RootNamespace> + <AssemblyName>Mono.Linker.Tests.Cases</AssemblyName> + <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE;INCLUDE_EXPECTATIONS</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>0</WarningLevel> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE;INCLUDE_EXPECTATIONS</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>0</WarningLevel> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Attributes.Debugger\DebuggerDisplayAttributeOnAssemblyUsingTarget.cs" /> + <Compile Include="Attributes.Debugger\DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs" /> + <Compile Include="Attributes.Debugger\DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs" /> + <Compile Include="Attributes.Debugger\DebuggerDisplayAttributeOnType.cs" /> + <Compile Include="Attributes.Debugger\DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs" /> + <Compile Include="Attributes.Debugger\DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs" /> + <Compile Include="Attributes.Debugger\DebuggerTypeProxyAttributeOnType.cs" /> + <Compile Include="Attributes.Debugger\Dependencies\DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly_Lib.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInSameAssembly.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfGenericTypeInOtherAssembly.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameOfNestedTypeInOtherAssembly.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnAssemblyUsingTargetTypeNameInOtherAssembly.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerTypeProxyAttributeOnAssemblyUsingTarget.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnAssemblyUsingTarget.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnAssemblyUsingTargetOnUnusedType.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerTypeProxyAttributeOnType.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnType.cs" /> + <Compile Include="Attributes.Debugger\KeepDebugMembers\DebuggerDisplayAttributeOnTypeThatIsNotUsed.cs" /> + <Compile Include="Attributes\AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly.cs" /> + <Compile Include="Attributes\AssemblyAttributeKeptInComplexCase.cs" /> + <Compile Include="Attributes\AttributeOnAssemblyIsKept.cs" /> + <Compile Include="Attributes\AttributeOnParameterInUsedMethodIsKept.cs" /> + <Compile Include="Attributes\AttributeOnPreservedTypeWithTypeUsedInConstructorIsKept.cs" /> + <Compile Include="Attributes\AttributeOnPreservedTypeWithTypeUsedInDifferentNamespaceIsKept.cs" /> + <Compile Include="Attributes\AttributeOnPreservedTypeWithTypeUsedInFieldIsKept.cs" /> + <Compile Include="Attributes\AttributeOnUsedFieldIsKept.cs" /> + <Compile Include="Attributes\AttributeOnPreservedTypeIsKept.cs" /> + <Compile Include="Attributes\AttributeOnPreservedTypeWithTypeUsedInPropertySetterIsKept.cs" /> + <Compile Include="Attributes\AttributeOnPreservedTypeWithUsedSetter.cs" /> + <Compile Include="Attributes\AttributeOnUsedMethodIsKept.cs" /> + <Compile Include="Attributes\AttributeOnUsedPropertyIsKept.cs" /> + <None Include="Attributes\OnlyKeepUsed\Dependencies\UnusedAttributeWithTypeForwarderIsRemoved_Forwarder.cs" /> + <Compile Include="Attributes\CoreLibraryAssemblyAttributesAreKept.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs" /> + <Compile Include="Attributes\Csc\OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs" /> + <Compile Include="Attributes\Dependencies\AttributeDefinedInReference.cs" /> + <Compile Include="Attributes\Dependencies\TypeDefinedInReference.cs" /> + <Compile Include="Attributes\Dependencies\TypeDefinedInReference2.cs" /> + <Compile Include="Attributes\Dependencies\TypeDefinedInReferenceWithReference.cs" /> + <Compile Include="Attributes\FixedLengthArrayAttributesArePreserved.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeArrayOnAttributeCtorOnType.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssembly.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnAssemblyOtherTypesInAttributeAssemblyUsed.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnEvent.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnMethod.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnProperty.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeCtorOnType.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnAssembly.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnEvent.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnMethod.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnProperty.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributeFieldOnType.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnAssembly.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnEvent.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnMethod.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnProperty.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyIsTypeOnAttributePropertyOnType.cs" /> + <Compile Include="Attributes\Mcs\OnlyTypeUsedInAssemblyWithReferenceIsTypeOnAttributeCtorOnType.cs" /> + <Compile Include="Attributes\NoSecurity\SecurityAttributesOnUsedMethodAreRemoved.cs" /> + <Compile Include="Attributes\NoSecurity\SecurityAttributesOnUsedTypeAreRemoved.cs" /> + <Compile Include="Attributes\NoSecurity\CoreLibrarySecurityAttributeTypesAreRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\ComAttributesArePreserved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\ComAttributesAreRemovedWhenFeatureExcluded.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\ContextStaticIsPreservedOnField.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\Dependencies\UnusedAttributeWithTypeForwarderIsRemoved_Lib.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\AttributeDefinedAndUsedInOtherAssemblyIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\AttributeUsedByAttributeIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\CoreLibraryUsedAssemblyAttributesAreKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\FixedLengthArrayAttributesArePreserved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\ThreadStaticIsPreservedOnField.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\CoreLibraryUnusedAssemblyAttributesAreRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeOnReturnTypeIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnModuleIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeWithTypeForwarderIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\CanLinkCoreLibrariesWithOnlyKeepUsedAttributes.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\Dependencies\AttributeDefinedAndUsedInOtherAssemblyIsKept_Lib.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributePreservedViaLinkXmlIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnAssemblyIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnEventIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnMethodIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnParameterIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnPropertyIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UnusedAttributeTypeOnTypeIsRemoved.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnAssemblyIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnEventIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnMethodIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnModuleIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnParameterIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnPropertyIsKept.cs" /> + <Compile Include="Attributes\OnlyKeepUsed\UsedAttributeTypeOnTypeIsKept.cs" /> + <Compile Include="Attributes\SecurityAttributesOnUsedMethodAreKept.cs" /> + <Compile Include="Attributes\SecurityAttributesOnUsedTypeAreKept.cs" /> + <Compile Include="Attributes\Dependencies\AssemblyAttributeIsRemovedIfOnlyTypesUsedInAssembly_Lib.cs" /> + <Compile Include="Attributes\Dependencies\AssemblyAttributeKeptInComplexCase_Lib.cs" /> + <Compile Include="Basic\ComplexNestedClassesHasUnusedRemoved.cs" /> + <Compile Include="Basic\InterfaceMethodImplementedOnBaseClassDoesNotGetStripped.cs" /> + <Compile Include="Basic\MultiLevelNestedClassesAllRemovedWhenNonUsed.cs" /> + <Compile Include="Basic\NestedDelegateInvokeMethodsPreserved.cs" /> + <Compile Include="Basic\InstantiatedTypeWithOverridesFromObject.cs" /> + <Compile Include="Basic\NeverInstantiatedTypeWithOverridesFromObject.cs" /> + <Compile Include="Basic\UninvokedInterfaceMemberGetsRemoved.cs" /> + <Compile Include="Basic\UnusedDelegateGetsRemoved.cs" /> + <Compile Include="Basic\UnusedEnumGetsRemoved.cs" /> + <Compile Include="Basic\UnusedEventGetsRemoved.cs" /> + <Compile Include="Basic\InitializerForArrayIsKept.cs" /> + <Compile Include="Basic\UnusedFieldsOfStructsAreKept.cs" /> + <Compile Include="Basic\UsedEnumIsKept.cs" /> + <Compile Include="Basic\UsedEventOnInterfaceIsKept.cs" /> + <Compile Include="Basic\UnusedFieldGetsRemoved.cs" /> + <Compile Include="Basic\UnusedMethodGetsRemoved.cs" /> + <Compile Include="Basic\UnusedPropertyGetsRemoved.cs" /> + <Compile Include="Basic\UnusedPropertySetterRemoved.cs" /> + <Compile Include="Basic\UsedEventIsKept.cs" /> + <Compile Include="Basic\UsedEventOnInterfaceIsRemovedWhenUsedFromClass.cs" /> + <Compile Include="Basic\UsedPropertyIsKept.cs" /> + <Compile Include="Basic\UsedStructIsKept.cs" /> + <Compile Include="BCLFeatures\ETW\LocalsOfModifiedMethodAreRemoved.cs" /> + <Compile Include="BCLFeatures\ETW\StubbedMethodWithExceptionHandlers.cs" /> + <Compile Include="CommandLine\ResponseFilesWork.cs" /> + <Compile Include="CoreLink\CanIncludeI18nAssemblies.cs" /> + <Compile Include="CoreLink\DelegateAndMulticastDelegateKeepInstantiatedReqs.cs" /> + <Compile Include="CoreLink\NeverInstantiatedTypeWithOverridesFromObject.cs" /> + <Compile Include="CoreLink\NoSecurityPlusOnlyKeepUsedRemovesAllSecurityAttributesFromCoreLibraries.cs" /> + <Compile Include="CoreLink\InstantiatedTypeWithOverridesFromObject.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\OverrideOfAbstractIsKept.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\OverrideOfVirtualCanBeRemoved.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\OverrideOfVirtualCanBeRemoved2.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\OverrideOfVirtualCanBeRemoved3.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\OverrideThatAlsoFulfilsInterface.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.cs" /> + <Compile Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.cs" /> + <Compile Include="Inheritance.AbstractClasses\UnusedAbstractMethodRemoved.cs" /> + <Compile Include="Inheritance.AbstractClasses\UnusedVirtualMethodRemoved.cs" /> + <Compile Include="Inheritance.AbstractClasses\UsedOverrideOfAbstractMethodIsKept.cs" /> + <Compile Include="Inheritance.AbstractClasses\UsedOverrideOfVirtualMethodIsKept.cs" /> + <Compile Include="Inheritance.Interfaces\Dependencies\InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Copy.cs" /> + <Compile Include="Inheritance.Interfaces\Dependencies\InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit_Link.cs" /> + <Compile Include="Inheritance.Interfaces\Dependencies\InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Copy.cs" /> + <Compile Include="Inheritance.Interfaces\Dependencies\InterfaceTypeInOtherUsedOnlyByCopiedAssembly_Link.cs" /> + <Compile Include="Inheritance.Interfaces\Dependencies\InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed_Lib.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplementingInterfaceMethodsNested.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplementingInterfaceMethodsNested2.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplemtingInterfaceMethodsThroughBaseClass2.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplemtingInterfaceMethodsThroughBaseClass3.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplemtingInterfaceMethodsThroughBaseClass4.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplemtingInterfaceMethodsThroughBaseClass5.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassImplemtingInterfaceMethodsThroughBaseClass6.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassUsedFromConcreteTypeHasInterfaceMethodRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ClassUsedFromInterfaceHasInterfaceMethodKept.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceMarkOrderingDoesNotMatter.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceMarkOrderingDoesNotMatter2.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceMarkOrderingDoesNotMatter3.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceTypeInOtherUsedOnlyByCopiedAssembly.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceUsedOnlyAsConstraintIsKept.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceWithInterfaceFromOtherAssemblyWhenExplicitMethodUsed.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\InterfaceTypeOnlyUsedHasInterfacesRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndAssemblyPreserveAll.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveAll.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveFields.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveMethods.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveNone.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\ArrayWithIndexAssignedToReturnValue.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\ArrayPassedAsParameter.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\FieldDowncastedToInterface.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\GenericType.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\GenericTypeWithConstraint2.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\GenericTypeWithConstraint3.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\InterfaceOnMultipleBases.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\LocalDowncastedToInterface.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\LocalPassedAsParameter.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\LocalPassedAsParameterToGeneric.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\LocalPassedAsParameterToGenericWithConstraint.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\LocalPassedAsParameterToGenericWithConstraint2.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\ReturnValueDowncastedToInterface.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtorButInterfaceNeeded\GenericTypeWithConstraint.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\ComInterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\ExplicitInterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\GenericType.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\InterfaceFromCopiedAssemblyCanBeRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\LocalDowncastDoesNotCuaseOtherTypesToKeepInterface.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\GenericWithConstraintDoesNotCauseOtherTypesToKeepInterface.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\ObjectHardCastedToInterface.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\PreserveDependencyPreservesInterfaceMethod.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeWithPreserveFields.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeWithPreserveMethods.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeHasInterfaceMethodPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ObjectCastedToSecondInterfaceHasMemberRemovedButInterfaceKept.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\ExplicitInterfaceMethodWhichCreatesInstanceOfParentType.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\TypeGetsMarkedThatImplementsAlreadyMarkedInterfaceMethod.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\UnusedComInterfaceIsKept.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\UnusedComInterfaceIsRemovedWhenComFeatureExcluded.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\UnusedExplicitInterfaceHasMethodPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\UnusedExplicitInterfaceIsRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\UnusedInterfaceHasMethodPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnReferenceType\UnusedInterfaceTypeIsRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\NoKeptCtor\InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsed.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\NoKeptCtor\InterfaceCanBeRemovedFromClassWithOnlyStaticMethodUsedWithCctor.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\NoKeptCtor\InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\NoKeptCtor\InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\StructImplementingInterfaceMethodsNested.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\StructImplementingInterfaceMethodsNested2.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\StructUsedFromConcreteTypeHasInterfaceMethodRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\StructUsedFromConcreteTypeHasInterfaceMethodRemoved2.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\StructUsedFromInterfaceHasInterfaceMethodKept.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\UnusedExplicitInterfaceHasMethodPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\UnusedExplicitInterfaceIsRemoved.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\UnusedInterfaceHasMethodPreservedViaXml.cs" /> + <Compile Include="Inheritance.Interfaces\OnValueType\UnusedInterfaceTypeIsRemoved.cs" /> + <Compile Include="Inheritance.VirtualMethods\HarderToDetectUnusedVirtualMethodGetsRemoved.cs" /> + <Compile Include="Inheritance.VirtualMethods\UnusedTypeWithOverrideOfVirtualMethodIsRemoved.cs" /> + <Compile Include="Inheritance.VirtualMethods\UnusedVirtualMethodRemoved.cs" /> + <Compile Include="Inheritance.VirtualMethods\UsedOverrideOfVirtualMethodIsKept.cs" /> + <Compile Include="Inheritance.VirtualMethods\UsedTypeWithOverrideOfVirtualMethodHasOverrideKept.cs" /> + <Compile Include="Inheritance.VirtualMethods\VirtualMethodGetsPerservedIfBaseMethodGetsInvoked.cs" /> + <Compile Include="Inheritance.VirtualMethods\VirtualMethodGetsStrippedIfImplementingMethodGetsInvokedDirectly.cs" /> + <Compile Include="Libraries\CanLinkPublicApisOfLibrary.cs" /> + <Compile Include="Libraries\DefaultLibraryLinkBehavior.cs" /> + <Compile Include="Libraries\Dependencies\UserAssemblyActionWorks_Lib.cs" /> + <Compile Include="Libraries\UserAssemblyActionWorks.cs" /> + <Compile Include="LinkXml\AssemblyWithPreserveAll.cs" /> + <Compile Include="LinkXml\CanPreserveTypesUsingRegex.cs" /> + <Compile Include="LinkXml\CanPreserveAnExportedType.cs" /> + <None Include="LinkXml\Dependencies\CanPreserveAnExportedType_Forwarder.cs" /> + <Compile Include="LinkXml\CanPreserveExportedTypesUsingRegex.cs" /> + <Compile Include="LinkXml\Dependencies\CanPreserveAnExportedType_Library.cs" /> + <Compile Include="LinkXml\Dependencies\EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod\Base.cs" /> + <Compile Include="LinkXml\Dependencies\EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod\Library1.cs" /> + <Compile Include="LinkXml\Dependencies\EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod\Library2.cs" /> + <Compile Include="LinkXml\EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod.cs" /> + <Compile Include="LinkXml\FeatureExclude\OnAssembly.cs" /> + <Compile Include="LinkXml\FeatureExclude\OnEvent.cs" /> + <Compile Include="LinkXml\FeatureExclude\OnField.cs" /> + <Compile Include="LinkXml\FeatureExclude\OnMethod.cs" /> + <Compile Include="LinkXml\FeatureExclude\OnProperty.cs" /> + <Compile Include="LinkXml\FeatureExclude\OnType.cs" /> + <Compile Include="LinkXml\FeatureExclude\Dependencies\OnAssembly_Lib1.cs" /> + <Compile Include="LinkXml\FeatureExclude\Dependencies\OnAssembly_Lib2.cs" /> + <Compile Include="LinkXml\UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.cs" /> + <Compile Include="LinkXml\UnusedEventPreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.cs" /> + <Compile Include="LinkXml\UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.cs" /> + <Compile Include="LinkXml\UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.cs" /> + <Compile Include="LinkXml\UnusedNonRequiredTypeIsRemoved.cs" /> + <Compile Include="LinkXml\UnusedTypePreservedByLinkXmlWithCommentIsKept.cs" /> + <Compile Include="LinkXml\UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.cs" /> + <Compile Include="LinkXml\UsedNonRequiredTypeIsKept.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInAssemblyLibrary.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInNonReferencedAssemblyBase.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInNonReferencedAssemblyBase2.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" /> + <Compile Include="PreserveDependencies\Dependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyField.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyMethod.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyMethodInAssembly.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyMethodInNonReferencedAssembly.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyMethodInNonReferencedAssemblyChained.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyMethodInNonReferencedAssemblyChainedReference.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssembly.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction.cs" /> + <Compile Include="PreserveDependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs" /> + <Compile Include="References\AssemblyOnlyUsedByUsingWithCsc.cs" /> + <Compile Include="References\AssemblyOnlyUsedByUsingWithCscWithKeepFacades.cs" /> + <Compile Include="References\AssemblyOnlyUsedByUsingWithMcs.cs" /> + <Compile Include="References\Dependencies\AssemblyOnlyUsedByUsing_Copied.cs" /> + <Compile Include="References\Dependencies\AssemblyOnlyUsedByUsing_Lib.cs" /> + <Compile Include="References\Individual\CanSkipUnresolved.cs" /> + <Compile Include="References\Individual\Dependencies\CanSkipUnresolved_Library.cs" /> + <Compile Include="References\Dependencies\UserAssembliesAreLinkedByDefault_Library1.cs" /> + <Compile Include="References\UserAssembliesAreLinkedByDefault.cs" /> + <Compile Include="Reflection\AssemblyImportedViaReflectionWithDerivedType.cs" /> + <Compile Include="Reflection\AssemblyImportedViaReflectionWithReference.cs" /> + <Compile Include="Reflection\ConstructorUsedViaReflection.cs" /> + <Compile Include="Reflection\Dependencies\AssemblyDependencyWithReference.cs" /> + <Compile Include="Reflection\Dependencies\AssemblyImportedViaReflectionWithDerivedType_Base.cs" /> + <Compile Include="Reflection\Dependencies\AssemblyImportedViaReflectionWithDerivedType_Reflect.cs" /> + <Compile Include="Reflection\EventUsedViaReflection.cs" /> + <Compile Include="Reflection\FieldUsedViaReflection.cs" /> + <Compile Include="Reflection\MethodUsedViaReflectionWithDefaultBindingFlags.cs" /> + <Compile Include="Reflection\MightKeepExtraThings.cs" /> + <Compile Include="Reflection\MethodUsedViaReflection.cs" /> + <Compile Include="Reflection\PropertyUsedViaReflection.cs" /> + <Compile Include="Reflection\TypeUsedViaReflection.cs" /> + <Compile Include="Reflection\TypeUsedViaReflectionAssemblyDoesntExist.cs" /> + <Compile Include="Reflection\TypeUsedViaReflectionInDifferentAssembly.cs" /> + <Compile Include="Reflection\TypeUsedViaReflectionLdstrIncomplete.cs" /> + <Compile Include="Reflection\TypeUsedViaReflectionLdstrValidButChanged.cs" /> + <Compile Include="Reflection\TypeUsedViaReflectionTypeDoesntExist.cs" /> + <Compile Include="Reflection\TypeUsedViaReflectionTypeNameIsSymbol.cs" /> + <Compile Include="Reflection\UsedViaReflectionIntegrationTest.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs" /> + <Compile Include="Resources\Dependencies\EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs" /> + <Compile Include="Resources\Dependencies\EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs" /> + <Compile Include="Resources\Dependencies\EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileIsProcessed.cs" /> + <Compile Include="Resources\EmbeddedLinkXmlFileIsProcessedAndKept.cs" /> + <Compile Include="Resources\NonLinkerEmbeddedResourceHasNoImpact.cs" /> + <Compile Include="Statics\DisableBeforeFieldInit\UnusedStaticFieldInitializer.cs" /> + <Compile Include="Symbols\Dependencies\LibraryWithEmbeddedPdbSymbols.cs" /> + <Compile Include="Symbols\Dependencies\LibraryWithPortablePdbSymbols.cs" /> + <Compile Include="Symbols\ReferenceWithEmbeddedPdb.cs" /> + <Compile Include="Symbols\ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithEmbeddedPdbCopyAction.cs" /> + <Compile Include="Symbols\ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithEmbeddedPdbDeleteAction.cs" /> + <Compile Include="Symbols\ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithMdbCopyAction.cs" /> + <Compile Include="Symbols\ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithMdbDeleteAction.cs" /> + <Compile Include="Symbols\ReferenceWithMdbDeleteActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithPdb.cs" /> + <Compile Include="Symbols\ReferenceWithPdbAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\AssemblyWithDefaultSymbolsAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\AssemblyWithDefaultSymbols.cs" /> + <Compile Include="Symbols\Dependencies\LibraryWithCompilerDefaultSymbols.cs" /> + <Compile Include="Symbols\Dependencies\LibraryWithPdb\LibraryWithPdb.cs" /> + <Compile Include="Symbols\Dependencies\LibraryWithMdb\LibraryWithMdb.cs" /> + <Compile Include="Symbols\ReferenceWithPdbCopyAction.cs" /> + <Compile Include="Symbols\ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithPdbDeleteAction.cs" /> + <Compile Include="Symbols\ReferenceWithPdbDeleteActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithPortablePdb.cs" /> + <Compile Include="Symbols\ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithPortablePdbCopyAction.cs" /> + <Compile Include="Symbols\ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithPortablePdbDeleteAction.cs" /> + <Compile Include="Symbols\ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs" /> + <Compile Include="TestFramework\CanCheckInitializersByIndex.cs" /> + <Compile Include="TestFramework\CanCompileILAssembly.cs" /> + <Compile Include="TestFramework\CanCompileReferencesUsingTypes.cs" /> + <Compile Include="TestFramework\CanCompileReferencesWithResources.cs" /> + <Compile Include="TestFramework\CanCompileReferencesWithResourcesWithCsc.cs" /> + <Compile Include="TestFramework\CanCompileReferencesWithResourcesWithMcs.cs" /> + <Compile Include="TestFramework\CanCompileTestCaseWithDebugPdbs.cs" /> + <Compile Include="TestFramework\CanCompileTestCaseWithCsc.cs" /> + <Compile Include="TestFramework\CanCompileTestCaseWithMsc.cs" /> + <Compile Include="TestFramework\CanSandboxDependenciesUsingType.cs" /> + <Compile Include="TestFramework\CanVerifyInterfacesOnTypesInAssembly.cs" /> + <Compile Include="TestFramework\Dependencies\CanCompileReferencesUsingTypes_LibSource1.cs" /> + <Compile Include="TestFramework\Dependencies\CanCompileReferencesUsingTypes_LibSource2.cs" /> + <Compile Include="TestFramework\Dependencies\CanCompileReferencesWithResources_Lib1.cs" /> + <Compile Include="TestFramework\Dependencies\CanCompileTestCaseWithCsc_Lib.cs" /> + <Compile Include="TestFramework\Dependencies\CanCompileTestCaseWithMcs_Lib.cs" /> + <Compile Include="TestFramework\Dependencies\CanSandboxDependenciesUsingType_Source1.cs" /> + <Compile Include="TestFramework\Dependencies\CanSandboxDependenciesUsingType_Source2.cs" /> + <Compile Include="TestFramework\Dependencies\CanVerifyInterfacesOnTypesInAssembly_Lib.cs" /> + <Compile Include="TestFramework\Dependencies\VerifyAttributesInAssemblyWorks_Base.cs" /> + <Compile Include="TestFramework\Dependencies\VerifyAttributesInAssemblyWorks_Lib.cs" /> + <Compile Include="TestFramework\VerifyAttributesInAssemblyWorks.cs" /> + <Compile Include="TestFramework\VerifyAttributesInAssemblyWorksWithStrings.cs" /> + <Compile Include="TestFramework\VerifyDefineAttributeBehavior.cs" /> + <None Include="TypeForwarding\Dependencies\ForwarderLibrary.cs" /> + <Compile Include="TestFramework\VerifyExpectModifiedAttributesWork.cs" /> + <Compile Include="TestFramework\VerifyResourceInAssemblyAttributesBehavior.cs" /> + <Compile Include="Tracing\Individual\CanDumpDependenciesToUncompressedXml.cs" /> + <Compile Include="Tracing\Individual\CanEnableDependenciesDump.cs" /> + <Compile Include="Tracing\Individual\CanEnableReducedTracing.cs" /> + <Compile Include="TypeForwarding\Dependencies\ImplementationLibrary.cs" /> + <Compile Include="TypeForwarding\Dependencies\LibraryUsingForwarder.cs" /> + <Compile Include="TypeForwarding\Dependencies\ReferenceImplementationLibrary.cs" /> + <Compile Include="TypeForwarding\TypeForwarderOnlyAssembliesRemoved.cs" /> + <Compile Include="TypeForwarding\TypeForwarderOnlyAssembliesKept.cs" /> + <Compile Include="TypeForwarding\TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.cs" /> + <Compile Include="CoreLink\CopyOfCoreLibrariesKeepsUnusedTypes.cs" /> + <Compile Include="CoreLink\LinkingOfCoreLibrariesRemovesUnusedMethods.cs" /> + <Compile Include="CoreLink\LinkingOfCoreLibrariesRemovesUnusedTypes.cs" /> + <Compile Include="Advanced\DeadCodeElimination1.cs" /> + <Compile Include="Advanced\FieldThatOnlyGetsSetIsRemoved.cs" /> + <Compile Include="Generics\CorrectOverloadedMethodGetsStrippedInGenericClass.cs" /> + <Compile Include="Generics\DerivedClassWithMethodOfSameNameAsBaseButDifferentNumberOfGenericParametersUnusedBaseWillGetStripped.cs" /> + <Compile Include="Generics\GenericInstanceInterfaceMethodImplementedWithDifferentGenericArgumentNameDoesNotGetStripped.cs" /> + <Compile Include="Generics\MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameter.cs" /> + <Compile Include="Generics\MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase.cs" /> + <Compile Include="Generics\MethodWithParameterWhichHasGenericParametersAndOverrideUsesADifferentNameForGenericParameterNestedCase2.cs" /> + <Compile Include="Generics\OverrideWithAnotherVirtualMethodOfSameNameWithDifferentParameterType.cs" /> + <Compile Include="Interop\InternalCalls\Com\DefaultConstructorOfParameterIsRemoved.cs" /> + <Compile Include="Interop\InternalCalls\Com\FieldsOfParameterAreRemoved.cs" /> + <Compile Include="Interop\InternalCalls\Com\FieldsOfReturnTypeAreRemoved.cs" /> + <Compile Include="Interop\InternalCalls\Com\FieldsOfThisAreRemoved.cs" /> + <Compile Include="Interop\InternalCalls\DefaultConstructorOfReturnTypeIsNotRemoved.cs" /> + <Compile Include="Interop\InternalCalls\Com\DefaultConstructorOfReturnTypeIsRemoved.cs" /> + <Compile Include="Interop\PInvoke\Com\DefaultConstructorOfParameterIsRemoved.cs" /> + <Compile Include="Interop\PInvoke\Com\DefaultConstructorOfReturnTypeIsRemoved.cs" /> + <Compile Include="Interop\PInvoke\Com\FieldsOfParameterAreRemoved.cs" /> + <Compile Include="Interop\PInvoke\Com\FieldsOfReturnTypeAreRemoved.cs" /> + <Compile Include="Interop\PInvoke\Com\FieldsOfThisAreRemoved.cs" /> + <Compile Include="Interop\PInvoke\DefaultConstructorOfReturnTypeIsNotRemoved.cs" /> + <Compile Include="Interop\InternalCalls\UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs" /> + <Compile Include="Interop\PInvoke\UnusedDefaultConstructorOfTypePassedByRefIsNotRemoved.cs" /> + <Compile Include="Interop\InternalCalls\UnusedDefaultConstructorIsRemoved.cs" /> + <Compile Include="Interop\PInvoke\UnusedDefaultConstructorIsRemoved.cs" /> + <Compile Include="Interop\InternalCalls\UnusedFieldsOfTypesAreNotRemoved.cs" /> + <Compile Include="Interop\InternalCalls\UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs" /> + <Compile Include="Interop\PInvoke\UnusedFieldsOfTypesAreNotRemoved.cs" /> + <Compile Include="Interop\PInvoke\UnusedFieldsOfTypesPassedByRefAreNotRemoved.cs" /> + <Compile Include="Interop\InternalCalls\UnusedFieldsOfTypesWhenHasThisAreNotRemoved.cs" /> + <Compile Include="LinkXml\TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.cs" /> + <Compile Include="LinkXml\UnusedFieldPreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\UnusedMethodPreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\UnusedNestedTypePreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\UnusedPropertyPreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.cs" /> + <Compile Include="LinkXml\UnusedTypePreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\UnusedTypeWithPreserveAllHasAllMembersPreserved.cs" /> + <Compile Include="LinkXml\UnusedTypeWithPreserveFieldsHasMethodsRemoved.cs" /> + <Compile Include="LinkXml\UnusedTypeWithPreserveMethodsHasFieldsRemoved.cs" /> + <Compile Include="LinkXml\UnusedTypeWithPreserveNothingAndPreserveMembers.cs" /> + <Compile Include="LinkXml\UnusedTypeWithPreserveNothingHasMembersRemoved.cs" /> + <Compile Include="References\ReferencesAreRemovedWhenAllUsagesAreRemoved.cs" /> + <Compile Include="Basic\UnusedClassGetsRemoved.cs" /> + <Compile Include="Basic\UnusedNestedClassGetsRemoved.cs" /> + <Compile Include="Statics\UnusedStaticMethodGetsRemoved.cs" /> + <Compile Include="Generics\UsedOverloadedGenericMethodInGenericClassIsNotStripped.cs" /> + <Compile Include="Generics\UsedOverloadedGenericMethodInstanceInGenericClassIsNotStripped.cs" /> + <Compile Include="Generics\UsedOverloadedGenericMethodWithNoParametersIsNotStripped.cs" /> + <Compile Include="Statics\UnusedStaticConstructorGetsRemoved.cs" /> + <Compile Include="TypeForwarding\MissingTargetReference.cs" /> + <None Include="TypeForwarding\Dependencies\TypeForwarderMissingReference.il" /> + <Compile Include="Basic\UsedInterfaceIsKept.cs" /> + <Compile Include="LinkXml\PreserveBackingFieldWhenPropertyIsKept.cs" /> + <Compile Include="Symbols\ReferencesWithMixedSymbolTypes.cs" /> + <Compile Include="Symbols\ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs" /> + <Compile Include="Symbols\ReferenceWithMdb.cs" /> + <Compile Include="Symbols\ReferenceWithMdbAndSymbolLinkingEnabled.cs" /> + <Compile Include="Attributes.StructLayout\SequentialClass.cs" /> + <Compile Include="Attributes.StructLayout\AutoClass.cs" /> + <Compile Include="Attributes.StructLayout\UnusedTypeWithSequentialLayoutIsRemoved.cs" /> + <Compile Include="Attributes.StructLayout\ExplicitClass.cs" /> + <Compile Include="Reflection\AssemblyImportedViaReflection.cs" /> + <Compile Include="Reflection\Dependencies\AssemblyDependency.cs" /> + <Compile Include="Statics\ExplicitStaticCtor.cs" /> + <Compile Include="Statics\UnusedStaticFieldInitializer.cs" /> + <Compile Include="Statics\StaticFieldInitializer.cs" /> + <Compile Include="Statics\MixedStaticFieldInitializerAndCtor.cs" /> + <Compile Include="LinkXml\UnusedTypeDeclarationPreservedByLinkXmlIsKept.cs" /> + <Compile Include="LinkXml\CanPreserveExcludedFeatureCom.cs" /> + <Compile Include="BCLFeatures\ETW\CustomEventSource.cs" /> + <Compile Include="BCLFeatures\ETW\Excluded.cs" /> + <Compile Include="BCLFeatures\ETW\BaseRemovedEventSource.cs" /> + <Compile Include="Generics\NewConstraintOnClass.cs" /> + <Compile Include="BCLFeatures\ETW\NonEventWithLog.cs" /> + </ItemGroup> + <ItemGroup> + <Content Include="Attributes\OnlyKeepUsed\Dependencies\AssemblyWithUnusedAttributeOnReturnParameterDefinition.il" /> + <Content Include="Attributes\OnlyKeepUsed\UnusedAttributePreservedViaLinkXmlIsKept.xml" /> + <Content Include="CommandLine\Dependencies\ResponseFilesWork.rsp" /> + <Content Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved.xml" /> + <Content Include="Inheritance.AbstractClasses\NoKeptCtor\OverrideRemoval\PreservesOverriddenMethodOverrideOfUsedVirtualStillRemoved2.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeHasExplicitInterfaceMethodPreservedViaXml.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeHasExplicitInterfacePropertyPreservedViaXml.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeHasInterfaceMethodPreservedViaXml.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\UnusedExplicitInterfaceHasMethodPreservedViaXml.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\Dependencies\NoInstanceCtorAndAssemblyPreserveAll_Lib.il" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndAssemblyPreserveAll.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveAll.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveFields.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveFieldsWithInterfacesMarked.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveMethods.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoInstanceCtor\NoInstanceCtorAndTypePreserveNone.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\InterfaceMarkOrderingDoesNotMatter.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\InterfaceMarkOrderingDoesNotMatter2.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\InterfaceMarkOrderingDoesNotMatter3.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeWithPreserveFields.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeWithPreserveMethods.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\NoKeptCtor\UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked.xml" /> + <Content Include="Inheritance.Interfaces\OnReferenceType\UnusedInterfaceHasMethodPreservedViaXml.xml" /> + <Content Include="Inheritance.Interfaces\OnValueType\UnusedExplicitInterfaceHasMethodPreservedViaXml.xml" /> + <Content Include="Inheritance.Interfaces\OnValueType\UnusedInterfaceHasMethodPreservedViaXml.xml" /> + <Content Include="LinkXml\AssemblyWithPreserveAll.xml" /> + <Content Include="LinkXml\CanPreserveTypesUsingRegex.xml" /> + <Content Include="LinkXml\CanPreserveAnExportedType.xml" /> + <Content Include="LinkXml\CanPreserveExportedTypesUsingRegex.xml" /> + <Content Include="LinkXml\Dependencies\EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod\Library1.xml" /> + <Content Include="LinkXml\FeatureExclude\OnAssembly.xml" /> + <Content Include="LinkXml\FeatureExclude\OnEvent.xml" /> + <Content Include="LinkXml\FeatureExclude\OnField.xml" /> + <Content Include="LinkXml\FeatureExclude\OnMethod.xml" /> + <Content Include="LinkXml\FeatureExclude\OnProperty.xml" /> + <Content Include="LinkXml\FeatureExclude\OnType.xml" /> + <Content Include="LinkXml\TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved.xml" /> + <Content Include="LinkXml\UnusedAssemblyWithNoDefinedPreserveHasAllTypesPreserved.xml" /> + <Content Include="LinkXml\UnusedEventPreservedByLinkXmlIsKept.xml" /> + <Content Include="LinkXml\UnusedFieldPreservedByLinkXmlIsKept.xml" /> + <Content Include="LinkXml\UnusedGenericTypeWithPreserveAllHasAllMembersPreserved.xml" /> + <Content Include="LinkXml\UnusedInterfaceTypeOnTypeWithPreserveAllIsKept.xml" /> + <Content Include="LinkXml\UnusedInterfaceTypeOnTypeWithPreserveNothingIsRemoved.xml" /> + <Content Include="LinkXml\UnusedMethodPreservedByLinkXmlIsKept.xml" /> + <Content Include="LinkXml\UnusedNestedTypePreservedByLinkXmlIsKept.xml" /> + <Content Include="LinkXml\UnusedNonRequiredTypeIsRemoved.xml" /> + <Content Include="LinkXml\UnusedPropertyPreservedByLinkXmlIsKept.xml" /> + <Content Include="LinkXml\UnusedTypeIsPresservedWhenEntireAssemblyIsPreserved.xml" /> + <Content Include="LinkXml\UnusedTypePreservedByLinkXmlIsKept.xml" /> + <Content Include="LinkXml\UnusedTypePreservedByLinkXmlWithCommentIsKept.xml" /> + <Content Include="LinkXml\UnusedTypeWithNoDefinedPreserveHasAllMembersPreserved.xml" /> + <Content Include="LinkXml\UnusedTypeWithPreserveAllHasAllMembersPreserved.xml" /> + <Content Include="LinkXml\UnusedTypeWithPreserveFieldsHasMethodsRemoved.xml" /> + <Content Include="LinkXml\UnusedTypeWithPreserveMethodsHasFieldsRemoved.xml" /> + <Content Include="LinkXml\UnusedTypeWithPreserveNothingAndPreserveMembers.xml" /> + <Content Include="LinkXml\UnusedTypeWithPreserveNothingHasMembersRemoved.xml" /> + <Content Include="LinkXml\UsedNonRequiredTypeIsKept.xml" /> + <Content Include="PreserveDependencies\Dependencies\PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileIsProcessed.xml" /> + <Content Include="Resources\Dependencies\EmbeddedLinkXmlFileIsProcessedAndKept.xml" /> + <Content Include="Resources\Dependencies\NonLinkerEmbeddedResourceHasNoImpact.xml" /> + <Content Include="TestFramework\Dependencies\CanCompileReferencesWithResources_Lib1.txt" /> + <Content Include="TestFramework\Dependencies\CanCompileReferencesWithResources_Lib1.log" /> + <Content Include="TestFramework\Dependencies\CanCompileTestCaseWithCsc.txt" /> + <Content Include="TestFramework\Dependencies\CanCompileTestCaseWithMcs.txt" /> + <Content Include="TestFramework\Dependencies\VerifyResourceInAssemblyAttributesBehavior.txt" /> + <Content Include="LinkXml\PreserveBackingFieldWhenPropertyIsKept.xml" /> + <Content Include="TypeForwarding\TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.xml" /> + <Content Include="LinkXml\UnusedTypeDeclarationPreservedByLinkXmlIsKept.xml" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Mono.Linker.Tests.Cases.Expectations\Mono.Linker.Tests.Cases.Expectations.csproj"> + <Project>{2C26601F-3E2F-45B9-A02F-58EE9296E19E}</Project> + <Name>Mono.Linker.Tests.Cases.Expectations</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <None Include="TestFramework\Dependencies\ILAssemblySample.il" /> + </ItemGroup> + <ItemGroup> + <Folder Include="Attributes.StructLayout\" /> + <Folder Include="Inheritance.Complex" /> + <Folder Include="Reflection\Dependencies\" /> + <Folder Include="BCLFeatures\" /> + <Folder Include="BCLFeatures\ETW\" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="LinkXml\CanPreserveExcludedFeatureCom.xml" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInAssemblyLibrary.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInAssemblyLibrary.cs new file mode 100644 index 000000000..e67672f38 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInAssemblyLibrary.cs @@ -0,0 +1,8 @@ +using System; +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public class PreserveDependencyMethodInAssemblyLibrary { + public PreserveDependencyMethodInAssemblyLibrary () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs new file mode 100644 index 000000000..b64962a85 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs @@ -0,0 +1,5 @@ +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public abstract class PreserveDependencyMethodInNonReferencedAssemblyBase { + public abstract string Method (); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase2.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase2.cs new file mode 100644 index 000000000..d5f7883ad --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase2.cs @@ -0,0 +1,8 @@ +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public class PreserveDependencyMethodInNonReferencedAssemblyBase2 : PreserveDependencyMethodInNonReferencedAssemblyBase { + public override string Method () + { + return "Base2"; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.cs new file mode 100644 index 000000000..6909b63d9 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.cs @@ -0,0 +1,16 @@ +using System.Runtime.CompilerServices; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public class PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary : PreserveDependencyMethodInNonReferencedAssemblyBase { + public override string Method () + { + Dependency (); + return "Dependency"; + } + + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.Advanced.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyBase2", "base2")] + public static void Dependency () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary.cs new file mode 100644 index 000000000..6a796ada6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary.cs @@ -0,0 +1,9 @@ +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public class PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary : PreserveDependencyMethodInNonReferencedAssemblyBase { + public override string Method () + { + PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.Dependency (); + return "Dependency"; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs new file mode 100644 index 000000000..57b5bc788 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs @@ -0,0 +1,12 @@ +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public class PreserveDependencyMethodInNonReferencedAssemblyLibrary : PreserveDependencyMethodInNonReferencedAssemblyBase { + public override string Method () + { + return "Dependency"; + } + + private void UnusedMethod () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml new file mode 100644 index 000000000..732b24680 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="PreserveDependencyMethodInNonReferencedAssemblyLibrary, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary" preserve="all" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib.cs new file mode 100644 index 000000000..222887fbc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/Dependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies { + public class PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib { + public static void MethodPreservedViaDependencyAttribute () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyField.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyField.cs new file mode 100644 index 000000000..8ce9e5ef8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyField.cs @@ -0,0 +1,24 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + public class PreserveDependencyField { + public static void Main () + { + var b = new B (); + b.field = 3; + } + + [KeptMember (".ctor()")] + class B { + [Kept] + [PreserveDependency ("ExtraMethod1")] + public int field; + + [Kept] + static void ExtraMethod1 () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs new file mode 100644 index 000000000..fc634f0a6 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethod.cs @@ -0,0 +1,94 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + class PreserveDependencyMethod { + public static void Main () + { + B.Method (); + B.SameContext (); + B.Broken (); + B.Conditional (); + } + + class B + { + [Kept] + int field; + + [Kept] + void Method2 (out sbyte arg) + { + arg = 1; + } + + [Kept] + [PreserveDependency ("Dependency1()", "Mono.Linker.Tests.Cases.PreserveDependencies.C")] + [PreserveDependency ("Dependency2`1 ( T[] , System.Int32 ) ", "Mono.Linker.Tests.Cases.PreserveDependencies.C")] + [PreserveDependency ("field", "Mono.Linker.Tests.Cases.PreserveDependencies.C")] + [PreserveDependency ("NextOne (Mono.Linker.Tests.Cases.PreserveDependencies.PreserveDependencyMethod+Nested&)", "Mono.Linker.Tests.Cases.PreserveDependencies.PreserveDependencyMethod+Nested")] + [PreserveDependency ("Property", "Mono.Linker.Tests.Cases.PreserveDependencies.C")] + [PreserveDependency ("get_Property()", "Mono.Linker.Tests.Cases.PreserveDependencies.C")] + public static void Method () + { + } + + [Kept] + [PreserveDependency ("field")] + [PreserveDependency ("Method2 (System.SByte&)")] + public static void SameContext () + { + } + + [Kept] + [PreserveDependency ("Missing", "Mono.Linker.Tests.Cases.Advanced.C")] + [PreserveDependency ("Dependency2`1 (T, System.Int32, System.Object)", "Mono.Linker.Tests.Cases.Advanced.C")] + [PreserveDependency ("")] + public static void Broken () + { + } + + [Kept] + [PreserveDependency ("ConditionalTest()", "Mono.Linker.Tests.Cases.Advanced.C", Condition = "don't have it")] + public static void Conditional () + { + } + } + + class Nested + { + [Kept] + private static void NextOne (ref Nested arg1) + { + } + } + } + + class C + { + [Kept] + internal string field; + + [Kept] + internal void Dependency1 () + { + } + + internal void Dependency1 (long arg1) + { + } + + [Kept] + internal void Dependency2<T> (T[] arg1, int arg2) + { + } + + [Kept] + [KeptBackingField] + internal string Property { [Kept] get; set; } + + internal void ConditionalTest () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInAssembly.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInAssembly.cs new file mode 100644 index 000000000..f3a258ebb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInAssembly.cs @@ -0,0 +1,22 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies +{ + [KeptMemberInAssembly ("library.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInAssemblyLibrary", ".ctor()")] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/PreserveDependencyMethodInAssemblyLibrary.cs" })] + public class PreserveDependencyMethodInAssembly + { + public static void Main () + { + Dependency (); + } + + [Kept] + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInAssemblyLibrary", "library")] + static void Dependency () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssembly.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssembly.cs new file mode 100644 index 000000000..b85e7cd58 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssembly.cs @@ -0,0 +1,38 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + [SetupCompileBefore ("base.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs" })] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" }, references: new [] { "base.dll" }, addAsReference: false)] + [KeptAssembly ("base.dll")] + [KeptAssembly ("library.dll")] + [KeptMemberInAssembly ("base.dll", typeof (PreserveDependencyMethodInNonReferencedAssemblyBase), "Method()")] + [KeptMemberInAssembly ("library.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "Method()")] + public class PreserveDependencyMethodInNonReferencedAssembly { + public static void Main () + { + var obj = new Foo (); + var val = obj.Method (); + Dependency (); + } + + [Kept] + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "library")] + static void Dependency () + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (PreserveDependencyMethodInNonReferencedAssemblyBase))] + class Foo : PreserveDependencyMethodInNonReferencedAssemblyBase { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyChained.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyChained.cs new file mode 100644 index 000000000..677fa113a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyChained.cs @@ -0,0 +1,42 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + [IgnoreTestCase ("Currently failing")] + [SetupCompileBefore ("base.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs" })] + [SetupCompileBefore ("base2.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase2.cs" }, references: new [] { "base.dll" }, addAsReference: false)] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.cs" }, references: new [] { "base.dll" }, addAsReference: false)] + [KeptAssembly ("base.dll")] + [KeptAssembly ("base2.dll")] + [KeptAssembly ("library.dll")] + [KeptMemberInAssembly ("base.dll", typeof (PreserveDependencyMethodInNonReferencedAssemblyBase), "Method()")] + [KeptMemberInAssembly ("base2.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyBase2", "Method()")] + [KeptMemberInAssembly ("library.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary", "Method()")] + public class PreserveDependencyMethodInNonReferencedAssemblyChained { + public static void Main () + { + var obj = new Foo (); + var val = obj.Method (); + Dependency (); + } + + [Kept] + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary", "library")] + static void Dependency () + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (PreserveDependencyMethodInNonReferencedAssemblyBase))] + class Foo : PreserveDependencyMethodInNonReferencedAssemblyBase { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReference.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReference.cs new file mode 100644 index 000000000..e86d31476 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReference.cs @@ -0,0 +1,45 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + [IgnoreTestCase ("Currently failing")] + [SetupCompileBefore ("base.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs" })] + [SetupCompileBefore ("base2.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase2.cs" }, references: new [] { "base.dll" }, addAsReference: false)] + [SetupCompileBefore ("reference.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary.cs" }, references: new [] { "base.dll" }, addAsReference: false)] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary.cs" }, references: new [] { "base.dll", "reference.dll" }, addAsReference: false)] + [KeptAssembly ("base.dll")] + [KeptAssembly ("base2.dll")] + [KeptAssembly ("library.dll")] + [KeptAssembly ("reference.dll")] + [KeptMemberInAssembly ("base.dll", typeof (PreserveDependencyMethodInNonReferencedAssemblyBase), "Method()")] + [KeptMemberInAssembly ("base2.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyBase2", "Method()")] + [KeptMemberInAssembly ("library.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary", "Method()")] + [KeptMemberInAssembly ("reference.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyChainedLibrary", "Method()")] + public class PreserveDependencyMethodInNonReferencedAssemblyChainedReference { + public static void Main () + { + var obj = new Foo (); + var val = obj.Method (); + Dependency (); + } + + [Kept] + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyChainedReferenceLibrary", "library")] + static void Dependency () + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (PreserveDependencyMethodInNonReferencedAssemblyBase))] + class Foo : PreserveDependencyMethodInNonReferencedAssemblyBase { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs new file mode 100644 index 000000000..12a989922 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml.cs @@ -0,0 +1,45 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + /// <summary> + /// This is an acceptable bug with the currently implementation. Embedded link xml files will not be processed + /// </summary> + [IncludeBlacklistStep (true)] + [SetupCompileBefore ("base.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs" })] + [SetupCompileBefore ( + "PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll", + new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" }, + references: new [] { "base.dll" }, + resources: new [] {"Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml"}, + addAsReference: false)] + [KeptAssembly ("base.dll")] + [RemovedMemberInAssembly ("PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "UnusedMethod()")] + public class PreserveDependencyMethodInNonReferencedAssemblyWithEmbeddedXml { + public static void Main () + { + var obj = new Foo (); + var val = obj.Method (); + Dependency (); + } + + [Kept] + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "PreserveDependencyMethodInNonReferencedAssemblyLibrary")] + static void Dependency () + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (PreserveDependencyMethodInNonReferencedAssemblyBase))] + class Foo : PreserveDependencyMethodInNonReferencedAssemblyBase { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssembly.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssembly.cs new file mode 100644 index 000000000..6a407e55a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssembly.cs @@ -0,0 +1,35 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + [SetupCompileBefore ("base.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs" })] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" }, references: new [] { "base.dll" }, addAsReference: false)] + [KeptAssembly ("base.dll")] + [RemovedAssembly ("library.dll")] + [KeptMemberInAssembly ("base.dll", typeof (PreserveDependencyMethodInNonReferencedAssemblyBase), "Method()")] + public class PreserveDependencyOnUnusedMethodInNonReferencedAssembly { + public static void Main () + { + var obj = new Foo (); + var val = obj.Method (); + } + + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "library")] + static void Dependency () + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (PreserveDependencyMethodInNonReferencedAssemblyBase))] + class Foo : PreserveDependencyMethodInNonReferencedAssemblyBase { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction.cs new file mode 100644 index 000000000..94ad0b56f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction.cs @@ -0,0 +1,19 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + [SetupLinkerUserAction ("copyused")] + [SetupCompileBefore ("library.dll", new [] {"Dependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib.cs"}, addAsReference: false)] + [RemovedAssembly ("library.dll")] + public class PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction { + public static void Main () + { + } + + [PreserveDependency ("MethodPreservedViaDependencyAttribute()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction_Lib", "library")] + static void Dependency () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs new file mode 100644 index 000000000..c9d61dfb0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/PreserveDependencies/PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs @@ -0,0 +1,43 @@ +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.PreserveDependencies { + /// <summary> + /// This test is here to ensure that link xml embedded in an assembly used by a [PreserveDependency] is not processed if the dependency is not used + /// </summary> + [IncludeBlacklistStep (true)] + [SetupCompileBefore ("base.dll", new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyBase.cs" })] + [SetupCompileBefore ( + "PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll", + new [] { "Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.cs" }, + references: new [] { "base.dll" }, + resources: new [] {"Dependencies/PreserveDependencyMethodInNonReferencedAssemblyLibrary.xml"}, + addAsReference: false)] + [KeptAssembly ("base.dll")] + [RemovedAssembly ("PreserveDependencyMethodInNonReferencedAssemblyLibrary.dll")] + public class PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml { + public static void Main () + { + var obj = new Foo (); + var val = obj.Method (); + } + + [PreserveDependency (".ctor()", "Mono.Linker.Tests.Cases.PreserveDependencies.Dependencies.PreserveDependencyMethodInNonReferencedAssemblyLibrary", "PreserveDependencyMethodInNonReferencedAssemblyLibrary")] + static void Dependency () + { + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (PreserveDependencyMethodInNonReferencedAssemblyBase))] + class Foo : PreserveDependencyMethodInNonReferencedAssemblyBase { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs b/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs new file mode 100644 index 000000000..47309dbba --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs @@ -0,0 +1,30 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Dependencies; + +namespace Mono.Linker.Tests.Cases.References { + /// <summary> + /// We can't detect the using usage in the assembly. As a result, nothing in `library` is going to be marked and that assembly will be deleted. + /// Because of that, `copied` needs to have it's reference to `library` removed even though we specified an assembly action of `copy` + /// </summary> + [SetupLinkerAction ("copy", "copied")] + [SetupLinkerArgument ("--keep-facades", "false")] + [SetupCompileBefore ("library.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Lib.cs"})] + + // When csc is used, `copied.dll` will have a reference to `library.dll` + [SetupCompileBefore ("copied.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Copied.cs"}, new [] {"library.dll"}, compilerToUse: "csc")] + + // Here to assert that the test is setup correctly to copy the copied assembly. This is an important aspect of the bug + [KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_Copied), "Unused()")] + + // We library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + [RemovedAssembly ("library.dll")] + [KeptReferencesInAssembly ("copied.dll", new [] {"mscorlib"})] + public class AssemblyOnlyUsedByUsingWithCsc { + public static void Main () + { + // Use something to keep the reference at compile time + AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCscWithKeepFacades.cs b/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCscWithKeepFacades.cs new file mode 100644 index 000000000..bf80d944f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCscWithKeepFacades.cs @@ -0,0 +1,32 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Dependencies; + +namespace Mono.Linker.Tests.Cases.References { + /// <summary> + /// We can't detect the using usage in the assembly. As a result, nothing in `library` is going to be marked and that assembly will be deleted. + /// Because of that, `copied` needs to have it's reference to `library` removed even though we specified an assembly action of `copy` + /// </summary> + [SetupLinkerAction ("copy", "copied")] + + // --keep-facades sends the sweep step down a different code path that caused problems for this corner case + [SetupLinkerArgument ("--keep-facades", "true")] + [SetupCompileBefore ("library.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Lib.cs"})] + + // When csc is used, `copied.dll` will have a reference to `library.dll` + [SetupCompileBefore ("copied.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Copied.cs"}, new [] {"library.dll"}, compilerToUse: "csc")] + + // Here to assert that the test is setup correctly to copy the copied assembly. This is an important aspect of the bug + [KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_Copied), "Unused()")] + + // We library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked + [RemovedAssembly ("library.dll")] + [KeptReferencesInAssembly ("copied.dll", new [] {"mscorlib"})] + public class AssemblyOnlyUsedByUsingWithCscWithKeepFacades { + public static void Main () + { + // Use something to keep the reference at compile time + AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithMcs.cs b/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithMcs.cs new file mode 100644 index 000000000..aae6e2773 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithMcs.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Dependencies; + +namespace Mono.Linker.Tests.Cases.References { + [SetupLinkerAction ("copy", "copied")] + [SetupCompileBefore ("library.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Lib.cs"})] + + // When mcs is used, `copied.dll` will not have a reference to `library.dll` + [SetupCompileBefore ("copied.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Copied.cs"}, new [] {"library.dll"}, compilerToUse: "mcs")] + + // Here to assert that the test is setup correctly to copy the copied assembly. This is an important aspect of the bug + [KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_Copied), "Unused()")] + + [RemovedAssembly ("library.dll")] + [KeptReferencesInAssembly ("copied.dll", new [] {"mscorlib"})] + public class AssemblyOnlyUsedByUsingWithMcs { + public static void Main () + { + // Use something to keep the reference at compile time + AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs b/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs new file mode 100644 index 000000000..31552b32c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs @@ -0,0 +1,16 @@ + +// This is what triggers the behavior difference between Roslyn and mcs. Roslyn will keep the reference +// to this assembly because of this whereas mcs will not +using ImportantForBug = Mono.Linker.Tests.Cases.References.Dependencies.AssemblyOnlyUsedByUsing_Lib; + +namespace Mono.Linker.Tests.Cases.References.Dependencies { + public class AssemblyOnlyUsedByUsing_Copied { + public static void UsedToKeepReference () + { + } + + private static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Lib.cs b/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Lib.cs new file mode 100644 index 000000000..7ec8becd0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Lib.cs @@ -0,0 +1,4 @@ +namespace Mono.Linker.Tests.Cases.References.Dependencies { + public class AssemblyOnlyUsedByUsing_Lib { + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/Dependencies/UserAssembliesAreLinkedByDefault_Library1.cs b/test/Mono.Linker.Tests.Cases/References/Dependencies/UserAssembliesAreLinkedByDefault_Library1.cs new file mode 100644 index 000000000..d8a45ab93 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/Dependencies/UserAssembliesAreLinkedByDefault_Library1.cs @@ -0,0 +1,15 @@ +using System; + +namespace Mono.Linker.Tests.Cases.References.Dependencies { + public class UserAssembliesAreLinkedByDefault_Library1 { + public void UsedMethod () + { + Console.WriteLine ("Used"); + } + + public void UnusedMethod () + { + Console.WriteLine ("NotUsed"); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/References/Individual/CanSkipUnresolved.cs b/test/Mono.Linker.Tests.Cases/References/Individual/CanSkipUnresolved.cs new file mode 100644 index 000000000..ec502e894 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/Individual/CanSkipUnresolved.cs @@ -0,0 +1,18 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Individual.Dependencies; + +namespace Mono.Linker.Tests.Cases.References.Individual { + [SetupCompileBefore ("library1.dll", new [] { "Dependencies/CanSkipUnresolved_Library.cs" })] + [SetupCompileAfter ("library1.dll", new [] { "Dependencies/CanSkipUnresolved_Library.cs" }, defines: new [] { "EXCLUDE_STUFF" })] + [SetupLinkerArgument ("--skip-unresolved", "true")] + public class CanSkipUnresolved { + static void Main () + { + var t1 = new CanSkipUnresolved_Library.TypeWithMissingMethod (); + t1.GoingToBeMissing (); + + var t2 = new CanSkipUnresolved_Library.TypeThatWillBeMissing (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/References/Individual/Dependencies/CanSkipUnresolved_Library.cs b/test/Mono.Linker.Tests.Cases/References/Individual/Dependencies/CanSkipUnresolved_Library.cs new file mode 100644 index 000000000..59e5cff44 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/Individual/Dependencies/CanSkipUnresolved_Library.cs @@ -0,0 +1,19 @@ +using System; + +namespace Mono.Linker.Tests.Cases.References.Individual.Dependencies { + public class CanSkipUnresolved_Library { + public class TypeWithMissingMethod { +#if !EXCLUDE_STUFF + public void GoingToBeMissing () + { + + } +#endif + } + +#if !EXCLUDE_STUFF + public class TypeThatWillBeMissing { + } +#endif + } +} diff --git a/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs b/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs new file mode 100644 index 000000000..5132208e1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/ReferencesAreRemovedWhenAllUsagesAreRemoved.cs @@ -0,0 +1,30 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.References { + [SetupLinkerCoreAction ("link")] + // Il8n & the blacklist step pollute the results with extra stuff that didn't need to be + // preserved for this test case so we need to disable them + [Il8n ("none")] + [Reference ("System.dll")] + [RemovedAssembly ("System.dll")] + [KeptReference ("mscorlib.dll")] + // Can be removed once this bug is fixed https://bugzilla.xamarin.com/show_bug.cgi?id=58168 + [SkipPeVerify(SkipPeVerifyForToolchian.Pedump)] + // System.Core.dll is referenced by System.dll in the .NET FW class libraries. Our GetType reflection marking code + // detects a GetType("SHA256CryptoServiceProvider") in System.dll, which then causes a type in System.Core.dll to be marked. + // PeVerify fails on the original GAC copy of System.Core.dll so it's expected that it will also fail on the stripped version we output + [SkipPeVerify ("System.Core.dll")] + class ReferencesAreRemovedWhenAllUsagesAreRemoved { + public static void Main () + { + } + + private static void Unused () + { + // Use something from System.dll so that we know the input assembly was compiled with the reference + var uri = new Uri ("w/e"); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/References/UserAssembliesAreLinkedByDefault.cs b/test/Mono.Linker.Tests.Cases/References/UserAssembliesAreLinkedByDefault.cs new file mode 100644 index 000000000..0c68e127c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/References/UserAssembliesAreLinkedByDefault.cs @@ -0,0 +1,18 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.References.Dependencies; + +namespace Mono.Linker.Tests.Cases.References { + [SetupCompileBefore ("library1.dll", new [] { "Dependencies/UserAssembliesAreLinkedByDefault_Library1.cs" })] + + [KeptAssembly ("library1.dll")] + [KeptMemberInAssembly ("library1.dll", typeof (UserAssembliesAreLinkedByDefault_Library1), "UsedMethod()")] + [RemovedMemberInAssembly ("library1.dll", typeof (UserAssembliesAreLinkedByDefault_Library1), "UnusedMethod()")] + class UserAssembliesAreLinkedByDefault { + public static void Main () + { + new UserAssembliesAreLinkedByDefault_Library1 ().UsedMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs new file mode 100644 index 000000000..147c31c60 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflection.cs @@ -0,0 +1,21 @@ +using System; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Reflection +{ + [IgnoreTestCase ("Requires support for using a type in an unreferences assembly via reflection")] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyDependency.cs" }, addAsReference: false)] + [KeptAssembly ("library.dll")] + [KeptTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency")] + public class AssemblyImportedViaReflection + { + public static void Main () + { + const string newAssemblyType = "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency, library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var res = Type.GetType (newAssemblyType, true); + return; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs new file mode 100644 index 000000000..5f4e8af1e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithDerivedType.cs @@ -0,0 +1,40 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Reflection.Dependencies; + +namespace Mono.Linker.Tests.Cases.Reflection +{ + [IgnoreTestCase ("Requires support for using a type in an unreferences assembly via reflection")] + [SetupCompileBefore ("base.dll", new [] { "Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs" })] + [SetupCompileBefore ("reflection.dll", new [] { "Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs" }, references: new [] {"base.dll"}, addAsReference: false)] + [KeptAssembly ("base.dll")] + [KeptAssembly ("reflection.dll")] + [KeptMemberInAssembly ("base.dll", typeof (AssemblyImportedViaReflectionWithDerivedType_Base), "Method()")] + [KeptMemberInAssembly ("reflection.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyImportedViaReflectionWithDerivedType_Reflect", "Method()")] + public class AssemblyImportedViaReflectionWithDerivedType + { + public static void Main () + { + // Cause a the new assembly to be included via reflection usage + const string newAssemblyType = "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyImportedViaReflectionWithDerivedType_Reflect, reflection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var res = Type.GetType (newAssemblyType, true); + + // Foo and the reflection assembly both have a class the inherits from the base type. + // by using `Method` here and marking the reflection type above, we've introduced a requirement that `Method` be marked on the type in the reflection assembly as well + var obj = new Foo (); + var val = obj.Method (); + } + + [Kept] + [KeptMember (".ctor()")] + [KeptBaseType (typeof (AssemblyImportedViaReflectionWithDerivedType_Base))] + class Foo : AssemblyImportedViaReflectionWithDerivedType_Base { + [Kept] + public override string Method () + { + return "Foo"; + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs new file mode 100644 index 000000000..716207d22 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithReference.cs @@ -0,0 +1,23 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Reflection +{ + [IgnoreTestCase ("Requires support for using a type in an unreferences assembly via reflection")] + [SetupCompileBefore ("reference.dll", new [] { "Dependencies/AssemblyDependency.cs" }, addAsReference: false)] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyDependencyWithReference.cs" }, references: new []{"reference.dll"}, addAsReference: false)] + [KeptAssembly ("reference.dll")] + [KeptAssembly ("library.dll")] + [KeptTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependencyWithReference")] + [KeptTypeInAssembly ("reference.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency")] + public class AssemblyImportedViaReflectionWithReference + { + public static void Main () + { + const string newAssemblyType = "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependencyWithReference, library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var res = Type.GetType (newAssemblyType, true); + return; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs new file mode 100644 index 000000000..16851b0cf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs @@ -0,0 +1,34 @@ +using System; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection +{ + public class ConstructorUsedViaReflection { + public static void Main () + { + var constructor = typeof (OnlyUsedViaReflection).GetConstructor (BindingFlags.Public, null, new Type[]{}, new ParameterModifier[]{}); + constructor.Invoke (null, new object[] { }); + } + + [Kept] + private class OnlyUsedViaReflection { + [Kept] + public OnlyUsedViaReflection () + { } + + [Kept] + public OnlyUsedViaReflection(string bar) + { } + + private OnlyUsedViaReflection (int foo) + { } + + protected OnlyUsedViaReflection(int foo, int bar) + { } + + internal OnlyUsedViaReflection(int foo, int bar, int baz) + { } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs new file mode 100644 index 000000000..84339ad4b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependency.cs @@ -0,0 +1,18 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Reflection.Dependencies +{ + public class AssemblyDependency + { + public AssemblyDependency () + { + } + + public static void UsedToKeepReferenceAtCompileTime () + { + } + + class TypeThatIsUsedViaReflection { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs new file mode 100644 index 000000000..889b5e141 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyDependencyWithReference.cs @@ -0,0 +1,4 @@ +namespace Mono.Linker.Tests.Cases.Reflection.Dependencies { + public class AssemblyDependencyWithReference : AssemblyDependency { + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs new file mode 100644 index 000000000..6323951ee --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Base.cs @@ -0,0 +1,5 @@ +namespace Mono.Linker.Tests.Cases.Reflection.Dependencies { + public abstract class AssemblyImportedViaReflectionWithDerivedType_Base { + public abstract string Method (); + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs new file mode 100644 index 000000000..e0c1bcb2a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/AssemblyImportedViaReflectionWithDerivedType_Reflect.cs @@ -0,0 +1,8 @@ +namespace Mono.Linker.Tests.Cases.Reflection.Dependencies { + public class AssemblyImportedViaReflectionWithDerivedType_Reflect : AssemblyImportedViaReflectionWithDerivedType_Base { + public override string Method () + { + return "Reflect"; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs new file mode 100644 index 000000000..774a46489 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs @@ -0,0 +1,18 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class EventUsedViaReflection { + public static void Main () + { + var eventInfo = typeof (EventUsedViaReflection).GetEvent ("Event"); + eventInfo.GetAddMethod (false); + } + + [Kept] + [KeptBackingField] + [KeptEventAddMethod] + [KeptEventRemoveMethod] + event EventHandler<EventArgs> Event; + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs new file mode 100644 index 000000000..c7c77abb5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs @@ -0,0 +1,15 @@ +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class FieldUsedViaReflection { + public static void Main () + { + var field = typeof (FieldUsedViaReflection).GetField ("field"); + field.GetValue (null); + } + + [Kept] + static int field; + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs new file mode 100644 index 000000000..39a7e12f4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class MethodUsedViaReflection { + public static void Main () + { + var method = typeof (MethodUsedViaReflection).GetMethod ("OnlyCalledViaReflection", BindingFlags.Static | BindingFlags.NonPublic); + method.Invoke (null, new object[] { }); + } + + [Kept] + private static int OnlyCalledViaReflection () + { + return 42; + } + + private int OnlyCalledViaReflection (int foo) + { + return 43; + } + + public int OnlyCalledViaReflection (int foo, int bar) + { + return 44; + } + + public static int OnlyCalledViaReflection (int foo, int bar, int baz) + { + return 45; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs new file mode 100644 index 000000000..7a2a4ae10 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflectionWithDefaultBindingFlags.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class MethodUsedViaReflectionWithDefaultBindingFlags { + public static void Main () + { + var method = typeof (MethodUsedViaReflectionWithDefaultBindingFlags).GetMethod ("OnlyCalledViaReflection"); + method.Invoke (null, new object[] { }); + } + + [Kept] + private static int OnlyCalledViaReflection () + { + return 42; + } + + [Kept] + private int OnlyCalledViaReflection (int foo) + { + return 43; + } + + [Kept] + public int OnlyCalledViaReflection (int foo, int bar) + { + return 44; + } + + [Kept] + public static int OnlyCalledViaReflection (int foo, int bar, int baz) + { + return 45; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs b/test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs new file mode 100644 index 000000000..b5b6a1c52 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/MightKeepExtraThings.cs @@ -0,0 +1,34 @@ +using System; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class MightKeepExtraThings { + public static void Main () + { + var typeA = typeof (A); + var typeB = typeof (B); + Console.WriteLine (typeB); // Use typeB so the C# compiler keeps it in the IL code. + var method = typeA.GetMethod ("Foo", BindingFlags.Public); + method.Invoke (null, new object[] { }); + } + + [Kept] + public class A { + [Kept] + public int Foo () + { + return 42; + } + } + + [Kept] + public class B { + [Kept] + public int Foo () + { + return 43; + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs new file mode 100644 index 000000000..2dc55aa2c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs @@ -0,0 +1,40 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class PropertyUsedViaReflection { + public static void Main () + { + var property = typeof (PropertyUsedViaReflection).GetProperty ("OnlyUsedViaReflection"); + property.GetValue (null, new object[] { }); + + property = typeof (PropertyUsedViaReflection).GetProperty ("SetterOnly"); + property.SetValue (null, 42, new object[] { }); + + property = typeof (PropertyUsedViaReflection).GetProperty ("GetterOnly"); + property.GetValue (null, new object[] { }); + } + + [Kept] + static int _field; + + [Kept] + static int OnlyUsedViaReflection { + [Kept] + get { return _field; } + [Kept] + set { _field = value; } + } + + [Kept] + static int SetterOnly { + [Kept] + set { _field = value; } + } + + [Kept] + static int GetterOnly { + [Kept] + get { return _field; } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs new file mode 100644 index 000000000..1fcef6673 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs @@ -0,0 +1,161 @@ +using System; +using System.Diagnostics; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class TypeUsedViaReflection { + public static void Main () + { + TestNull (); + TestEmptyString (); + TestFullString (); + TestGenericString (); + TestFullStringConst(); + TestTypeAsmName (); + TestType (); + TestPointer (); + TestReference (); + TestArray (); + TestArrayOfArray (); + TestMultiDimensionalArray (); + TestMultiDimensionalArrayFullString (); + TestMultiDimensionalArrayAsmName (); + } + + [Kept] + public static void TestNull () + { + string reflectionTypeKeptString = null; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public static void TestEmptyString () + { + string reflectionTypeKeptString = ""; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class Full { } + + [Kept] + public static void TestFullString () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Full, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class Generic<T> { } + + [Kept] + public static void TestGenericString () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Generic`1, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class FullConst { } + + [Kept] + public static void TestFullStringConst() + { + const string reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+FullConst, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var typeKept = Type.GetType(reflectionTypeKeptString, false); + } + + [Kept] + public class TypeAsmName { } + + [Kept] + public static void TestTypeAsmName () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+TypeAsmName, test"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class AType { } + + [Kept] + public static void TestType () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+AType"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class Pointer { } + + [Kept] + public static void TestPointer () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Pointer*"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class Reference { } + + [Kept] + public static void TestReference () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Reference&"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class Array { } + + [Kept] + public static void TestArray () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+Array[]"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class ArrayOfArray{ } + + [Kept] + public static void TestArrayOfArray () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+ArrayOfArray[][]"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + + [Kept] + public class MultiDimensionalArray{ } + + [Kept] + public static void TestMultiDimensionalArray () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+MultiDimensionalArray[,]"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class MultiDimensionalArrayFullString { } + + [Kept] + public static void TestMultiDimensionalArrayFullString () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+MultiDimensionalArrayFullString[,], test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + + [Kept] + public class MultiDimensionalArrayAsmName { } + + [Kept] + public static void TestMultiDimensionalArrayAsmName () + { + var reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+MultiDimensionalArrayAsmName[,], test"; + var typeKept = Type.GetType (reflectionTypeKeptString, false); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs new file mode 100644 index 000000000..1311ac46f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionAssemblyDoesntExist.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class TypeUsedViaReflectionAssemblyDoesntExist { + public static void Main () + { + var typeName = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionAssemblyDoesntExist+DoesntExist, test"; + var typeKept = Type.GetType (typeName, false); + } + + public class Full { } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs new file mode 100644 index 000000000..8df8ee25d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionInDifferentAssembly.cs @@ -0,0 +1,23 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Reflection.Dependencies; + +namespace Mono.Linker.Tests.Cases.Reflection { + [SetupCompileBefore ("library.dll", new [] { "Dependencies/AssemblyDependency.cs" })] + [KeptAssembly ("library.dll")] + [KeptTypeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency/TypeThatIsUsedViaReflection")] + public class TypeUsedViaReflectionInDifferentAssembly { + public static void Main () + { + AssemblyDependency.UsedToKeepReferenceAtCompileTime (); + Helper (); + } + + [Kept] + static Type Helper () + { + return Type.GetType ("Mono.Linker.Tests.Cases.Reflection.Dependencies.AssemblyDependency+TypeThatIsUsedViaReflection, library"); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs new file mode 100644 index 000000000..56c1077bf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrIncomplete.cs @@ -0,0 +1,24 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + /// <summary> + /// This case we can't detect and need to gracefully do nothing + /// </summary> + public class TypeUsedViaReflectionLdstrIncomplete { + public static void Main () + { + var typePart = GetTypePart (); + var assemblyPart = ",test"; + var typeKept = Type.GetType (string.Concat (typePart, assemblyPart), false); + } + + public class Full { } + + [Kept] + static string GetTypePart () + { + return "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionLdstrIncomplete+Full"; + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs new file mode 100644 index 000000000..c4e6b6a38 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionLdstrValidButChanged.cs @@ -0,0 +1,21 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection { + /// <summary> + /// We don't know if `typeName` will be changed or not. If we error on the side of caution and preserve something + /// that we found, I don't think that's a big deal + /// </summary> + public class TypeUsedViaReflectionLdstrValidButChanged { + public static void Main () + { + var replace = "Mono.Linker"; + var with = "Blah.Blah"; + var typeName = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionLdstrValidButChanged+Full, test"; + var typeKept = Type.GetType (typeName.Replace (replace, with), false); + } + + [Kept] + public class Full { } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs new file mode 100644 index 000000000..067d08739 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class TypeUsedViaReflectionTypeDoesntExist { + public static void Main () + { + var typeName = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflectionTypeDoesntExist+Full, DoesntExist"; + var typeKept = Type.GetType (typeName, false); + } + + public class Full { } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs new file mode 100644 index 000000000..70500994e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeNameIsSymbol.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Reflection { + public class TypeUsedViaReflectionTypeNameIsSymbol { + public static void Main () + { + var typeName = "+, test"; + var typeKept = Type.GetType (typeName, false); + } + + public class Full { } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs b/test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs new file mode 100644 index 000000000..e0f7edd79 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Reflection/UsedViaReflectionIntegrationTest.cs @@ -0,0 +1,64 @@ +using System; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Reflection +{ + public class UsedViaReflectionIntegrationTest + { + public static void Main () + { + var test = 42; + + var constructor = typeof (OnlyUsedViaReflection).GetConstructor (BindingFlags.Public, null, new Type [] { }, new ParameterModifier [] { }); + constructor.Invoke(null, new object[] { }); + + if (test == 42) { + var method = typeof (OnlyUsedViaReflection).GetMethod ("OnlyCalledViaReflection", BindingFlags.Static | BindingFlags.NonPublic); + method.Invoke (null, new object [] { }); + } + } + + [Kept] + private class OnlyUsedViaReflection + { + [Kept] + public OnlyUsedViaReflection () + { } + + [Kept] + public OnlyUsedViaReflection (string bar) + { } + + private OnlyUsedViaReflection (int foo) + { } + + protected OnlyUsedViaReflection (int foo, int bar) + { } + + internal OnlyUsedViaReflection (int foo, int bar, int baz) + { } + + [Kept] + private static int OnlyCalledViaReflection () + { + return 42; + } + + private int OnlyCalledViaReflection (int foo) + { + return 43; + } + + public int OnlyCalledViaReflection (int foo, int bar) + { + return 44; + } + + public static int OnlyCalledViaReflection (int foo, int bar, int baz) + { + return 45; + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.cs b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.cs new file mode 100644 index 000000000..e90010c7b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Resources.Dependencies { + public class EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1 { + public static void Used () + { + } + + public static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml new file mode 100644 index 000000000..6547ff296 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.Dependencies.EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1" preserve="all"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.cs b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.cs new file mode 100644 index 000000000..a1ca4d678 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Resources.Dependencies { + public class EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1 { + public static void Used () + { + } + + public static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml new file mode 100644 index 000000000..3ee976f4c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.Dependencies.EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1" preserve="all"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.cs b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.cs new file mode 100644 index 000000000..65e1ef600 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Resources.Dependencies { + public class EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1 { + public static void Used () + { + } + + public static void Unused () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml new file mode 100644 index 000000000..9f01cc0e1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml @@ -0,0 +1,6 @@ +<linker> + <assembly fullname="EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.Dependencies.EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1" preserve="all"> + </type> + </assembly> +</linker> diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.xml new file mode 100644 index 000000000..8494ad013 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly/Unused" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.xml new file mode 100644 index 000000000..11c0c1f42 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled/Unused" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml new file mode 100644 index 000000000..518addf3d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessed.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.EmbeddedLinkXmlFileIsProcessed/Unused" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessedAndKept.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessedAndKept.xml new file mode 100644 index 000000000..84d733343 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/EmbeddedLinkXmlFileIsProcessedAndKept.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + <type fullname="Mono.Linker.Tests.Cases.Resources.EmbeddedLinkXmlFileIsProcessedAndKept/Unused" /> + </assembly> +</linker>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/Dependencies/NonLinkerEmbeddedResourceHasNoImpact.xml b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/NonLinkerEmbeddedResourceHasNoImpact.xml new file mode 100644 index 000000000..1fb65aa9f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/Dependencies/NonLinkerEmbeddedResourceHasNoImpact.xml @@ -0,0 +1,2 @@ +<someotherxmlformat> +</someotherxmlformat>
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs new file mode 100644 index 000000000..05cb22124 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Resources.Dependencies; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupCompileBefore ( + "EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.dll", + new [] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.cs" }, + resources: new [] {"Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml"})] + [SetupLinkerAction ("copy", "EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1")] + [IncludeBlacklistStep (true)] + + [KeptResourceInAssembly ("EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.dll", "EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.xml")] + [KeptMemberInAssembly ("EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.dll", typeof (EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1), "Unused()")] + public class EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy { + public static void Main () + { + EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfActionIsCopy_Lib1.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs new file mode 100644 index 000000000..4259b1c58 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Resources.Dependencies; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupCompileBefore ( + "library.dll", + new [] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.cs" }, + resources: new [] {"Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml"})] + [IncludeBlacklistStep (true)] + + [KeptResourceInAssembly ("library.dll", "EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1_NotMatchingName.xml")] + [RemovedMemberInAssembly ("library.dll", typeof (EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1), "Unused()")] + public class EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly { + public static void Main () + { + EmbeddedLinkXmlFileInReferencedAssemblyIsNotProcessedIfNameDoesNotMatchAnAssembly_Lib1.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs new file mode 100644 index 000000000..8b477c037 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Resources.Dependencies; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupCompileBefore ( + "EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.dll", + new [] { "Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.cs" }, + resources: new [] {"Dependencies/EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml"})] + [SetupLinkerAction ("link", "EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1")] + [IncludeBlacklistStep (true)] + + [RemovedResourceInAssembly ("EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.dll", "EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.xml")] + [KeptMemberInAssembly ("EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.dll", typeof (EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1), "Unused()")] + public class EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink { + public static void Main () + { + EmbeddedLinkXmlFileInReferencedAssemblyIsProcessedIfActionIsLink_Lib1.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.cs new file mode 100644 index 000000000..69d1d1dc4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.cs @@ -0,0 +1,19 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupLinkerCoreAction ("link")] + [IncludeBlacklistStep (true)] + [SetupCompileResource ("Dependencies/EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly.xml", "NotMatchingAnAssemblyName.xml")] + [SkipPeVerify] + [KeptResource ("NotMatchingAnAssemblyName.xml")] + public class EmbeddedLinkXmlFileIsNotProcessedIfNameDoesNotMatchAnAssembly { + public static void Main () + { + } + + public class Unused { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.cs new file mode 100644 index 000000000..604520899 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.cs @@ -0,0 +1,21 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupLinkerCoreAction ("link")] + [IncludeBlacklistStep (false)] + + // We need to rename the resource so that it matches the name of an assembly being processed. This is a requriement of the black list step + [SetupCompileResource ("Dependencies/EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled.xml", "test.xml")] + [SkipPeVerify] + [KeptResource ("test.xml")] + public class EmbeddedLinkXmlFileIsNotProcessedWhenBlacklistStepIsDisabled { + public static void Main () + { + } + + public class Unused { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs new file mode 100644 index 000000000..c7a043aaf --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessed.cs @@ -0,0 +1,22 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupLinkerCoreAction ("link")] + [IncludeBlacklistStep (true)] + + // We need to rename the resource so that it matches the name of an assembly being processed. This is a requriement of the black list step + [SetupCompileResource ("Dependencies/EmbeddedLinkXmlFileIsProcessed.xml", "test.xml")] + [SkipPeVerify] + public class EmbeddedLinkXmlFileIsProcessed { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + public class Unused { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessedAndKept.cs b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessedAndKept.cs new file mode 100644 index 000000000..a6b25d31b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/EmbeddedLinkXmlFileIsProcessedAndKept.cs @@ -0,0 +1,25 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Resources +{ + [SetupLinkerCoreAction ("link")] + [IncludeBlacklistStep (true)] + [StripResources (false)] + + // We need to rename the resource so that it matches the name of an assembly being processed. This is a requriement of the black list step + [SetupCompileResource ("Dependencies/EmbeddedLinkXmlFileIsProcessedAndKept.xml", "test.xml")] + [SkipPeVerify] + [KeptResource ("test.xml")] + public class EmbeddedLinkXmlFileIsProcessedAndKept { + public static void Main () + { + } + + [Kept] + [KeptMember (".ctor()")] + public class Unused { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Resources/NonLinkerEmbeddedResourceHasNoImpact.cs b/test/Mono.Linker.Tests.Cases/Resources/NonLinkerEmbeddedResourceHasNoImpact.cs new file mode 100644 index 000000000..b2112b92f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Resources/NonLinkerEmbeddedResourceHasNoImpact.cs @@ -0,0 +1,18 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Resources { + [SetupLinkerCoreAction ("link")] + [IncludeBlacklistStep (true)] + + // We need to rename the resource so that it matches the name of an assembly being processed. This is a requriement of the black list step + [SetupCompileResource ("Dependencies/NonLinkerEmbeddedResourceHasNoImpact.xml", "test.xml")] + [SkipPeVerify] + [KeptResource ("test.xml")] + public class NonLinkerEmbeddedResourceHasNoImpact { + public static void Main () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Statics/DisableBeforeFieldInit/UnusedStaticFieldInitializer.cs b/test/Mono.Linker.Tests.Cases/Statics/DisableBeforeFieldInit/UnusedStaticFieldInitializer.cs new file mode 100644 index 000000000..a74d1a567 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/DisableBeforeFieldInit/UnusedStaticFieldInitializer.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Statics.DisableBeforeFieldInit +{ + [SetupLinkerArgument ("--disable-opt", "BeforeFieldInit")] + public class UnusedStaticFieldInitializer + { + public static void Main () + { + C.Foo (); + } + + [KeptMember (".cctor()")] + static class C + { + [Kept] + public static object o = new object (); + + [Kept] + public static void Foo () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Statics/ExplicitStaticCtor.cs b/test/Mono.Linker.Tests.Cases/Statics/ExplicitStaticCtor.cs new file mode 100644 index 000000000..5c1d85343 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/ExplicitStaticCtor.cs @@ -0,0 +1,48 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Statics +{ + [SetupCompileArgument ("/optimize+")] + public class ExplicitStaticCtor + { + public static void Main () + { + C.Foo (); + CEmpty.Foo (); + } + + static class C + { + [Kept] + static C () + { + new object (); + } + + [Kept] + public static void Foo () + { + } + } + + [AddedPseudoAttributeAttribute ((uint)TypeAttributes.BeforeFieldInit)] + static class CEmpty + { + static CEmpty () + { + } + + [Kept] + public static void Foo () + { + ++count; + } + + [Kept] + static int count; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Statics/MixedStaticFieldInitializerAndCtor.cs b/test/Mono.Linker.Tests.Cases/Statics/MixedStaticFieldInitializerAndCtor.cs new file mode 100644 index 000000000..da0a68714 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/MixedStaticFieldInitializerAndCtor.cs @@ -0,0 +1,28 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Statics +{ + public class MixedStaticFieldInitializerAndCtor + { + public static void Main () + { + C.Foo (); + } + + static class C + { + [Kept] + public static object o = new object (); + + [Kept] + static C () + { + } + + [Kept] + public static void Foo () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Statics/StaticFieldInitializer.cs b/test/Mono.Linker.Tests.Cases/Statics/StaticFieldInitializer.cs new file mode 100644 index 000000000..8e460e091 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/StaticFieldInitializer.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Statics +{ + public class StaticFieldInitializer + { + public static void Main () + { + C.Foo (); + } + + [KeptMember(".cctor()")] + static class C + { + [Kept] + public static object o = new object (); + + [Kept] + public static object Foo () + { + return o; + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticConstructorGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticConstructorGetsRemoved.cs new file mode 100644 index 000000000..83c1d1ea8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticConstructorGetsRemoved.cs @@ -0,0 +1,20 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Statics { + class UnusedStaticConstructorGetsRemoved { + public static void Main () + { + } + + static void Dead () + { + new B (); + } + + class B { + static B () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticFieldInitializer.cs b/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticFieldInitializer.cs new file mode 100644 index 000000000..5f0b96f77 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticFieldInitializer.cs @@ -0,0 +1,22 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Statics +{ + public class UnusedStaticFieldInitializer + { + public static void Main () + { + C.Foo (); + } + + static class C + { + public static object o = new object (); + + [Kept] + public static void Foo () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticMethodGetsRemoved.cs b/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticMethodGetsRemoved.cs new file mode 100644 index 000000000..31c7c6ef0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Statics/UnusedStaticMethodGetsRemoved.cs @@ -0,0 +1,23 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.Statics { + public class UnusedStaticMethodGetsRemoved { + public static void Main () + { + A.UsedMethod (); + } + } + + [Kept] + class A { + [Kept] + public static void UsedMethod () + { + } + + static void UnusedMethod () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/AssemblyWithDefaultSymbols.cs b/test/Mono.Linker.Tests.Cases/Symbols/AssemblyWithDefaultSymbols.cs new file mode 100644 index 000000000..eb8b2bb16 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/AssemblyWithDefaultSymbols.cs @@ -0,0 +1,15 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileArgument ("/debug:full")] + [SetupLinkerLinkSymbols ("false")] + [RemovedSymbols ("test.exe")] + public class AssemblyWithDefaultSymbols { + static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/AssemblyWithDefaultSymbolsAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/AssemblyWithDefaultSymbolsAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..b861f0eb8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/AssemblyWithDefaultSymbolsAndSymbolLinkingEnabled.cs @@ -0,0 +1,15 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileArgument ("/debug:full")] + [SetupLinkerLinkSymbols ("true")] + [KeptSymbols ("test.exe")] + public class AssemblyWithDefaultSymbolsAndSymbolLinkingEnabled { + static void Main () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithCompilerDefaultSymbols.cs b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithCompilerDefaultSymbols.cs new file mode 100644 index 000000000..38de58e93 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithCompilerDefaultSymbols.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Symbols.Dependencies { + public class LibraryWithCompilerDefaultSymbols { + public static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithEmbeddedPdbSymbols.cs b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithEmbeddedPdbSymbols.cs new file mode 100644 index 000000000..578d8bf36 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithEmbeddedPdbSymbols.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Symbols.Dependencies { + public class LibraryWithEmbeddedPdbSymbols { + public static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.cs b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.cs new file mode 100644 index 000000000..efb2d5481 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Symbols.Dependencies { + public class LibraryWithMdb { + public static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.dll b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.dll Binary files differnew file mode 100755 index 000000000..574071f27 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.dll diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb Binary files differnew file mode 100644 index 000000000..0a1dee3e7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/compile.sh b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/compile.sh new file mode 100755 index 000000000..023ed3cf7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithMdb/compile.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# Run this script from a VS command prompt + +BASEDIR=$(dirname $0) +mcs /debug:full /out:$BASEDIR/LibraryWithMdb.dll /target:library $BASEDIR/LibraryWithMdb.cs diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.cs b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.cs new file mode 100644 index 000000000..339c836fe --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.Symbols.Dependencies { + public class LibraryWithPdb { + public static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.dll b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.dll Binary files differnew file mode 100644 index 000000000..66b764d0c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.dll diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.pdb b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.pdb Binary files differnew file mode 100644 index 000000000..f18c63de2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/LibraryWithPdb.pdb diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/compile.bat b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/compile.bat new file mode 100644 index 000000000..8ffff2143 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPdb/compile.bat @@ -0,0 +1,5 @@ +@ECHO OFF + +REM Run this script from a VS command prompt + +csc /debug:full /out:%~dp0LibraryWithPdb.dll /target:library %~dp0LibraryWithPdb.cs diff --git a/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPortablePdbSymbols.cs b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPortablePdbSymbols.cs new file mode 100644 index 000000000..0c574f554 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/Dependencies/LibraryWithPortablePdbSymbols.cs @@ -0,0 +1,13 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Symbols.Dependencies { + public class LibraryWithPortablePdbSymbols { + public static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs new file mode 100644 index 000000000..d79b85df3 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdb.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + + [KeptMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "NotUsed()")] + class ReferenceWithEmbeddedPdb { + static void Main () + { + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..e99e5701b --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("true")] + + [KeptSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + + [KeptMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "NotUsed()")] + class ReferenceWithEmbeddedPdbAndSymbolLinkingEnabled { + static void Main () + { + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs new file mode 100644 index 000000000..d58ef3041 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyAction.cs @@ -0,0 +1,21 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("false")] + [SetupLinkerAction ("copy", "LibraryWithEmbeddedPdbSymbols")] + + [RemovedSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + + // Copying with symbol linking off is a little more complex for embedded pdbs. + // Do a little extra asserting here to make sure the assembly wasn't accidentally linked + [KeptMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "NotUsed()")] + public class ReferenceWithEmbeddedPdbCopyAction { + static void Main () + { + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..ca173f827 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("true")] + [SetupLinkerAction ("copy", "LibraryWithEmbeddedPdbSymbols")] + + [KeptSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + public class ReferenceWithEmbeddedPdbCopyActionAndSymbolLinkingEnabled { + static void Main () + { + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs new file mode 100644 index 000000000..ecbe6aa89 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteAction.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedAssembly ("LibraryWithEmbeddedPdbSymbols.dll")] + [RemovedSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + public class ReferenceWithEmbeddedPdbDeleteAction { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..d31e0753f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("true")] + + [RemovedAssembly ("LibraryWithEmbeddedPdbSymbols.dll")] + [RemovedSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + public class ReferenceWithEmbeddedPdbDeleteActionAndSymbolLinkingEnabled { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdb.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdb.cs new file mode 100644 index 000000000..657317dda --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdb.cs @@ -0,0 +1,33 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedSymbols ("LibraryWithMdb.dll")] + + [KeptMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "NotUsed()")] + public class ReferenceWithMdb { + static void Main() + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod (); + + LibraryWithMdb.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..5b6961974 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbAndSymbolLinkingEnabled.cs @@ -0,0 +1,33 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + [SetupLinkerLinkSymbols ("true")] + + [KeptSymbols ("LibraryWithMdb.dll")] + + [KeptMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "NotUsed()")] + public class ReferenceWithMdbAndSymbolLinkingEnabled { + static void Main () + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod (); + + LibraryWithMdb.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyAction.cs new file mode 100644 index 000000000..9be79875e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyAction.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + [SetupLinkerLinkSymbols ("false")] + [SetupLinkerAction ("copy", "LibraryWithMdb")] + + [RemovedSymbols ("LibraryWithMdb.dll")] + public class ReferenceWithMdbCopyAction { + static void Main () + { + LibraryWithMdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..6dcf76fa7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbCopyActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + [SetupLinkerLinkSymbols ("true")] + [SetupLinkerAction ("copy", "LibraryWithMdb")] + + [KeptSymbols ("LibraryWithMdb.dll")] + public class ReferenceWithMdbCopyActionAndSymbolLinkingEnabled { + static void Main () + { + LibraryWithMdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbDeleteAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbDeleteAction.cs new file mode 100644 index 000000000..7b8ce67d7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbDeleteAction.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedAssembly ("LibraryWithMdb.dll")] + [RemovedSymbols ("LibraryWithMdb.dll")] + public class ReferenceWithMdbDeleteAction { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithMdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbDeleteActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbDeleteActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..1f32f61ef --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithMdbDeleteActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + [SetupLinkerLinkSymbols ("true")] + + [RemovedAssembly ("LibraryWithMdb.dll")] + [RemovedSymbols ("LibraryWithMdb.dll")] + public class ReferenceWithMdbDeleteActionAndSymbolLinkingEnabled { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithMdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdb.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdb.cs new file mode 100644 index 000000000..fd51cdb07 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdb.cs @@ -0,0 +1,31 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedSymbols ("LibraryWithPdb.dll")] + + [KeptMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPdb.dll",typeof (LibraryWithPdb), "NotUsed()")] + public class ReferenceWithPdb { + static void Main () + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod (); + LibraryWithPdb.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..1749b2e69 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbAndSymbolLinkingEnabled.cs @@ -0,0 +1,35 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + [SetupLinkerLinkSymbols( "true")] + +#if WIN32 + [KeptSymbols ("LibraryWithPdb.dll")] +#else + [RemovedSymbols ("LibraryWithPdb.dll")] +#endif + [KeptMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "NotUsed()")] + class ReferenceWithPdbAndSymbolLinkingEnabled { + static void Main () + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod(); + LibraryWithPdb.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyAction.cs new file mode 100644 index 000000000..18e6c817a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyAction.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + [SetupLinkerLinkSymbols ("false")] + [SetupLinkerAction ("copy", "LibraryWithPdb")] + + [RemovedSymbols ("LibraryWithPdb.dll")] + public class ReferenceWithPdbCopyAction { + static void Main () + { + LibraryWithPdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..b67756bfb --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbCopyActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,18 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + [SetupLinkerLinkSymbols ("true")] + [SetupLinkerAction ("copy", "LibraryWithPdb")] + + [KeptSymbols ("LibraryWithPdb.dll")] + public class ReferenceWithPdbCopyActionAndSymbolLinkingEnabled { + static void Main () + { + LibraryWithPdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbDeleteAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbDeleteAction.cs new file mode 100644 index 000000000..8f5e037f8 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbDeleteAction.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedAssembly ("LibraryWithPdb.dll")] + [RemovedSymbols ("LibraryWithPdb.dll")] + public class ReferenceWithPdbDeleteAction { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithPdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbDeleteActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbDeleteActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..44b3df38c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPdbDeleteActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,25 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + [SetupLinkerLinkSymbols ("true")] + + [RemovedAssembly ("LibraryWithPdb.dll")] + [RemovedSymbols ("LibraryWithPdb.dll")] + public class ReferenceWithPdbDeleteActionAndSymbolLinkingEnabled { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithPdb.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs new file mode 100644 index 000000000..cb16c5dd1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdb.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedSymbols ("LibraryWithPortablePdbSymbols.dll")] + + [KeptMemberInAssembly("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "NotUsed()")] + class ReferenceWithPortablePdb { + static void Main () + { + LibraryWithPortablePdbSymbols.SomeMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..dd35d6abc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbAndSymbolLinkingEnabled.cs @@ -0,0 +1,20 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("true")] + + [KeptSymbols ("LibraryWithPortablePdbSymbols.dll")] + + [KeptMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "NotUsed()")] + class ReferenceWithPortablePdbAndSymbolLinkingEnabled { + static void Main() + { + LibraryWithPortablePdbSymbols.SomeMethod (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs new file mode 100644 index 000000000..2f4e428f2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyAction.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("false")] + [SetupLinkerAction ("copy", "LibraryWithPortablePdbSymbols")] + + [RemovedSymbols ("LibraryWithPortablePdbSymbols.dll")] + public class ReferenceWithPortablePdbCopyAction { + static void Main () + { + LibraryWithPortablePdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..292ed8bc0 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("true")] + [SetupLinkerAction ("copy", "LibraryWithPortablePdbSymbols")] + + [KeptSymbols ("LibraryWithPortablePdbSymbols.dll")] + public class ReferenceWithPortablePdbCopyActionAndSymbolLinkingEnabled { + static void Main () + { + LibraryWithPortablePdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs new file mode 100644 index 000000000..f9382472f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteAction.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedAssembly ("LibraryWithPortablePdbSymbols.dll")] + [RemovedSymbols ("LibraryWithPortablePdbSymbols.dll")] + public class ReferenceWithPortablePdbDeleteAction { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithPortablePdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..3ec76815f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +namespace Mono.Linker.Tests.Cases.Symbols { + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupLinkerLinkSymbols ("true")] + + [RemovedAssembly ("LibraryWithPortablePdbSymbols.dll")] + [RemovedSymbols ("LibraryWithPortablePdbSymbols.dll")] + public class ReferenceWithPortablePdbDeleteActionAndSymbolLinkingEnabled { + static void Main () + { + } + + /// <summary> + /// By not using this method we will cause the linker to delete the reference + /// </summary> + static void UnusedCodePath () + { + LibraryWithPortablePdbSymbols.SomeMethod (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs new file mode 100644 index 000000000..7ffcca41c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypes.cs @@ -0,0 +1,65 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + + [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: "/debug:full")] + [SetupCompileBefore("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + + [SetupCompileArgument ("/debug:full")] + [SetupLinkerLinkSymbols ("false")] + + [RemovedSymbols ("test.exe")] + [RemovedSymbols ("LibraryWithMdb.dll")] + [RemovedSymbols ("LibraryWithPdb.dll")] + [RemovedSymbols ("LibraryWithCompilerDefaultSymbols.dll")] + [RemovedSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + [RemovedSymbols ("LibraryWithPortablePdbSymbols.dll")] + + + [KeptMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithCompilerDefaultSymbols.dll", typeof (LibraryWithCompilerDefaultSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithCompilerDefaultSymbols.dll", typeof (LibraryWithCompilerDefaultSymbols), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof(LibraryWithEmbeddedPdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof(LibraryWithEmbeddedPdbSymbols), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "NotUsed()")] + public class ReferencesWithMixedSymbolTypes { + static void Main() + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod (); + LibraryWithCompilerDefaultSymbols.SomeMethod (); + LibraryWithPdb.SomeMethod (); + LibraryWithMdb.SomeMethod (); + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + LibraryWithPortablePdbSymbols.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs new file mode 100644 index 000000000..610752051 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Symbols/ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled.cs @@ -0,0 +1,69 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.Symbols.Dependencies; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.Symbols { + [Reference ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithMdb/LibraryWithMdb.dll.mdb")] + + [Reference ("Dependencies/LibraryWithPdb/LibraryWithPdb.dll")] + [ReferenceDependency ("Dependencies/LibraryWithPdb/LibraryWithPdb.pdb")] + + [SetupCompileBefore ("LibraryWithCompilerDefaultSymbols.dll", new[] { "Dependencies/LibraryWithCompilerDefaultSymbols.cs" }, additionalArguments: "/debug:full")] + [SetupCompileBefore ("LibraryWithPortablePdbSymbols.dll", new[] { "Dependencies/LibraryWithPortablePdbSymbols.cs" }, additionalArguments: "/debug:portable", compilerToUse: "csc")] + [SetupCompileBefore ("LibraryWithEmbeddedPdbSymbols.dll", new[] { "Dependencies/LibraryWithEmbeddedPdbSymbols.cs" }, additionalArguments: "/debug:embedded", compilerToUse: "csc")] + + [SetupCompileArgument ("/debug:full")] + [SetupLinkerLinkSymbols ("true")] + + [KeptSymbols ("test.exe")] + [KeptSymbols ("LibraryWithMdb.dll")] +#if WIN32 + [KeptSymbols ("LibraryWithPdb.dll")] +#else + [RemovedSymbols ("LibraryWithPdb.dll")] +#endif + [KeptSymbols ("LibraryWithCompilerDefaultSymbols.dll")] + [KeptSymbols ("LibraryWithEmbeddedPdbSymbols.dll")] + [KeptSymbols ("LibraryWithPortablePdbSymbols.dll")] + + + [KeptMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithMdb.dll", typeof (LibraryWithMdb), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPdb.dll", typeof (LibraryWithPdb), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithCompilerDefaultSymbols.dll", typeof (LibraryWithCompilerDefaultSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithCompilerDefaultSymbols.dll", typeof (LibraryWithCompilerDefaultSymbols), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithEmbeddedPdbSymbols.dll", typeof (LibraryWithEmbeddedPdbSymbols), "NotUsed()")] + + [KeptMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "SomeMethod()")] + [RemovedMemberInAssembly ("LibraryWithPortablePdbSymbols.dll", typeof (LibraryWithPortablePdbSymbols), "NotUsed()")] + public class ReferencesWithMixedSymbolTypesAndSymbolLinkingEnabled { + static void Main () + { + // Use some stuff so that we can verify that the linker output correct results + SomeMethod (); + LibraryWithCompilerDefaultSymbols.SomeMethod (); + LibraryWithPdb.SomeMethod (); + LibraryWithMdb.SomeMethod (); + LibraryWithEmbeddedPdbSymbols.SomeMethod (); + LibraryWithPortablePdbSymbols.SomeMethod (); + } + + [Kept] + static void SomeMethod () + { + } + + static void NotUsed () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCheckInitializersByIndex.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCheckInitializersByIndex.cs new file mode 100644 index 000000000..6f7747398 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCheckInitializersByIndex.cs @@ -0,0 +1,34 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.TestFramework { + public class CanCheckInitializersByIndex { + public static void Main () + { + Method1 (); + Method2 (); + } + + [Kept] + [KeptInitializerData (0)] + [KeptInitializerData (1)] + [KeptInitializerData (2)] + static void Method1 () + { + Helper (new [] {1, 2, 3}); + Helper (new [] {1, 2, 3, 4}); + Helper (new [] {3, 4, 5}); + } + + [Kept] + [KeptInitializerData (0)] + static void Method2 () + { + Helper(new [] {10, 11, 12}); + } + + [Kept] + static void Helper<T> (T [] arr) + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileILAssembly.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileILAssembly.cs new file mode 100644 index 000000000..2662e8f7d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileILAssembly.cs @@ -0,0 +1,19 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TestFramework +{ + [Define ("IL_ASSEMBLY_AVAILABLE")] + [SetupCompileBefore ("ILAssembly.dll", new [] { "Dependencies/ILAssemblySample.il" })] + [KeptMemberInAssembly ("ILAssembly.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.ILAssemblySample", "GiveMeAValue()")] + public class CanCompileILAssembly + { + static void Main () + { +#if IL_ASSEMBLY_AVAILABLE + Console.WriteLine (new Mono.Linker.Tests.Cases.TestFramework.Dependencies.ILAssemblySample ().GiveMeAValue ()); +#endif + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesUsingTypes.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesUsingTypes.cs new file mode 100644 index 000000000..0bcddb212 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesUsingTypes.cs @@ -0,0 +1,14 @@ +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileBefore ("library1.dll", new [] { typeof (CanCompileReferencesUsingTypes_LibSource1), typeof (CanCompileReferencesUsingTypes_LibSource2.Nested1.Nested2) })] + public class CanCompileReferencesUsingTypes { + public static void Main () + { + // Only the compile before assembly types are used because we wouldn't have access to the after types + CanCompileReferencesUsingTypes_LibSource1.MethodFromParentType (); + CanCompileReferencesUsingTypes_LibSource2.Nested1.Nested2.MethodFromNestedNested (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs new file mode 100644 index 000000000..c55e96a98 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResources.cs @@ -0,0 +1,24 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileBefore ("library.dll", + new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, + resources: new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" })] + + // Compile the same assembly again with another resource to get coverage on SetupCompileAfter + [SetupCompileAfter ("library.dll", + new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, + resources: new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" })] + + [KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.txt")] + [KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.log")] + public class CanCompileReferencesWithResources { + public static void Main () + { + // Use something so that reference isn't removed at compile time + CanCompileReferencesWithResources_Lib1.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs new file mode 100644 index 000000000..75e85d8b7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithCsc.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileBefore ("library.dll", + new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, + resources: new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" }, + compilerToUse: "csc")] + + // Compile the same assembly again with another resource to get coverage on SetupCompileAfter + [SetupCompileAfter ("library.dll", + new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, + resources: new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" }, + compilerToUse: "csc")] + + [KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.txt")] + [KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.log")] + public class CanCompileReferencesWithResourcesWithCsc { + public static void Main () + { + // Use something so that reference isn't removed at compile time + CanCompileReferencesWithResources_Lib1.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs new file mode 100644 index 000000000..42fa53931 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileReferencesWithResourcesWithMcs.cs @@ -0,0 +1,26 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileBefore ("library.dll", + new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, + resources: new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt" }, + compilerToUse: "mcs")] + + // Compile the same assembly again with another resource to get coverage on SetupCompileAfter + [SetupCompileAfter ("library.dll", + new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.cs" }, + resources: new [] { "Dependencies/CanCompileReferencesWithResources_Lib1.txt", "Dependencies/CanCompileReferencesWithResources_Lib1.log" }, + compilerToUse: "mcs")] + + [KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.txt")] + [KeptResourceInAssembly ("library.dll", "CanCompileReferencesWithResources_Lib1.log")] + public class CanCompileReferencesWithResourcesWithMcs { + public static void Main () + { + // Use something so that reference isn't removed at compile time + CanCompileReferencesWithResources_Lib1.Used (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithCsc.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithCsc.cs new file mode 100644 index 000000000..5ecaea8aa --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithCsc.cs @@ -0,0 +1,39 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCSharpCompilerToUse ("csc")] + + // Use all of the compiler setup attributes so that we can verify they all work + // when roslyn is used + [SetupCompileArgument ("/debug:portable")] + [SetupCompileResource ("Dependencies/CanCompileTestCaseWithCsc.txt")] + [Define ("VERIFY_DEFINE_WORKS")] + [Reference ("System.dll")] + + [SetupCompileBefore ("library.dll", new [] { "Dependencies/CanCompileTestCaseWithCsc_Lib.cs" }, compilerToUse: "csc")] + + [KeptResource ("CanCompileTestCaseWithCsc.txt")] + [KeptMemberInAssembly ("library.dll", typeof (CanCompileTestCaseWithCsc_Lib), "Used()")] + class CanCompileTestCaseWithCsc { + static void Main () + { +#if VERIFY_DEFINE_WORKS + UsedByDefine (); +#endif + // Use something from System.dll so that we can verify the reference attribute works + var timer = new System.Timers.Timer (); + + CanCompileTestCaseWithCsc_Lib.Used (); + } + + [Kept] + static void UsedByDefine () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithDebugPdbs.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithDebugPdbs.cs new file mode 100644 index 000000000..22e6525c1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithDebugPdbs.cs @@ -0,0 +1,25 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +// Because we compiled with debug information, this attribute should exist +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileArgument ("/debug:pdbonly")] + class CanCompileTestCaseWithDebugPdbs { + static void Main () + { + new Foo ().Method (); + } + + [Kept] + [KeptMember (".ctor()")] + class Foo { + [Kept] + public void Method () + { + } + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMsc.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMsc.cs new file mode 100644 index 000000000..7bafdc3d2 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanCompileTestCaseWithMsc.cs @@ -0,0 +1,39 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +[assembly: KeptAttributeAttribute (typeof (System.Diagnostics.DebuggableAttribute))] + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCSharpCompilerToUse ("mcs")] + + // Use all of the compiler setup attributes so that we can verify they all work + // when roslyn is used + [SetupCompileArgument ("/debug:pdbonly")] + [SetupCompileResource ("Dependencies/CanCompileTestCaseWithMcs.txt")] + [Define ("VERIFY_DEFINE_WORKS")] + [Reference ("System.dll")] + + [SetupCompileBefore ("library.dll", new[] { "Dependencies/CanCompileTestCaseWithMcs_Lib.cs" }, compilerToUse: "mcs")] + + [KeptResource ("CanCompileTestCaseWithMcs.txt")] + [KeptMemberInAssembly ("library.dll", typeof (CanCompileTestCaseWithMcs_Lib), "Used()")] + class CanCompileTestCaseWithMsc { + static void Main () + { +#if VERIFY_DEFINE_WORKS + UsedByDefine (); +#endif + // Use something from System.dll so that we can verify the reference attribute works + var timer = new System.Timers.Timer (); + + CanCompileTestCaseWithMcs_Lib.Used (); + } + + [Kept] + static void UsedByDefine () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanSandboxDependenciesUsingType.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanSandboxDependenciesUsingType.cs new file mode 100644 index 000000000..baa322be1 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanSandboxDependenciesUsingType.cs @@ -0,0 +1,14 @@ +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SandboxDependency (typeof (CanSandboxDependenciesUsingType_Source1))] + [SandboxDependency (typeof (CanSandboxDependenciesUsingType_Source2.Nested1.Nested2), "NameChanged.cs")] + public class CanSandboxDependenciesUsingType { + public static void Main () + { + CanSandboxDependenciesUsingType_Source1.Method (); + CanSandboxDependenciesUsingType_Source2.Nested1.Nested2.Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/CanVerifyInterfacesOnTypesInAssembly.cs b/test/Mono.Linker.Tests.Cases/TestFramework/CanVerifyInterfacesOnTypesInAssembly.cs new file mode 100644 index 000000000..964d5e779 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/CanVerifyInterfacesOnTypesInAssembly.cs @@ -0,0 +1,16 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileBefore ("library.dll", new [] {"Dependencies/CanVerifyInterfacesOnTypesInAssembly_Lib.cs"})] + [KeptInterfaceOnTypeInAssembly ("library", typeof (CanVerifyInterfacesOnTypesInAssembly_Lib.A), "library", typeof (CanVerifyInterfacesOnTypesInAssembly_Lib.IFoo))] + [RemovedInterfaceOnTypeInAssembly ("library", typeof (CanVerifyInterfacesOnTypesInAssembly_Lib.A), "library", typeof (CanVerifyInterfacesOnTypesInAssembly_Lib.IBar))] + public class CanVerifyInterfacesOnTypesInAssembly { + public static void Main () + { + CanVerifyInterfacesOnTypesInAssembly_Lib.IFoo a = new CanVerifyInterfacesOnTypesInAssembly_Lib.A (); + a.Foo (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesUsingTypes_LibSource1.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesUsingTypes_LibSource1.cs new file mode 100644 index 000000000..01e15ec32 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesUsingTypes_LibSource1.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class CanCompileReferencesUsingTypes_LibSource1 { + public static void MethodFromParentType () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesUsingTypes_LibSource2.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesUsingTypes_LibSource2.cs new file mode 100644 index 000000000..b9c983b77 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesUsingTypes_LibSource2.cs @@ -0,0 +1,11 @@ +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class CanCompileReferencesUsingTypes_LibSource2 { + public class Nested1 { + public class Nested2 { + public static void MethodFromNestedNested () + { + } + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.cs new file mode 100644 index 000000000..358cd3c42 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.cs @@ -0,0 +1,7 @@ +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class CanCompileReferencesWithResources_Lib1 { + public static void Used () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.log b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.log new file mode 100644 index 000000000..b27f91d6f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.log @@ -0,0 +1 @@ +Hello diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.txt b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.txt new file mode 100644 index 000000000..5ab2f8a43 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileReferencesWithResources_Lib1.txt @@ -0,0 +1 @@ +Hello
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithCsc.txt b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithCsc.txt new file mode 100644 index 000000000..540b7baa7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithCsc.txt @@ -0,0 +1 @@ +Resource that is kept
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithCsc_Lib.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithCsc_Lib.cs new file mode 100644 index 000000000..120b2d367 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithCsc_Lib.cs @@ -0,0 +1,9 @@ +using System; + +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class CanCompileTestCaseWithCsc_Lib { + public static void Used () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithMcs.txt b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithMcs.txt new file mode 100644 index 000000000..540b7baa7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithMcs.txt @@ -0,0 +1 @@ +Resource that is kept
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithMcs_Lib.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithMcs_Lib.cs new file mode 100644 index 000000000..09b05174c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanCompileTestCaseWithMcs_Lib.cs @@ -0,0 +1,9 @@ +using System; + +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class CanCompileTestCaseWithMcs_Lib { + public static void Used () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanSandboxDependenciesUsingType_Source1.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanSandboxDependenciesUsingType_Source1.cs new file mode 100644 index 000000000..ada073096 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanSandboxDependenciesUsingType_Source1.cs @@ -0,0 +1,11 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + [Kept] + public class CanSandboxDependenciesUsingType_Source1 { + [Kept] + public static void Method () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanSandboxDependenciesUsingType_Source2.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanSandboxDependenciesUsingType_Source2.cs new file mode 100644 index 000000000..2a730074f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanSandboxDependenciesUsingType_Source2.cs @@ -0,0 +1,17 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; + +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + [Kept] + public class CanSandboxDependenciesUsingType_Source2 { + [Kept] + public class Nested1 { + [Kept] + public class Nested2 { + [Kept] + public static void Method () + { + } + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanVerifyInterfacesOnTypesInAssembly_Lib.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanVerifyInterfacesOnTypesInAssembly_Lib.cs new file mode 100644 index 000000000..06aa2f050 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/CanVerifyInterfacesOnTypesInAssembly_Lib.cs @@ -0,0 +1,20 @@ +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class CanVerifyInterfacesOnTypesInAssembly_Lib { + public interface IFoo { + void Foo (); + } + public interface IBar { + void Bar (); + } + + public class A : IFoo, IBar { + public void Foo () + { + } + + public void Bar () + { + } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/ILAssemblySample.il b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/ILAssemblySample.il new file mode 100644 index 000000000..0060542bd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/ILAssemblySample.il @@ -0,0 +1,42 @@ +.assembly extern mscorlib +{ +} + +.assembly ILAssembly +{ + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} + +.module ILAssembly.dll + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit Mono.Linker.Tests.Cases.TestFramework.Dependencies.ILAssemblySample + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method ILAssemblySample::.ctor + + .method public hidebysig instance string + GiveMeAValue() cil managed + { + .maxstack 1 + .locals init (string V_0) + IL_0000: nop + IL_0001: ldstr "Bar" + IL_0006: stloc.0 + IL_0007: br IL_000c + + IL_000c: ldloc.0 + IL_000d: ret + } // end of method ILAssemblySample::GiveMeAValue + +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyAttributesInAssemblyWorks_Base.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyAttributesInAssemblyWorks_Base.cs new file mode 100644 index 000000000..92eb9ef8a --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyAttributesInAssemblyWorks_Base.cs @@ -0,0 +1,11 @@ +using System; + +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class VerifyAttributesInAssemblyWorks_Base { + public class ForAssertingKeptAttribute : Attribute { + } + + public class ForAssertingRemoveAttribute : Attribute { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyAttributesInAssemblyWorks_Lib.cs b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyAttributesInAssemblyWorks_Lib.cs new file mode 100644 index 000000000..57dd0c380 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyAttributesInAssemblyWorks_Lib.cs @@ -0,0 +1,37 @@ + +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +[assembly: VerifyAttributesInAssemblyWorks_Base.ForAssertingKept] +[assembly: VerifyAttributesInAssemblyWorks_Base.ForAssertingRemove] + +namespace Mono.Linker.Tests.Cases.TestFramework.Dependencies { + public class VerifyAttributesInAssemblyWorks_Lib { + [VerifyAttributesInAssemblyWorks_Base.ForAssertingKept] + public static class TypeWithKeptAttribute { + [VerifyAttributesInAssemblyWorks_Base.ForAssertingKept] + public static int Field; + + [VerifyAttributesInAssemblyWorks_Base.ForAssertingKept] + public static void Method () + { + } + + [VerifyAttributesInAssemblyWorks_Base.ForAssertingKept] + public static int Property { get; set; } + } + + [VerifyAttributesInAssemblyWorks_Base.ForAssertingRemove] + public class TypeWithRemovedAttribute { + [VerifyAttributesInAssemblyWorks_Base.ForAssertingRemove] + public static int Field; + + [VerifyAttributesInAssemblyWorks_Base.ForAssertingRemove] + public static void Method () + { + } + + [VerifyAttributesInAssemblyWorks_Base.ForAssertingRemove] + public static int Property { get; set; } + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyResourceInAssemblyAttributesBehavior.txt b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyResourceInAssemblyAttributesBehavior.txt new file mode 100644 index 000000000..540b7baa7 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/Dependencies/VerifyResourceInAssemblyAttributesBehavior.txt @@ -0,0 +1 @@ +Resource that is kept
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyAttributesInAssemblyWorks.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyAttributesInAssemblyWorks.cs new file mode 100644 index 000000000..ae450e2a5 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyAttributesInAssemblyWorks.cs @@ -0,0 +1,38 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupLinkerArgument ("--used-attrs-only", "true")] + // Put the attribute types in a different assembly than where we will assert since that is a more complex use case + [SetupCompileBefore ("base.dll", new [] { "Dependencies/VerifyAttributesInAssemblyWorks_Base.cs" })] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/VerifyAttributesInAssemblyWorks_Lib.cs" }, new [] { "base.dll" })] + + [KeptAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute))] + [KeptAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute))] + [KeptAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute), "Field")] + [KeptAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute), "Property")] + [KeptAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute), "Method()")] + + [RemovedAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingRemoveAttribute))] + [RemovedAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingRemoveAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute))] + [RemovedAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingRemoveAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute), "Field")] + [RemovedAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingRemoveAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute), "Property")] + [RemovedAttributeInAssembly ("library.dll", typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingRemoveAttribute), typeof (VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute), "Method()")] + public class VerifyAttributesInAssemblyWorks { + public static void Main () + { + // Use the attribute type we want to keep + var tmp = typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute).ToString (); + + // Now use the members of both types + VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute.Field = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute.Property = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute.Method (); + + VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute.Field = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute.Property = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute.Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyAttributesInAssemblyWorksWithStrings.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyAttributesInAssemblyWorksWithStrings.cs new file mode 100644 index 000000000..bf1e0f18f --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyAttributesInAssemblyWorksWithStrings.cs @@ -0,0 +1,38 @@ +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TestFramework.Dependencies; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupLinkerArgument ("--used-attrs-only", "true")] + // Put the attribute types in a different assembly than where we will assert since that is a more complex use case + [SetupCompileBefore ("base.dll", new [] { "Dependencies/VerifyAttributesInAssemblyWorks_Base.cs"} )] + [SetupCompileBefore ("library.dll", new [] { "Dependencies/VerifyAttributesInAssemblyWorks_Lib.cs"}, new [] { "base.dll" })] + + [KeptAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingKeptAttribute")] + [KeptAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingKeptAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithKeptAttribute")] + [KeptAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingKeptAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithKeptAttribute", "Field")] + [KeptAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingKeptAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithKeptAttribute", "Property")] + [KeptAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingKeptAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithKeptAttribute", "Method()")] + + [RemovedAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingRemoveAttribute")] + [RemovedAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingRemoveAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithRemovedAttribute")] + [RemovedAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingRemoveAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithRemovedAttribute", "Field")] + [RemovedAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingRemoveAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithRemovedAttribute", "Property")] + [RemovedAttributeInAssembly ("library.dll", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Base/ForAssertingRemoveAttribute", "Mono.Linker.Tests.Cases.TestFramework.Dependencies.VerifyAttributesInAssemblyWorks_Lib/TypeWithRemovedAttribute", "Method()")] + public class VerifyAttributesInAssemblyWorksWithStrings { + public static void Main () + { + // Use the attribute type we want to keep + var tmp = typeof (VerifyAttributesInAssemblyWorks_Base.ForAssertingKeptAttribute).ToString (); + + // Now use the members of both types + VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute.Field = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute.Property = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithKeptAttribute.Method (); + + VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute.Field = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute.Property = 1; + VerifyAttributesInAssemblyWorks_Lib.TypeWithRemovedAttribute.Method (); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyDefineAttributeBehavior.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyDefineAttributeBehavior.cs new file mode 100644 index 000000000..abe143042 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyDefineAttributeBehavior.cs @@ -0,0 +1,26 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TestFramework { + + /// <summary> + /// The purpose of this test is to verify that the testing framework's define attribute is working correctly + /// </summary> + [Define("SOME_DEFINE")] + public class VerifyDefineAttributeBehavior { + static void Main () + { +#if SOME_DEFINE + MethodThatIsUsedIfDefineIsWorkingProperly (); +#endif + } + + + [Kept] + static void MethodThatIsUsedIfDefineIsWorkingProperly () + { + Console.WriteLine ("Foo"); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs new file mode 100644 index 000000000..2cd46fc79 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyExpectModifiedAttributesWork.cs @@ -0,0 +1,85 @@ +using System; +using System.Diagnostics.Tracing; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TestFramework { + /// <summary> + /// This test is here to give some coverage to the attribute to ensure it doesn't break. We need to leverage the ETW feature since it is the only + /// one that modifies bodies currently + /// </summary> + [SetupLinkerArgument ("--exclude-feature", "etw")] + // Used to avoid different compilers generating different IL which can mess up the instruction asserts + [SetupCompileArgument ("/optimize+")] + public class VerifyExpectModifiedAttributesWork { + public static void Main () + { + var b = VerifyExpectModifiedAttributesWork_RemovedEventSource.Log.IsEnabled (); + if (b) + VerifyExpectModifiedAttributesWork_RemovedEventSource.Log.SomeMethod (); + } + + public class ClassForLocal { + } + + public static void CallsToForceALocal (int arg1, int arg2, int arg3) + { + } + } + + [Kept] + [KeptBaseType (typeof (EventSource))] + [KeptMember (".ctor()")] + [KeptMember (".cctor()")] + [EventSource (Name = "MyCompany")] + class VerifyExpectModifiedAttributesWork_RemovedEventSource : EventSource { + public class Keywords { + public const EventKeywords Page = (EventKeywords)1; + + public int Unused; + } + + [Kept] + public static VerifyExpectModifiedAttributesWork_RemovedEventSource Log = new VerifyExpectModifiedAttributesWork_RemovedEventSource (); + + [Kept] + [ExpectBodyModified] + [ExpectExceptionHandlersModified] + [ExpectLocalsModified] + protected override void OnEventCommand (EventCommandEventArgs command) + { + try { + // Do some extra stuff to be extra certain the compiler introduced a local instead of using `dup` + var tmp = new VerifyExpectModifiedAttributesWork.ClassForLocal (); + VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 3, 4); + VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 4, 4); + var hashcode = tmp.GetHashCode (); + VerifyExpectModifiedAttributesWork.CallsToForceALocal(1, hashcode, 3); + } catch { + try { + Removed (); + } catch { + var tmp = new VerifyExpectModifiedAttributesWork.ClassForLocal (); + VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 3, 4); + VerifyExpectModifiedAttributesWork.CallsToForceALocal (1, 4, 4); + var hashcode = tmp.GetHashCode (); + VerifyExpectModifiedAttributesWork.CallsToForceALocal(1, hashcode, 3); + throw; + } + throw; + } + } + + [Kept] + [Event (8)] + [ExpectBodyModified] + public void SomeMethod () + { + Removed (); + } + + public void Removed () + { + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TestFramework/VerifyResourceInAssemblyAttributesBehavior.cs b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyResourceInAssemblyAttributesBehavior.cs new file mode 100644 index 000000000..c54be7565 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TestFramework/VerifyResourceInAssemblyAttributesBehavior.cs @@ -0,0 +1,18 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TestFramework { + [SetupCompileResource ("Dependencies/VerifyResourceInAssemblyAttributesBehavior.txt")] + [KeptResource ("VerifyResourceInAssemblyAttributesBehavior.txt")] + // These are technically redundant, but the goal of this test is to verify the attributes are working which we can do + // by using them on the test case assembly even though you would normally use these attributes for other checking other + // supporting assemblies + [KeptResourceInAssembly ("test.exe", "VerifyResourceInAssemblyAttributesBehavior.txt")] + [RemovedResourceInAssembly ("test.exe", "NeverExistedResource.txt")] + public class VerifyResourceInAssemblyAttributesBehavior { + public static void Main () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanDumpDependenciesToUncompressedXml.cs b/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanDumpDependenciesToUncompressedXml.cs new file mode 100644 index 000000000..5e4d82e8e --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanDumpDependenciesToUncompressedXml.cs @@ -0,0 +1,13 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Tracing.Individual { + + [SetupLinkerArgument ("--dump-dependencies")] + [SetupLinkerArgument ("--dependencies-file", "linker-dependencies.xml")] + public class CanDumpDependenciesToUncompressedXml { + public static void Main () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanEnableDependenciesDump.cs b/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanEnableDependenciesDump.cs new file mode 100644 index 000000000..810023860 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanEnableDependenciesDump.cs @@ -0,0 +1,12 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Tracing.Individual { + + [SetupLinkerArgument ("--dump-dependencies")] + public class CanEnableDependenciesDump { + public static void Main () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanEnableReducedTracing.cs b/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanEnableReducedTracing.cs new file mode 100644 index 000000000..cc91dc1dc --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/Tracing/Individual/CanEnableReducedTracing.cs @@ -0,0 +1,16 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.Tracing.Individual { + + [SetupLinkerArgument ("--dump-dependencies")] + [SetupLinkerArgument ("--reduced-tracing", "true")] + + // Need to define a custom name so that the linker outputs in uncompressed format, which is more useful for making assertions + [SetupLinkerArgument ("--dependencies-file", "linker-dependencies.xml")] + public class CanEnableReducedTracing { + public static void Main () + { + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ForwarderLibrary.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ForwarderLibrary.cs new file mode 100644 index 000000000..bb1521525 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ForwarderLibrary.cs @@ -0,0 +1,3 @@ +using System; + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo (typeof (Mono.Linker.Tests.Cases.TypeForwarding.Dependencies.ImplementationLibrary))] diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ImplementationLibrary.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ImplementationLibrary.cs new file mode 100644 index 000000000..35c2252f4 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ImplementationLibrary.cs @@ -0,0 +1,14 @@ +using System; +using System.Reflection; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +[assembly: AssemblyVersion ("2.0")] + +namespace Mono.Linker.Tests.Cases.TypeForwarding.Dependencies { + public class ImplementationLibrary { + public string GetSomeValue () + { + return "Hello"; + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/LibraryUsingForwarder.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/LibraryUsingForwarder.cs new file mode 100644 index 000000000..97c728e7d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/LibraryUsingForwarder.cs @@ -0,0 +1,12 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TypeForwarding.Dependencies { + [NotATestCase] + public class LibraryUsingForwarder { + public string GetValueFromOtherAssembly () + { + return new ImplementationLibrary ().GetSomeValue (); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ReferenceImplementationLibrary.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ReferenceImplementationLibrary.cs new file mode 100644 index 000000000..00bb1e30c --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/ReferenceImplementationLibrary.cs @@ -0,0 +1,17 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TypeForwarding.Dependencies { + [NotATestCase] + public class ReferenceImplementationLibrary { + } + +#if INCLUDE_REFERENCE_IMPL + public class ImplementationLibrary { + public string GetSomeValue () + { + return null; + } + } +#endif +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/TypeForwarderMissingReference.il b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/TypeForwarderMissingReference.il new file mode 100644 index 000000000..0f8a1e93d --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/Dependencies/TypeForwarderMissingReference.il @@ -0,0 +1,37 @@ +.assembly extern mscorlib +{ +} +.assembly extern 'missing-reference' +{ + .ver 0:0:0:0 +} + +.assembly 'TypeForwarderMissingReference' +{ + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} + +.class extern forwarder C +{ + .assembly extern 'missing-reference' +} +.class extern forwarder G`1 +{ + .assembly extern 'missing-reference' +} + +.module 'TypeForwarderMissingReference.dll' + + +.class public auto ansi beforefieldinit DummyClass + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/MissingTargetReference.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/MissingTargetReference.cs new file mode 100644 index 000000000..5e8b11571 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/MissingTargetReference.cs @@ -0,0 +1,24 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.TypeForwarding +{ + [SkipUnresolved (true)] + [Define ("IL_ASSEMBLY_AVAILABLE")] + [SetupCompileBefore ("TypeForwarderMissingReference.dll", new [] { "Dependencies/TypeForwarderMissingReference.il" })] + [SetupLinkerAction ("link", "TypeForwarderMissingReference.dll")] + + [KeptMemberInAssembly ("TypeForwarderMissingReference.dll", "DummyClass", ".ctor()")] + [RemovedForwarder ("TypeForwarderMissingReference.dll", "C")] + [RemovedForwarder ("TypeForwarderMissingReference.dll", "G<>")] + public class MissingTargetReference + { + public static void Main () + { +#if IL_ASSEMBLY_AVAILABLE + Console.WriteLine (new DummyClass ()); +#endif + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesKept.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesKept.cs new file mode 100644 index 000000000..e8a41a259 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesKept.cs @@ -0,0 +1,26 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TypeForwarding.Dependencies; + +namespace Mono.Linker.Tests.Cases.TypeForwarding { + [KeepTypeForwarderOnlyAssemblies ("true")] + [SetupCompileBefore ("Forwarder.dll", new[] { "Dependencies/ReferenceImplementationLibrary.cs" }, defines: new[] { "INCLUDE_REFERENCE_IMPL" })] + // Add another assembly in that uses the forwarder just to make things a little more complex + [SetupCompileBefore ("Library.dll", new[] { "Dependencies/LibraryUsingForwarder.cs" }, references: new[] { "Forwarder.dll" })] + + // After compiling the test case we then replace the reference impl with implementation + type forwarder + [SetupCompileAfter ("Implementation.dll", new[] { "Dependencies/ImplementationLibrary.cs" })] + [SetupCompileAfter ("Forwarder.dll", new[] { "Dependencies/ForwarderLibrary.cs" }, references: new[] { "Implementation.dll" })] + + [KeptAssembly ("Forwarder.dll")] + [KeptMemberInAssembly ("Library.dll", typeof (LibraryUsingForwarder), "GetValueFromOtherAssembly()")] + [KeptMemberInAssembly ("Implementation.dll", typeof (ImplementationLibrary), "GetSomeValue()")] + public class TypeForwarderOnlyAssembliesKept { + public static void Main () + { + Console.WriteLine (new ImplementationLibrary ().GetSomeValue ()); + Console.WriteLine (new LibraryUsingForwarder ().GetValueFromOtherAssembly ()); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesRemoved.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesRemoved.cs new file mode 100644 index 000000000..91ddd58ee --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssembliesRemoved.cs @@ -0,0 +1,27 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TypeForwarding.Dependencies; + +namespace Mono.Linker.Tests.Cases.TypeForwarding +{ + [KeepTypeForwarderOnlyAssemblies ("false")] + [SetupCompileBefore ("Forwarder.dll", new[] { "Dependencies/ReferenceImplementationLibrary.cs" }, defines: new[] { "INCLUDE_REFERENCE_IMPL" })] + // Add another assembly in that uses the forwarder just to make things a little more complex + [SetupCompileBefore ("Library.dll", new[] { "Dependencies/LibraryUsingForwarder.cs" }, references: new[] { "Forwarder.dll" })] + + // After compiling the test case we then replace the reference impl with implementation + type forwarder + [SetupCompileAfter ("Implementation.dll", new[] { "Dependencies/ImplementationLibrary.cs" })] + [SetupCompileAfter ("Forwarder.dll", new[] { "Dependencies/ForwarderLibrary.cs" }, references: new[] { "Implementation.dll" })] + + [RemovedAssembly ("Forwarder.dll")] + [KeptMemberInAssembly ("Implementation.dll", typeof (ImplementationLibrary), "GetSomeValue()")] + [KeptMemberInAssembly ("Library.dll", typeof (LibraryUsingForwarder), "GetValueFromOtherAssembly()")] + class TypeForwarderOnlyAssembliesRemoved { + static void Main() + { + Console.WriteLine (new ImplementationLibrary ().GetSomeValue ()); + Console.WriteLine (new LibraryUsingForwarder ().GetValueFromOtherAssembly ()); + } + } +} diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.cs b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.cs new file mode 100644 index 000000000..95a0ad138 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.cs @@ -0,0 +1,28 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; +using Mono.Linker.Tests.Cases.TypeForwarding.Dependencies; + +namespace Mono.Linker.Tests.Cases.TypeForwarding { + [KeepTypeForwarderOnlyAssemblies ("false")] + [SetupCompileBefore ("Forwarder.dll", new[] { "Dependencies/ReferenceImplementationLibrary.cs" }, defines: new[] { "INCLUDE_REFERENCE_IMPL" })] + // Add another assembly in that uses the forwarder just to make things a little more complex + [SetupCompileBefore ("Library.dll", new[] { "Dependencies/LibraryUsingForwarder.cs" }, references: new[] { "Forwarder.dll" })] + + // After compiling the test case we then replace the reference impl with implementation + type forwarder + [SetupCompileAfter ("Implementation.dll", new[] { "Dependencies/ImplementationLibrary.cs" })] + [SetupCompileAfter ("Forwarder.dll", new[] { "Dependencies/ForwarderLibrary.cs" }, references: new[] { "Implementation.dll" })] + + [KeptAssembly ("Forwarder.dll")] + [KeptMemberInAssembly ("Implementation.dll", typeof (ImplementationLibrary), "GetSomeValue()")] + [KeptMemberInAssembly ("Library.dll", typeof (LibraryUsingForwarder), "GetValueFromOtherAssembly()")] + + [KeptTypeInAssembly("Forwarder.dll", typeof (ImplementationLibrary))] + public class TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml { + static void Main() + { + Console.WriteLine (new ImplementationLibrary ().GetSomeValue ()); + Console.WriteLine (new LibraryUsingForwarder ().GetValueFromOtherAssembly ()); + } + } +}
\ No newline at end of file diff --git a/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.xml b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.xml new file mode 100644 index 000000000..28d5c08cd --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/TypeForwarding/TypeForwarderOnlyAssemblyCanBePreservedViaLinkXml.xml @@ -0,0 +1,4 @@ +<linker> + <assembly fullname="Forwarder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> + </assembly> +</linker>
\ No newline at end of file |