2012-02-09 00:27:01 +00:00
|
|
|
"""
|
|
|
|
Test that 'stty -a' displays the same output before and after running the lldb command.
|
|
|
|
"""
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2015-10-22 20:06:20 +00:00
|
|
|
|
2012-02-09 00:27:01 +00:00
|
|
|
import os
|
|
|
|
import lldb
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2012-02-09 00:27:01 +00:00
|
|
|
|
2015-10-29 21:54:50 +00:00
|
|
|
class TestSTTYBeforeAndAfter(TestBase):
|
2012-02-09 00:27:01 +00:00
|
|
|
|
2013-12-10 23:19:29 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2012-02-09 00:27:01 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def classCleanup(cls):
|
|
|
|
"""Cleanup the test byproducts."""
|
2012-06-20 10:13:40 +00:00
|
|
|
cls.RemoveTempFile("child_send1.txt")
|
|
|
|
cls.RemoveTempFile("child_read1.txt")
|
|
|
|
cls.RemoveTempFile("child_send2.txt")
|
|
|
|
cls.RemoveTempFile("child_read2.txt")
|
2012-02-09 00:27:01 +00:00
|
|
|
|
2015-06-09 17:39:27 +00:00
|
|
|
@expectedFailureHostWindows("llvm.org/pr22274: need a pexpect replacement for windows")
|
2015-09-30 10:12:40 +00:00
|
|
|
@no_debug_info_test
|
2012-02-09 00:27:01 +00:00
|
|
|
def test_stty_dash_a_before_and_afetr_invoking_lldb_command(self):
|
|
|
|
"""Test that 'stty -a' displays the same output before and after running the lldb command."""
|
2014-07-18 01:02:02 +00:00
|
|
|
import pexpect
|
2012-02-09 02:01:59 +00:00
|
|
|
if not which('expect'):
|
|
|
|
self.skipTest("The 'expect' program cannot be located, skip the test")
|
|
|
|
|
2012-02-09 00:27:01 +00:00
|
|
|
# The expect prompt.
|
2012-02-09 00:51:41 +00:00
|
|
|
expect_prompt = "expect[0-9.]+> "
|
2012-02-09 00:27:01 +00:00
|
|
|
# The default lldb prompt.
|
|
|
|
lldb_prompt = "(lldb) "
|
|
|
|
|
|
|
|
# So that the child gets torn down after the test.
|
|
|
|
self.child = pexpect.spawn('expect')
|
|
|
|
child = self.child
|
|
|
|
|
|
|
|
child.expect(expect_prompt)
|
|
|
|
child.setecho(True)
|
|
|
|
if self.TraceOn():
|
|
|
|
child.logfile = sys.stdout
|
|
|
|
|
2015-04-02 18:24:03 +00:00
|
|
|
if self.platformIsDarwin():
|
2012-02-09 19:34:25 +00:00
|
|
|
child.sendline('set env(TERM) xterm')
|
|
|
|
else:
|
|
|
|
child.sendline('set env(TERM) vt100')
|
2012-02-09 01:16:04 +00:00
|
|
|
child.expect(expect_prompt)
|
|
|
|
child.sendline('puts $env(TERM)')
|
|
|
|
child.expect(expect_prompt)
|
|
|
|
|
2012-02-09 00:27:01 +00:00
|
|
|
# Turn on loggings for input/output to/from the child.
|
|
|
|
with open('child_send1.txt', 'w') as f_send1:
|
|
|
|
with open('child_read1.txt', 'w') as f_read1:
|
|
|
|
child.logfile_send = f_send1
|
|
|
|
child.logfile_read = f_read1
|
|
|
|
|
|
|
|
child.sendline('stty -a')
|
|
|
|
child.expect(expect_prompt)
|
|
|
|
|
|
|
|
# Now that the stage1 logging is done, restore logfile to None to
|
|
|
|
# stop further logging.
|
|
|
|
child.logfile_send = None
|
|
|
|
child.logfile_read = None
|
|
|
|
|
|
|
|
# Invoke the lldb command.
|
2015-05-18 19:39:03 +00:00
|
|
|
child.sendline('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
|
2012-02-09 00:27:01 +00:00
|
|
|
child.expect_exact(lldb_prompt)
|
|
|
|
|
|
|
|
# Immediately quit.
|
|
|
|
child.sendline('quit')
|
|
|
|
child.expect(expect_prompt)
|
|
|
|
|
|
|
|
with open('child_send2.txt', 'w') as f_send2:
|
|
|
|
with open('child_read2.txt', 'w') as f_read2:
|
|
|
|
child.logfile_send = f_send2
|
|
|
|
child.logfile_read = f_read2
|
|
|
|
|
|
|
|
child.sendline('stty -a')
|
|
|
|
child.expect(expect_prompt)
|
|
|
|
|
|
|
|
child.sendline('exit')
|
|
|
|
|
|
|
|
# Now that the stage2 logging is done, restore logfile to None to
|
|
|
|
# stop further logging.
|
|
|
|
child.logfile_send = None
|
|
|
|
child.logfile_read = None
|
2012-02-09 01:16:04 +00:00
|
|
|
|
2012-02-09 00:27:01 +00:00
|
|
|
with open('child_send1.txt', 'r') as fs:
|
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("\n\nContents of child_send1.txt:")
|
|
|
|
print(fs.read())
|
2012-02-09 00:27:01 +00:00
|
|
|
with open('child_read1.txt', 'r') as fr:
|
|
|
|
from_child1 = fr.read()
|
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("\n\nContents of child_read1.txt:")
|
|
|
|
print(from_child1)
|
2012-02-09 00:27:01 +00:00
|
|
|
|
|
|
|
with open('child_send2.txt', 'r') as fs:
|
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("\n\nContents of child_send2.txt:")
|
|
|
|
print(fs.read())
|
2012-02-09 00:27:01 +00:00
|
|
|
with open('child_read2.txt', 'r') as fr:
|
|
|
|
from_child2 = fr.read()
|
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("\n\nContents of child_read2.txt:")
|
|
|
|
print(from_child2)
|
2012-02-09 00:27:01 +00:00
|
|
|
|
|
|
|
stty_output1_lines = from_child1.splitlines()
|
|
|
|
stty_output2_lines = from_child2.splitlines()
|
2015-10-26 16:51:28 +00:00
|
|
|
zipped = list(zip(stty_output1_lines, stty_output2_lines))
|
2012-02-09 00:27:01 +00:00
|
|
|
for tuple in zipped:
|
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("tuple->%s" % str(tuple))
|
2012-02-09 00:27:01 +00:00
|
|
|
# Every line should compare equal until the first blank line.
|
|
|
|
if len(tuple[0]) == 0:
|
|
|
|
break
|
|
|
|
self.assertTrue(tuple[0] == tuple[1])
|