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. 6
      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

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

@ -174,13 +174,19 @@ namespace Debugger @@ -174,13 +174,19 @@ namespace Debugger
process.Start();
}
internal object ProcessIsBeingCreatedLock = new object();
public Process Start(string filename, string workingDirectory, string arguments)
{
InitDebugger(GetProgramVersion(filename));
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)
{

9
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs

@ -114,14 +114,7 @@ namespace Debugger @@ -114,14 +114,7 @@ namespace Debugger
}
}
static 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)
static unsafe public Process CreateProcess(NDebugger debugger, string filename, string workingDirectory, string arguments)
{
debugger.TraceMessage("Executing " + filename);

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

@ -73,7 +73,11 @@ namespace Debugger @@ -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");

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

@ -5,24 +5,14 @@ @@ -5,24 +5,14 @@
// <version>$Revision$</version>
// </file>
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
{

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

@ -26,6 +26,8 @@ namespace Debugger.Tests @@ -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 @@ -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);

4
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs

@ -108,7 +108,7 @@ namespace Debugger.Tests { @@ -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 { @@ -145,7 +145,7 @@ namespace Debugger.Tests {
<Eval> </Eval>
<Eval> (5 + 6) % (1 + 2) = 2 </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 + 4 == i = False </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 { @@ -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 { @@ -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 { @@ -75,8 +74,8 @@ namespace Debugger.Tests {
<ModuleLoaded>MemoryReadWrite.exe (Has symbols)</ModuleLoaded>
<ModuleLoaded>System.dll (No symbols)</ModuleLoaded>
<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>
<world>54 B7 A1 79 6 0 0 0 20 0 20 0 20 0 20 0 20 0 21 0 </world>
<hello>5 0 0 0 48 0 65 0 6C 0 6C 0 6F 0 </hello>
<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.Xml.dll (No symbols)</ModuleLoaded>
<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 @@ -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

Loading…
Cancel
Save