From 08b3a84a5de6ff9be054c6474881299c10b84354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Tue, 1 Jul 2008 22:56:51 +0000 Subject: [PATCH] Process.Terminate blocks until the process is terminated. Improved termination unit tests git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3158 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Control/Process-StateControl.cs | 14 ++++++--- .../Project/Src/TestPrograms/Exception.cs | 16 +++++++++- .../TestPrograms/TerminatePausedProcess.cs | 3 +- .../TestPrograms/TerminateRunningProcess.cs | 30 +++++++++++++++---- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-StateControl.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-StateControl.cs index c4f4786d4f..b3c0a780ca 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-StateControl.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-StateControl.cs @@ -223,9 +223,15 @@ namespace Debugger } /// Terminates the execution of the process - /// The process does not terminate immediately - /// after the call public void Terminate() + { + AsyncTerminate(); + // Wait until ExitProcess callback is received + WaitForExit(); + } + + /// Terminates the execution of the process + public void AsyncTerminate() { // Resume stoped tread if (this.IsPaused) { @@ -240,8 +246,8 @@ namespace Debugger corProcess.Stop(uint.MaxValue); corProcess.Terminate(0); - // Just give the command and continue without marking the process as - // exited. We will get ExitProcess callback soon + // Do not mark the process as exited + // This is done once ExitProcess callback is received } void SelectSomeThread() diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Exception.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Exception.cs index f64d283f08..7ee9b6eb68 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Exception.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Exception.cs @@ -13,6 +13,8 @@ namespace Debugger.Tests.TestPrograms { public static void Main() { + System.Diagnostics.Debugger.Break(); + throw new System.Exception("test"); } } @@ -20,6 +22,8 @@ namespace Debugger.Tests.TestPrograms #if TEST_CODE namespace Debugger.Tests { + using NUnit.Framework; + public partial class DebuggerTests { [NUnit.Framework.Test] @@ -27,6 +31,16 @@ namespace Debugger.Tests { { StartTest("Exception.cs"); + process.ExceptionThrown += delegate { + process.Terminate(); + }; + process.Paused += delegate { + // Should not be raised for dead process + Assert.Fail(); + }; + + process.AsyncContinue(); + process.WaitForExit(); EndTest(); } } @@ -40,8 +54,8 @@ namespace Debugger.Tests { mscorlib.dll Exception.exe + Break test - Exception diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminatePausedProcess.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminatePausedProcess.cs index 2641080ead..5b4c86a1f7 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminatePausedProcess.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminatePausedProcess.cs @@ -27,11 +27,10 @@ namespace Debugger.Tests { { StartTest("TerminatePausedProcess.cs"); process.Terminate(); - process.WaitForExit(); StartTest("TerminatePausedProcess.cs"); process.Terminate(); - process.WaitForExit(); + CheckXmlOutput(); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminateRunningProcess.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminateRunningProcess.cs index ad95c93ee8..c7c3de3b18 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminateRunningProcess.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/TerminateRunningProcess.cs @@ -16,6 +16,8 @@ namespace Debugger.Tests.TestPrograms public static void Main() { + int i = 42; + System.Diagnostics.Debugger.Break(); doSomething.WaitOne(); } } @@ -23,18 +25,24 @@ namespace Debugger.Tests.TestPrograms #if TEST_CODE namespace Debugger.Tests { + using NUnit.Framework; + public partial class DebuggerTests { [NUnit.Framework.Test] public void TerminateRunningProcess() { - StartTest("TerminateRunningProcess.cs", false); - process.Terminate(); - process.WaitForExit(); + for(int i = 0; i < 2; i++) { + StartTest("TerminateRunningProcess.cs"); + process.SelectedStackFrame.StepOver(); + process.Paused += delegate { + Assert.Fail("Should not have received any callbacks after Terminate"); + }; + process.SelectedStackFrame.AsyncStepOver(); + ObjectDump("Log", "Calling terminate"); + process.Terminate(); + } - StartTest("TerminateRunningProcess.cs", false); - process.Terminate(); - process.WaitForExit(); CheckXmlOutput(); } } @@ -46,8 +54,18 @@ namespace Debugger.Tests { + mscorlib.dll + TerminateRunningProcess.exe + Break + StepComplete + Calling terminate + mscorlib.dll + TerminateRunningProcess.exe + Break + StepComplete + Calling terminate