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