Browse Source

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
shortcuts
David Srbecký 16 years ago
parent
commit
a63473d1da
  1. 12
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs
  2. 9
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs
  3. 6
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs
  4. 14
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs
  5. 4
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTestsBase.cs
  6. 4
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs
  7. 9
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs
  8. 22
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs

12
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger.cs

@ -174,12 +174,18 @@ namespace Debugger
process.Start(); process.Start();
} }
internal object ProcessIsBeingCreatedLock = new object();
public Process Start(string filename, string workingDirectory, string arguments) public Process Start(string filename, string workingDirectory, string arguments)
{ {
InitDebugger(GetProgramVersion(filename)); InitDebugger(GetProgramVersion(filename));
Process process = Process.CreateProcess(this, filename, workingDirectory, arguments); lock(ProcessIsBeingCreatedLock) {
this.Processes.Add(process); Process process = Process.CreateProcess(this, filename, workingDirectory, arguments);
return process; // Expose a race conditon
System.Threading.Thread.Sleep(0);
this.Processes.Add(process);
return process;
}
} }
public Process Attach(System.Diagnostics.Process existingProcess) public Process Attach(System.Diagnostics.Process existingProcess)

9
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) static unsafe public Process CreateProcess(NDebugger debugger, string filename, string workingDirectory, string arguments)
{
return debugger.MTA2STA.Call<Process>(delegate{
return StartInternal(debugger, filename, workingDirectory, arguments);
});
}
static unsafe Process StartInternal(NDebugger debugger, string filename, string workingDirectory, string arguments)
{ {
debugger.TraceMessage("Executing " + filename); debugger.TraceMessage("Executing " + filename);

6
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs

@ -73,7 +73,11 @@ namespace Debugger
public ManagedCallback GetProcessCallbackInterface(string name, ICorDebugProcess pProcess) 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 // Make *really* sure the process is not dead
if (process == null) { if (process == null) {
debugger.TraceMessage("Ignoring callback \"" + name + "\": Process not found"); debugger.TraceMessage("Ignoring callback \"" + name + "\": Process not found");

14
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs

@ -5,24 +5,14 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using Debugger;
using Debugger.Interop;
using Microsoft.CSharp;
using NUnit.Framework;
using System; using System;
using System.CodeDom.Compiler; using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Threading;
using NIgnore = NUnit.Framework.IgnoreAttribute; using NIgnore = NUnit.Framework.IgnoreAttribute;
namespace Debugger.Tests namespace Debugger.Tests
{ {
[TestFixture] [TestFixture]
[NIgnore] //[NIgnore]
public partial class DebuggerTests: DebuggerTestsBase public partial class DebuggerTests: DebuggerTestsBase
{ {

4
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTestsBase.cs

@ -26,6 +26,8 @@ namespace Debugger.Tests
{ {
public class DebuggerTestsBase public class DebuggerTestsBase
{ {
string expetedOutputEnvVar = "SD_TESTS_DEBUGGER_XML_OUT";
protected NDebugger debugger; protected NDebugger debugger;
protected Process process; protected Process process;
protected string log; protected string log;
@ -105,7 +107,7 @@ namespace Debugger.Tests
if (actualXml != expectedXml) { if (actualXml != expectedXml) {
// Update the source code file with the new output // 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) { if (path != null) {
string filename = Path.Combine(path, testName); string filename = Path.Combine(path, testName);
string newSourceCode = File.ReadAllText(filename, Encoding.UTF8); string newSourceCode = File.ReadAllText(filename, Encoding.UTF8);

4
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); Value result = ExpressionEvaluator.Evaluate(expr, SupportedLanguage.CSharp, process.SelectedStackFrame);
restultFmted = ExpressionEvaluator.FormatValue(result); restultFmted = ExpressionEvaluator.FormatValue(result);
} catch (GetValueException e) { } catch (GetValueException e) {
restultFmted = "Error: " + e.Message; restultFmted = e.Message;
} }
} }
if (restultFmted != null) { if (restultFmted != null) {
@ -145,7 +145,7 @@ namespace Debugger.Tests {
<Eval> </Eval> <Eval> </Eval>
<Eval> (5 + 6) % (1 + 2) = 2 </Eval> <Eval> (5 + 6) % (1 + 2) = 2 </Eval>
<Eval> 15 &amp; 255 = 15 </Eval> <Eval> 15 &amp; 255 = 15 </Eval>
<Eval> 15 &amp;&amp; 255 = Error: Unsupported operator for integers: LogicalAnd </Eval> <Eval> 15 &amp;&amp; 255 = Error evaluating "15 &amp;&amp; 255": Unsupported operator for integers: LogicalAnd </Eval>
<Eval> b + 3 == i = True </Eval> <Eval> b + 3 == i = True </Eval>
<Eval> b + 4 == i = False </Eval> <Eval> b + 4 == i = False </Eval>
<Eval> true == true = True </Eval> <Eval> true == true = True </Eval>

9
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs

@ -26,7 +26,6 @@ namespace Debugger.Tests {
public partial class DebuggerTests public partial class DebuggerTests
{ {
[NUnit.Framework.Test] [NUnit.Framework.Test]
[NUnit.Framework.Ignore("Different tokens in .NET 4")]
public void MemoryReadWrite() public void MemoryReadWrite()
{ {
StartTest("MemoryReadWrite.cs"); StartTest("MemoryReadWrite.cs");
@ -37,8 +36,8 @@ namespace Debugger.Tests {
addrHello = DeRef(process.ReadMemory(addrHello, 4)); addrHello = DeRef(process.ReadMemory(addrHello, 4));
addrWorld = DeRef(process.ReadMemory(addrWorld, 4)); addrWorld = DeRef(process.ReadMemory(addrWorld, 4));
byte[] hello = process.ReadMemory(addrHello, 18); byte[] hello = process.ReadMemory(addrHello + 4, 14);
byte[] world = process.ReadMemory(addrWorld, 20); byte[] world = process.ReadMemory(addrWorld + 4, 16);
ObjectDump("hello", ToHex(hello)); ObjectDump("hello", ToHex(hello));
ObjectDump("world", ToHex(world)); ObjectDump("world", ToHex(world));
@ -75,8 +74,8 @@ namespace Debugger.Tests {
<ModuleLoaded>MemoryReadWrite.exe (Has symbols)</ModuleLoaded> <ModuleLoaded>MemoryReadWrite.exe (Has symbols)</ModuleLoaded>
<ModuleLoaded>System.dll (No symbols)</ModuleLoaded> <ModuleLoaded>System.dll (No symbols)</ModuleLoaded>
<DebuggingPaused>Break MemoryReadWrite.cs:18,4-18,40</DebuggingPaused> <DebuggingPaused>Break MemoryReadWrite.cs:18,4-18,40</DebuggingPaused>
<hello>54 B7 A1 79 5 0 0 0 48 0 65 0 6C 0 6C 0 6F 0 </hello> <hello>5 0 0 0 48 0 65 0 6C 0 6C 0 6F 0 </hello>
<world>54 B7 A1 79 6 0 0 0 20 0 20 0 20 0 20 0 20 0 21 0 </world> <world>6 0 0 0 20 0 20 0 20 0 20 0 20 0 21 0 </world>
<ModuleLoaded>System.Configuration.dll (No symbols)</ModuleLoaded> <ModuleLoaded>System.Configuration.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>System.Xml.dll (No symbols)</ModuleLoaded> <ModuleLoaded>System.Xml.dll (No symbols)</ModuleLoaded>
<LogMessage>Hello world!\r\n</LogMessage> <LogMessage>Hello world!\r\n</LogMessage>

22
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs

@ -28,17 +28,17 @@ namespace Debugger.Tests.TestPrograms
namespace Debugger.Tests { namespace Debugger.Tests {
public partial class DebuggerTests public partial class DebuggerTests
{ {
[NUnit.Framework.Test] // [NUnit.Framework.Test]
[NUnit.Framework.Ignore("Different behaviour in .NET 4")] // [NUnit.Framework.Ignore("Different behaviour in .NET 4")]
public void StackOverflow() // public void StackOverflow()
{ // {
StartTest("StackOverflow.cs"); // StartTest("StackOverflow.cs");
//
process.Continue(); // process.Continue();
//ObjectDump("LastStackFrame", process.SelectedThread.MostRecentStackFrame); // //ObjectDump("LastStackFrame", process.SelectedThread.MostRecentStackFrame);
//
EndTest(); // EndTest();
} // }
} }
} }
#endif #endif

Loading…
Cancel
Save