2 Test that 'stty -a' displays the same output before and after running the lldb command.
5 from __future__
import print_function
10 from lldbsuite
.test
.decorators
import *
11 from lldbsuite
.test
.lldbtest
import *
12 from lldbsuite
.test
import lldbutil
15 class TestSTTYBeforeAndAfter(TestBase
):
17 mydir
= TestBase
.compute_mydir(__file__
)
20 def classCleanup(cls
):
21 """Cleanup the test byproducts."""
22 cls
.RemoveTempFile("child_send1.txt")
23 cls
.RemoveTempFile("child_read1.txt")
24 cls
.RemoveTempFile("child_send2.txt")
25 cls
.RemoveTempFile("child_read2.txt")
28 hostoslist
=["windows"],
29 bugnumber
="llvm.org/pr22274: need a pexpect replacement for windows")
31 def test_stty_dash_a_before_and_afetr_invoking_lldb_command(self
):
32 """Test that 'stty -a' displays the same output before and after running the lldb command."""
34 if not which('expect'):
36 "The 'expect' program cannot be located, skip the test")
39 expect_prompt
= "expect[0-9.]+> "
40 # The default lldb prompt.
41 lldb_prompt
= "(lldb) "
43 # So that the child gets torn down after the test.
45 if sys
.version_info
.major
== 3:
46 self
.child
= pexpect
.spawnu('expect')
48 self
.child
= pexpect
.spawn('expect')
51 child
.expect(expect_prompt
)
54 child
.logfile
= sys
.stdout
56 if self
.platformIsDarwin():
57 child
.sendline('set env(TERM) xterm')
59 child
.sendline('set env(TERM) vt100')
60 child
.expect(expect_prompt
)
61 child
.sendline('puts $env(TERM)')
62 child
.expect(expect_prompt
)
64 # Turn on loggings for input/output to/from the child.
65 child
.logfile_send
= child_send1
= six
.StringIO()
66 child
.logfile_read
= child_read1
= six
.StringIO()
67 child
.sendline('stty -a')
68 child
.expect(expect_prompt
)
70 # Now that the stage1 logging is done, restore logfile to None to
71 # stop further logging.
72 child
.logfile_send
= None
73 child
.logfile_read
= None
75 # Invoke the lldb command.
76 child
.sendline(lldbtest_config
.lldbExec
)
77 child
.expect_exact(lldb_prompt
)
80 child
.sendline('quit')
81 child
.expect(expect_prompt
)
83 child
.logfile_send
= child_send2
= six
.StringIO()
84 child
.logfile_read
= child_read2
= six
.StringIO()
85 child
.sendline('stty -a')
86 child
.expect(expect_prompt
)
88 child
.sendline('exit')
90 # Now that the stage2 logging is done, restore logfile to None to
91 # stop further logging.
92 child
.logfile_send
= None
93 child
.logfile_read
= None
96 print("\n\nContents of child_send1:")
97 print(child_send1
.getvalue())
98 print("\n\nContents of child_read1:")
99 print(child_read1
.getvalue())
100 print("\n\nContents of child_send2:")
101 print(child_send2
.getvalue())
102 print("\n\nContents of child_read2:")
103 print(child_read2
.getvalue())
105 stty_output1_lines
= child_read1
.getvalue().splitlines()
106 stty_output2_lines
= child_read2
.getvalue().splitlines()
107 zipped
= list(zip(stty_output1_lines
, stty_output2_lines
))
110 print("tuple->%s" % str(tuple))
111 # Every line should compare equal until the first blank line.
112 if len(tuple[0]) == 0:
114 self
.assertTrue(tuple[0] == tuple[1])