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

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Boemer <sbomer@gmail.com>2021-11-16 20:21:59 +0300
committerSven Boemer <sbomer@gmail.com>2021-11-16 20:39:54 +0300
commita556862ea401d080a2b9dab1615f3e8cc8892026 (patch)
tree467a67802e4519e8250c9eb650ee7e19b25c28cb /test/Mono.Linker.Tests.Cases/Reflection
parent2aed9937115a6bd5a81e37658431272ce4be3317 (diff)
parent53c5d48842fe53e05272d163c7f49e54ddcb4b37 (diff)
Merge remote-tracking branch 'origin/main' into updateFromMain
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/Reflection')
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs32
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs19
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs47
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs26
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs21
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs26
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs49
7 files changed, 212 insertions, 8 deletions
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
index ba33cdc4e..5f93cf879 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
@@ -17,6 +17,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestNameBindingFlags ();
TestNameWrongBindingFlags ();
TestNameUnknownBindingFlags (BindingFlags.Public);
+ TestNameUnknownBindingFlagsAndName (BindingFlags.Public, "DoesntMatter");
TestNullName ();
TestEmptyName ();
TestNonExistingName ();
@@ -72,6 +73,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ static void TestNameUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
+ {
+ // Since the binding flags are not known linker should mark all events on the type
+ var eventInfo = typeof (UnknownBindingFlagsAndName).GetEvent (name, bindingFlags);
+ }
+
+ [Kept]
static void TestNullName ()
{
var eventInfo = typeof (EventUsedViaReflection).GetEvent (null);
@@ -221,6 +229,30 @@ namespace Mono.Linker.Tests.Cases.Reflection
public event EventHandler<EventArgs> PublicEvent;
}
+ class UnknownBindingFlagsAndName
+ {
+ [Kept]
+ [KeptEventAddMethod]
+ [KeptEventRemoveMethod]
+ [method: ExpectBodyModified]
+ internal event EventHandler<EventArgs> InternalEvent;
+ [Kept]
+ [KeptBackingField]
+ [KeptEventAddMethod]
+ [KeptEventRemoveMethod]
+ static event EventHandler<EventArgs> Static;
+ [Kept]
+ [KeptEventAddMethod]
+ [KeptEventRemoveMethod]
+ [method: ExpectBodyModified]
+ private event EventHandler<EventArgs> PrivateEvent;
+ [Kept]
+ [KeptEventAddMethod]
+ [KeptEventRemoveMethod]
+ [method: ExpectBodyModified]
+ public event EventHandler<EventArgs> PublicEvent;
+ }
+
class IfClass
{
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
index 7d7fc22d3..94535adb1 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
@@ -15,6 +15,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestNameBindingFlags ();
TestNameWrongBindingFlags ();
TestNameUnknownBindingFlags (BindingFlags.Public);
+ TestNameUnknownBindingFlagsAndName (BindingFlags.Public, "DoesntMatter");
TestNullName ();
TestEmptyName ();
TestNonExistingName ();
@@ -67,6 +68,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ static void TestNameUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
+ {
+ // Since the binding flags and name are not known linker should mark all fields on the type
+ var field = typeof (UnknownBindingFlagsAndName).GetField (name, bindingFlags);
+ }
+
+ [Kept]
static void TestNullName ()
{
var field = typeof (FieldUsedViaReflection).GetField (null);
@@ -187,6 +195,17 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ private class UnknownBindingFlagsAndName
+ {
+ [Kept]
+ public static int field;
+ [Kept]
+ public int nonStatic;
+ [Kept]
+ private static int privatefield;
+ }
+
+ [Kept]
private class IfClass
{
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
index 18e70c058..bff3994a2 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
@@ -17,6 +17,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
GetMethod_Name_Types.TestNameAndType ();
GetMethod_Name_BindingAttr.TestExplicitBindingFlags ();
GetMethod_Name_BindingAttr.TestUnknownBindingFlags (BindingFlags.Public);
+ GetMethod_Name_BindingAttr.TestUnknownBindingFlagsAndName (BindingFlags.Public, "DoesntMatter");
GetMethod_Name_BindingAttr.TestUnknownNullBindingFlags (BindingFlags.Public);
GetMethod_Name_BindingAttr_Binder_Types_Modifiers.TestNameBindingFlagsAndParameterModifier ();
GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers.TestNameBindingFlagsCallingConventionParameterModifier ();
@@ -37,6 +38,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
DerivedAndBase.TestMethodInBaseType ();
IgnoreCaseBindingFlags.TestIgnoreCaseBindingFlags ();
FailIgnoreCaseBindingFlags.TestFailIgnoreCaseBindingFlags ();
+ IgnorableBindingFlags.TestIgnorableBindingFlags ();
UnsupportedBindingFlags.TestUnsupportedBindingFlags ();
}
@@ -200,6 +202,25 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ class UnknownBindingFlagsAndName
+ {
+ [Kept]
+ private static int OnlyCalledViaReflection ()
+ {
+ return 42;
+ }
+ }
+
+ [Kept]
+ [RecognizedReflectionAccessPattern]
+ public static void TestUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
+ {
+ // Since the binding flags and name are not known linker should mark all methods on the type
+ var method = typeof (UnknownBindingFlagsAndName).GetMethod (name, bindingFlags);
+ method.Invoke (null, new object[] { });
+ }
+
+ [Kept]
private class NullBindingFlags
{
[Kept]
@@ -732,6 +753,28 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ class IgnorableBindingFlags
+ {
+ [Kept]
+ public int OnlyCalledViaReflection ()
+ {
+ return 54;
+ }
+
+ private bool Unmarked ()
+ {
+ return true;
+ }
+
+ [Kept]
+ public static void TestIgnorableBindingFlags ()
+ {
+ var method = typeof (IgnorableBindingFlags).GetMethod ("OnlyCalledViaReflection", BindingFlags.Public | BindingFlags.InvokeMethod);
+ method.Invoke (null, new object[] { });
+ }
+ }
+
+ [Kept]
class UnsupportedBindingFlags
{
[Kept]
@@ -741,7 +784,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- private bool MarkedDueToInvokeMethod ()
+ private bool MarkedDueToChangeType ()
{
return true;
}
@@ -749,7 +792,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
[Kept]
public static void TestUnsupportedBindingFlags ()
{
- var method = typeof (UnsupportedBindingFlags).GetMethod ("OnlyCalledViaReflection", BindingFlags.InvokeMethod);
+ var method = typeof (UnsupportedBindingFlags).GetMethod ("OnlyCalledViaReflection", BindingFlags.Public | BindingFlags.SuppressChangeType);
method.Invoke (null, new object[] { });
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
index 9fdbf389a..5658a1a99 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
@@ -22,6 +22,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestDataFlowWithAnnotation (typeof (MyType));
TestIfElse (1);
TestIgnoreCaseBindingFlags ();
+ TestIgnorableBindingFlags ();
TestUnsupportedBindingFlags ();
}
@@ -100,9 +101,15 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ static void TestIgnorableBindingFlags ()
+ {
+ var methods = typeof (InvokeMethodClass).GetMethods (BindingFlags.Public | BindingFlags.InvokeMethod);
+ }
+
+ [Kept]
static void TestUnsupportedBindingFlags ()
{
- var methods = typeof (InvokeMethodClass).GetMethods (BindingFlags.InvokeMethod);
+ var methods = typeof (SuppressChangeTypeClass).GetMethods (BindingFlags.Public | BindingFlags.SuppressChangeType);
}
[Kept]
@@ -287,8 +294,23 @@ namespace Mono.Linker.Tests.Cases.Reflection
return 54;
}
+ private bool Unmarked ()
+ {
+ return true;
+ }
+ }
+
+ [Kept]
+ private class SuppressChangeTypeClass
+ {
+ [Kept]
+ public int OnlyCalledViaReflection ()
+ {
+ return 54;
+ }
+
[Kept]
- private bool MarkedDueToInvokeMethod ()
+ private bool MarkedDueToSuppressChangeType ()
{
return true;
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
index cda87ee85..2700a8793 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
@@ -16,6 +16,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestPrivateByName ();
TestByBindingFlags ();
TestByUnknownBindingFlags (BindingFlags.Public);
+ TestByUnknownBindingFlagsAndName (BindingFlags.Public, "DoesntMatter");
TestNonExistingName ();
TestNullType ();
TestIgnoreCaseBindingFlags ();
@@ -81,6 +82,16 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ [RecognizedReflectionAccessPattern (
+ typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
+ typeof (UnknownBindingFlagsAndName.PublicNestedType), null, (Type[]) null)]
+ static void TestByUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
+ {
+ // Since the binding flags and name are not known linker should mark all nested types on the type
+ _ = typeof (UnknownBindingFlagsAndName).GetNestedType (name, bindingFlags);
+ }
+
+ [Kept]
static void TestNonExistingName ()
{
_ = typeof (NestedTypeUsedViaReflection).GetNestedType ("NonExisting");
@@ -125,6 +136,16 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ private class UnknownBindingFlagsAndName
+ {
+ [Kept]
+ public static class PublicNestedType { }
+
+ [Kept]
+ private static class PrivateNestedType { }
+ }
+
+ [Kept]
private class IgnoreCaseClass
{
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
index a7b7dbea8..4f8346b7c 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
@@ -23,6 +23,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestDataFlowWithAnnotation (typeof (MyType));
TestIfElse (1);
TestIgnoreCaseBindingFlags ();
+ TestIgnorableBindingFlags ();
TestUnsupportedBindingFlags ();
}
@@ -107,9 +108,16 @@ namespace Mono.Linker.Tests.Cases.Reflection
[Kept]
[RecognizedReflectionAccessPattern]
+ static void TestIgnorableBindingFlags ()
+ {
+ var properties = typeof (ExactBindingBindingFlagsClass).GetProperties (BindingFlags.Public | BindingFlags.ExactBinding);
+ }
+
+ [Kept]
+ [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
- var properties = typeof (ExactBindingBindingFlagsClass).GetProperties (BindingFlags.ExactBinding);
+ var properties = typeof (ChangeTypeBindingFlagsClass).GetProperties (BindingFlags.Public | BindingFlags.SuppressChangeType);
}
[Kept]
@@ -256,8 +264,22 @@ namespace Mono.Linker.Tests.Cases.Reflection
set { _field = value; }
}
+ private static int Unmarked {
+ get { return _field; }
+ }
+ }
+
+ [Kept]
+ class ChangeTypeBindingFlagsClass
+ {
+ [Kept]
+ public static int SetterOnly {
+ [Kept]
+ set { _field = value; }
+ }
+
[Kept]
- private static int MarkedDueToExactBinding {
+ private static int KeptDueToChangeType {
[Kept]
get { return _field; }
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
index 3971f9108..4004e894b 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
@@ -17,6 +17,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestGetterOnly ();
TestBindingFlags ();
TestUnknownBindingFlags (BindingFlags.Public);
+ TestUnknownBindingFlagsAndName (BindingFlags.Public, "IrrelevantName");
TestNullName ();
TestEmptyName ();
TestNonExistingName ();
@@ -27,6 +28,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestPropertyInBaseType ();
TestIgnoreCaseBindingFlags ();
TestFailIgnoreCaseBindingFlags ();
+ TestIgnorableBindingFlags ();
TestUnsupportedBindingFlags ();
}
@@ -90,6 +92,17 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ [RecognizedReflectionAccessPattern (
+ typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
+ typeof (UnknownBindingFlagsAndName), nameof (UnknownBindingFlagsAndName.SomeProperty), (Type[]) null)]
+ static void TestUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
+ {
+ // Since the binding flags and name are not known linker should mark all properties on the type
+ var property = typeof (UnknownBindingFlagsAndName).GetProperty (name, bindingFlags);
+ property.GetValue (null, new object[] { });
+ }
+
+ [Kept]
static void TestNullName ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty (null);
@@ -194,9 +207,15 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ static void TestIgnorableBindingFlags ()
+ {
+ var property = typeof (ExactBindingBindingFlagsClass).GetProperty ("SetterOnly", BindingFlags.Public | BindingFlags.ExactBinding);
+ }
+
+ [Kept]
static void TestUnsupportedBindingFlags ()
{
- var property = typeof (ExactBindingBindingFlagsClass).GetProperty ("SetterOnly", BindingFlags.ExactBinding);
+ var property = typeof (ChangeTypeBindingFlagsClass).GetProperty ("SetterOnly", BindingFlags.Public | BindingFlags.SuppressChangeType);
}
[Kept]
@@ -314,6 +333,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ class UnknownBindingFlagsAndName
+ {
+ [Kept]
+ internal static int SomeProperty {
+ [Kept]
+ private get { return _field; }
+ [Kept]
+ set { _field = value; }
+ }
+ }
+
+ [Kept]
class IgnoreCaseBindingFlagsClass
{
[Kept]
@@ -346,8 +377,22 @@ namespace Mono.Linker.Tests.Cases.Reflection
set { _field = value; }
}
+ public static int Unmarked {
+ get { return _field; }
+ }
+ }
+
+ [Kept]
+ class ChangeTypeBindingFlagsClass
+ {
+ [Kept]
+ public static int SetterOnly {
+ [Kept]
+ set { _field = value; }
+ }
+
[Kept]
- public static int MarkedDueToExactBinding {
+ public static int Marked {
[Kept]
get { return _field; }
}