Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test that the lldb driver's batch mode works correctly. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
Zachary Turner | 0c42631 | 2015-01-20 22:36:03 +0000 | [diff] [blame] | 8 | try: |
| 9 | import pexpect |
| 10 | except: |
| 11 | pexpect = None |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 12 | from lldbtest import * |
| 13 | |
| 14 | class DriverBatchModeTest (TestBase): |
| 15 | |
| 16 | mydir = TestBase.compute_mydir(__file__) |
| 17 | |
Pavel Labath | 11282dc | 2015-09-14 16:11:11 +0000 | [diff] [blame] | 18 | @skipIfRemote # test not remote-ready llvm.org/pr24813 |
Zachary Turner | 0c42631 | 2015-01-20 22:36:03 +0000 | [diff] [blame] | 19 | @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 20 | def test_driver_batch_mode(self): |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 21 | """Test that the lldb driver's batch mode works correctly.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 22 | self.build() |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 23 | self.setTearDownCleanup() |
| 24 | self.batch_mode() |
| 25 | |
| 26 | def setUp(self): |
| 27 | # Call super's setUp(). |
| 28 | TestBase.setUp(self) |
| 29 | # Our simple source filename. |
| 30 | self.source = 'main.c' |
| 31 | |
| 32 | def expect_string (self, string): |
| 33 | """This expects for "string", with timeout & EOF being test fails.""" |
| 34 | try: |
| 35 | self.child.expect_exact(string) |
| 36 | except pexpect.EOF: |
| 37 | self.fail ("Got EOF waiting for '%s'"%(string)) |
| 38 | except pexpect.TIMEOUT: |
| 39 | self.fail ("Timed out waiting for '%s'"%(string)) |
| 40 | |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 41 | def batch_mode (self): |
| 42 | 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 Ingham | c570590 | 2014-11-21 00:14:57 +0000 | [diff] [blame] | 46 | run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"' |
Vince Harron | 790d95c | 2015-05-18 19:39:03 +0000 | [diff] [blame] | 47 | self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe)) |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 48 | 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 Ingham | c570590 | 2014-11-21 00:14:57 +0000 | [diff] [blame] | 59 | # The -k option should have printed the frame variable once: |
| 60 | self.expect_string ('(char *) touch_me_not') |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 61 | # 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 Harron | 790d95c | 2015-05-18 19:39:03 +0000 | [diff] [blame] | 70 | self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe)) |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 71 | 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 | |