blob: 382b806ff7be319d354515c3cfcc125a9aacef12 [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
40 # Turn on loggings for input/output to/from the child.
41 with open('child_send1.txt', 'w') as f_send1:
42 with open('child_read1.txt', 'w') as f_read1:
43 child.logfile_send = f_send1
44 child.logfile_read = f_read1
45
46 child.sendline('stty -a')
47 child.expect(expect_prompt)
48
49 # Now that the stage1 logging is done, restore logfile to None to
50 # stop further logging.
51 child.logfile_send = None
52 child.logfile_read = None
53
54 # Invoke the lldb command.
55 child.sendline('%s %s' % (self.lldbHere, self.lldbOption))
56 child.expect_exact(lldb_prompt)
57
58 # Immediately quit.
59 child.sendline('quit')
60 child.expect(expect_prompt)
61
62 with open('child_send2.txt', 'w') as f_send2:
63 with open('child_read2.txt', 'w') as f_read2:
64 child.logfile_send = f_send2
65 child.logfile_read = f_read2
66
67 child.sendline('stty -a')
68 child.expect(expect_prompt)
69
70 child.sendline('exit')
71
72 # Now that the stage2 logging is done, restore logfile to None to
73 # stop further logging.
74 child.logfile_send = None
75 child.logfile_read = None
76
77 with open('child_send1.txt', 'r') as fs:
78 if self.TraceOn():
79 print "\n\nContents of child_send1.txt:"
80 print fs.read()
81 with open('child_read1.txt', 'r') as fr:
82 from_child1 = fr.read()
83 if self.TraceOn():
84 print "\n\nContents of child_read1.txt:"
85 print from_child1
86
87 with open('child_send2.txt', 'r') as fs:
88 if self.TraceOn():
89 print "\n\nContents of child_send2.txt:"
90 print fs.read()
91 with open('child_read2.txt', 'r') as fr:
92 from_child2 = fr.read()
93 if self.TraceOn():
94 print "\n\nContents of child_read2.txt:"
95 print from_child2
96
97 stty_output1_lines = from_child1.splitlines()
98 stty_output2_lines = from_child2.splitlines()
99 zipped = zip(stty_output1_lines, stty_output2_lines)
100 for tuple in zipped:
101 if self.TraceOn():
102 print "tuple->%s" % str(tuple)
103 # Every line should compare equal until the first blank line.
104 if len(tuple[0]) == 0:
105 break
106 self.assertTrue(tuple[0] == tuple[1])
107
108
109if __name__ == '__main__':
110 import atexit
111 lldb.SBDebugger.Initialize()
112 atexit.register(lambda: lldb.SBDebugger.Terminate())
113 unittest2.main()