blob: 733cfe65db5781b93663c48d4e6620d4528cb1a8 [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
Pavel Labath11282dc2015-09-14 16:11:11 +000018 @skipIfRemote # test not remote-ready llvm.org/pr24813
Pavel Labath6934ef32015-10-14 08:57:55 +000019 @expectedFlakeyLinux("llvm.org/pr25172")
Zachary Turner0c426312015-01-20 22:36:03 +000020 @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000021 def test_driver_batch_mode(self):
Jim Inghamda3a3862014-10-16 23:02:14 +000022 """Test that the lldb driver's batch mode works correctly."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000023 self.build()
Jim Inghamda3a3862014-10-16 23:02:14 +000024 self.setTearDownCleanup()
25 self.batch_mode()
26
27 def setUp(self):
28 # Call super's setUp().
29 TestBase.setUp(self)
30 # Our simple source filename.
31 self.source = 'main.c'
32
33 def expect_string (self, string):
34 """This expects for "string", with timeout & EOF being test fails."""
35 try:
36 self.child.expect_exact(string)
37 except pexpect.EOF:
38 self.fail ("Got EOF waiting for '%s'"%(string))
39 except pexpect.TIMEOUT:
40 self.fail ("Timed out waiting for '%s'"%(string))
41
Jim Inghamda3a3862014-10-16 23:02:14 +000042 def batch_mode (self):
43 exe = os.path.join(os.getcwd(), "a.out")
44 prompt = "(lldb) "
45
46 # First time through, pass CRASH so the process will crash and stop in batch mode.
Jim Inghamc5705902014-11-21 00:14:57 +000047 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 +000048 self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
Jim Inghamda3a3862014-10-16 23:02:14 +000049 child = self.child
50 # Turn on logging for what the child sends back.
51 if self.TraceOn():
52 child.logfile_read = sys.stdout
53
54 # We should see the "run":
55 self.expect_string ("run")
56 # We should have hit the breakpoint & continued:
57 self.expect_string ("continue")
58 # The App should have crashed:
59 self.expect_string("About to crash")
Jim Inghamc5705902014-11-21 00:14:57 +000060 # The -k option should have printed the frame variable once:
61 self.expect_string ('(char *) touch_me_not')
Jim Inghamda3a3862014-10-16 23:02:14 +000062 # Then we should have a live prompt:
63 self.expect_string (prompt)
64 self.child.sendline("frame variable touch_me_not")
65 self.expect_string ('(char *) touch_me_not')
66
67 self.deletePexpectChild()
68
69 # Now do it again, and see make sure if we don't crash, we quit:
70 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
Vince Harron790d95c2015-05-18 19:39:03 +000071 self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
Jim Inghamda3a3862014-10-16 23:02:14 +000072 child = self.child
73 # Turn on logging for what the child sends back.
74 if self.TraceOn():
75 child.logfile_read = sys.stdout
76
77 # We should see the "run":
78 self.expect_string ("run")
79 # We should have hit the breakpoint & continued:
80 self.expect_string ("continue")
81 # The App should have not have crashed:
82 self.expect_string("Got there on time and it did not crash.")
83 # Then we should have a live prompt:
84 self.expect_string ("exited")
85 index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
86 self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")
87