From a63473d1da2b3ef6823512160ea23bb818ff0d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 30 Aug 2009 12:36:07 +0000 Subject: [PATCH] Fixed race condition that was causing unit tests to fail git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4826 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Control/NDebugger.cs | 12 +++++++--- .../Project/Src/Control/Process.cs | 9 +------- .../Src/Internal/ManagedCallbackSwitch.cs | 6 ++++- .../Project/Src/DebuggerTests.cs | 14 ++---------- .../Project/Src/DebuggerTestsBase.cs | 4 +++- .../Project/Src/TestPrograms/AstEval.cs | 4 ++-- .../Src/TestPrograms/MemoryReadWrite.cs | 9 ++++---- .../Project/Src/TestPrograms/StackOverflow.cs | 22 +++++++++---------- 8 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs index f016ee6987..4eada62ac2 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs @@ -174,12 +174,18 @@ namespace Debugger process.Start(); } + internal object ProcessIsBeingCreatedLock = new object(); + public Process Start(string filename, string workingDirectory, string arguments) { InitDebugger(GetProgramVersion(filename)); - Process process = Process.CreateProcess(this, filename, workingDirectory, arguments); - this.Processes.Add(process); - return process; + lock(ProcessIsBeingCreatedLock) { + Process process = Process.CreateProcess(this, filename, workingDirectory, arguments); + // Expose a race conditon + System.Threading.Thread.Sleep(0); + this.Processes.Add(process); + return process; + } } public Process Attach(System.Diagnostics.Process existingProcess) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs index 501966b2f3..7bf5458e51 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs @@ -114,14 +114,7 @@ namespace Debugger } } - static public Process CreateProcess(NDebugger debugger, string filename, string workingDirectory, string arguments) - { - return debugger.MTA2STA.Call(delegate{ - return StartInternal(debugger, filename, workingDirectory, arguments); - }); - } - - static unsafe Process StartInternal(NDebugger debugger, string filename, string workingDirectory, string arguments) + static unsafe public Process CreateProcess(NDebugger debugger, string filename, string workingDirectory, string arguments) { debugger.TraceMessage("Executing " + filename); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs index b91524d15d..39898ace60 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs @@ -73,7 +73,11 @@ namespace Debugger public ManagedCallback GetProcessCallbackInterface(string name, ICorDebugProcess pProcess) { - Process process = debugger.Processes[pProcess]; + Process process; + // We have to wait until the created process is added into the collection + lock(debugger.ProcessIsBeingCreatedLock) { + process = debugger.Processes[pProcess]; + } // Make *really* sure the process is not dead if (process == null) { debugger.TraceMessage("Ignoring callback \"" + name + "\": Process not found"); diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs index 4b7d76ec1c..53f4c3a34d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs @@ -5,24 +5,14 @@ // $Revision$ // -using Debugger; -using Debugger.Interop; -using Microsoft.CSharp; -using NUnit.Framework; using System; -using System.CodeDom.Compiler; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Resources; -using System.Threading; +using NUnit.Framework; using NIgnore = NUnit.Framework.IgnoreAttribute; namespace Debugger.Tests { [TestFixture] - [NIgnore] + //[NIgnore] public partial class DebuggerTests: DebuggerTestsBase { diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTestsBase.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTestsBase.cs index f9c392920b..79c55cedbe 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTestsBase.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTestsBase.cs @@ -26,6 +26,8 @@ namespace Debugger.Tests { public class DebuggerTestsBase { + string expetedOutputEnvVar = "SD_TESTS_DEBUGGER_XML_OUT"; + protected NDebugger debugger; protected Process process; protected string log; @@ -105,7 +107,7 @@ namespace Debugger.Tests if (actualXml != expectedXml) { // Update the source code file with the new output - string path = Environment.GetEnvironmentVariable("SD_TESTS_DEBUGGER_XML_OUT"); + string path = Environment.GetEnvironmentVariable(expetedOutputEnvVar); if (path != null) { string filename = Path.Combine(path, testName); string newSourceCode = File.ReadAllText(filename, Encoding.UTF8); diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs index 96c490a48b..ab97484b76 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs @@ -108,7 +108,7 @@ namespace Debugger.Tests { Value result = ExpressionEvaluator.Evaluate(expr, SupportedLanguage.CSharp, process.SelectedStackFrame); restultFmted = ExpressionEvaluator.FormatValue(result); } catch (GetValueException e) { - restultFmted = "Error: " + e.Message; + restultFmted = e.Message; } } if (restultFmted != null) { @@ -145,7 +145,7 @@ namespace Debugger.Tests { (5 + 6) % (1 + 2) = 2 15 & 255 = 15 - 15 && 255 = Error: Unsupported operator for integers: LogicalAnd + 15 && 255 = Error evaluating "15 && 255": Unsupported operator for integers: LogicalAnd b + 3 == i = True b + 4 == i = False true == true = True diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs index 00e43b9267..5b8e9fd8d4 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs @@ -26,7 +26,6 @@ namespace Debugger.Tests { public partial class DebuggerTests { [NUnit.Framework.Test] - [NUnit.Framework.Ignore("Different tokens in .NET 4")] public void MemoryReadWrite() { StartTest("MemoryReadWrite.cs"); @@ -37,8 +36,8 @@ namespace Debugger.Tests { addrHello = DeRef(process.ReadMemory(addrHello, 4)); addrWorld = DeRef(process.ReadMemory(addrWorld, 4)); - byte[] hello = process.ReadMemory(addrHello, 18); - byte[] world = process.ReadMemory(addrWorld, 20); + byte[] hello = process.ReadMemory(addrHello + 4, 14); + byte[] world = process.ReadMemory(addrWorld + 4, 16); ObjectDump("hello", ToHex(hello)); ObjectDump("world", ToHex(world)); @@ -75,8 +74,8 @@ namespace Debugger.Tests { MemoryReadWrite.exe (Has symbols) System.dll (No symbols) Break MemoryReadWrite.cs:18,4-18,40 - 54 B7 A1 79 5 0 0 0 48 0 65 0 6C 0 6C 0 6F 0 - 54 B7 A1 79 6 0 0 0 20 0 20 0 20 0 20 0 20 0 21 0 + 5 0 0 0 48 0 65 0 6C 0 6C 0 6F 0 + 6 0 0 0 20 0 20 0 20 0 20 0 20 0 21 0 System.Configuration.dll (No symbols) System.Xml.dll (No symbols) Hello world!\r\n diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs index 96c70d17e8..0f2b07469e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs @@ -28,17 +28,17 @@ namespace Debugger.Tests.TestPrograms namespace Debugger.Tests { public partial class DebuggerTests { - [NUnit.Framework.Test] - [NUnit.Framework.Ignore("Different behaviour in .NET 4")] - public void StackOverflow() - { - StartTest("StackOverflow.cs"); - - process.Continue(); - //ObjectDump("LastStackFrame", process.SelectedThread.MostRecentStackFrame); - - EndTest(); - } +// [NUnit.Framework.Test] +// [NUnit.Framework.Ignore("Different behaviour in .NET 4")] +// public void StackOverflow() +// { +// StartTest("StackOverflow.cs"); +// +// process.Continue(); +// //ObjectDump("LastStackFrame", process.SelectedThread.MostRecentStackFrame); +// +// EndTest(); +// } } } #endif