~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/DebugTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// DebugTests.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using NUnit.Framework;
 
29
using UnitTests;
 
30
using Mono.Debugging.Client;
 
31
using MonoDevelop.Core;
 
32
using MonoDevelop.Core.Execution;
 
33
using System.IO;
 
34
using System.Threading;
 
35
using MonoDevelop.Projects.Text;
 
36
 
 
37
namespace MonoDevelop.Debugger.Tests
 
38
{
 
39
        public abstract class DebugTests: TestBase
 
40
        {
 
41
                string eid;
 
42
                DebuggerEngine engine;
 
43
                
 
44
                public DebugTests (string engineId)
 
45
                {
 
46
                        eid = engineId;
 
47
                }
 
48
                
 
49
                public override void Setup ()
 
50
                {
 
51
                        base.Setup ();
 
52
                        foreach (DebuggerEngine e in DebuggingService.GetDebuggerEngines ()) {
 
53
                                if (e.Id == eid) {
 
54
                                        engine = e;
 
55
                                        break;
 
56
                                }
 
57
                        }
 
58
                }
 
59
 
 
60
                
 
61
                protected DebuggerSession Start (string test)
 
62
                {
 
63
                        DotNetExecutionCommand cmd = new DotNetExecutionCommand ();
 
64
                        cmd.Command = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "MonoDevelop.Debugger.Tests.TestApp.exe");
 
65
                        cmd.Arguments = test;
 
66
                        
 
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;
 
72
 
 
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);
 
77
                        if (i == -1)
 
78
                                throw new Exception ("Test not found: " + test);
 
79
                        i = file.Text.IndexOf ("/*break*/", i);
 
80
                        if (i == -1)
 
81
                                throw new Exception ("Break marker not found: " + test);
 
82
                        int line, col;
 
83
                        file.GetLineColumnFromPosition (i, out line, out col);
 
84
                        Breakpoint bp = session.Breakpoints.Add (path, line);
 
85
                        bp.Enabled = true;
 
86
                        
 
87
                        ManualResetEvent done = new ManualResetEvent (false);
 
88
                        
 
89
                        session.OutputWriter = delegate (bool isStderr, string text) {
 
90
                                Console.WriteLine ("PROC:" + text);
 
91
                        };
 
92
                        
 
93
                        session.TargetHitBreakpoint += delegate {
 
94
                                done.Set ();
 
95
                        };
 
96
                                
 
97
                        session.Run (si, ops);
 
98
                        if (!done.WaitOne (3000))
 
99
                                throw new Exception ("Timeout while waiting for initial breakpoint");
 
100
                        
 
101
                        return session;
 
102
                }
 
103
        }
 
104
        
 
105
        static class EvalHelper
 
106
        {
 
107
                public static ObjectValue Sync (this ObjectValue val)
 
108
                {
 
109
                        if (!val.IsEvaluating)
 
110
                                return val;
 
111
                        
 
112
                        object locker = new object ();
 
113
                        EventHandler h = delegate {
 
114
                                lock (locker) {
 
115
                                        Monitor.PulseAll (locker);
 
116
                                }
 
117
                        };
 
118
                        
 
119
                        val.ValueChanged += h;
 
120
                        
 
121
                        lock (locker) {
 
122
                                while (val.IsEvaluating) {
 
123
                                        if (!Monitor.Wait (locker, 4000))
 
124
                                                throw new Exception ("Timeout while waiting for value evaluation");
 
125
                                }
 
126
                        }
 
127
                        
 
128
                        val.ValueChanged -= h;
 
129
                        return val;
 
130
                }
 
131
        }
 
132
}