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
.Threading
.Tasks
;
13 using System
.Collections
.Generic
;
15 using System
.Net
.Sockets
;
16 using MonoTests
.Helpers
;
18 public class TestsBase
20 #pragma warning disable 0414
21 #pragma warning disable 0169
22 public int base_field_i
;
23 public string base_field_s
;
24 static int base_static_i
= 57;
25 static string base_static_s
= "C";
26 #pragma warning restore 0414
27 #pragma warning restore 0169
29 public virtual string virtual_method () {
39 public sealed class Tests3
{
40 public static void M1 () {
54 public static class Tests4
{
59 public class AAttribute
: Attribute
{
63 public class BAttribute
: AAttribute
{
67 [DebuggerDisplay ("Tests", Name
="FOO", Target
=typeof (int))]
68 [DebuggerTypeProxy (typeof (Tests
))]
69 [BAttribute (afield
= 1, bfield
= 2)]
71 [DebuggerBrowsableAttribute (DebuggerBrowsableState
.Collapsed
)]
73 public static int static_field_j
;
75 [DebuggerBrowsableAttribute (DebuggerBrowsableState
.Collapsed
)]
76 public int AProperty
{
82 public void invoke () {
86 public struct AStruct
: ITest2
{
101 public AStruct (int arg
) {
109 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
110 public int foo (int val
) {
114 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
115 public static int static_foo (int val
) {
119 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
120 public int invoke_return_int () {
124 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
125 public static int invoke_static () {
129 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
130 public IntPtr
invoke_return_intptr () {
134 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
135 public void invoke_mutate () {
139 public int invoke_iface () {
143 public override string ToString () {
144 return i
.ToString ();
148 public class GClass
<T
> {
150 public static T static_field
;
152 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
156 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
157 public void bp
<T2
> () {
161 public struct GStruct
<T
> {
166 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
167 public int invoke_return_int () {
172 public struct NestedStruct
{
173 NestedInner nested1
, nested2
;
176 public struct NestedInner
{
179 public interface IRecStruct
{
183 struct RecStruct
: IRecStruct
{
186 public void foo (object o
) {
203 class TestIfaces
: ITest
211 TestIfaces
<int> Baz () {
216 class TestIfaces
<T
> : ITest
<T
>
218 void ITest
<T
>.Foo () {
221 void ITest
<T
>.Bar () {
225 public interface ITest2
230 public class Tests
: TestsBase
, ITest2
232 #pragma warning disable 0414
236 bool field_bool1
, field_bool2
;
249 static int static_i
= 55;
250 static string static_s
= "A";
251 public const int literal_i
= 56;
252 public const string literal_s
= "B";
254 public AStruct field_struct
;
255 public object field_boxed_struct
;
256 public GStruct
<int> generic_field_struct
;
257 public KeyValuePair
<int, object> boxed_struct_field
;
259 public static int tls_i
;
260 public static bool is_attached
= Debugger
.IsAttached
;
261 public NestedStruct nested_struct
;
263 #pragma warning restore 0414
265 public class NestedClass
{
268 public int IntProperty
{
277 public int ReadOnlyProperty
{
283 public int this [int index
] {
289 public static void wait_one ()
291 ManualResetEvent evt
= new ManualResetEvent (false);
295 public static int Main (String
[] args
) {
298 if (args
.Length
> 0 && args
[0] == "suspend-test")
299 /* This contains an infinite loop, so execute it conditionally */
301 if (args
.Length
>0 && args
[0] == "unhandled-exception") {
302 unhandled_exception ();
305 if (args
.Length
>0 && args
[0] == "unhandled-exception-endinvoke") {
306 unhandled_exception_endinvoke ();
309 if (args
.Length
>0 && args
[0] == "unhandled-exception-user") {
310 unhandled_exception_user ();
313 if (args
.Length
>0 && args
[0] == "wait-one") {
317 if (args
.Length
>0 && args
[0] == "threadpool-io") {
343 if (args
.Length
> 0 && args
[0] == "domain-test")
344 /* This takes a lot of time, so execute it conditionally */
346 if (args
.Length
> 0 && args
[0] == "ref-emit-test")
348 if (args
.Length
> 0 && args
[0] == "frames-in-native")
350 if (args
.Length
> 0 && args
[0] == "invoke-single-threaded")
351 new Tests ().invoke_single_threaded ();
352 if (args
.Length
> 0 && args
[0] == "invoke-abort")
353 new Tests ().invoke_abort ();
354 new Tests ().evaluate_method ();
358 public static void local_reflect () {
359 //Breakpoint line below, and reflect someField via ObjectMirror;
360 LocalReflectClass
.RunMe ();
363 public static void breakpoints () {
364 /* Call these early so it is JITted by the time a breakpoint is placed on it */
376 bp6
<string> (new GClass
<int> ());
381 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
382 public static void bp1 () {
385 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
386 public static void bp2 () {
389 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
390 public static void bp3 () {
393 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
394 public static void bp4 () {
397 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
398 public static void bp5 () {
401 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
402 public static void bp6
<T
> (GClass
<int> gc
) {
406 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
407 public static void bp7
<T
> () {
410 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
411 public static void single_stepping () {
418 ss5 (new int [] { 1, 2, 3 }
, new Func
<int, bool> (is_even
));
425 ss_regress_654694 ();
431 ss_recursive_chaotic ();
435 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
436 public static void ss1 () {
439 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
440 public static void ss2 () {
443 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
444 public static int ss3 () {
447 for (int i
= 0; i
< 10; ++i
)
453 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
454 public static void ss3_2 () {
458 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
459 public static void ss3_2_2 () {
462 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
463 public static int ss4 () {
469 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
470 public static void ss5 (int[] arr
, Func
<int, bool> selector
) {
471 // Call into linq which calls back into this assembly
472 arr
.Count (selector
);
475 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
476 public static void ss6 (bool b
) {
479 throw new Exception ();
483 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
484 public static void ss6_2 () {
487 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
488 public static void ss7 () {
497 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
498 public static void ss7_2 () {
501 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
502 public static void ss7_3 () {
503 throw new Exception ();
506 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
507 public static void ss_nested () {
508 ss_nested_1 (ss_nested_2 ());
509 ss_nested_1 (ss_nested_2 ());
513 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
514 public static void ss_nested_1 (int i
) {
517 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
518 public static int ss_nested_2 () {
522 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
523 public static void ss_nested_3 () {
526 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
527 public static void ss_step_through () {
529 StepThroughClass
.step_through_2 ();
533 [DebuggerStepThrough
]
534 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
535 public static void step_through_1 () {
538 [DebuggerStepThrough
]
539 class StepThroughClass
{
540 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
541 public static void step_through_2 () {
545 [DebuggerStepThrough
]
546 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
547 public static void step_through_3 () {
550 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
551 public static void ss_non_user_code () {
553 StepNonUserCodeClass
.non_user_code_2 ();
557 [DebuggerNonUserCode
]
558 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
559 public static void non_user_code_1 () {
562 [DebuggerNonUserCode
]
563 class StepNonUserCodeClass
{
564 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
565 public static void non_user_code_2 () {
569 [DebuggerNonUserCode
]
570 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
571 public static void non_user_code_3 () {
574 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
575 public static void ss_recursive (int n
) {
578 ss_recursive (n
+ 1);
581 // Breakpoint will be placed here
582 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
583 public static void ss_recursive2_trap ()
587 public static void ss_recursive2_at (string s
)
589 // Console.WriteLine (s);
592 // This method is used both for a step over and step out test.
593 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
594 public static void ss_recursive2 (int x
)
596 ss_recursive2_at ( "ss_recursive2 in " + x
);
599 ss_recursive2_at ("ss_recursive2 descend " + x
);
600 ss_recursive2_trap ();
601 ss_recursive2 (next
);
603 ss_recursive2_at ("ss_recursive2 out " + x
);
606 // Breakpoint will be placed here
607 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
608 public static void ss_recursive_chaotic_trap ()
612 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
613 public static void ss_recursive_chaotic_at (bool exiting
, string at
, int n
)
615 // string indent = "";
616 // for (int count = 5 - n; count > 0; count--)
618 // Console.WriteLine (indent + (exiting ? "<--" : "-->") + " " + at + " " + n);
621 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
622 public static void ss_recursive_chaotic_fizz (int n
)
624 ss_recursive_chaotic_at (false, "fizz", n
);
627 ss_recursive_chaotic_buzz (next
);
628 ss_recursive_chaotic_fizzbuzz (next
);
630 ss_recursive_chaotic_trap ();
632 ss_recursive_chaotic_at (true, "fizz", n
);
635 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
636 public static void ss_recursive_chaotic_buzz (int n
)
638 ss_recursive_chaotic_at (false, "buzz", n
);
641 ss_recursive_chaotic_fizz (next
);
642 ss_recursive_chaotic_fizzbuzz (next
);
644 ss_recursive_chaotic_at (true, "buzz", n
);
647 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
648 public static void ss_recursive_chaotic_fizzbuzz (int n
)
650 ss_recursive_chaotic_at (false, "fizzbuzz", n
);
653 ss_recursive_chaotic_fizz (next
);
654 ss_recursive_chaotic_buzz (next
);
655 ss_recursive_chaotic_fizzbuzz (next
);
657 ss_recursive_chaotic_at (true, "fizzbuzz", n
);
660 // Call a complex tree of recursive calls that has tripped up "step out" in the past.
661 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
662 public static void ss_recursive_chaotic ()
664 ss_recursive_chaotic_fizz (5);
667 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
668 public static void ss_fp_clobber () {
669 double v
= ss_fp_clobber_1 (5.0);
673 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
674 public static double ss_fp_clobber_1 (double d
) {
678 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
679 public static void ss_fp_clobber_2 (double d
) {
682 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
683 public static bool is_even (int i
) {
689 Console.WriteLine ("HIT!");
695 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
696 public static void arguments () {
697 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));
699 arg2 ("FOO", null, "BLA", ref i
, new GClass
<int> { field = 42 }
, new object (), '\0'.ToString () + "A");
700 Tests t
= new Tests () { field_i = 42, field_s = "S" }
;
704 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
705 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
) {
706 return (int)(sb
+ b
+ (bl
? 0 : 1) + s
+ us
+ (int)c
+ i
+ ui
+ l
+ (long)ul
+ f
+ d
+ (int)ip
+ (int)uip
);
709 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
710 public static string arg2 (string s
, string s3
, object o
, ref int i
, GClass
<int> gc
, object o2
, string s4
) {
711 return s
+ (s3
!= null ? "" : "") + o
+ i
+ gc
.field
+ o2
;
714 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
715 public object arg3 (string s
) {
716 return s
+ s
+ s
+ s
+ this;
719 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
720 public static void objects () {
721 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), field_nullable = null }
;
722 t
.o1 (new Tests2 () { field_j = 43 }
, new GClass
<int> { field = 42 }
, new GClass
<string> { field = "FOO" }
);
723 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 }
);
726 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
727 public object o1 (Tests2 t
, GClass
<int> gc1
, GClass
<string> gc2
) {
728 if (t
== null || gc1
== null || gc2
== null)
734 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
735 public static string o2 (string[] s2
, int[] s3
, int[,] s4
, int[,] s5
, IList
<int> s6
) {
736 return s2
[0] + s3
[0] + s4
[0, 0] + s6
[0];
739 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
740 public static void objrefs () {
741 Tests t
= new Tests () {};
749 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
750 public static void set_child (Tests t
) {
751 t
.child
= new Tests ();
754 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
755 public void objrefs1 () {
758 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
759 public static void objrefs2 () {
762 public static void vtypes () {
763 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 }
, boxed_struct_field
= new KeyValuePair
<int, object> (1, (long)42 ) };
764 AStruct s
= new AStruct { i = 44, s = "T", k = 45 }
;
765 AStruct
[] arr
= new AStruct
[] {
766 new AStruct () { i = 1, s = "S1" }
,
767 new AStruct () { i = 2, s = "S2" }
};
768 TypedReference typedref
= __makeref (s
);
769 t
.vtypes1 (s
, arr
, typedref
);
775 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
776 public object vtypes1 (AStruct s
, AStruct
[] arr
, TypedReference typedref
) {
783 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
784 public static void vtypes2 (AStruct s
) {
788 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
789 public static void vtypes3 (AStruct s
) {
790 AStruct
.static_foo (5);
793 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
794 public static void vtypes4_2 (IRecStruct o
) {
797 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
798 public static void vtypes4 () {
799 IRecStruct s
= new RecStruct ();
804 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
805 public static void locals () {
807 var astruct
= new AStruct () { i = 42 }
;
809 locals2
<string> (null, 5, "ABC", ref s
, ref astruct
);
815 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
816 static void locals11 (double a
, ref double b
) {
819 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
820 public static void locals1 (string[] args
) {
824 locals11 (b
: ref ri
, a
: ri
);
826 for (int j
= 0; j
< 10; ++j
) {
831 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
832 [StateMachine (typeof (int))]
833 public static void locals2
<T
> (string[] args
, int arg
, T t
, ref string rs
, ref AStruct astruct
) {
837 for (int j
= 0; j
< 10; ++j
) {
842 astruct
= new AStruct ();
845 List
<int> alist
= new List
<int> () { 12 }
;
849 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
850 public static void locals3 () {
870 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
871 public static void locals4 () {
874 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
875 public static void locals5 () {
878 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
879 public static void locals6 () {
882 for (i
= 0; i
< 10; ++i
)
885 for (i
= 0; i
< 10; ++i
)
895 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
896 public static void locals6_1 () {
899 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
900 public static void locals6_2 (int arg
) {
903 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
904 public static void locals6_3 () {
905 // Clobber all registers
906 int sum
= 0, i
, j
, k
, l
, m
;
907 for (i
= 0; i
< 100; ++i
)
909 for (j
= 0; j
< 100; ++j
)
911 for (k
= 0; k
< 100; ++k
)
913 for (l
= 0; l
< 100; ++l
)
915 for (m
= 0; m
< 100; ++m
)
919 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
920 public static void locals6_4 (int arg
) {
923 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
924 public static void locals6_5 () {
927 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
928 public static void locals6_6 (int arg
) {
931 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
932 public static void locals7
<T
> (T arg
) {
937 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
938 public static void line_numbers () {
942 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
943 public static void suspend () {
951 struct TypedRefTest
{
955 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
956 public static void type_info () {
957 Tests t
= new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B }
;
958 t
.ti1 (new Tests2 () { field_j = 43 }
, new GClass
<int> { field = 42 }
, new GClass
<string> { field = "FOO" }
);
961 AStruct s
= new AStruct () { i = 42, s = "S", k = 43 }
;
962 TypedRefTest reftest
= new TypedRefTest () { MaxValue = 12 }
;
963 TypedReference typedref
= __makeref (reftest
);
964 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
, typedref
);
968 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
969 public object ti1 (Tests2 t
, GClass
<int> gc1
, GClass
<string> gc2
) {
970 if (t
== null || gc1
== null || gc2
== null)
976 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
977 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
, TypedReference typedref
) {
978 return s2
[0] + s3
[0] + s4
[0, 0];
981 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
982 public static void assembly_load () {
986 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
987 public static void assembly_load_2 () {
988 // This will load System.dll while holding the loader lock
992 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
993 public static void invoke () {
994 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }
, new GStruct
<int> { j = 42 }
);
995 new Tests ().invoke_ex ();
998 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
999 public void invoke1 (Tests2 t
, AStruct s
, GStruct
<int> g
) {
1003 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1004 public void invoke2 () {
1007 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1008 public void invoke_ex () {
1012 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1013 public void invoke_ex_inner () {
1015 throw new Exception ();
1022 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1023 public void invoke_single_threaded () {
1024 // Spawn a thread incrementing a counter
1025 bool finished
= false;
1027 new Thread (delegate () {
1034 invoke_single_threaded_2 ();
1039 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1040 public void invoke_single_threaded_2 () {
1043 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1044 public void invoke_abort () {
1047 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1048 public void invoke_abort_2 () {
1049 Thread
.Sleep (1000000);
1052 public void invoke_return_void () {
1055 public string invoke_return_ref () {
1059 public object invoke_return_null () {
1063 public int invoke_return_primitive () {
1067 public int? invoke_return_nullable () {
1071 public int? invoke_return_nullable_null () {
1075 public void invoke_type_load () {
1082 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
) {
1083 return ub
+ sb
+ ss
+ us
+ i
+ ui
+ l
+ (long)ul
+ (int)c
+ (b
? 1 : 0) + (int)f
+ (int)d
;
1086 public int invoke_pass_primitive2 (bool b
) {
1090 public string invoke_pass_ref (string s
) {
1094 public static string invoke_static_pass_ref (string s
) {
1098 public static void invoke_static_return_void () {
1101 public static void invoke_throws () {
1102 throw new Exception ();
1105 public int invoke_iface () {
1109 public void invoke_out (out int foo
, out int[] arr
) {
1114 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1115 public static void exceptions () {
1117 throw new OverflowException ();
1118 } catch (Exception
) {
1121 throw new OverflowException ();
1122 } catch (Exception
) {
1125 throw new ArgumentException ();
1126 } catch (Exception
) {
1129 throw new OverflowException ();
1130 } catch (Exception
) {
1134 throw new OverflowException ();
1135 } catch (Exception
) {
1138 throw new Exception ();
1139 } catch (Exception
) {
1145 } catch (Exception
) {
1150 } catch (Exception
) {
1154 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1155 public static void unhandled_exception () {
1156 ThreadPool
.QueueUserWorkItem (delegate {
1157 throw new InvalidOperationException ();
1159 Thread
.Sleep (10000);
1162 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1163 public static void unhandled_exception_endinvoke_2 () {
1166 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1167 public static void unhandled_exception_endinvoke () {
1168 Action action
= new Action (() =>
1170 throw new Exception ("thrown");
1172 action
.BeginInvoke ((ar
) => {
1174 action
.EndInvoke (ar
);
1175 } catch (Exception ex
) {
1176 //Console.WriteLine (ex);
1179 Thread
.Sleep (1000);
1180 unhandled_exception_endinvoke_2 ();
1183 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1184 public static void unhandled_exception_user () {
1185 System
.Threading
.Tasks
.Task
.Factory
.StartNew (() => {
1188 Thread
.Sleep (10000);
1191 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1192 public static void Throw () {
1193 throw new Exception ();
1196 internal static Delegate
create_filter_delegate (Delegate dlg
, MethodInfo filter_method
)
1199 throw new ArgumentNullException ();
1200 if (dlg
.Target
!= null)
1201 throw new ArgumentException ();
1202 if (dlg
.Method
== null)
1203 throw new ArgumentException ();
1205 var ret_type
= dlg
.Method
.ReturnType
;
1206 var param_types
= dlg
.Method
.GetParameters ().Select (x
=> x
.ParameterType
).ToArray ();
1208 var dynamic = new DynamicMethod (Guid
.NewGuid ().ToString (), ret_type
, param_types
, typeof (object), true);
1209 var ig
= dynamic.GetILGenerator ();
1211 LocalBuilder retval
= null;
1212 if (ret_type
!= typeof (void))
1213 retval
= ig
.DeclareLocal (ret_type
);
1215 var label
= ig
.BeginExceptionBlock ();
1217 for (int i
= 0; i
< param_types
.Length
; i
++)
1218 ig
.Emit (OpCodes
.Ldarg
, i
);
1219 ig
.Emit (OpCodes
.Call
, dlg
.Method
);
1222 ig
.Emit (OpCodes
.Stloc
, retval
);
1224 ig
.Emit (OpCodes
.Leave
, label
);
1226 ig
.BeginExceptFilterBlock ();
1228 ig
.Emit (OpCodes
.Call
, filter_method
);
1230 ig
.BeginCatchBlock (null);
1232 ig
.Emit (OpCodes
.Pop
);
1234 ig
.EndExceptionBlock ();
1237 ig
.Emit (OpCodes
.Ldloc
, retval
);
1239 ig
.Emit (OpCodes
.Ret
);
1241 return dynamic.CreateDelegate (dlg
.GetType ());
1244 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1245 static void exception_filter_method () {
1246 throw new InvalidOperationException ();
1249 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1250 static int exception_filter_filter (Exception exc
) {
1254 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1255 public static void exception_filter () {
1256 var method
= typeof (Tests
).GetMethod (
1257 "exception_filter_method", BindingFlags
.NonPublic
| BindingFlags
.Static
);
1258 var filter_method
= typeof (Tests
).GetMethod (
1259 "exception_filter_filter", BindingFlags
.NonPublic
| BindingFlags
.Static
);
1261 var dlg
= Delegate
.CreateDelegate (typeof (Action
), method
);
1263 var wrapper
= (Action
) create_filter_delegate (dlg
, filter_method
);
1268 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1269 public static bool return_true () {
1273 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1274 public static void exceptions2 () {
1276 throw new Exception ();
1277 Console
.WriteLine ();
1280 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1281 public static void threads () {
1282 Thread t
= new Thread (delegate () {});
1288 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1289 public static void domains () {
1290 AppDomain domain
= AppDomain
.CreateDomain ("domain");
1292 CrossDomain o
= (CrossDomain
)domain
.CreateInstanceAndUnwrap (
1293 typeof (CrossDomain
).Assembly
.FullName
, "CrossDomain");
1295 domains_print_across (o
);
1297 domains_2 (o
, new CrossDomain ());
1305 AppDomain
.Unload (domain
);
1309 typeof (Tests
).GetMethod ("called_from_invoke").Invoke (null, null);
1312 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1313 public static void called_from_invoke () {
1316 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1317 public static void domains_2 (object o
, object o2
) {
1320 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1321 public static void domains_print_across (object o
) {
1324 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1325 public static void domains_3 () {
1328 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1329 public static void invoke_in_domain () {
1332 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1333 public static void invoke_in_domain_2 () {
1336 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1337 public static void dynamic_methods () {
1338 var m
= new DynamicMethod ("dyn_method", typeof (void), new Type
[] { typeof (int) }
, typeof (object).Module
);
1339 var ig
= m
.GetILGenerator ();
1341 ig
.Emit (OpCodes
.Ldstr
, "FOO");
1342 ig
.Emit (OpCodes
.Call
, typeof (Tests
).GetMethod ("dyn_call"));
1343 ig
.Emit (OpCodes
.Ret
);
1345 var del
= (Action
<int>)m
.CreateDelegate (typeof (Action
<int>));
1350 public static void dyn_call (string s
) {
1353 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1354 public static void ref_emit () {
1355 AssemblyName assemblyName
= new AssemblyName ();
1356 assemblyName
.Name
= "foo";
1358 AssemblyBuilder assembly
=
1359 Thread
.GetDomain ().DefineDynamicAssembly (
1360 assemblyName
, AssemblyBuilderAccess
.RunAndSave
);
1362 ModuleBuilder module
= assembly
.DefineDynamicModule ("foo.dll");
1364 TypeBuilder tb
= module
.DefineType ("foo", TypeAttributes
.Public
, typeof (object));
1365 MethodBuilder mb
= tb
.DefineMethod ("ref_emit_method", MethodAttributes
.Public
|MethodAttributes
.Static
, CallingConventions
.Standard
, typeof (void), new Type
[] { }
);
1366 ILGenerator ig
= mb
.GetILGenerator ();
1367 ig
.Emit (OpCodes
.Ldstr
, "FOO");
1368 ig
.Emit (OpCodes
.Call
, typeof (Tests
).GetMethod ("ref_emit_call"));
1369 ig
.Emit (OpCodes
.Ret
);
1371 Type t
= tb
.CreateType ();
1373 t
.GetMethod ("ref_emit_method").Invoke (null, null);
1376 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1377 public static void ref_emit_call (string s
) {
1380 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1381 public static void frames_in_native () {
1383 var evt
= new ManualResetEvent (false);
1385 object mon
= new object ();
1386 ThreadPool
.QueueUserWorkItem (delegate {
1387 frames_in_native_2 ();
1393 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1394 static void frames_in_native_2 () {
1395 frames_in_native_3 ();
1398 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1399 static void frames_in_native_3 () {
1402 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1403 public static void string_call (string s
) {
1406 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1407 public static void ss_regress_654694 () {
1414 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1415 public static void user () {
1418 Debugger
.Log (5, Debugger
.IsLogging () ? "A" : "", "B");
1421 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1422 public static void type_load () {
1426 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1427 static void type_load_2 () {
1428 var c1
= new Dictionary
<int, int> ();
1430 var c
= new TypeLoadClass ();
1432 var c2
= new TypeLoadClass2 ();
1436 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1437 public static void regress () {
1438 regress_2755 (DateTime
.Now
);
1441 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1442 public static unsafe void regress_2755 (DateTime d
) {
1443 int* buffer
= stackalloc int [128];
1448 for (int i
= 0; i
< 128; ++i
)
1451 regress_2755_3 (sum
);
1454 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1455 public static void regress_2755_2 () {
1458 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1459 public static void regress_2755_3 (int sum
) {
1462 static object gc_suspend_field
;
1464 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1465 static unsafe void set_gc_suspend_field () {
1466 set_gc_suspend_field_2 ();
1468 int* buffer
= stackalloc int [4096];
1471 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1472 static void set_gc_suspend_field_2 () {
1473 gc_suspend_field
= new object ();
1476 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1477 static void gc_suspend_1 () {
1480 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1481 public static void gc_suspend_invoke () {
1482 gc_suspend_field
= null;
1484 GC
.WaitForPendingFinalizers ();
1487 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1488 public static void gc_suspend () {
1489 set_gc_suspend_field ();
1493 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1494 public static void generic_method
<T
> () where T
: class {
1497 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1498 public void evaluate_method_2 () {
1501 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1502 public void evaluate_method () {
1504 evaluate_method_2 ();
1507 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1508 static void set_ip_1 () {
1511 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1512 static void set_ip_2 () {
1515 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1516 public static void set_ip () {
1527 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1528 public static void step_filters () {
1529 ClassWithCctor
.cctor_filter ();
1532 class ClassWithCctor
{
1533 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1534 static ClassWithCctor () {
1539 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1540 public static void cctor_filter () {
1544 public override string virtual_method () {
1548 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1549 public static void threadpool_bp () { }
1551 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1552 public static void threadpool_io () {
1553 // Start a threadpool task that blocks on I/O.
1554 // Regression test for #42625
1555 const int nbytes
= 16;
1556 var bsOut
= new byte[nbytes
];
1557 for (int i
= 0; i
< nbytes
; i
++) {
1560 var endPoint
= NetworkHelpers
.LocalEphemeralEndPoint ();
1561 var l
= new TcpListener (endPoint
);
1563 Task
<byte[]> t
= Task
.Run (async () => {
1564 var c
= new TcpClient ();
1565 await c
.ConnectAsync (endPoint
.Address
, endPoint
.Port
);
1566 var streamIn
= c
.GetStream ();
1567 var bs
= new byte[nbytes
];
1569 int nremain
= nbytes
;
1570 while (nread
< nbytes
) {
1571 int r
= await streamIn
.ReadAsync (bs
, nread
, nremain
);
1578 var s
= l
.AcceptTcpClient ();
1580 // write bytes in two groups so that the task blocks on the ReadAsync
1581 var streamOut
= s
.GetStream ();
1582 var nbytesFirst
= nbytes
/ 2;
1583 var nbytesRest
= nbytes
- nbytesFirst
;
1584 streamOut
.Write (bsOut
, 0, nbytesFirst
);
1586 streamOut
.Write (bsOut
, nbytesFirst
, nbytesRest
);
1588 var bsIn
= t
.Result
;
1592 class TypeLoadClass
{
1595 class TypeLoadClass2
{
1598 public class SentinelClass
: MarshalByRefObject
{
1601 public class CrossDomain
: MarshalByRefObject
1603 SentinelClass printMe
= new SentinelClass ();
1605 public void invoke () {
1606 Tests
.invoke_in_domain ();
1609 public void invoke_2 () {
1610 Tests
.invoke_in_domain_2 ();
1613 public int invoke_3 () {
1620 public ProcessStartInfo info
;
1623 class LocalReflectClass
1625 public static void RunMe ()
1627 var reflectMe
= new someClass ();
1628 var temp
= reflectMe
; // Breakpoint location
1629 reflectMe
.someMethod ();
1632 class someClass
: ContextBoundObject
1634 public object someField
;
1636 public void someMethod ()
1642 // Class used for line number info testing, don't change its layout
1643 public class LineNumbers
1645 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1646 public static void ln1 () {
1652 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1653 public static void ln2 () {
1656 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1657 public static void ln3 () {
1658 #pragma warning disable 0219
1660 #pragma warning restore 0219