Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium 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 using NativeClientVSAddIn; | |
| 6 using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| 7 using EnvDTE80; | |
| 8 using System; | |
| 9 using System.Collections.Generic; | |
| 10 using System.Diagnostics; | |
| 11 using System.IO; | |
| 12 using System.Reflection; | |
| 13 using System.Threading; | |
| 14 | |
| 15 namespace UnitTests | |
| 16 { | |
| 17 /// <summary> | |
| 18 ///This is a test class for PluginDebuggerHelperTest and is intended | |
| 19 ///to contain all PluginDebuggerHelperTest Unit Tests | |
| 20 ///</summary> | |
| 21 [TestClass()] | |
| 22 public class PluginDebuggerHelperTest | |
| 23 { | |
| 24 /// <summary> | |
| 25 /// The dummy loop solution is a valid nacl/pepper plug-in VS solution | |
| 26 /// It is copied into the testing deployment directory and opened in some te sts | |
| 27 /// Because unit-tests run in any order, the solution should not be written to | |
| 28 /// in any tests. | |
| 29 /// </summary> | |
| 30 private const String DummyLoopSolution = @"\DummyLoop\DummyLoop.sln"; | |
| 31 | |
| 32 /// <summary> | |
| 33 ///Gets or sets the test context which provides | |
| 34 ///information about and functionality for the current test run. | |
| 35 ///</summary> | |
| 36 public TestContext TestContext { get; set; } | |
|
elijahtaylor1
2012/07/11 20:56:18
property naming
tysand
2012/07/12 23:56:15
Done.
| |
| 37 | |
| 38 /// <summary> | |
| 39 /// The main visual studio object | |
| 40 /// </summary> | |
| 41 private DTE2 dte_ = null; | |
| 42 | |
| 43 /// <summary> | |
| 44 /// Run before each test to create test resources | |
| 45 /// </summary> | |
| 46 [TestInitialize] | |
| 47 public void TestSetup() | |
| 48 { | |
| 49 dte_ = TestUtilities.StartVisualStudioInstance(); | |
| 50 } | |
| 51 | |
| 52 /// <summary> | |
| 53 /// Run after each test to clean up things created in TestSetup() | |
| 54 /// </summary> | |
| 55 [TestCleanup] | |
| 56 public void TestCleanup() | |
| 57 { | |
| 58 TestUtilities.CleanUpVisualStudioInstance(dte_); | |
| 59 } | |
| 60 | |
| 61 /// <summary> | |
| 62 ///A test for PluginDebuggerHelper Constructor | |
| 63 ///</summary> | |
| 64 [TestMethod()] | |
| 65 public void PluginDebuggerHelperConstructorTest() | |
| 66 { | |
| 67 // Check null dte fails | |
| 68 try | |
| 69 { | |
| 70 PluginDebuggerHelper nullDte = new PluginDebuggerHelper(null); | |
| 71 Assert.Fail("Using null DTE instance did not throw exception"); | |
| 72 } | |
| 73 catch (ArgumentNullException) | |
| 74 { | |
| 75 // This is expected for a correct implementation | |
|
elijahtaylor1
2012/07/11 20:56:18
you should set something here to verify you did ge
tysand
2012/07/12 23:56:15
Note that we Assert.Fail above in the try block if
| |
| 76 } | |
| 77 catch | |
| 78 { | |
| 79 Assert.Fail("Using null DTE instance threw something other than Argument NullException"); | |
| 80 } | |
| 81 | |
| 82 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 83 Assert.AreEqual(dte_, target.dte_); | |
| 84 Assert.IsNull(target.webServerOutputPane_); | |
| 85 Assert.IsFalse(target.IsDebuggerRunning); | |
| 86 Assert.IsFalse(target.isProperlyInitialized_); | |
| 87 } | |
| 88 | |
| 89 /// <summary> | |
| 90 /// This unit test verifies that the gdb init file is written correctly, | |
| 91 /// and old-existing GDB processes are cleaned up | |
| 92 /// Verification of actual attachment is the responsibility of integration | |
| 93 /// tests and NaCl-GDB itself | |
| 94 ///</summary> | |
| 95 [TestMethod()] | |
| 96 [DeploymentItem("NativeClientVSAddIn.dll")] | |
| 97 public void AttachNaClGDBTest() | |
| 98 { | |
| 99 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 100 String existingGDB = "AttachNaClGDBTest_existingGDB"; | |
| 101 try | |
| 102 { | |
| 103 target.pluginProjectDirectory_ = TestContext.DeploymentDirectory; | |
| 104 target.pluginAssembly_ = "fakeAssemblyString"; | |
| 105 target.irtPath_ = "fakeIrtPath"; | |
| 106 target.gdbPath_ = "python.exe"; | |
| 107 target.gdbProcess_ = TestUtilities.StartProcessForKilling(existingGDB, 2 0); | |
| 108 String existingInitFileName = Path.GetTempFileName(); | |
| 109 target.gdbInitFileName_ = existingInitFileName; | |
| 110 target.IsDebuggerRunning = true; | |
| 111 target.isProperlyInitialized_ = true; | |
| 112 | |
| 113 // Visual studio won't allow adding a breakpoint unless it is associated with | |
| 114 // an existing file and valid line number | |
| 115 dte_.Solution.Open(TestContext.DeploymentDirectory + DummyLoopSolution); | |
| 116 String fileName = "main.cpp"; | |
| 117 String functionName = "DummyInstance::HandleMessage"; | |
| 118 int lineNumber = 35; | |
| 119 dte_.Debugger.Breakpoints.Add(Function: functionName); | |
| 120 dte_.Debugger.Breakpoints.Add(Line: lineNumber, File: fileName); | |
| 121 | |
| 122 target.AttachNaClGDB(null, new PluginFoundEventArgs(0)); | |
| 123 | |
| 124 Assert.IsTrue(File.Exists(target.gdbInitFileName_), "Init file not writt en"); | |
| 125 | |
| 126 String[] gdbCommands = File.ReadAllLines(target.gdbInitFileName_); | |
| 127 bool functionBP = false; | |
| 128 bool lineBP = false; | |
| 129 | |
| 130 // Validate that commands contain what we specified | |
| 131 // Syntax itself is not validated since this add-in is not responsible f or | |
| 132 // the syntax and it could change | |
| 133 foreach (String command in gdbCommands) | |
| 134 { | |
| 135 if (command.Contains(fileName) && command.Contains(lineNumber.ToString ())) | |
| 136 { | |
| 137 lineBP = true; | |
| 138 } | |
| 139 | |
| 140 if (command.Contains(functionName)) | |
| 141 { | |
| 142 functionBP = true; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 Assert.IsFalse(TestUtilities.DoesProcessExist("python.exe", existingGDB) , | |
| 147 "Failed to kill existing GDB process"); | |
| 148 Assert.IsFalse(File.Exists(existingInitFileName), | |
| 149 "Failed to delete existing temp gdb init file"); | |
| 150 Assert.IsTrue(lineBP, "Line breakpoint not properly set"); | |
| 151 Assert.IsTrue(functionBP, "Function breakpoint not properly set"); | |
| 152 } | |
| 153 finally | |
| 154 { | |
| 155 if (dte_.Debugger.Breakpoints != null) | |
| 156 { | |
| 157 // Remove all breakpoints | |
| 158 foreach (EnvDTE.Breakpoint bp in dte_.Debugger.Breakpoints) | |
| 159 { | |
| 160 bp.Delete(); | |
| 161 } | |
| 162 } | |
| 163 if (!String.IsNullOrEmpty(target.gdbInitFileName_) && File.Exists(target .gdbInitFileName_)) | |
| 164 { | |
| 165 File.Delete(target.gdbInitFileName_); | |
| 166 } | |
| 167 | |
| 168 if (target.gdbProcess_ != null && !target.gdbProcess_.HasExited) | |
| 169 { | |
| 170 target.gdbProcess_.Kill(); | |
| 171 } | |
| 172 } | |
| 173 } | |
| 174 | |
| 175 /// <summary> | |
| 176 ///A test for FindAndAttachToPlugin | |
| 177 ///</summary> | |
| 178 [TestMethod()] | |
| 179 [DeploymentItem("NativeClientVSAddIn.dll")] | |
| 180 public void FindAndAttachToPluginTest() | |
| 181 { | |
| 182 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 183 target.IsDebuggerRunning = true; | |
| 184 target.isProperlyInitialized_ = true; | |
| 185 | |
| 186 MockProcessSearcher processResults = new MockProcessSearcher(); | |
| 187 uint currentProcId = (uint)System.Diagnostics.Process.GetCurrentProcess(). Id; | |
| 188 String naclCommandLine = Strings.NaClProcessTypeFlag + " " + Strings.NaClD ebugFlag; | |
| 189 target.pluginAssembly_ = "testAssemblyPath"; | |
| 190 String pluginLoadFlag = String.Format( | |
| 191 Strings.PepperProcessPluginFlagFormat, target.pluginAssembly_); | |
| 192 String pepperCommandLine = String.Concat( | |
| 193 pluginLoadFlag, " ", Strings.PepperProcessTypeFlag); | |
| 194 | |
| 195 // Fake the list of processes on the system | |
| 196 processResults.Results.Add( | |
| 197 new ProcessInfo(currentProcId, currentProcId, "", "", "devenv.exe")); | |
| 198 processResults.Results.Add( | |
| 199 new ProcessInfo(1, currentProcId, "", "", "MyParentProcess")); | |
| 200 processResults.Results.Add( | |
| 201 new ProcessInfo(10, 1, "", pepperCommandLine, Strings.PepperProcessNam e)); | |
| 202 processResults.Results.Add( | |
| 203 new ProcessInfo(11, 1, "", naclCommandLine, Strings.NaClProcessName)); | |
| 204 processResults.Results.Add( | |
| 205 new ProcessInfo(12, 1, "", | |
| 206 String.Format(Strings.PepperProcessPluginFlagFormat, target.pluginAsse mbly_), | |
| 207 Strings.PepperProcessName)); | |
| 208 processResults.Results.Add( | |
| 209 new ProcessInfo(13, 1, "", Strings.NaClDebugFlag, Strings.NaClProcessN ame)); | |
| 210 | |
| 211 // These two don't have this process as their parent, so they should not b e attached to | |
| 212 processResults.Results.Add( | |
| 213 new ProcessInfo(14, 14, "", pepperCommandLine, Strings.PepperProcessNa me)); | |
| 214 processResults.Results.Add( | |
| 215 new ProcessInfo(15, 15, "", naclCommandLine, Strings.NaClProcessName)) ; | |
| 216 | |
| 217 // Set the private value to the mock object (can't use accessor since no v alid cast) | |
| 218 typeof(PluginDebuggerHelper).GetField( | |
| 219 "_processSearcher", BindingFlags.NonPublic | BindingFlags.Instance). | |
| 220 SetValue(target.Target, processResults); | |
| 221 | |
| 222 // Test that the correct processes are attached to | |
| 223 bool goodNaCl = false; | |
| 224 bool goodPepper = false; | |
| 225 EventHandler<PluginFoundEventArgs> handler = new EventHandler<PluginFoundE ventArgs>( | |
| 226 delegate(object unused, PluginFoundEventArgs args) | |
| 227 { | |
| 228 switch (args.ProcessID) | |
| 229 { | |
| 230 case 10: | |
| 231 if (goodPepper) | |
| 232 { | |
| 233 Assert.Fail("Should not attach twice to same pepper process"); | |
| 234 } | |
| 235 | |
| 236 if (target.projectPlatformType_ == | |
| 237 PluginDebuggerHelper_Accessor.ProjectPlatformType.NaCl) | |
| 238 { | |
| 239 Assert.Fail("Attached to pepper process when NaCl was the target "); | |
| 240 } | |
| 241 | |
| 242 goodPepper = true; | |
| 243 break; | |
| 244 case 11: | |
| 245 if (goodNaCl) | |
| 246 { | |
| 247 Assert.Fail("Should not attach twice to same nacl process"); | |
| 248 } | |
| 249 | |
| 250 if (target.projectPlatformType_ == | |
| 251 PluginDebuggerHelper_Accessor.ProjectPlatformType.Pepper) | |
| 252 { | |
| 253 Assert.Fail("Attached to nacl process when pepper was the target "); | |
| 254 } | |
| 255 | |
| 256 goodNaCl = true; | |
| 257 break; | |
| 258 case 12: | |
| 259 Assert.Fail("Should not attach to pepper process with bad args"); | |
| 260 break; | |
| 261 case 13: | |
| 262 Assert.Fail("Should not attach to nacl process with bad args"); | |
| 263 break; | |
| 264 case 14: | |
| 265 Assert.Fail("Should not attach to pepper process that is not " | |
| 266 + "descendant of Visual Studio"); | |
| 267 break; | |
| 268 case 15: | |
| 269 Assert.Fail("Should not attach to nacl process that is not " | |
| 270 + "descendant of Visual Studio"); | |
| 271 break; | |
| 272 default: | |
| 273 Assert.Fail("Should not attach to non-pepper/non-nacl process"); | |
| 274 break; | |
| 275 } | |
| 276 }); | |
| 277 | |
| 278 target.add_PluginFoundEvent(handler); | |
| 279 target.projectPlatformType_ = PluginDebuggerHelper_Accessor.ProjectPlatfor mType.Pepper; | |
| 280 target.FindAndAttachToPlugin(null, null); | |
| 281 target.projectPlatformType_ = PluginDebuggerHelper_Accessor.ProjectPlatfor mType.NaCl; | |
| 282 target.FindAndAttachToPlugin(null, null); | |
| 283 target.remove_PluginFoundEvent(handler); | |
| 284 Assert.IsTrue(goodPepper, "Failed to attach to pepper process"); | |
| 285 Assert.IsTrue(goodNaCl, "Failed to attach to NaCl process"); | |
| 286 } | |
| 287 | |
| 288 /// <summary> | |
| 289 ///A test for InitializeFromProjectSettings | |
| 290 ///</summary> | |
| 291 [TestMethod()] | |
| 292 public void InitializeFromProjectSettingsTest() | |
| 293 { | |
| 294 String expectedSDKRootDir = | |
| 295 Environment.GetEnvironmentVariable(Strings.SDKPathEnvironmentVariable) ; | |
| 296 Assert.IsNotNull(expectedSDKRootDir, "SDK Path environment variable not se t!"); | |
| 297 | |
| 298 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 299 target.IsDebuggerRunning = false; | |
| 300 target.isProperlyInitialized_ = false; | |
| 301 try | |
| 302 { | |
| 303 target.InitializeFromProjectSettings(); | |
| 304 Assert.Fail("Initializing with no loaded solution shouldn't succeed"); | |
| 305 } | |
| 306 catch (ArgumentOutOfRangeException) | |
| 307 { | |
| 308 // This is expected for a correct implementation | |
| 309 } | |
| 310 | |
| 311 dte_.Solution.Open(TestContext.DeploymentDirectory + DummyLoopSolution); | |
| 312 | |
| 313 // Set start-up project to a non-cpp project, should not initialize | |
| 314 String badProjectUniqueName = @"NotNaCl\NotNaCl.csproj"; | |
| 315 object[] badStartupProj = { badProjectUniqueName }; | |
| 316 dte_.Solution.SolutionBuild.StartupProjects = badStartupProj; | |
| 317 Assert.IsFalse(target.InitializeFromProjectSettings()); | |
| 318 Assert.IsFalse(target.isProperlyInitialized_); | |
| 319 | |
| 320 // Set start-up project to correct C++ project, but set platform to non-na cl/pepper | |
| 321 // Initialization should fail | |
| 322 String projectUniqueName = @"DummyLoop\DummyLoop.vcxproj"; | |
| 323 object[] startupProj = { projectUniqueName }; | |
| 324 dte_.Solution.SolutionBuild.StartupProjects = startupProj; | |
| 325 TestUtilities.SetSolutionConfiguration(dte_, projectUniqueName, "Debug", " Win32"); | |
| 326 Assert.IsFalse(target.InitializeFromProjectSettings()); | |
| 327 Assert.IsFalse(target.isProperlyInitialized_); | |
| 328 | |
| 329 // Set platform to NaCl, should succeed | |
| 330 TestUtilities.SetSolutionConfiguration( | |
| 331 dte_, projectUniqueName, "Debug", Strings.NaClPlatformName); | |
| 332 Assert.IsTrue(target.InitializeFromProjectSettings()); | |
| 333 Assert.IsTrue(target.isProperlyInitialized_); | |
| 334 Assert.AreEqual(target.projectPlatformType_, | |
| 335 PluginDebuggerHelper_Accessor.ProjectPlatformType.NaCl); | |
| 336 Assert.AreEqual(target.debuggerType_, PluginDebuggerHelper_Accessor.Debugg erType.GDB); | |
| 337 Assert.AreEqual(target.pluginProjectDirectory_, | |
| 338 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\"); | |
| 339 Assert.AreEqual(target.pluginAssembly_, | |
| 340 TestContext.DeploymentDirectory | |
| 341 + @"\DummyLoop\DummyLoop\NaCl\Debug\DummyLoop.nexe"); | |
| 342 Assert.AreEqual(target.pluginOutputDirectory_, | |
| 343 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\NaCl\Debug\") ; | |
| 344 Assert.AreEqual(target.sdkRootDirectory_, expectedSDKRootDir); | |
| 345 Assert.AreEqual(target.webServerExecutable_, "python.exe"); | |
| 346 //Assert.AreEqual(target._webServerArguments, ""); | |
| 347 //Assert.AreEqual(target._gdbPath, ""); | |
| 348 | |
| 349 // Set platform to Pepper, should succeed | |
| 350 TestUtilities.SetSolutionConfiguration( | |
| 351 dte_, projectUniqueName, "Debug", Strings.PepperPlatformName); | |
| 352 Assert.IsTrue(target.InitializeFromProjectSettings()); | |
| 353 Assert.IsTrue(target.isProperlyInitialized_); | |
| 354 Assert.AreEqual(target.projectPlatformType_, | |
| 355 PluginDebuggerHelper_Accessor.ProjectPlatformType.Pepper); | |
| 356 Assert.AreEqual(target.debuggerType_, PluginDebuggerHelper_Accessor.Debugg erType.VS); | |
| 357 Assert.AreEqual(target.pluginProjectDirectory_, | |
| 358 TestContext.DeploymentDirectory + @"\DummyLoop\DummyLoop\"); | |
| 359 Assert.AreEqual(target.pluginAssembly_, | |
| 360 TestContext.DeploymentDirectory + @"\DummyLoop\Debug\PPAPI\DummyLoop.d ll"); | |
| 361 Assert.AreEqual(target.pluginOutputDirectory_, | |
| 362 TestContext.DeploymentDirectory + @"\DummyLoop\Debug\PPAPI\"); | |
| 363 Assert.AreEqual(target.sdkRootDirectory_, expectedSDKRootDir); | |
| 364 Assert.AreEqual(target.webServerExecutable_, "python.exe"); | |
| 365 //Assert.AreEqual(target._webServerArguments, ""); | |
| 366 //Assert.AreEqual(target._gdbPath, ""); | |
| 367 } | |
| 368 | |
| 369 /// <summary> | |
| 370 /// Checks that VS properly attaches debugger | |
| 371 ///</summary> | |
| 372 [TestMethod()] | |
| 373 [DeploymentItem("NativeClientVSAddIn.dll")] | |
| 374 public void AttachVSDebuggerTest() | |
| 375 { | |
| 376 using (Process dummyProc = TestUtilities.StartProcessForKilling("DummyProc ", 20)) | |
| 377 { | |
| 378 try | |
| 379 { | |
| 380 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Access or(dte_); | |
| 381 target.debuggerType_ = PluginDebuggerHelper_Accessor.DebuggerType.VS; | |
| 382 target.projectPlatformType_ = PluginDebuggerHelper_Accessor.ProjectPla tformType.Pepper; | |
| 383 target.IsDebuggerRunning = true; | |
| 384 target.isProperlyInitialized_ = true; | |
| 385 | |
| 386 target.AttachVSDebugger(null, new PluginFoundEventArgs(((uint)dummyPro c.Id))); | |
| 387 | |
| 388 bool isBeingDebugged = false; | |
| 389 foreach (EnvDTE.Process proc in dte_.Debugger.DebuggedProcesses) | |
| 390 { | |
| 391 if (proc.ProcessID == dummyProc.Id) | |
| 392 { | |
| 393 isBeingDebugged = true; | |
| 394 } | |
| 395 } | |
| 396 Assert.IsTrue(isBeingDebugged, "Visual Studio debugger did not attach" ); | |
| 397 } | |
| 398 finally | |
| 399 { | |
| 400 if (dummyProc != null && !dummyProc.HasExited) | |
| 401 { | |
| 402 dummyProc.Kill(); | |
| 403 } | |
| 404 } | |
| 405 } | |
| 406 } | |
| 407 | |
| 408 /// <summary> | |
| 409 ///A test for StartDebugging | |
| 410 ///Also implicitly tests IsDebuggerRunningTest | |
| 411 ///</summary> | |
| 412 [TestMethod()] | |
| 413 public void StartDebuggingTest() | |
| 414 { | |
| 415 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 416 | |
| 417 // Neutralize StartWebServer by providing dummy executable settings: | |
| 418 target.webServerExecutable_ = "python.exe"; | |
| 419 target.webServerArguments_ = "-c \"print 'test'\""; | |
| 420 target.pluginProjectDirectory_ = TestContext.DeploymentDirectory; | |
| 421 | |
| 422 // Have the timer call a function to set success to true | |
| 423 ManualResetEvent finderSuccess = new ManualResetEvent(false); | |
| 424 target.pluginFinderTimer_ = new System.Windows.Forms.Timer(); | |
| 425 target.pluginFinderTimer_.Tick += (a,b) => { finderSuccess.Set(); }; | |
| 426 | |
| 427 // Check that nothing happens when not initialized | |
| 428 target.IsDebuggerRunning = false; | |
| 429 target.isProperlyInitialized_ = false; | |
| 430 target.StartDebugging(); | |
| 431 Assert.IsFalse(target.IsDebuggerRunning, "Debugging started when not initi alized"); | |
| 432 | |
| 433 // Properly start debugging and wait for event signal | |
| 434 target.isProperlyInitialized_ = true; | |
| 435 target.StartDebugging(); | |
| 436 | |
| 437 // Pump events waiting for signal, time-out after 10 seconds | |
| 438 bool success = false; | |
| 439 for (int i = 0; i < 20; i++) | |
| 440 { | |
| 441 System.Windows.Forms.Application.DoEvents(); | |
| 442 if (finderSuccess.WaitOne(500)) | |
| 443 { | |
| 444 success = true; | |
| 445 break; | |
| 446 } | |
| 447 } | |
| 448 | |
| 449 Assert.IsTrue(success, "Plug-in finder timer did not fire"); | |
| 450 Assert.IsTrue(target.IsDebuggerRunning, "IsDebuggerRunning false after deb ugging started"); | |
| 451 } | |
| 452 | |
| 453 /// <summary> | |
| 454 /// Tests that StartWebServer executes webServerExecutable_ with webServerAr guments_ | |
| 455 /// as arguments, sets the working directory to the project directory, and h ooks | |
| 456 /// up stdout and stderr from the web server to the Web Server output panel in VS. | |
| 457 /// This test implicitly covers WebServerMessageReceive | |
| 458 ///</summary> | |
| 459 [TestMethod()] | |
| 460 [DeploymentItem("NativeClientVSAddIn.dll")] | |
| 461 public void StartWebServerTest() | |
| 462 { | |
| 463 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 464 try | |
| 465 { | |
| 466 String successMessage = "successful test!"; | |
| 467 String stderrMessage = "stderr test"; | |
| 468 target.webServerExecutable_ = "python.exe"; | |
| 469 | |
| 470 // To save pain, if modifying this in the future avoid special character s, | |
| 471 // or make sure to double escape them. Ex: \n --> \\n | |
| 472 String program = | |
| 473 "import os;" + | |
| 474 "import sys;" + | |
| 475 String.Format("sys.stdout.write('{0}');", successMessage) + | |
| 476 String.Format("sys.stderr.write('{0}');", stderrMessage) + | |
| 477 "sys.stdout.write(os.getcwd());" + | |
| 478 "sys.stdout.flush();" + | |
| 479 "sys.stderr.flush()"; | |
| 480 target.webServerArguments_ = String.Format("-c \"{0}\"", program); | |
| 481 target.pluginProjectDirectory_ = TestContext.DeploymentDirectory; | |
| 482 target.IsDebuggerRunning = false; | |
| 483 target.isProperlyInitialized_ = true; | |
| 484 target.StartWebServer(); | |
| 485 | |
| 486 // Check that the output pane exists | |
| 487 EnvDTE.OutputWindowPane window = dte_.ToolWindows.OutputWindow.OutputWin dowPanes.Item( | |
| 488 Strings.WebServerOutputWindowTitle); | |
| 489 Assert.IsNotNull(window, "Web server output pane failed to create"); | |
| 490 | |
| 491 // Wait for results to arrive for up to 10 seconds, checking every 0.5 s econds | |
| 492 String result = TestUtilities.GetPaneText(target.webServerOutputPane_); | |
| 493 for (int repeat = 0; repeat < 20; repeat++) | |
| 494 { | |
| 495 if (result != null && | |
| 496 result.Contains(successMessage) && | |
| 497 result.Contains(stderrMessage) && | |
| 498 result.Contains(TestContext.DeploymentDirectory)) | |
| 499 { | |
| 500 break; | |
| 501 } | |
| 502 Thread.Sleep(500); | |
| 503 result = TestUtilities.GetPaneText(target.webServerOutputPane_); | |
| 504 } | |
| 505 | |
| 506 Assert.IsFalse(String.IsNullOrEmpty(result), "Nothing printed to output pane"); | |
| 507 StringAssert.Contains(result, successMessage, | |
| 508 "Executable did not successfully run given arguments"); | |
| 509 StringAssert.Contains(result, TestContext.DeploymentDirectory, | |
| 510 "Web server working directory was not set to project directory"); | |
| 511 StringAssert.Contains(result, stderrMessage, "Standard error message was not captured"); | |
| 512 } | |
| 513 finally | |
| 514 { | |
| 515 if (!target.webServer_.WaitForExit(1000)) | |
| 516 { | |
| 517 target.webServer_.Kill(); | |
| 518 } | |
| 519 } | |
| 520 } | |
| 521 | |
| 522 /// <summary> | |
| 523 /// Ensures that StopDebugging() kills GDB and the web server, and resets th e state of | |
| 524 /// PluginDebuggerHelper to before debugging started | |
| 525 /// Implicitly tests KillGDBProcess() | |
| 526 ///</summary> | |
| 527 [TestMethod()] | |
| 528 public void StopDebuggingTest() | |
| 529 { | |
| 530 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 531 String webServerIdentifier = "StartVisualStudioInstance_TestWebServer"; | |
| 532 String gdbIdentifier = "StartVisualStudioInstance_TestGDB"; | |
| 533 | |
| 534 // Setup up items that should exist given a successful calling of StartDeb ugging() | |
| 535 target.gdbInitFileName_ = Path.GetTempFileName(); | |
| 536 target.IsDebuggerRunning = true; | |
| 537 target.pluginFinderForbiddenPids_.Add(123); | |
| 538 target.webServer_ = TestUtilities.StartProcessForKilling(webServerIdentifi er, 20); | |
| 539 target.gdbProcess_ = TestUtilities.StartProcessForKilling(gdbIdentifier, 2 0); | |
| 540 target.isProperlyInitialized_ = true; | |
| 541 | |
| 542 target.StopDebugging(); | |
| 543 | |
| 544 Assert.IsFalse(target.IsDebuggerRunning, "Failed to set debug running stat e to false"); | |
| 545 Assert.IsFalse(target.isProperlyInitialized_, "Failed to set initialized s tate to false"); | |
| 546 Assert.IsFalse(target.pluginFinderTimer_.Enabled, "Plug-in finder timer no t stopped"); | |
| 547 Assert.IsFalse(TestUtilities.DoesProcessExist("python.exe", webServerIdent ifier), | |
| 548 "Failed to kill web server process"); | |
| 549 Assert.IsFalse(TestUtilities.DoesProcessExist("python.exe", gdbIdentifier) , | |
| 550 "Failed to kill gdb process"); | |
| 551 Assert.IsFalse(File.Exists(target.gdbInitFileName_), | |
| 552 "Failed to delete temp gdb init file"); | |
| 553 Assert.IsTrue(target.pluginFinderForbiddenPids_.Count == 0, | |
| 554 "Plugin finder Process IDs not cleared"); | |
| 555 } | |
| 556 | |
| 557 /// <summary> | |
| 558 ///A test for WebServerWriteLine | |
| 559 ///</summary> | |
| 560 [TestMethod()] | |
| 561 [DeploymentItem("NativeClientVSAddIn.dll")] | |
| 562 public void WebServerWriteLineTest() | |
| 563 { | |
| 564 PluginDebuggerHelper_Accessor target = new PluginDebuggerHelper_Accessor(d te_); | |
| 565 String successMessage = "successful test!"; | |
| 566 target.webServerOutputPane_ = dte_.ToolWindows.OutputWindow.OutputWindowPa nes.Add( | |
| 567 Strings.WebServerOutputWindowTitle); | |
| 568 target.IsDebuggerRunning = true; | |
| 569 target.isProperlyInitialized_ = true; | |
| 570 target.WebServerWriteLine(successMessage); | |
| 571 String result = TestUtilities.GetPaneText(target.webServerOutputPane_); | |
| 572 | |
| 573 // Wait for results to arrive for up to 10 seconds, checking every 0.5 sec onds | |
| 574 for (int repeat = 0; repeat < 20; repeat++) | |
| 575 { | |
| 576 if (result != null && | |
| 577 result.Contains(successMessage)) | |
| 578 { | |
| 579 break; | |
| 580 } | |
| 581 | |
| 582 Thread.Sleep(500); | |
| 583 result = TestUtilities.GetPaneText(target.webServerOutputPane_); | |
| 584 } | |
| 585 StringAssert.Contains(result, successMessage, "Message failed to print"); | |
| 586 } | |
| 587 } | |
| 588 } | |
| OLD | NEW |