2 Test that 'stty -a' displays the same output before and after running the lldb command.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
13 class TestSTTYBeforeAndAfter(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
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")
25 @expectedFailureHostWindows("llvm.org/pr22274: need a pexpect replacement for windows")
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."""
30 if not which('expect'):
31 self.skipTest("The 'expect' program cannot be located, skip the test")
34 expect_prompt = "expect[0-9.]+> "
35 # The default lldb prompt.
36 lldb_prompt = "(lldb) "
38 # So that the child gets torn down after the test.
39 self.child = pexpect.spawn('expect')
42 child.expect(expect_prompt)
45 child.logfile = sys.stdout
47 if self.platformIsDarwin():
48 child.sendline('set env(TERM) xterm')
50 child.sendline('set env(TERM) vt100')
51 child.expect(expect_prompt)
52 child.sendline('puts $env(TERM)')
53 child.expect(expect_prompt)
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
61 child.sendline('stty -a')
62 child.expect(expect_prompt)
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
69 # Invoke the lldb command.
70 child.sendline('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
71 child.expect_exact(lldb_prompt)
74 child.sendline('quit')
75 child.expect(expect_prompt)
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
82 child.sendline('stty -a')
83 child.expect(expect_prompt)
85 child.sendline('exit')
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
92 with open('child_send1.txt', 'r') as fs:
94 print("\n\nContents of child_send1.txt:")
96 with open('child_read1.txt', 'r') as fr:
97 from_child1 = fr.read()
99 print("\n\nContents of child_read1.txt:")
102 with open('child_send2.txt', 'r') as fs:
104 print("\n\nContents of child_send2.txt:")
106 with open('child_read2.txt', 'r') as fr:
107 from_child2 = fr.read()
109 print("\n\nContents of child_read2.txt:")
112 stty_output1_lines = from_child1.splitlines()
113 stty_output2_lines = from_child2.splitlines()
114 zipped = list(zip(stty_output1_lines, stty_output2_lines))
117 print("tuple->%s" % str(tuple))
118 # Every line should compare equal until the first blank line.
119 if len(tuple[0]) == 0:
121 self.assertTrue(tuple[0] == tuple[1])