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