Author: martin
Date: 2007-01-23 16:25:56 -0500 (Tue, 23 Jan 2007)
New Revision: 71560

Added:
   trunk/debugger/test/src/TestMultiThread.cs
   trunk/debugger/test/testsuite/TestMultiThread.cs
Modified:
   trunk/debugger/ChangeLog
   trunk/debugger/test/src/Makefile.am
   trunk/debugger/test/testsuite/Makefile.am
Log:
2007-01-23  Martin Baulig  <[EMAIL PROTECTED]>

        * test/testsuite/TestMultiThread.cs: New test.
        * test/src/TestMultiThread.cs: New test.



Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog    2007-01-23 21:25:05 UTC (rev 71559)
+++ trunk/debugger/ChangeLog    2007-01-23 21:25:56 UTC (rev 71560)
@@ -1,5 +1,10 @@
 2007-01-23  Martin Baulig  <[EMAIL PROTECTED]>
 
+       * test/testsuite/TestMultiThread.cs: New test.
+       * test/src/TestMultiThread.cs: New test.
+
+2007-01-23  Martin Baulig  <[EMAIL PROTECTED]>
+
        * frontend/Interpreter.cs
        (Interpreter.WaitAll): Store the threads in a Hashtable instead of
        an ArrayList and only start each thread once.

Modified: trunk/debugger/test/src/Makefile.am
===================================================================
--- trunk/debugger/test/src/Makefile.am 2007-01-23 21:25:05 UTC (rev 71559)
+++ trunk/debugger/test/src/Makefile.am 2007-01-23 21:25:56 UTC (rev 71560)
@@ -11,7 +11,7 @@
        TestToString.exe TestObject.exe TestProperty.exe TestAbort.exe \
        TestBreakpoint.exe TestNamespace.exe TestException.exe \
        TestRestart.exe TestExec.exe TestChild.exe TestAttach.exe \
-       TestMethodLookup.exe
+       TestMethodLookup.exe TestMultiThread.exe
 
 EXTRA_DIST = \
        TestManagedTypes.cs TestInvocation.cs TestInheritance.cs \
@@ -20,7 +20,7 @@
        TestToString.cs TestObject.cs TestProperty.cs TestAbort.cs \
        TestBreakpoint.cs TestNamespace.cs TestException.cs \
        TestRestart.cs TestExec.cs TestChild.cs TestAttach.cs \
-       TestMethodLookup.cs
+       TestMethodLookup.cs TestMultiThread.exe
 
 noinst_PROGRAMS = \
        testnativefork testnativeexec testnativechild testnativeattach

Added: trunk/debugger/test/src/TestMultiThread.cs
===================================================================
--- trunk/debugger/test/src/TestMultiThread.cs  2007-01-23 21:25:05 UTC (rev 
71559)
+++ trunk/debugger/test/src/TestMultiThread.cs  2007-01-23 21:25:56 UTC (rev 
71560)
@@ -0,0 +1,48 @@
+using System;
+using System.Threading;
+
+class X
+{
+       public static bool Silent = false;
+
+       public X (string name)
+       {
+               this.Name = name;
+       }
+
+       public readonly string Name;
+       public int Counter;
+
+       static void Loop (int seconds)
+       {
+               Thread.Sleep (seconds * 50);
+       }
+
+       void LoopDone ()
+       {
+               if (!Silent)
+                       Console.WriteLine ("Loop: {0} {1}", Name, ++Counter);
+       }
+
+       void CommonFunction (int seconds)
+       {
+               for (;;) {
+                       Loop (seconds);
+                       LoopDone ();
+               }
+       }
+
+       static void ThreadMain ()
+       {
+               X x = new X ("child");
+               x.CommonFunction (7);
+       }
+
+       static void Main ()
+       {
+               Thread thread = new Thread (new ThreadStart (ThreadMain));
+               thread.Start ();
+               X x = new X ("main");
+               x.CommonFunction (11);
+       }
+}

Modified: trunk/debugger/test/testsuite/Makefile.am
===================================================================
--- trunk/debugger/test/testsuite/Makefile.am   2007-01-23 21:25:05 UTC (rev 
71559)
+++ trunk/debugger/test/testsuite/Makefile.am   2007-01-23 21:25:56 UTC (rev 
71560)
@@ -6,5 +6,5 @@
        TestManagedTypes.cs TestMethodLookup.cs TestNamespace.cs \
        testnativeattach.cs testnativeexec.cs testnativefork.cs \
        TestNull.cs TestObject.cs TestProperty.cs TestRestart.cs \
