blob: bd0f3fa4432b392b6c3f0b009db3a390325dd7d0 [file] [log] [blame]
Jim Inghamda3a3862014-10-16 23:02:14 +00001"""
2Test that the lldb driver's batch mode works correctly.
3"""
4
Zachary Turner77db4a82015-10-22 20:06:20 +00005import lldb_shared
6
Jim Inghamda3a3862014-10-16 23:02:14 +00007import os, time
Jim Inghamda3a3862014-10-16 23:02:14 +00008import lldb
Jim Inghamda3a3862014-10-16 23:02:14 +00009from lldbtest import *
10
11class DriverBatchModeTest (TestBase):
12
13 mydir = TestBase.compute_mydir(__file__)
14
Pavel Labath11282dc2015-09-14 16:11:11 +000015 @skipIfRemote # test not remote-ready llvm.org/pr24813
Pavel Labath6934ef32015-10-14 08:57:55 +000016 @expectedFlakeyLinux("llvm.org/pr25172")
Zachary Turner0c426312015-01-20 22:36:03 +000017 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000018 def test_driver_batch_mode(self):
Jim Inghamda3a3862014-10-16 23:02:14 +000019 """Test that the lldb driver's batch mode works correctly."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000020 self.build()
Jim Inghamda3a3862014-10-16 23:02:14 +000021 self.setTearDownCleanup()
22 self.batch_mode()
23
24 def setUp(self):
25 # Call super's setUp().
26 TestBase.setUp(self)
27 # Our simple source filename.
28 self.source = 'main.c'
29
30 def expect_string (self, string):
Zachary Turner77db4a82015-10-22 20:06:20 +000031 import pexpect
Jim Inghamda3a3862014-10-16 23:02:14 +000032 """This expects for "string", with timeout & EOF being test fails."""
33 try:
34 self.child.expect_exact(string)
35 except pexpect.EOF:
36 self.fail ("Got EOF waiting for '%s'"%(string))
37 except pexpect.TIMEOUT:
38 self.fail ("Timed out waiting for '%s'"%(string))
39
Jim Inghamda3a3862014-10-16 23:02:14 +000040 def batch_mode (self):
Zachary Turner77db4a82015-10-22 20:06:20 +000041 import pexpect
Jim Inghamda3a3862014-10-16 23:02:14 +000042 exe = os.path.join(os.getcwd(), "a.out")
43 prompt = "(lldb) "
44
45 # First time through, pass CRASH so the process will crash and stop in batch mode.
Jim Inghamc5705902014-11-21 00:14:57 +000046 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"'
Vince Harron790d95c2015-05-18 19:39:03 +000047 self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
Jim Inghamda3a3862014-10-16 23:02:14 +000048 child = self.child
49 # Turn on logging for what the child sends back.
50 if self.TraceOn():
51 child.logfile_read = sys.stdout
52
53 # We should see the "run":
54 self.expect_string ("run")
55 # We should have hit the breakpoint & continued:
56 self.expect_string ("continue")
57 # The App should have crashed:
58 self.expect_string("About to crash")
Jim Inghamc5705902014-11-21 00:14:57 +000059 # The -k option should have printed the frame variable once:
60 self.expect_string ('(char *) touch_me_not')
Jim Inghamda3a3862014-10-16 23:02:14 +000061 # Then we should have a live prompt:
62 self.expect_string (prompt)
63 self.child.sendline("frame variable touch_me_not")
64 self.expect_string ('(char *) touch_me_not')
65
66 self.deletePexpectChild()
67
68 # Now do it again, and see make sure if we don't crash, we quit:
69 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
Vince Harron790d95c2015-05-18 19:39:03 +000070 self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
Jim Inghamda3a3862014-10-16 23:02:14 +000071 child = self.child
72 # Turn on logging for what the child sends back.
73 if self.TraceOn():
74 child.logfile_read = sys.stdout
75
76 # We should see the "run":
77 self.expect_string ("run")
78 # We should have hit the breakpoint & continued:
79 self.expect_string ("continue")
80 # The App should have not have crashed:
81 self.expect_string("Got there on time and it did not crash.")
82 # Then we should have a live prompt:
83 self.expect_string ("exited")
84 index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
85 self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")
86