4 * Application program used by the debugger tests.
7 using System
.Runtime
.CompilerServices
;
8 using System
.Reflection
;
9 using System
.Reflection
.Emit
;
10 using System
.Diagnostics
;
11 using System
.Threading
;
12 using System
.Collections
.Generic
;
15 public class TestsBase
17 #pragma warning disable 0414
18 #pragma warning disable 0169
19 public int base_field_i
;
20 public string base_field_s
;
21 static int base_static_i
= 57;
22 static string base_static_s
= "C";
23 #pragma warning restore 0414
24 #pragma warning restore 0169
32 [DebuggerDisplay ("Tests", Name
="FOO", Target
=typeof (int))]
33 [DebuggerTypeProxy (typeof (Tests
))]
35 [DebuggerBrowsableAttribute (DebuggerBrowsableState
.Collapsed
)]
37 public static int static_field_j
;
39 [DebuggerBrowsableAttribute (DebuggerBrowsableState
.Collapsed
)]
40 public int AProperty
{
46 public void invoke () {
50 public struct AStruct
{
56 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
57 public int foo (int val
) {
61 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
62 public static int static_foo (int val
) {
66 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
67 public int invoke_return_int () {
71 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
72 public static int invoke_static () {
76 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
77 public IntPtr
invoke_return_intptr () {
82 public class GClass
<T
> {
84 public static T static_field
;
86 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
91 public struct GStruct
<T
> {
96 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
97 public int invoke_return_int () {
102 public class Tests
: TestsBase
104 #pragma warning disable 0414
108 bool field_bool1
, field_bool2
;
120 static int static_i
= 55;
121 static string static_s
= "A";
122 public const int literal_i
= 56;
123 public const string literal_s
= "B";
125 public AStruct field_struct
;
126 public object field_boxed_struct
;
127 public GStruct
<int> generic_field_struct
;
129 public static int tls_i
;
130 public static bool is_attached
= Debugger
.IsAttached
;
132 #pragma warning restore 0414
134 public class NestedClass
{
137 public int IntProperty
{
146 public int ReadOnlyProperty
{
152 public int this [int index
] {
158 public static int Main (String
[] args
) {
159 if (args
.Length
> 0 && args
[0] == "suspend-test")
160 /* This contains an infinite loop, so execute it conditionally */
176 if (args
.Length
> 0 && args
[0] == "domain-test")
177 /* This takes a lot of time, so execute it conditionally */
179 if (args
.Length
> 0 && args
[0] == "ref-emit-test")
181 if (args
.Length
> 0 && args
[0] == "frames-in-native")
183 if (args
.Length
>0 && args
[0] == "invoke-single-threaded")
184 new Tests ().invoke_single_threaded ();
188 public static void breakpoints () {
189 /* Call these early so it is JITted by the time a breakpoint is placed on it */
206 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
207 public static void bp1 () {
210 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
211 public static void bp2 () {
214 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
215 public static void bp3 () {
218 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
219 public static void bp4 () {
222 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
223 public static void bp5 () {
226 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
227 public static void bp6
<T
> () {
230 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
231 public static void bp7
<T
> () {
234 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
235 public static void single_stepping () {
241 ss5 (new int [] { 1, 2, 3 }
, new Func
<int, bool> (is_even
));
248 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
249 public static void ss1 () {
252 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
253 public static void ss2 () {
256 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
257 public static int ss3 () {
260 for (int i
= 0; i
< 10; ++i
)
266 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
267 public static void ss3_2 () {
271 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
272 public static void ss3_2_2 () {
275 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
276 public static int ss4 () {
282 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
283 public static void ss5 (int[] arr
, Func
<int, bool> selector
) {
284 // Call into linq which calls back into this assembly
285 arr
.Count (selector
);
288 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
289 public static void ss6 (bool b
) {
292 throw new Exception ();
296 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
297 public static void ss7 () {
300 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
301 public static bool is_even (int i
) {
307 Console.WriteLine ("HIT!");
313 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
314 public static void arguments () {
315 arg1 (SByte
.MaxValue
- 5, Byte
.MaxValue
- 5, true, Int16
.MaxValue
- 5, UInt16
.MaxValue
- 5, 'F', Int32
.MaxValue
- 5, UInt32
.MaxValue
- 5, Int64
.MaxValue
- 5, UInt64
.MaxValue
- 5, 1.2345f
, 6.78910, new IntPtr (Int32
.MaxValue
- 5), new UIntPtr (UInt32
.MaxValue
- 5));
317 arg2 ("FOO", null, "BLA", ref i
, new GClass
<int> { field = 42 }
, new object ());
318 Tests t
= new Tests () { field_i = 42, field_s = "S" }
;
322 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
323 public static int arg1 (sbyte sb
, byte b
, bool bl
, short s
, ushort us
, char c
, int i
, uint ui
, long l
, ulong ul
, float f
, double d
, IntPtr ip
, UIntPtr uip
) {
324 return (int)(sb
+ b
+ (bl
? 0 : 1) + s
+ us
+ (int)c
+ i
+ ui
+ l
+ (long)ul
+ f
+ d
+ (int)ip
+ (int)uip
);
327 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
328 public static string arg2 (string s
, string s3
, object o
, ref int i
, GClass
<int> gc
, object o2
) {
329 return s
+ (s3
!= null ? "" : "") + o
+ i
+ gc
.field
+ o2
;
332 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
333 public object arg3 (string s
) {
334 return s
+ s
+ s
+ s
+ this;
337 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
338 public static void objects () {
339 Tests t
= new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null, field_intptr = new IntPtr (Int32.MaxValue - 5) }
;
340 t
.o1 (new Tests2 () { field_j = 43 }
, new GClass
<int> { field = 42 }
, new GClass
<string> { field = "FOO" }
);
341 o2 (new string [] { "BAR", "BAZ" }
, new int[] { 42, 43 }
, new int [,] { { 1, 2 }
, { 3, 4 }}
, (int[,])Array
.CreateInstance (typeof (int), new int [] { 2, 2}
, new int [] { 1, 3}
), new int[] { 0 }
);
344 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
345 public object o1 (Tests2 t
, GClass
<int> gc1
, GClass
<string> gc2
) {
346 if (t
== null || gc1
== null || gc2
== null)
352 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
353 public static string o2 (string[] s2
, int[] s3
, int[,] s4
, int[,] s5
, IList
<int> s6
) {
354 return s2
[0] + s3
[0] + s4
[0, 0] + s6
[0];
357 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
358 public static void objrefs () {
359 Tests t
= new Tests () {};
367 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
368 public static void set_child (Tests t
) {
369 t
.child
= new Tests ();
372 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
373 public void objrefs1 () {
376 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
377 public static void objrefs2 () {
380 public static void vtypes () {
381 Tests t
= new Tests () { field_struct = new AStruct () { i = 42, s = "S", k = 43 }
, generic_field_struct
= new GStruct
<int> () { i = 42 }
, field_boxed_struct
= new AStruct () { i = 42 }}
;
382 AStruct s
= new AStruct { i = 44, s = "T", k = 45 }
;
383 AStruct
[] arr
= new AStruct
[] {
384 new AStruct () { i = 1, s = "S1" }
,
385 new AStruct () { i = 2, s = "S2" }
};
391 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
392 public object vtypes1 (AStruct s
, AStruct
[] arr
) {
399 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
400 public static void vtypes2 (AStruct s
) {
404 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
405 public static void vtypes3 (AStruct s
) {
406 AStruct
.static_foo (5);
409 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
410 public static void locals () {
415 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
416 public static void locals1 (string[] args
) {
419 for (int j
= 0; j
< 10; ++j
) {
424 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
425 public static void locals2 (string[] args
, int arg
) {
429 for (int j
= 0; j
< 10; ++j
) {
435 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
436 public static void line_numbers () {
440 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
441 public static void suspend () {
449 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
450 public static void type_info () {
451 Tests t
= new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B }
;
452 t
.ti1 (new Tests2 () { field_j = 43 }
, new GClass
<int> { field = 42 }
, new GClass
<string> { field = "FOO" }
);
455 AStruct s
= new AStruct () { i = 42, s = "S", k = 43 }
;
457 ti2 (new string [] { "BAR", "BAZ" }
, new int[] { 42, 43 }
, new int [,] { { 1, 2 }
, { 3, 4 }}
, ref val
, (int*)IntPtr
.Zero
, 5, s
, new Tests (), new Tests2 (), new GClass
<int> (), AnEnum
.B
);
461 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
462 public object ti1 (Tests2 t
, GClass
<int> gc1
, GClass
<string> gc2
) {
463 if (t
== null || gc1
== null || gc2
== null)
469 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
470 public static unsafe string ti2 (string[] s2
, int[] s3
, int[,] s4
, ref int ri
, int* ptr
, int i
, AStruct s
, Tests t
, Tests2 t2
, GClass
<int> g
, AnEnum ae
) {
471 return s2
[0] + s3
[0] + s4
[0, 0];
474 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
475 public static void assembly_load () {
479 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
480 public static void assembly_load_2 () {
481 // This will load System.dll while holding the loader lock
485 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
486 public static void invoke () {
487 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }
, new GStruct
<int> { j = 42 }
);
490 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
491 public void invoke1 (Tests2 t
, AStruct s
, GStruct
<int> g
) {
495 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
496 public void invoke2 () {
501 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
502 public void invoke_single_threaded () {
503 // Spawn a thread incrementing a counter
504 bool finished
= false;
506 new Thread (delegate () {
513 invoke_single_threaded_2 ();
518 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
519 public void invoke_single_threaded_2 () {
522 public void invoke_return_void () {
525 public string invoke_return_ref () {
529 public object invoke_return_null () {
533 public int invoke_return_primitive () {
537 public void invoke_type_load () {
544 public long invoke_pass_primitive (byte ub
, sbyte sb
, short ss
, ushort us
, int i
, uint ui
, long l
, ulong ul
, char c
, bool b
, float f
, double d
) {
545 return ub
+ sb
+ ss
+ us
+ i
+ ui
+ l
+ (long)ul
+ (int)c
+ (b
? 1 : 0) + (int)f
+ (int)d
;
548 public int invoke_pass_primitive2 (bool b
) {
552 public string invoke_pass_ref (string s
) {
556 public static string invoke_static_pass_ref (string s
) {
560 public static void invoke_static_return_void () {
563 public static void invoke_throws () {
564 throw new Exception ();
567 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
568 public static void exceptions () {
570 throw new OverflowException ();
571 } catch (Exception
) {
574 throw new OverflowException ();
575 } catch (Exception
) {
578 throw new ArgumentException ();
579 } catch (Exception
) {
582 throw new OverflowException ();
583 } catch (Exception
) {
589 } catch (Exception
) {
593 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
594 public static void threads () {
595 Thread t
= new Thread (delegate () {});
601 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
602 public static void domains () {
603 AppDomain domain
= AppDomain
.CreateDomain ("domain");
605 CrossDomain o
= (CrossDomain
)domain
.CreateInstanceAndUnwrap (
606 typeof (CrossDomain
).Assembly
.FullName
, "CrossDomain");
610 AppDomain
.Unload (domain
);
615 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
616 public static void domains_2 () {
619 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
620 public static void invoke_in_domain () {
623 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
624 public static void dynamic_methods () {
625 var m
= new DynamicMethod ("dyn_method", typeof (void), new Type
[] { typeof (int) }
, typeof (object).Module
);
626 var ig
= m
.GetILGenerator ();
628 ig
.Emit (OpCodes
.Ldstr
, "FOO");
629 ig
.Emit (OpCodes
.Call
, typeof (Tests
).GetMethod ("dyn_call"));
630 ig
.Emit (OpCodes
.Ret
);
632 var del
= (Action
<int>)m
.CreateDelegate (typeof (Action
<int>));
637 public static void dyn_call (string s
) {
640 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
641 public static void ref_emit () {
642 AssemblyName assemblyName
= new AssemblyName ();
643 assemblyName
.Name
= "foo";
645 AssemblyBuilder assembly
=
646 Thread
.GetDomain ().DefineDynamicAssembly (
647 assemblyName
, AssemblyBuilderAccess
.RunAndSave
);
649 ModuleBuilder module
= assembly
.DefineDynamicModule ("foo.dll");
651 TypeBuilder tb
= module
.DefineType ("foo", TypeAttributes
.Public
, typeof (object));
652 MethodBuilder mb
= tb
.DefineMethod ("ref_emit_method", MethodAttributes
.Public
|MethodAttributes
.Static
, CallingConventions
.Standard
, typeof (void), new Type
[] { }
);
653 ILGenerator ig
= mb
.GetILGenerator ();
654 ig
.Emit (OpCodes
.Ldstr
, "FOO");
655 ig
.Emit (OpCodes
.Call
, typeof (Tests
).GetMethod ("ref_emit_call"));
656 ig
.Emit (OpCodes
.Ret
);
658 Type t
= tb
.CreateType ();
660 t
.GetMethod ("ref_emit_method").Invoke (null, null);
663 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
664 public static void ref_emit_call (string s
) {
667 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
668 public static void frames_in_native () {
673 public class CrossDomain
: MarshalByRefObject
675 public void invoke () {
676 Tests
.invoke_in_domain ();
682 public ProcessStartInfo info
;
685 // Class used for line number info testing, don't change its layout
686 public class LineNumbers
688 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
689 public static void ln1 () {
694 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
695 public static void ln2 () {
698 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
699 public static void ln3 () {