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 |
| 8 | import pexpect |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class DriverBatchModeTest (TestBase): |
| 12 | |
| 13 | mydir = TestBase.compute_mydir(__file__) |
| 14 | |
| 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 16 | @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect") |
| 17 | @dsym_test |
| 18 | def test_driver_batch_mode_with_dsym(self): |
| 19 | """Test that the lldb driver's batch mode works correctly.""" |
| 20 | self.buildDsym() |
| 21 | self.setTearDownCleanup() |
| 22 | self.batch_mode () |
| 23 | |
| 24 | @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect") |
| 25 | @dwarf_test |
| 26 | def test_driver_batch_mode_with_dwarf(self): |
| 27 | """Test that the lldb driver's batch mode works correctly.""" |
| 28 | self.buildDwarf() |
| 29 | self.setTearDownCleanup() |
| 30 | self.batch_mode() |
| 31 | |
| 32 | def setUp(self): |
| 33 | # Call super's setUp(). |
| 34 | TestBase.setUp(self) |
| 35 | # Our simple source filename. |
| 36 | self.source = 'main.c' |
| 37 | |
| 38 | def expect_string (self, string): |
| 39 | """This expects for "string", with timeout & EOF being test fails.""" |
| 40 | try: |
| 41 | self.child.expect_exact(string) |
| 42 | except pexpect.EOF: |
| 43 | self.fail ("Got EOF waiting for '%s'"%(string)) |
| 44 | except pexpect.TIMEOUT: |
| 45 | self.fail ("Timed out waiting for '%s'"%(string)) |
| 46 | |
| 47 | |
| 48 | def batch_mode (self): |
| 49 | exe = os.path.join(os.getcwd(), "a.out") |
| 50 | prompt = "(lldb) " |
| 51 | |
| 52 | # 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^] | 53 | run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"' |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 54 | self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (self.lldbHere, self.lldbOption, run_commands, exe)) |
| 55 | child = self.child |
| 56 | # Turn on logging for what the child sends back. |
| 57 | if self.TraceOn(): |
| 58 | child.logfile_read = sys.stdout |
| 59 | |
| 60 | # We should see the "run": |
| 61 | self.expect_string ("run") |
| 62 | # We should have hit the breakpoint & continued: |
| 63 | self.expect_string ("continue") |
| 64 | # The App should have crashed: |
| 65 | self.expect_string("About to crash") |
Jim Ingham | c570590 | 2014-11-21 00:14:57 +0000 | [diff] [blame^] | 66 | # The -k option should have printed the frame variable once: |
| 67 | self.expect_string ('(char *) touch_me_not') |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 68 | # Then we should have a live prompt: |
| 69 | self.expect_string (prompt) |
| 70 | self.child.sendline("frame variable touch_me_not") |
| 71 | self.expect_string ('(char *) touch_me_not') |
| 72 | |
| 73 | self.deletePexpectChild() |
| 74 | |
| 75 | # Now do it again, and see make sure if we don't crash, we quit: |
| 76 | run_commands = ' -b -o "break set -n main" -o "run" -o "continue" ' |
| 77 | self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (self.lldbHere, self.lldbOption, run_commands, exe)) |
| 78 | child = self.child |
| 79 | # Turn on logging for what the child sends back. |
| 80 | if self.TraceOn(): |
| 81 | child.logfile_read = sys.stdout |
| 82 | |
| 83 | # We should see the "run": |
| 84 | self.expect_string ("run") |
| 85 | # We should have hit the breakpoint & continued: |
| 86 | self.expect_string ("continue") |
| 87 | # The App should have not have crashed: |
| 88 | self.expect_string("Got there on time and it did not crash.") |
| 89 | # Then we should have a live prompt: |
| 90 | self.expect_string ("exited") |
| 91 | index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT]) |
| 92 | self.assertTrue(index == 0, "lldb didn't close on successful batch completion.") |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |