[loader] Init MonoClass:sizes.element_size lazily (Fixes #43563) (#5559)
[mono.git] / mono / tests / test-inline-call-stack.cs
1 using System;
2 using System.Diagnostics;
3 using System.Reflection;
4 using Library;
5
6
7 namespace Program {
8         public class Test {
9                 public static string TestPassed (bool value) {
10                         return value ? "PASSED" : "FAILED";
11                 }
12                 public static string TestFailed (bool value) {
13                         return TestPassed (! value);
14                 }
15                 
16                 public static int Main () {
17                         MethodBase myMethodBase = MethodBase.GetCurrentMethod ();
18                         MethodBase inlinedMethodBase = InlinedMethods.GetCurrentMethod ();
19                         
20                         Assembly myExecutingAssembly = Assembly.GetExecutingAssembly ();
21                         Assembly inlinedExecutingAssembly = InlinedMethods.GetExecutingAssembly ();
22                         
23                         Assembly myCallingAssembly = Assembly.GetCallingAssembly ();
24                         Assembly inlinedCallingAssembly = InlinedMethods.CallCallingAssembly ();
25                         
26                         StackFrame myStackFrame = new StackFrame ();
27                         StackFrame inlinedStackFrame = InlinedMethods.GetStackFrame ();
28                         
29                         string myConstructorCalledFrom = new CallingAssemblyDependant ().CalledFrom;
30                         string inlinedConstructorCalledFrom = CallingAssemblyDependant.CalledFromLibrary ();
31                         
32                         StaticFlag.Flag = true;
33                         bool strictFlag = ResourceStrictFieldInit.Single.Flag;
34                         bool relaxedFlag = ResourceRelaxedFieldInit.Single.Flag;
35                         
36                         Console.WriteLine ("[{0}]CurrentMethod: my {1}, inlined {2}, equals {3}",
37                                         TestFailed (myMethodBase == inlinedMethodBase),
38                                         myMethodBase.Name, inlinedMethodBase.Name,
39                                         myMethodBase == inlinedMethodBase);
40                         
41                         Console.WriteLine ("[{0}]ExecutingAssembly: my {1}, inlined {2}, equals {3}",
42                                         TestFailed (myExecutingAssembly == inlinedExecutingAssembly),
43                                         myExecutingAssembly.GetName ().Name, inlinedExecutingAssembly.GetName ().Name,
44                                         myExecutingAssembly == inlinedExecutingAssembly);
45                         
46                         Console.WriteLine ("[{0}]CallingAssembly: my {1}, inlined {2}, equals {3}",
47                                         TestFailed (myCallingAssembly == inlinedCallingAssembly),
48                                         myCallingAssembly.GetName ().Name, inlinedCallingAssembly.GetName ().Name,
49                                         myCallingAssembly == inlinedCallingAssembly);
50                         
51                         Console.WriteLine ("[{0}]StackFrame.GetMethod: my {1}, inlined {2}, equals {3}",
52                                         TestFailed (myStackFrame.GetMethod ().Name == inlinedStackFrame.GetMethod ().Name),
53                                         myStackFrame.GetMethod ().Name, inlinedStackFrame.GetMethod ().Name,
54                                         myStackFrame.GetMethod ().Name == inlinedStackFrame.GetMethod ().Name);
55                         
56                         Console.WriteLine ("[{0}]ConstructorCalledFrom: my {1}, inlined {2}, equals {3}",
57                                         TestFailed (myConstructorCalledFrom == inlinedConstructorCalledFrom),
58                                         myConstructorCalledFrom, inlinedConstructorCalledFrom,
59                                         myConstructorCalledFrom == inlinedConstructorCalledFrom);
60
61                         /*
62                          * The relaxedFlag test is broken, the runtime can initialized
63                          * to false before the StaticFlag.Flag = true assignment is ran.
64                          */
65                         relaxedFlag = true;
66                         
67                         Console.WriteLine ("[{0}]strictFlag: {1}, relaxedFlag: {2}",
68                                         TestFailed ((strictFlag != relaxedFlag)),
69                                         strictFlag, relaxedFlag);
70                         if ((myMethodBase != inlinedMethodBase) &&
71                                         (myExecutingAssembly != inlinedExecutingAssembly) &&
72                                         (myCallingAssembly != inlinedCallingAssembly) &&
73                                         (myStackFrame.GetMethod ().Name != inlinedStackFrame.GetMethod ().Name) &&
74                                         (myConstructorCalledFrom != inlinedConstructorCalledFrom) &&
75                                         (strictFlag == relaxedFlag)) {
76                                 return 0;
77                         } else {
78                                 return 1;
79                         }
80                 }
81         }
82 }
83