Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: experimental/visual_studio_plugin/src/NaClVsx.Package/NaClVsx.Package_UnitTestProject/DwarfReaderImplTest.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.Collections.Generic;
8 using Google.NaClVsx.DebugSupport.DWARF;
9 using Microsoft.VisualStudio.TestTools.UnitTesting;
10
11 #endregion
12
13 namespace NaClVsx.Package_UnitTestProject {
14 ///<summary>
15 /// This is a test class for DwarfReaderImplTest and is intended
16 /// to contain all DwarfReaderImplTest Unit Tests
17 ///</summary>
18 [TestClass]
19 public class DwarfReaderImplTest {
20 ///<summary>
21 /// Gets or sets the test context which provides
22 /// information about and functionality for the current test run.
23 ///</summary>
24 public TestContext TestContext { get; set; }
25
26 #region Additional test attributes
27
28 //Use TestInitialize to run code before running each test
29 [TestInitialize]
30 public void MyTestInitialize() {
31 testDb_ = new SymbolDatabase();
32 target_ = null;
33 attributeCount_ = 0;
34 }
35
36 #endregion
37
38 /// <summary>
39 /// A test that exercises the entire interface. There are quite a few
40 /// functions in the interface that don't return a value or have effects
41 /// that can only be verified by calling other functions. The asserts
42 /// to validate these functions are in the test functions that are being
43 /// called here.
44 /// </summary>
45 [TestMethod]
46 public void InterfaceExerciseTest() {
47 DwarfReaderImplConstructorTest();
48 const string kAttributeData = "sample_data";
49
50 StartCompilationUnitTest();
51 StartDIETest();
52 ProcessAttributeTest(
53 kDieOffset,
54 kDieOffset,
55 DwarfAttribute.DW_AT_name,
56 kAttributeData);
57 target_.EndDIE(kDieOffset);
58 DefineDirTest();
59 DefineFileTest();
60 AddLineTest();
61 AddLocListEntryTest();
62 target_.EndCompilationUnit();
63 BeginCfiEntryTest();
64 AddCfiRuleTest();
65 EndCfiEntryTest();
66 }
67
68 /// <summary>
69 /// A test for StartDIE
70 /// </summary>
71 [TestMethod]
72 public void StartDIETest() {
73 DwarfReaderImplConstructorTest();
74 const ulong kParent = 0;
75 const DwarfTag kTag = DwarfTag.DW_TAG_variable;
76 target_.StartDIE(kParent, kDieOffset, kTag);
77 // Check that the DIE was added to the symbol database
78 var dbEntry = testDb_.Entries[kDieOffset];
79 Assert.IsNotNull(dbEntry);
80 Assert.AreEqual(dbEntry.ParentKey, kParent);
81 Assert.AreEqual(dbEntry.Tag, kTag);
82 }
83
84 // <summary>
85 // A test for StartCompilationUnit.
86 // </summary>
87 [TestMethod]
88 public void StartCompilationUnitTest() {
89 DwarfReaderImplConstructorTest();
90 var privates = GetPrivates();
91 var compIndex = (ushort) privates.GetField("compilationUnitIndex_");
92 Assert.AreEqual(0, compIndex);
93 target_.StartCompilationUnit();
94 compIndex = (ushort) privates.GetField("compilationUnitIndex_");
95 Assert.AreEqual(1, compIndex);
96 }
97
98 ///<summary>
99 /// A test for ProcessAttribute
100 ///</summary>
101 [TestMethod]
102 public void ProcessAttributeTest() {
103 DwarfReaderImplConstructorTest();
104 const DwarfAttribute kNameAttribute = DwarfAttribute.DW_AT_name;
105 const string kNameAttributeData = "variable_name";
106
107 const DwarfAttribute kDeclarationAttribute =
108 DwarfAttribute.DW_AT_declaration;
109 const byte kDeclarationAttributeData = 1;
110
111 const DwarfAttribute kTypeAttribute = DwarfAttribute.DW_AT_type;
112 // This should actually point to another DIE but structure doesn't
113 // matter for this test.
114 const string kTypeAttributeData = "bogus";
115
116 StartDIETest();
117
118 ProcessAttributeTest(
119 kDieOffset,
120 kDieOffset,
121 kNameAttribute,
122 kNameAttributeData);
123 ProcessAttributeTest(
124 kDieOffset,
125 kDieOffset,
126 kDeclarationAttribute,
127 kDeclarationAttributeData);
128 ProcessAttributeTest(
129 kDieOffset,
130 kDieOffset,
131 kTypeAttribute,
132 kTypeAttributeData);
133 }
134
135 /// <summary>
136 /// A test for ProcessAttribute
137 /// </summary>
138 [TestMethod]
139 public void ProcessAttributeTestRangesAttribute() {
140 DwarfReaderImplConstructorTest();
141 const DwarfAttribute kRangesAttribute = DwarfAttribute.DW_AT_ranges;
142 const ulong kRangesAttributeData = 1;
143
144 StartDIETest();
145 var targetPrivates = new PrivateObject(target_);
146 var targetScopeStack = targetPrivates.GetField("scopeStack_") as Stack<Deb ugInfoEntry>;
147 Assert.IsNotNull(targetScopeStack);
148 var beforeScopeCount = targetScopeStack.Count;
149 ProcessAttributeTest(
150 kDieOffset,
151 kDieOffset,
152 kRangesAttribute,
153 kRangesAttributeData);
154 var afterScopeCount = targetScopeStack.Count;
155 Assert.AreEqual(beforeScopeCount + 1, afterScopeCount);
156 }
157
158 ///<summary>
159 /// A test for MakeFileKey
160 ///</summary>
161 [TestMethod]
162 [DeploymentItem("NaClVsx.Package.dll")]
163 public void MakeFileKeyTest() {
164 DwarfReaderImplConstructorTest();
165 var privates = GetPrivates();
166 const uint kFileNum = 4;
167 privates.Invoke("StartCompilationUnit");
168 var actual1 = (ulong) privates.Invoke("MakeFileKey", kFileNum);
169 privates.Invoke("StartCompilationUnit");
170 var actual2 = (ulong) privates.Invoke("MakeFileKey", kFileNum);
171 Assert.AreNotEqual(actual1, actual2);
172 }
173
174 /// <summary>
175 /// A test for EndDIE
176 /// </summary>
177 [TestMethod]
178 public void EndDIETest() {
179 DwarfReaderImplConstructorTest();
180 const ulong kLowData = 123456;
181 const ulong kHighData = 123654;
182 Assert.AreEqual(0, testDb_.ScopeTransitions.Count);
183 StartDIETest();
184 ProcessAttributeTest(
185 kDieOffset,
186 kDieOffset,
187 DwarfAttribute.DW_AT_low_pc,
188 kLowData);
189 ProcessAttributeTest(
190 kDieOffset,
191 kDieOffset,
192 DwarfAttribute.DW_AT_high_pc,
193 kHighData);
194 target_.EndDIE(kDieOffset);
195 Assert.AreEqual(2, testDb_.ScopeTransitions.Count);
196 }
197
198 /// <summary>
199 /// A test for EndCompilationUnit
200 /// </summary>
201 [TestMethod]
202 public void EndCompilationUnitTest() {
203 DwarfReaderImplConstructorTest();
204 // No point in having a test here since the function does nothing.
205 }
206
207 /// <summary>
208 /// A test for EndCfiEntry
209 /// </summary>
210 [TestMethod]
211 public void EndCfiEntryTest() {
212 DwarfReaderImplConstructorTest();
213 const bool kExpected = true;
214 BeginCfiEntryTest();
215 Assert.AreEqual(0, testDb_.CallFrames.Count);
216 var actual = target_.EndCfiEntry();
217 Assert.AreEqual(kExpected, actual);
218
219 Assert.IsNull(GetPrivates().GetField("currentFrame_"));
220 Assert.AreEqual(1, testDb_.CallFrames.Count);
221 var callFrame = testDb_.CallFrames[kCfiEntryAddress];
222 Assert.IsNotNull(callFrame);
223 }
224
225 /// <summary>
226 /// A test for DefineFile
227 /// </summary>
228 [TestMethod]
229 public void DefineFileTest() {
230 DwarfReaderImplConstructorTest();
231 const string kFileName = "sampleFileName";
232 target_.DefineFile(kFileName, 1, 1);
233 Assert.AreEqual(testDb_.Files.Count, 1);
234 var key = (ulong) GetPrivates().Invoke("MakeFileKey", (uint) 1);
235 Assert.AreEqual(kFileName, testDb_.Files[key].Filename);
236 }
237
238 ///<summary>
239 /// A test for DefineDir
240 ///</summary>
241 [TestMethod]
242 public void DefineDirTest() {
243 DwarfReaderImplConstructorTest();
244 const string kDirName = "sampleDirName";
245 const uint kDirNum = 42;
246 target_.DefineDir(kDirName, kDirNum);
247 var dirs = (Dictionary<uint, string>) GetPrivates().GetField("dirs_");
248 Assert.AreEqual(dirs[kDirNum], kDirName);
249 }
250
251 ///<summary>
252 /// A test for BeginCfiEntry
253 ///</summary>
254 [TestMethod]
255 public void BeginCfiEntryTest() {
256 DwarfReaderImplConstructorTest();
257 var actual = target_.BeginCfiEntry(kCfiEntryAddress);
258 Assert.AreEqual(true, actual);
259 Assert.AreNotEqual(null, GetPrivates().GetField("currentFrame_"));
260 }
261
262 ///<summary>
263 /// A test for AddLocListEntry
264 ///</summary>
265 [TestMethod]
266 public void AddLocListEntryTest() {
267 DwarfReaderImplConstructorTest();
268 const ulong kLocListOffset = 1234567;
269 const ulong kLocListLowPC = 654321;
270 const ulong kLocListHighPC = 654324;
271 var rawData = new byte[4];
272 rawData[0] = 1;
273 rawData[1] = 2;
274 rawData[2] = 3;
275 rawData[3] = 4;
276 target_.AddLocListEntry(
277 kLocListOffset,
278 true,
279 kLocListLowPC,
280 kLocListHighPC,
281 rawData);
282 var locList = testDb_.LocLists[kLocListOffset];
283 Assert.IsNotNull(locList);
284 Assert.AreEqual(1, locList.Count);
285 var entry = locList[0];
286 Assert.IsNotNull(entry);
287 Assert.AreEqual(entry.StartAddress, kLocListLowPC);
288 Assert.AreEqual(entry.EndAddress, kLocListHighPC);
289 Assert.AreEqual(entry.Data, rawData);
290 }
291
292 ///<summary>
293 /// A test for AddLine
294 ///</summary>
295 [TestMethod]
296 public void AddLineTest() {
297 DwarfReaderImplConstructorTest();
298 const ulong kLineAddress = 1234567;
299 const ulong kLineLength = 78;
300 target_.AddLine(kLineAddress, kLineLength, 1, 6, 4);
301
302 var sourceCodeLine = testDb_.Locations[kLineAddress];
303 Assert.IsNotNull(sourceCodeLine);
304 Assert.AreEqual(sourceCodeLine.Length, kLineLength);
305 }
306
307 ///<summary>
308 /// A test for AddCfiRule
309 ///</summary>
310 [TestMethod]
311 public void AddCfiRuleTest() {
312 DwarfReaderImplConstructorTest();
313 const int kUniqueId = 889999;
314 const int kBaseRegister = 15;
315 BeginCfiEntryTest();
316 target_.AddCfiRule(
317 kCfiEntryAddress,
318 kUniqueId,
319 IDwarfReader.CfiRuleType.Offset,
320 kBaseRegister,
321 987654,
322 new byte[4]);
323 var currentFrame =
324 (SymbolDatabase.CallFrame) GetPrivates().GetField("currentFrame_");
325 Assert.AreNotEqual(null, currentFrame);
326
327 var rule = currentFrame.Rules[0];
328 Assert.IsNotNull(rule);
329 Assert.AreEqual(rule.Address, kCfiEntryAddress);
330 Assert.AreEqual(rule.BaseRegister, kBaseRegister);
331 Assert.AreEqual(rule.RegisterId, kUniqueId);
332 }
333
334 ///<summary>
335 /// A test for AddRangeListEntry
336 ///</summary>
337 [TestMethod]
338 public void AddRangeListEntryTest() {
339 DwarfReaderImplConstructorTest();
340 const ulong kOffset = 123456;
341 const ulong kBaseAddress = 12345;
342 const ulong kLowPC = 123;
343 const ulong kHighPC = 456;
344 Assert.AreEqual(0, testDb_.RangeLists.Count);
345 target_.AddRangeListEntry(kOffset, kBaseAddress, kLowPC, kHighPC);
346 Assert.AreEqual(1, testDb_.RangeLists.Count);
347 }
348
349 /// <summary>
350 /// A test for DwarfReaderImpl Constructor
351 /// This function can be called from the beginning of any of the unit
352 /// tests in this file. It will only overwrite target_ if target is null
353 /// so that the unit test functions can call each other to build more
354 /// complex tests.
355 /// </summary>
356 [TestMethod]
357 public void DwarfReaderImplConstructorTest() {
358 // This function can be called from the beginning of any of the unit
359 // tests in this file.
360 if (null == target_) {
361 target_ = new DwarfReaderImpl(testDb_);
362 }
363 Assert.AreNotEqual(null, target_);
364 }
365
366 #region private implementation
367
368 #region Private Implementation
369
370 private const ulong kCfiEntryAddress = 2048;
371 private const ulong kDieOffset = 1024;
372
373 #endregion
374
375 #region Private Implementation
376
377 private ulong attributeCount_;
378 private DwarfReaderImpl target_;
379 private SymbolDatabase testDb_;
380
381 #endregion
382
383 #region Private Implementation
384
385 private PrivateObject GetPrivates() {
386 DwarfReaderImplConstructorTest();
387 return new PrivateObject(target_);
388 }
389
390 /// <summary>
391 /// Helper function to add a particular attribute and confirm that it was
392 /// created.
393 /// </summary>
394 private void ProcessAttributeTest(ulong offset,
395 ulong parent,
396 DwarfAttribute attr,
397 object data) {
398 target_.ProcessAttribute(offset, parent, attr, data);
399
400 var die = testDb_.Entries[offset];
401 Assert.IsNotNull(die);
402 Assert.AreEqual(die.Attributes[attr], data);
403
404 var attribute =
405 testDb_.Attributes[attributeCount_];
406 Assert.IsNotNull(attribute);
407 Assert.AreEqual(attribute.Tag, attr);
408 ++attributeCount_;
409 }
410
411 #endregion
412
413 #endregion
414 }
415 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698