]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/terminal/TestSTTYBeforeAndAfter.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / terminal / TestSTTYBeforeAndAfter.py
1 """
2 Test that 'stty -a' displays the same output before and after running the lldb command.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os
10 import lldb
11 from lldbsuite.test.lldbtest import *
12
13 class TestSTTYBeforeAndAfter(TestBase):
14
15     mydir = TestBase.compute_mydir(__file__)
16
17     @classmethod
18     def classCleanup(cls):
19         """Cleanup the test byproducts."""
20         cls.RemoveTempFile("child_send1.txt")
21         cls.RemoveTempFile("child_read1.txt")
22         cls.RemoveTempFile("child_send2.txt")
23         cls.RemoveTempFile("child_read2.txt")
24
25     @expectedFailureHostWindows("llvm.org/pr22274: need a pexpect replacement for windows")
26     @no_debug_info_test
27     def test_stty_dash_a_before_and_afetr_invoking_lldb_command(self):
28         """Test that 'stty -a' displays the same output before and after running the lldb command."""
29         import pexpect
30         if not which('expect'):
31             self.skipTest("The 'expect' program cannot be located, skip the test")
32
33         # The expect prompt.
34         expect_prompt = "expect[0-9.]+> "
35         # The default lldb prompt.
36         lldb_prompt = "(lldb) "
37
38         # So that the child gets torn down after the test.
39         self.child = pexpect.spawn('expect')
40         child = self.child
41
42         child.expect(expect_prompt)
43         child.setecho(True)
44         if self.TraceOn():
45             child.logfile = sys.stdout
46
47         if self.platformIsDarwin():
48             child.sendline('set env(TERM) xterm')
49         else:
50             child.sendline('set env(TERM) vt100')
51         child.expect(expect_prompt)
52         child.sendline('puts $env(TERM)')
53         child.expect(expect_prompt)
54
55         # Turn on loggings for input/output to/from the child.
56         with open('child_send1.txt', 'w') as f_send1:
57             with open('child_read1.txt', 'w') as f_read1:
58                 child.logfile_send = f_send1
59                 child.logfile_read = f_read1
60
61                 child.sendline('stty -a')
62                 child.expect(expect_prompt)
63
64         # Now that the stage1 logging is done, restore logfile to None to
65         # stop further logging.
66         child.logfile_send = None
67         child.logfile_read = None
68
69         # Invoke the lldb command.
70         child.sendline('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
71         child.expect_exact(lldb_prompt)
72
73         # Immediately quit.
74         child.sendline('quit')
75         child.expect(expect_prompt)
76
77         with open('child_send2.txt', 'w') as f_send2:
78             with open('child_read2.txt', 'w') as f_read2:
79                 child.logfile_send = f_send2
80                 child.logfile_read = f_read2
81
82                 child.sendline('stty -a')
83                 child.expect(expect_prompt)
84
85                 child.sendline('exit')
86
87         # Now that the stage2 logging is done, restore logfile to None to
88         # stop further logging.
89         child.logfile_send = None
90         child.logfile_read = None
91
92         with open('child_send1.txt', 'r') as fs:
93             if self.TraceOn():
94                 print("\n\nContents of child_send1.txt:")
95                 print(fs.read())
96         with open('child_read1.txt', 'r') as fr:
97             from_child1 = fr.read()
98             if self.TraceOn():
99                 print("\n\nContents of child_read1.txt:")
100                 print(from_child1)
101
102         with open('child_send2.txt', 'r') as fs:
103             if self.TraceOn():
104                 print("\n\nContents of child_send2.txt:")
105                 print(fs.read())
106         with open('child_read2.txt', 'r') as fr:
107             from_child2 = fr.read()
108             if self.TraceOn():
109                 print("\n\nContents of child_read2.txt:")
110                 print(from_child2)
111
112         stty_output1_lines = from_child1.splitlines()
113         stty_output2_lines = from_child2.splitlines()
114         zipped = list(zip(stty_output1_lines, stty_output2_lines))
115         for tuple in zipped:
116             if self.TraceOn():
117                 print("tuple->%s" % str(tuple))
118             # Every line should compare equal until the first blank line.
119             if len(tuple[0]) == 0:
120                 break
121             self.assertTrue(tuple[0] == tuple[1])