blob: f08119b4cecfa99369d3f6a6c8f4a1526e678d7a [file] [log] [blame]
Johnny Chen8f82f822012-02-09 00:27:01 +00001"""
2Test that 'stty -a' displays the same output before and after running the lldb command.
3"""
4
5import os
6import unittest2
7import lldb
8import pexpect
9from lldbtest import *
10
11class CommandLineCompletionTestCase(TestBase):
12
13 mydir = os.path.join("functionalities", "completion")
14
15 @classmethod
16 def classCleanup(cls):
17 """Cleanup the test byproducts."""
18 system(["/bin/sh", "-c", "rm -f child_send1.txt"])
19 system(["/bin/sh", "-c", "rm -f child_read1.txt"])
20 system(["/bin/sh", "-c", "rm -f child_send2.txt"])
21 system(["/bin/sh", "-c", "rm -f child_read2.txt"])
22
23 def test_stty_dash_a_before_and_afetr_invoking_lldb_command(self):
24 """Test that 'stty -a' displays the same output before and after running the lldb command."""
25
26 # The expect prompt.
Johnny Chenb82faf72012-02-09 00:51:41 +000027 expect_prompt = "expect[0-9.]+> "
Johnny Chen8f82f822012-02-09 00:27:01 +000028 # The default lldb prompt.
29 lldb_prompt = "(lldb) "
30
31 # So that the child gets torn down after the test.
32 self.child = pexpect.spawn('expect')
33 child = self.child
34
35 child.expect(expect_prompt)
36 child.setecho(True)
37 if self.TraceOn():
38 child.logfile = sys.stdout
39
Johnny Chenf9fa91b2012-02-09 01:16:04 +000040 child.sendline('set env(TERM) xterm')
41 child.expect(expect_prompt)
42 child.sendline('puts $env(TERM)')
43 child.expect(expect_prompt)
44
Johnny Chen8f82f822012-02-09 00:27:01 +000045 # Turn on loggings for input/output to/from the child.
46 with open('child_send1.txt', 'w') as f_send1:
47 with open('child_read1.txt', 'w') as f_read1:
48 child.logfile_send = f_send1
49 child.logfile_read = f_read1
50
51 child.sendline('stty -a')
52 child.expect(expect_prompt)
53
54 # Now that the stage1 logging is done, restore logfile to None to
55 # stop further logging.
56 child.logfile_send = None
57 child.logfile_read = None
58
59 # Invoke the lldb command.
60 child.sendline('%s %s' % (self.lldbHere, self.lldbOption))
61 child.expect_exact(lldb_prompt)
62
63 # Immediately quit.
64 child.sendline('quit')
65 child.expect(expect_prompt)
66
67 with open('child_send2.txt', 'w') as f_send2:
68 with open('child_read2.txt', 'w') as f_read2:
69 child.logfile_send = f_send2
70 child.logfile_read = f_read2
71
72 child.sendline('stty -a')
73 child.expect(expect_prompt)
74
75 child.sendline('exit')
76
77 # Now that the stage2 logging is done, restore logfile to None to
78 # stop further logging.
79 child.logfile_send = None
80 child.logfile_read = None
Johnny Chenf9fa91b2012-02-09 01:16:04 +000081
Johnny Chen8f82f822012-02-09 00:27:01 +000082 with open('child_send1.txt', 'r') as fs:
83 if self.TraceOn():
84 print "\n\nContents of child_send1.txt:"
85 print fs.read()
86 with open('child_read1.txt', 'r') as fr:
87 from_child1 = fr.read()
88 if self.TraceOn():
89 print "\n\nContents of child_read1.txt:"
90 print from_child1
91
92 with open('child_send2.txt', 'r') as fs:
93 if self.TraceOn():
94 print "\n\nContents of child_send2.txt:"
95 print fs.read()
96 with open('child_read2.txt', 'r') as fr:
97 from_child2 = fr.read()
98 if self.TraceOn():
99 print "\n\nContents of child_read2.txt:"
100 print from_child2
101
102 stty_output1_lines = from_child1.splitlines()
103 stty_output2_lines = from_child2.splitlines()
104 zipped = zip(stty_output1_lines, stty_output2_lines)
105 for tuple in zipped:
106 if self.TraceOn():
107 print "tuple->%s" % str(tuple)
108 # Every line should compare equal until the first blank line.
109 if len(tuple[0]) == 0:
110 break
111 self.assertTrue(tuple[0] == tuple[1])
112
113
114if __name__ == '__main__':
115 import atexit
116 lldb.SBDebugger.Initialize()
117 atexit.register(lambda: lldb.SBDebugger.Terminate())
118 unittest2.main()