2009-11-20 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mono / tests / dtest.cs
index c00d73cec2f593ba8d5d18c0e44eef763a11f8ab..1aa9638dd19baac48d15c6cd5adeb5a8c94ae7e7 100644 (file)
@@ -4,6 +4,7 @@ using System.Threading;
 using System.Net;
 using Mono.Cecil.Cil;
 using Mono.Debugger;
+using Diag = System.Diagnostics;
 
 using NUnit.Framework;
 
@@ -33,7 +34,14 @@ public class DebuggerTests
 
        void Start (string[] args) {
                if (!listening) {
-                       vm = VirtualMachineManager.Launch (args, new LaunchOptions { Runtime = runtime != null ? runtime : null, AgentArgs = "loglevel=0" });
+                       var pi = new Diag.ProcessStartInfo ();
+
+                       if (runtime != null)
+                               pi.FileName = runtime;
+                       else
+                               pi.FileName = "mono";
+                       pi.Arguments = String.Join (" ", args);
+                       vm = VirtualMachineManager.Launch (pi, new LaunchOptions { AgentArgs = "loglevel=0" });
                } else {
                        Console.WriteLine ("Listening...");
                        vm = VirtualMachineManager.Listen (new IPEndPoint (IPAddress.Any, 10000));
@@ -1202,11 +1210,14 @@ public class DebuggerTests
        }
 
        [Test]
-       public void Modules () {
+       public void AssemblyInfo () {
                Event e = run_until ("single_stepping");
 
                StackFrame frame = e.Thread.GetFrames () [0];
 
+               var aname = frame.Method.DeclaringType.Assembly.GetName ();
+               Assert.AreEqual ("dtest-app, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", aname.ToString ());
+
                ModuleMirror m = frame.Method.DeclaringType.Module;
 
                Assert.AreEqual ("dtest-app.exe", m.Name);
@@ -1738,6 +1749,9 @@ public class DebuggerTests
                        if (!finished)
                                Monitor.Wait (wait);
                }
+
+               // Check InvokeOptions.DisableBreakpoints flag
+               o.InvokeMethod (e.Thread, m, null, InvokeOptions.DisableBreakpoints);
        }
 
        [Test]
@@ -1757,7 +1771,8 @@ public class DebuggerTests
 
                e = vm.GetNextEvent ();
                Assert.IsInstanceOfType (typeof (ThreadStartEvent), e);
-               Assert.AreEqual (ThreadState.Running, e.Thread.ThreadState);
+               var state = e.Thread.ThreadState;
+               Assert.IsTrue (state == ThreadState.Running || state == ThreadState.Unstarted);
 
                vm.Resume ();
 
@@ -2014,4 +2029,36 @@ public class DebuggerTests
 
                AssertValue (true, entry_point.DeclaringType.GetValue (f));
        }
+
+       [Test]
+       public void StackTraceInNative () {
+               // Check that stack traces can be produced for threads in native code
+               vm.Dispose ();
+
+               Start (new string [] { "dtest-app.exe", "frames-in-native" });
+
+               var e = run_until ("frames_in_native");
+
+               // FIXME: This is racy
+               vm.Resume ();
+
+               Thread.Sleep (100);
+
+               vm.Suspend ();
+
+               StackFrame[] frames = e.Thread.GetFrames ();
+
+               int frame_index = -1;
+               for (int i = 0; i < frames.Length; ++i) {
+                       if (frames [i].Method.Name == "Sleep") {
+                               frame_index = i;
+                               break;
+                       }
+               }
+
+               Assert.IsTrue (frame_index != -1);
+               Assert.AreEqual ("Sleep", frames [frame_index].Method.Name);
+               Assert.AreEqual ("frames_in_native", frames [frame_index + 1].Method.Name);
+               Assert.AreEqual ("Main", frames [frame_index + 2].Method.Name);
+       }
 }
\ No newline at end of file