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