5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using NUnit.Framework;
30
using Mono.Debugging.Client;
31
using MonoDevelop.Core;
32
using MonoDevelop.Core.Execution;
34
using System.Threading;
35
using MonoDevelop.Projects.Text;
37
namespace MonoDevelop.Debugger.Tests
39
public abstract class DebugTests: TestBase
42
DebuggerEngine engine;
44
public DebugTests (string engineId)
49
public override void Setup ()
52
foreach (DebuggerEngine e in DebuggingService.GetDebuggerEngines ()) {
61
protected DebuggerSession Start (string test)
63
DotNetExecutionCommand cmd = new DotNetExecutionCommand ();
64
cmd.Command = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "MonoDevelop.Debugger.Tests.TestApp.exe");
67
DebuggerStartInfo si = engine.CreateDebuggerStartInfo (cmd);
68
DebuggerSession session = engine.CreateSession ();
69
DebuggerSessionOptions ops = new DebuggerSessionOptions ();
70
ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
71
ops.EvaluationOptions.EvaluationTimeout = 100000;
73
FilePath path = Util.TestsRootDir;
74
path = path.ParentDirectory.Combine ("src","addins","MonoDevelop.Debugger","MonoDevelop.Debugger.Tests.TestApp","Main.cs").FullPath;
75
TextFile file = TextFile.ReadFile (path);
76
int i = file.Text.IndexOf ("void " + test);
78
throw new Exception ("Test not found: " + test);
79
i = file.Text.IndexOf ("/*break*/", i);
81
throw new Exception ("Break marker not found: " + test);
83
file.GetLineColumnFromPosition (i, out line, out col);
84
Breakpoint bp = session.Breakpoints.Add (path, line);
87
ManualResetEvent done = new ManualResetEvent (false);
89
session.OutputWriter = delegate (bool isStderr, string text) {
90
Console.WriteLine ("PROC:" + text);
93
session.TargetHitBreakpoint += delegate {
97
session.Run (si, ops);
98
if (!done.WaitOne (3000))
99
throw new Exception ("Timeout while waiting for initial breakpoint");
105
static class EvalHelper
107
public static ObjectValue Sync (this ObjectValue val)
109
if (!val.IsEvaluating)
112
object locker = new object ();
113
EventHandler h = delegate {
115
Monitor.PulseAll (locker);
119
val.ValueChanged += h;
122
while (val.IsEvaluating) {
123
if (!Monitor.Wait (locker, 4000))
124
throw new Exception ("Timeout while waiting for value evaluation");
128
val.ValueChanged -= h;