2 Test that the lldb driver's batch mode works correctly.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
15 class DriverBatchModeTest (TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Our simple source filename.
23 self.source = 'main.c'
26 def expect_string (self, string):
28 """This expects for "string", with timeout & EOF being test fails."""
30 self.child.expect_exact(string)
32 self.fail ("Got EOF waiting for '%s'"%(string))
33 except pexpect.TIMEOUT:
34 self.fail ("Timed out waiting for '%s'"%(string))
36 @skipIfRemote # test not remote-ready llvm.org/pr24813
37 @expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
38 @expectedFlakeyLinux("llvm.org/pr25172")
39 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
40 def test_batch_mode_run_crash (self):
41 """Test that the lldb driver's batch mode works correctly."""
43 self.setTearDownCleanup()
46 exe = os.path.join(os.getcwd(), "a.out")
49 # Pass CRASH so the process will crash and stop in batch mode.
50 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"'
51 self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
53 # Turn on logging for what the child sends back.
55 child.logfile_read = sys.stdout
57 # We should see the "run":
58 self.expect_string ("run")
59 # We should have hit the breakpoint & continued:
60 self.expect_string ("continue")
61 # The App should have crashed:
62 self.expect_string("About to crash")
63 # The -k option should have printed the frame variable once:
64 self.expect_string ('(char *) touch_me_not')
65 # Then we should have a live prompt:
66 self.expect_string (prompt)
67 self.child.sendline("frame variable touch_me_not")
68 self.expect_string ('(char *) touch_me_not')
70 self.deletePexpectChild()
73 @skipIfRemote # test not remote-ready llvm.org/pr24813
74 @expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
75 @expectedFlakeyLinux("llvm.org/pr25172")
76 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
77 def test_batch_mode_run_exit (self):
78 """Test that the lldb driver's batch mode works correctly."""
80 self.setTearDownCleanup()
83 exe = os.path.join(os.getcwd(), "a.out")
86 # Now do it again, and make sure if we don't crash, we quit:
87 run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
88 self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
90 # Turn on logging for what the child sends back.
92 child.logfile_read = sys.stdout
94 # We should see the "run":
95 self.expect_string ("run")
96 # We should have hit the breakpoint & continued:
97 self.expect_string ("continue")
98 # The App should have not have crashed:
99 self.expect_string("Got there on time and it did not crash.")
100 # Then we should have a live prompt:
101 self.expect_string ("exited")
102 index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
103 self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")
105 def closeVictim(self):
106 if self.victim != None:
110 @skipIfRemote # test not remote-ready llvm.org/pr24813
111 @expectedFlakeyFreeBSD("llvm.org/pr25172 fails rarely on the buildbot")
112 @expectedFlakeyLinux("llvm.org/pr25172")
113 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
114 def test_batch_mode_attach_exit (self):
115 """Test that the lldb driver's batch mode works correctly."""
117 self.setTearDownCleanup()
120 exe = os.path.join(os.getcwd(), "a.out")
123 # Finally, start up the process by hand, attach to it, and wait for its completion.
124 # Attach is funny, since it looks like it stops with a signal on most Unixen so
125 # care must be taken not to treat that as a reason to exit batch mode.
127 # Start up the process by hand and wait for it to get to the wait loop.
129 self.victim = pexpect.spawn('%s WAIT' %(exe))
130 if self.victim == None:
131 self.fail("Could not spawn ", exe, ".")
133 self.addTearDownHook (self.closeVictim)
136 self.victim.logfile_read = sys.stdout
138 self.victim.expect("PID: ([0-9]+) END")
139 if self.victim.match == None:
140 self.fail("Couldn't get the target PID.")
142 victim_pid = int(self.victim.match.group(1))
144 self.victim.expect("Waiting")
146 run_commands = ' -b -o "process attach -p %d" -o "breakpoint set --file %s -p \'Stop here to unset keep_waiting\' -N keep_waiting" -o "continue" -o "break delete keep_waiting" -o "expr keep_waiting = 0" -o "continue" ' % (victim_pid, self.source)
147 self.child = pexpect.spawn('%s %s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe))
150 # Turn on logging for what the child sends back.
152 child.logfile_read = sys.stdout
154 # We should see the "run":
155 self.expect_string ("attach")
157 self.expect_string(prompt + "continue")
159 self.expect_string(prompt + "continue")
161 # Then we should see the process exit:
162 self.expect_string ("Process %d exited with status"%(victim_pid))
164 victim_index = self.victim.expect([pexpect.EOF, pexpect.TIMEOUT])
165 self.assertTrue(victim_index == 0, "Victim didn't really exit.")
167 index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
168 self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")