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:
authorVitek Karas <vitek.karas@microsoft.com>2020-01-22 11:05:48 +0300
committerMarek Safar <marek.safar@gmail.com>2020-01-22 11:05:48 +0300
commit103e30ddfcd10d1ba60c0701657ce215ca1d3c72 (patch)
tree47f42f2e5d3ae6353346dbc438e4ea6dd88b82af /test/Mono.Linker.Tests.Cases.Expectations/Assertions
parentb2e82f3efc5ed5a5a503565d32c7275ca052fc51 (diff)
Introduce IReflectionPatternRecorder to allow recording of patte… (#907)
* Introduce IReflectionPatternRecorder to allow external recording of patterns The Mark step performs pattern matching for some reflection methods to be able to figure out depenedncies even across reflection calls. Currently it only writes to log when it finds a pattern it can't recognize. This change introduces a new interface IReflectionPatternRecorder which is called every time the pattern matching either sucessfuly recognizes a pattern or fails to do so. By default this is implemented to log on failure (just like before the change). This allows additional tools to record the failures and or the successes in a different way. Added support to test this functionality and modified a couple of tests to validate the basics. The biggest change is in the MarkStep where the pattern matching has been refactored a little bit to fullfill a promise of always reporting success/failure for a given callsite. This is important for some consumers to be able to handle multiple call sites to the same reflection method in calling method body (without this we would have to somehow report the actual call site location which complicates things quite a bit on the consumption side). * Fix build break on Mono C# 7.3 doesn't support static local functions. * Modify test attribute for pattern recognition to be strongly typed * Fixes Activator.CreateInstance<T>() pattern matching This pattern is not supported (recognized), so it should be reported as such. The existing code had two bugs: - It didn't report it through the new interface - It didn't match the CreateInstance<T> correctly and would never actually trigger As such this effectively adds a new unrecognized pattern to the linker, but given that before it only reported these as low importance output messages it's a change I think we should take. Adds a test for this as well. * Refactor the reflection pattern matching per PR feedback
Diffstat (limited to 'test/Mono.Linker.Tests.Cases.Expectations/Assertions')
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs24
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs22
2 files changed, 46 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs
new file mode 100644
index 000000000..09d83aa65
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace Mono.Linker.Tests.Cases.Expectations.Assertions
+{
+ [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
+ public class RecognizedReflectionAccessPatternAttribute : BaseExpectedLinkedBehaviorAttribute
+ {
+ public RecognizedReflectionAccessPatternAttribute (Type reflectionMethodType, string reflectionMethodName, Type[] reflectionMethodParameters,
+ Type accessedItemType, string accessedItemName, Type[] accessedItemParameters)
+ {
+ if (reflectionMethodType == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodType));
+ if (reflectionMethodName == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodName));
+ if (reflectionMethodParameters == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodParameters));
+
+ if (accessedItemType == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (accessedItemType));
+ if (accessedItemName == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (accessedItemName));
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs
new file mode 100644
index 000000000..666c2da63
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace Mono.Linker.Tests.Cases.Expectations.Assertions
+{
+ [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
+ public class UnrecognizedReflectionAccessPatternAttribute : BaseExpectedLinkedBehaviorAttribute
+ {
+ public UnrecognizedReflectionAccessPatternAttribute (Type reflectionMethodType, string reflectionMethodName, Type [] reflectionMethodParameters,
+ string message = null)
+ {
+ if (reflectionMethodType == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodType));
+ if (reflectionMethodName == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodName));
+ if (reflectionMethodParameters == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodParameters));
+
+ if (message == null)
+ throw new ArgumentException ("Value cannot be null or empty.", nameof (message));
+ }
+ }
+}