-       TestToString.cs
+       TestToString.cs TestMultiThread.cs
 

Added: trunk/debugger/test/testsuite/TestMultiThread.cs
===================================================================
--- trunk/debugger/test/testsuite/TestMultiThread.cs    2007-01-23 21:25:05 UTC 
(rev 71559)
+++ trunk/debugger/test/testsuite/TestMultiThread.cs    2007-01-23 21:25:56 UTC 
(rev 71560)
@@ -0,0 +1,103 @@
+using System;
+using NUnit.Framework;
+
+using Mono.Debugger;
+using Mono.Debugger.Languages;
+using Mono.Debugger.Frontend;
+
+namespace Mono.Debugger.Tests
+{
+       [TestFixture]
+       public class TestMultiThread : TestSuite
+       {
+               public TestMultiThread ()
+                       : base ("TestMultiThread")
+               { }
+
+               const int LineMain = 43;
+               const int LineLoop = 25;
+
+               int bpt_loop;
+
+               [Test]
+               [Category("Threads")]
+               public void Main ()
+               {
+                       Process process = Interpreter.Start ();
+                       Assert.IsTrue (process.IsManaged);
+                       Assert.IsTrue (process.MainThread.IsStopped);
+
+                       Thread thread = process.MainThread;
+                       AssertStopped (thread, "X.Main()", LineMain);
+
+                       bpt_loop = AssertBreakpoint (LineLoop);
+
+                       AssertExecute ("next");
+                       AssertStopped (thread, "X.Main()", LineMain + 1);
+
+                       AssertExecute ("next");
+                       Thread child = AssertThreadCreated ();
+                       AssertStopped (thread, "X.Main()", LineMain + 2);
+
+                       Assert.IsTrue (thread.IsStopped);
+                       Assert.IsTrue (child.IsStopped);
+                       Assert.IsTrue (Interpreter.CurrentThread == thread);
+
+                       AssertExecute ("continue");
+                       AssertTargetOutput ("Loop: child 1");
+                       AssertHitBreakpoint (child, bpt_loop, "X.LoopDone()", 
LineLoop);
+
+                       Assert.IsTrue (thread.IsStopped);
+                       Assert.IsTrue (child.IsStopped);
+                       Assert.IsTrue (Interpreter.CurrentThread == child);
+
+                       AssertExecute ("continue");
+                       AssertTargetOutput ("Loop: main 1");
+                       AssertHitBreakpoint (thread, bpt_loop, "X.LoopDone()", 
LineLoop);
+
+                       Assert.IsTrue (thread.IsStopped);
+                       Assert.IsTrue (child.IsStopped);
+                       Assert.IsTrue (Interpreter.CurrentThread == thread);
+
+                       AssertExecute ("continue -wait -thread " + thread.ID);
+                       AssertTargetOutput ("Loop: child 2");
+
+                       bool child_event = false, thread_event = false;
+
+                       while (!child_event || !thread_event) {
+                               DebuggerEvent e = AssertEvent ();
+
+                               if (e.Type == DebuggerEventType.TargetEvent) {
+                                       Thread e_thread = (Thread) e.Data;
+                                       TargetEventArgs args = 
(TargetEventArgs) e.Data2;
+
+                                       if ((args.Type == 
TargetEventType.TargetHitBreakpoint) &&
+                                           ((int) args.Data == bpt_loop)) {
+                                               if ((e_thread == thread) && 
!thread_event) {
+                                                       thread_event = true;
+                                                       continue;
+                                               } else if ((e_thread == child) 
&& !child_event) {
+                                                       child_event = true;
+                                                       continue;
+                                               }
+                                       }
+                               }
+
+                               Assert.Fail ("Received unexpected event {0}", 
e);
+                       }
+
+                       AssertTargetOutput ("Loop: main 2");
+                       AssertNoTargetOutput ();
+
+                       Assert.IsTrue (thread.IsStopped);
+                       Assert.IsTrue (child.IsStopped);
+                       Assert.IsTrue (Interpreter.CurrentThread == thread);
+
+                       AssertFrame (thread, "X.LoopDone()", LineLoop);
+                       AssertFrame (child, "X.LoopDone()", LineLoop);
+
+                       AssertExecute ("kill");
+
+               }
+       }
+}

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to