Home | History | Annotate | Download | only in single-quote-in-filename-to-lldb
      1 """
      2 Test the lldb command line takes a filename with single quote chars.
      3 """
      4 
      5 import os
      6 import unittest2
      7 import lldb
      8 import pexpect
      9 from lldbtest import *
     10 
     11 class SingleQuoteInCommandLineTestCase(TestBase):
     12 
     13     mydir = os.path.join("functionalities", "single-quote-in-filename-to-lldb")
     14     myexe = "path with '09/a.out"
     15 
     16     @classmethod
     17     def classCleanup(cls):
     18         """Cleanup the test byproducts."""
     19         try:
     20             os.remove("child_send.txt")
     21             os.remove("child_read.txt")
     22             os.remove(cls.myexe)
     23         except:
     24             pass
     25 
     26     @skipIfLinux # llvm.org/pr14637: this test case fails sometimes because the input prompt "(lldb)" is missing
     27     def test_lldb_invocation_with_single_quote_in_filename(self):
     28         """Test that 'lldb my_file_name' works where my_file_name is a string with a single quote char in it."""
     29         self.buildDefault()
     30         system(["/bin/sh", "-c", "cp a.out \"%s\"" % self.myexe])
     31 
     32         # The default lldb prompt.
     33         prompt = "(lldb) "
     34 
     35         # So that the child gets torn down after the test.
     36         self.child = pexpect.spawn('%s %s "%s"' % (self.lldbHere, self.lldbOption, self.myexe))
     37         child = self.child
     38         child.setecho(True)
     39         # Turn on logging for input/output to/from the child.
     40         with open('child_send.txt', 'w') as f_send:
     41             with open('child_read.txt', 'w') as f_read:
     42                 child.logfile_send = f_send
     43                 child.logfile_read = f_read
     44 
     45                 child.expect_exact(prompt)
     46 
     47                 child.send("help watchpoint")
     48                 child.sendline('')
     49                 child.expect_exact(prompt)
     50 
     51         # Now that the necessary logging is done, restore logfile to None to
     52         # stop further logging.
     53         child.logfile_send = None
     54         child.logfile_read = None
     55         
     56         with open('child_send.txt', 'r') as fs:
     57             if self.TraceOn():
     58                 print "\n\nContents of child_send.txt:"
     59                 print fs.read()
     60         with open('child_read.txt', 'r') as fr:
     61             from_child = fr.read()
     62             if self.TraceOn():
     63                 print "\n\nContents of child_read.txt:"
     64                 print from_child
     65 
     66             self.expect(from_child, exe=False,
     67                 substrs = ["Current executable set to"])
     68 
     69 
     70 if __name__ == '__main__':
     71     import atexit
     72     lldb.SBDebugger.Initialize()
     73     atexit.register(lambda: lldb.SBDebugger.Terminate())
     74     unittest2.main()
     75