1""" 2Test lldb-vscode disconnect request 3""" 4 5 6import unittest2 7import vscode 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11import lldbvscode_testcase 12import subprocess 13import time 14import os 15 16 17class TestVSCode_launch(lldbvscode_testcase.VSCodeTestCaseBase): 18 19 mydir = TestBase.compute_mydir(__file__) 20 source = 'main.cpp' 21 22 def disconnect_and_assert_no_output_printed(self): 23 self.vscode.request_disconnect() 24 # verify we didn't get any input after disconnect 25 time.sleep(2) 26 output = self.get_stdout() 27 self.assertTrue(output is None or len(output) == 0) 28 29 @skipIfDarwin 30 @skipIfWindows 31 @skipIfRemote 32 def test_launch(self): 33 """ 34 This test launches a process that would creates a file, but we disconnect 35 before the file is created, which terminates the process and thus the file is not 36 created. 37 """ 38 program = self.getBuildArtifact("a.out") 39 self.build_and_launch(program, disconnectAutomatically=False) 40 41 # We set a breakpoint right before the side effect file is created 42 self.set_source_breakpoints(self.source, [line_number(self.source, '// breakpoint')]) 43 self.continue_to_next_stop() 44 45 self.vscode.request_disconnect() 46 # verify we didn't produce the side effect file 47 time.sleep(1) 48 self.assertFalse(os.path.exists(program + ".side_effect")) 49 50 51 @skipIfDarwin 52 @skipIfWindows 53 @skipIfRemote 54 @expectedFailureNetBSD 55 def test_attach(self): 56 """ 57 This test attaches to a process that creates a file. We attach and disconnect 58 before the file is created, and as the process is not terminated upon disconnection, 59 the file is created anyway. 60 """ 61 self.build_and_create_debug_adaptor() 62 program = self.getBuildArtifact("a.out") 63 64 # Use a file as a synchronization point between test and inferior. 65 sync_file_path = lldbutil.append_to_process_working_directory(self, 66 "sync_file_%d" % (int(time.time()))) 67 self.addTearDownHook( 68 lambda: self.run_platform_command( 69 "rm %s" % 70 (sync_file_path))) 71 72 self.process = subprocess.Popen([program, sync_file_path]) 73 lldbutil.wait_for_file_on_target(self, sync_file_path) 74 75 self.attach(pid=self.process.pid, disconnectAutomatically=False) 76 response = self.vscode.request_evaluate("wait_for_attach = false;") 77 self.assertTrue(response['success']) 78 79 # verify we haven't produced the side effect file yet 80 self.assertFalse(os.path.exists(program + ".side_effect")) 81 82 self.vscode.request_disconnect() 83 time.sleep(2) 84 # verify we produced the side effect file, as the program continued after disconnecting 85 self.assertTrue(os.path.exists(program + ".side_effect")) 86