blob: 2cd3fe56dcfec738a27345f9bd51a2a9f0698f6b [file] [log] [blame]
Jim Inghamda3a3862014-10-16 23:02:14 +00001"""
2Test that the lldb driver's batch mode works correctly.
3"""
4
5import os, time
6import unittest2
7import lldb
8import pexpect
9from lldbtest import *
10
11class DriverBatchModeTest (TestBase):
12
13 mydir = TestBase.compute_mydir(__file__)
14
15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16 @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect")
17 @dsym_test
18 def test_driver_batch_mode_with_dsym(self):
19 """Test that the lldb driver's batch mode works correctly."""
20 self.buildDsym()
21 self.setTearDownCleanup()
22 self.batch_mode ()
23
24 @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect")
25 @dwarf_test
26 def test_driver_batch_mode_with_dwarf(self):
27 """Test that the lldb driver's batch mode works correctly."""
28 self.buildDwarf()
29 self.setTearDownCleanup()
30 self.batch_mode()
31
32 def setUp(self):
33 # Call super's setUp().
34 TestBase.setUp(self)
35 # Our simple source filename.
36 self.source = 'main.c'
37
38 def expect_string (self, string):
39 """This expects for "string", with timeout & EOF being test fails."""
40 try:
41 self.child.expect_exact(string)
42 except pexpect.EOF:
43 self.fail ("Got EOF waiting for '%s'"%(string))
44 except pexpect.TIMEOUT:
45 self.fail ("Timed out waiting for '%s'"%(string))
46
47
48 def batch_mode (self):
49 exe = os.path.join(os.getcwd(), "a.out")
50 prompt = "(lldb) "
51
52 # First time through, pass CRASH so the process will crash and stop in batch mode.
53 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
54 self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
55 child = self.child
56 # Turn on logging for what the child sends back.
57 if self.TraceOn():
58 child.logfile_read = sys.stdout
59
60 # We should see the "run":
61 self.expect_string ("run")
62 # We should have hit the breakpoint & continued:
63 self.expect_string ("continue")
64 # The App should have crashed:
65 self.expect_string("About to crash")
66 # Then we should have a live prompt:
67 self.expect_string (prompt)
68 self.child.sendline("frame variable touch_me_not")
69 self.expect_string ('(char *) touch_me_not')
70
71 self.deletePexpectChild()
72
73 # Now do it again, and see make sure if we don't crash, we quit:
74 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
75 self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
76 child = self.child
77 # Turn on logging for what the child sends back.
78 if self.TraceOn():
79 child.logfile_read = sys.stdout
80
81 # We should see the "run":
82 self.expect_string ("run")
83 # We should have hit the breakpoint & continued:
84 self.expect_string ("continue")
85 # The App should have not have crashed:
86 self.expect_string("Got there on time and it did not crash.")
87 # Then we should have a live prompt:
88 self.expect_string ("exited")
89 index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
90 self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")
91
92
93
94
95
96
97
98
99