OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #region | |
6 | |
7 using System; | |
8 using System.IO; | |
9 using System.Linq; | |
10 using Google.MsAd7.BaseImpl; | |
11 using Google.MsAd7.BaseImpl.Interfaces; | |
12 using Google.NaClVsx.DebugSupport; | |
13 using Microsoft.VisualStudio.TestTools.UnitTesting; | |
14 | |
15 #endregion | |
16 | |
17 namespace NaClVsx.Package_UnitTestProject { | |
18 /// <summary> | |
19 /// Contains various utilities that are useful for multiple tests. | |
20 /// </summary> | |
21 class NaClPackageTestUtils { | |
22 #region constants | |
23 | |
24 /// <summary> | |
25 /// This points at an empty line inside of a function. | |
26 /// </summary> | |
27 public const uint kBlankLineInPrintLoop = 22; | |
28 | |
29 /// <summary> | |
30 /// This is the location at which I is declared in print_line in loop.cc. | |
31 /// </summary> | |
32 public const uint kDeclarationOfIRow = 8; | |
33 | |
34 /// <summary> | |
35 /// This is the location at which test_string is declared in void main in
loop.cc. | |
36 /// </summary> | |
37 public const uint kDeclarationOfTestStringRow = 46; | |
38 | |
39 /// <summary> | |
40 /// This is the call site of the foo function in loop.cc. | |
41 /// </summary> | |
42 public const uint kFooCallSiteRow = 49; | |
43 | |
44 /// <summary> | |
45 /// This is the line of the closing paren of the main function in loop.cc. | |
46 /// </summary> | |
47 public const uint kMainEndRow = 52; | |
48 | |
49 /// <summary> | |
50 /// This is the first line of the body of the main function in loop.cc. | |
51 /// </summary> | |
52 public const uint kMainStartRow = 44; | |
53 | |
54 /// <summary> | |
55 /// This is the location of the printf in print_char_type in loop.cc | |
56 /// </summary> | |
57 public const uint kPrintCharTypePrintfRow = 39; | |
58 | |
59 /// <summary> | |
60 /// This is the call site of the print_line function in loop.cc. | |
61 /// </summary> | |
62 public const uint kPrintLineCallSiteRow = 24; | |
63 | |
64 /// <summary> | |
65 /// This is a line number somewhere in the print_line function in loop.cc. | |
66 /// We don't care exactly which one. | |
67 /// </summary> | |
68 public const uint kPrintLineRow = 10; | |
69 | |
70 /// <summary> | |
71 /// This is the call site of the print_loop function in loop.cc. | |
72 /// </summary> | |
73 public const uint kPrintLoopCallSiteRow = 31; | |
74 | |
75 #endregion | |
76 | |
77 /// <summary> | |
78 /// Creates a new NaClSymbolProvider and parses our loop.nexe sample | |
79 /// binary. | |
80 /// </summary> | |
81 /// <returns>The pre-loaded symbol provider.</returns> | |
82 public static NaClSymbolProvider LoadLoopNexe() { | |
83 var symbolProvider = new NaClSymbolProvider(null); | |
84 string status; | |
85 var ok = symbolProvider.LoadModule( | |
86 Path.Combine( | |
87 GetVsxRootDir(), | |
88 kNexePath), | |
89 kBaseAddr, | |
90 out status); | |
91 Assert.IsTrue(ok, "LoadModule failed"); | |
92 return symbolProvider; | |
93 } | |
94 | |
95 public static string GetLoopCCPath() { | |
96 return vsxRootDir + kCCPath; | |
97 } | |
98 | |
99 /// <summary> | |
100 /// Finds the SDK root, using the system environment. Will fail to assert | |
101 /// if root cannot be located. | |
102 /// </summary> | |
103 /// <returns>The location of the VSX root directory.</returns> | |
104 public static string GetVsxRootDir() { | |
105 if (null == vsxRootDir) { | |
106 vsxRootDir = Environment.GetEnvironmentVariable("NACL_VSX_ROOT"); | |
107 } | |
108 Assert.IsNotNull( | |
109 vsxRootDir, | |
110 "Could not get NACL_VSX_ROOT from environment."); | |
111 return vsxRootDir; | |
112 } | |
113 | |
114 public static ulong GetAddressForPosition( | |
115 string path, uint line, ISimpleSymbolProvider symbolProvider) { | |
116 var pos = new DocumentPosition(path, line); | |
117 var addresses = symbolProvider.AddressesFromPosition(pos); | |
118 Assert.IsNotNull(addresses); | |
119 Assert.AreEqual(1, addresses.Count()); | |
120 return addresses.First(); | |
121 } | |
122 | |
123 public static PendingBreakpoint GetPendingBreakpoint() { | |
124 var sdbMock = new NaClDebuggerMock(); | |
125 sdbMock.Symbols = new NaClSymbolProvider(sdbMock); | |
126 var requestMock = new BreakpointRequestMock(); | |
127 var request = new BreakpointRequest(requestMock); | |
128 | |
129 // The instance to test. | |
130 return new PendingBreakpoint(sdbMock, request); | |
131 } | |
132 | |
133 #region Private Implementation | |
134 | |
135 /// <summary> | |
136 /// The location, relative to |vsxRootDir|, at which the loop.cc source | |
137 /// is to be found. | |
138 /// </summary> | |
139 private static readonly string kCCPath = @"src\loop\loop.cc"; | |
140 | |
141 /// <summary> | |
142 /// The location, relative to |vsxRootDir|, at which the loop.nexe is to | |
143 /// be found. | |
144 /// </summary> | |
145 private static readonly string kNexePath = @"src\loop\loop.nexe"; | |
146 | |
147 /// <summary> | |
148 /// The location of the visual studio plugin code. | |
149 /// </summary> | |
150 private static string vsxRootDir; | |
151 | |
152 #endregion | |
153 | |
154 /// <summary> | |
155 /// The base address at which symbol information should start in nexe code
. | |
156 /// </summary> | |
157 public static readonly ulong kBaseAddr = 0x0000000c00000000; | |
158 } | |
159 } | |
OLD | NEW |