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 | |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame^] | 5 | import lldb_shared |
| 6 | |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 7 | import os, time |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 8 | import lldb |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 9 | from lldbtest import * |
| 10 | |
| 11 | class DriverBatchModeTest (TestBase): |
| 12 | |
| 13 | mydir = TestBase.compute_mydir(__file__) |
| 14 | |
Pavel Labath | 11282dc | 2015-09-14 16:11:11 +0000 | [diff] [blame] | 15 | @skipIfRemote # test not remote-ready llvm.org/pr24813 |
Pavel Labath | 6934ef3 | 2015-10-14 08:57:55 +0000 | [diff] [blame] | 16 | @expectedFlakeyLinux("llvm.org/pr25172") |
Zachary Turner | 0c42631 | 2015-01-20 22:36:03 +0000 | [diff] [blame] | 17 | @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 18 | def test_driver_batch_mode(self): |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 19 | """Test that the lldb driver's batch mode works correctly.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 20 | self.build() |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 21 | 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 Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame^] | 31 | import pexpect |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 32 | """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 Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 40 | def batch_mode (self): |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame^] | 41 | import pexpect |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 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 | |