18fa2394bSMichał Górnyimport lldb 28fa2394bSMichał Górnyfrom lldbsuite.test.lldbtest import * 38fa2394bSMichał Górnyfrom lldbsuite.test.decorators import * 48fa2394bSMichał Górnyfrom gdbclientutils import * 58fa2394bSMichał Górny 68fa2394bSMichał Górny 78fa2394bSMichał Górny@skipIfWindows 88fa2394bSMichał Górnyclass TestPty(GDBRemoteTestBase): 98fa2394bSMichał Górny mydir = TestBase.compute_mydir(__file__) 108fa2394bSMichał Górny server_socket_class = PtyServerSocket 118fa2394bSMichał Górny 12*4a7b4beaSMichał Górny def get_term_attrs(self): 13*4a7b4beaSMichał Górny import termios 14*4a7b4beaSMichał Górny return termios.tcgetattr(self.server._socket._slave) 15*4a7b4beaSMichał Górny 16*4a7b4beaSMichał Górny def setUp(self): 17*4a7b4beaSMichał Górny super().setUp() 18*4a7b4beaSMichał Górny self.orig_attr = self.get_term_attrs() 19*4a7b4beaSMichał Górny 20*4a7b4beaSMichał Górny def assert_raw_mode(self, current_attr): 21*4a7b4beaSMichał Górny import termios 22*4a7b4beaSMichał Górny self.assertEqual(current_attr[0] & (termios.BRKINT | 23*4a7b4beaSMichał Górny termios.PARMRK | 24*4a7b4beaSMichał Górny termios.ISTRIP | termios.INLCR | 25*4a7b4beaSMichał Górny termios.IGNCR | termios.ICRNL | 26*4a7b4beaSMichał Górny termios.IXON), 27*4a7b4beaSMichał Górny 0) 28*4a7b4beaSMichał Górny self.assertEqual(current_attr[1] & termios.OPOST, 0) 29*4a7b4beaSMichał Górny self.assertEqual(current_attr[2] & termios.CSIZE, termios.CS8) 30*4a7b4beaSMichał Górny self.assertEqual(current_attr[3] & (termios.ICANON | termios.ECHO | 31*4a7b4beaSMichał Górny termios.ISIG | termios.IEXTEN), 32*4a7b4beaSMichał Górny 0) 33*4a7b4beaSMichał Górny self.assertEqual(current_attr[6][termios.VMIN], 1) 34*4a7b4beaSMichał Górny self.assertEqual(current_attr[6][termios.VTIME], 0) 35*4a7b4beaSMichał Górny 36*4a7b4beaSMichał Górny def get_parity_flags(self, attr): 37*4a7b4beaSMichał Górny import termios 38*4a7b4beaSMichał Górny return attr[2] & (termios.PARENB | termios.PARODD) 39*4a7b4beaSMichał Górny 40*4a7b4beaSMichał Górny def get_stop_bit_flags(self, attr): 41*4a7b4beaSMichał Górny import termios 42*4a7b4beaSMichał Górny return attr[2] & termios.CSTOPB 43*4a7b4beaSMichał Górny 448fa2394bSMichał Górny def test_process_connect_sync(self): 458fa2394bSMichał Górny """Test the process connect command in synchronous mode""" 468fa2394bSMichał Górny try: 478fa2394bSMichał Górny self.dbg.SetAsync(False) 488fa2394bSMichał Górny self.expect("platform select remote-gdb-server", 498fa2394bSMichał Górny substrs=['Platform: remote-gdb-server', 'Connected: no']) 508fa2394bSMichał Górny self.expect("process connect " + self.server.get_connect_url(), 518fa2394bSMichał Górny substrs=['Process', 'stopped']) 52*4a7b4beaSMichał Górny 53*4a7b4beaSMichał Górny current_attr = self.get_term_attrs() 54*4a7b4beaSMichał Górny # serial:// should set raw mode 55*4a7b4beaSMichał Górny self.assert_raw_mode(current_attr) 56*4a7b4beaSMichał Górny # other parameters should be unmodified 57*4a7b4beaSMichał Górny self.assertEqual(current_attr[4:6], self.orig_attr[4:6]) 58*4a7b4beaSMichał Górny self.assertEqual(self.get_parity_flags(current_attr), 59*4a7b4beaSMichał Górny self.get_parity_flags(self.orig_attr)) 60*4a7b4beaSMichał Górny self.assertEqual(self.get_stop_bit_flags(current_attr), 61*4a7b4beaSMichał Górny self.get_stop_bit_flags(self.orig_attr)) 628fa2394bSMichał Górny finally: 6345f97950SMichał Górny self.dbg.GetSelectedTarget().GetProcess().Kill() 64*4a7b4beaSMichał Górny # original mode should be restored on exit 65*4a7b4beaSMichał Górny self.assertEqual(self.get_term_attrs(), self.orig_attr) 668fa2394bSMichał Górny 678fa2394bSMichał Górny def test_process_connect_async(self): 688fa2394bSMichał Górny """Test the process connect command in asynchronous mode""" 698fa2394bSMichał Górny try: 708fa2394bSMichał Górny self.dbg.SetAsync(True) 718fa2394bSMichał Górny self.expect("platform select remote-gdb-server", 728fa2394bSMichał Górny substrs=['Platform: remote-gdb-server', 'Connected: no']) 738fa2394bSMichał Górny self.expect("process connect " + self.server.get_connect_url(), 748fa2394bSMichał Górny matching=False, 758fa2394bSMichał Górny substrs=['Process', 'stopped']) 768fa2394bSMichał Górny lldbutil.expect_state_changes(self, self.dbg.GetListener(), 778fa2394bSMichał Górny self.process(), [lldb.eStateStopped]) 78*4a7b4beaSMichał Górny 79*4a7b4beaSMichał Górny current_attr = self.get_term_attrs() 80*4a7b4beaSMichał Górny # serial:// should set raw mode 81*4a7b4beaSMichał Górny self.assert_raw_mode(current_attr) 82*4a7b4beaSMichał Górny # other parameters should be unmodified 83*4a7b4beaSMichał Górny self.assertEqual(current_attr[4:6], self.orig_attr[4:6]) 84*4a7b4beaSMichał Górny self.assertEqual(self.get_parity_flags(current_attr), 85*4a7b4beaSMichał Górny self.get_parity_flags(self.orig_attr)) 86*4a7b4beaSMichał Górny self.assertEqual(self.get_stop_bit_flags(current_attr), 87*4a7b4beaSMichał Górny self.get_stop_bit_flags(self.orig_attr)) 888fa2394bSMichał Górny finally: 8945f97950SMichał Górny self.dbg.GetSelectedTarget().GetProcess().Kill() 9045f97950SMichał Górny lldbutil.expect_state_changes(self, self.dbg.GetListener(), 9145f97950SMichał Górny self.process(), [lldb.eStateExited]) 92*4a7b4beaSMichał Górny # original mode should be restored on exit 93*4a7b4beaSMichał Górny self.assertEqual(self.get_term_attrs(), self.orig_attr) 94*4a7b4beaSMichał Górny 95*4a7b4beaSMichał Górny def test_connect_via_file(self): 96*4a7b4beaSMichał Górny """Test connecting via the legacy file:// URL""" 97*4a7b4beaSMichał Górny import termios 98*4a7b4beaSMichał Górny try: 99*4a7b4beaSMichał Górny self.expect("platform select remote-gdb-server", 100*4a7b4beaSMichał Górny substrs=['Platform: remote-gdb-server', 'Connected: no']) 101*4a7b4beaSMichał Górny self.expect("process connect file://" + 102*4a7b4beaSMichał Górny self.server.get_connect_address(), 103*4a7b4beaSMichał Górny substrs=['Process', 'stopped']) 104*4a7b4beaSMichał Górny 105*4a7b4beaSMichał Górny # file:// sets baud rate and some raw-related flags 106*4a7b4beaSMichał Górny current_attr = self.get_term_attrs() 107*4a7b4beaSMichał Górny self.assertEqual(current_attr[3] & (termios.ICANON | termios.ECHO | 108*4a7b4beaSMichał Górny termios.ECHOE | termios.ISIG), 109*4a7b4beaSMichał Górny 0) 110*4a7b4beaSMichał Górny self.assertEqual(current_attr[4], termios.B115200) 111*4a7b4beaSMichał Górny self.assertEqual(current_attr[5], termios.B115200) 112*4a7b4beaSMichał Górny self.assertEqual(current_attr[6][termios.VMIN], 1) 113*4a7b4beaSMichał Górny self.assertEqual(current_attr[6][termios.VTIME], 0) 114*4a7b4beaSMichał Górny finally: 115*4a7b4beaSMichał Górny self.dbg.GetSelectedTarget().GetProcess().Kill() 116*4a7b4beaSMichał Górny 117*4a7b4beaSMichał Górny def test_process_connect_params(self): 118*4a7b4beaSMichał Górny """Test serial:// URL with parameters""" 119*4a7b4beaSMichał Górny import termios 120*4a7b4beaSMichał Górny try: 121*4a7b4beaSMichał Górny self.expect("platform select remote-gdb-server", 122*4a7b4beaSMichał Górny substrs=['Platform: remote-gdb-server', 'Connected: no']) 123*4a7b4beaSMichał Górny self.expect("process connect " + self.server.get_connect_url() + 124*4a7b4beaSMichał Górny "?baud=115200&stop-bits=2", 125*4a7b4beaSMichał Górny substrs=['Process', 'stopped']) 126*4a7b4beaSMichał Górny 127*4a7b4beaSMichał Górny current_attr = self.get_term_attrs() 128*4a7b4beaSMichał Górny self.assert_raw_mode(current_attr) 129*4a7b4beaSMichał Górny self.assertEqual(current_attr[4:6], 2 * [termios.B115200]) 130*4a7b4beaSMichał Górny self.assertEqual(self.get_parity_flags(current_attr), 131*4a7b4beaSMichał Górny self.get_parity_flags(self.orig_attr)) 132*4a7b4beaSMichał Górny self.assertEqual(self.get_stop_bit_flags(current_attr), 133*4a7b4beaSMichał Górny termios.CSTOPB) 134*4a7b4beaSMichał Górny finally: 135*4a7b4beaSMichał Górny self.dbg.GetSelectedTarget().GetProcess().Kill() 136*4a7b4beaSMichał Górny # original mode should be restored on exit 137*4a7b4beaSMichał Górny self.assertEqual(self.get_term_attrs(), self.orig_attr) 138