blob: 02f4ec6d9c47e36a78e1e9a72128cd87c54dec80 [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
Zachary Turner0c426312015-01-20 22:36:03 +00008try:
9 import pexpect
10except:
11 pexpect = None
Jim Inghamda3a3862014-10-16 23:02:14 +000012from lldbtest import *
13
14class DriverBatchModeTest (TestBase):
15
16 mydir = TestBase.compute_mydir(__file__)
17
Robert Flack13c7ad92015-03-30 14:12:17 +000018 @skipUnlessDarwin
Jim Inghamda3a3862014-10-16 23:02:14 +000019 @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect")
20 @dsym_test
21 def test_driver_batch_mode_with_dsym(self):
22 """Test that the lldb driver's batch mode works correctly."""
23 self.buildDsym()
24 self.setTearDownCleanup()
25 self.batch_mode ()
26
27 @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect")
Zachary Turner0c426312015-01-20 22:36:03 +000028 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
Jim Inghamda3a3862014-10-16 23:02:14 +000029 @dwarf_test
30 def test_driver_batch_mode_with_dwarf(self):
31 """Test that the lldb driver's batch mode works correctly."""
32 self.buildDwarf()
33 self.setTearDownCleanup()
34 self.batch_mode()
35
36 def setUp(self):
37 # Call super's setUp().
38 TestBase.setUp(self)
39 # Our simple source filename.
40 self.source = 'main.c'
41
42 def expect_string (self, string):
43 """This expects for "string", with timeout & EOF being test fails."""
44 try:
45 self.child.expect_exact(string)
46 except pexpect.EOF:
47 self.fail ("Got EOF waiting for '%s'"%(string))
48 except pexpect.TIMEOUT:
49 self.fail ("Timed out waiting for '%s'"%(string))
50
51
52 def batch_mode (self):
53 exe = os.path.join(os.getcwd(), "a.out")
54 prompt = "(lldb) "
55
56 # First time through, pass CRASH so the process will crash and stop in batch mode.
Jim Inghamc5705902014-11-21 00:14:57 +000057 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"'
Jim Inghamda3a3862014-10-16 23:02:14 +000058 self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
59 child = self.child
60 # Turn on logging for what the child sends back.
61 if self.TraceOn():
62 child.logfile_read = sys.stdout
63
64 # We should see the "run":
65 self.expect_string ("run")
66 # We should have hit the breakpoint & continued:
67 self.expect_string ("continue")
68 # The App should have crashed:
69 self.expect_string("About to crash")
Jim Inghamc5705902014-11-21 00:14:57 +000070 # The -k option should have printed the frame variable once:
71 self.expect_string ('(char *) touch_me_not')
Jim Inghamda3a3862014-10-16 23:02:14 +000072 # Then we should have a live prompt:
73 self.expect_string (prompt)
74 self.child.sendline("frame variable touch_me_not")
75 self.expect_string ('(char *) touch_me_not')
76
77 self.deletePexpectChild()
78
79 # Now do it again, and see make sure if we don't crash, we quit:
80 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
81 self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
82 child = self.child
83 # Turn on logging for what the child sends back.
84 if self.TraceOn():
85 child.logfile_read = sys.stdout
86
87 # We should see the "run":
88 self.expect_string ("run")
89 # We should have hit the breakpoint & continued:
90 self.expect_string ("continue")
91 # The App should have not have crashed:
92 self.expect_string("Got there on time and it did not crash.")
93 # Then we should have a live prompt:
94 self.expect_string ("exited")
95 index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
96 self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")
97
98
99
100
101
102
103
104
105