diff options
| author | Zachary Turner <zturner@google.com> | 2015-10-28 17:43:26 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2015-10-28 17:43:26 +0000 |
| commit | c432c8f856e0bd84de980a9d9bb2d31b06fa95b1 (patch) | |
| tree | 4efa528e074a6e2df782345e4cd97f5d85d038c4 /lldb/packages/Python/lldbsuite/test/driver/batch_mode | |
| parent | a8a3bd210086b50242903ed95048fe5e53897878 (diff) | |
| download | bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.tar.gz bcm5719-llvm-c432c8f856e0bd84de980a9d9bb2d31b06fa95b1.zip | |
Move lldb/test to lldb/packages/Python/lldbsuite/test.
This is the conclusion of an effort to get LLDB's Python code
structured into a bona-fide Python package. This has a number
of benefits, but most notably the ability to more easily share
Python code between different but related pieces of LLDB's Python
infrastructure (for example, `scripts` can now share code with
`test`).
llvm-svn: 251532
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/driver/batch_mode')
3 files changed, 108 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/driver/batch_mode/Makefile b/lldb/packages/Python/lldbsuite/test/driver/batch_mode/Makefile new file mode 100644 index 00000000000..0d70f259501 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/driver/batch_mode/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/driver/batch_mode/TestBatchMode.py b/lldb/packages/Python/lldbsuite/test/driver/batch_mode/TestBatchMode.py new file mode 100644 index 00000000000..640f6120b26 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/driver/batch_mode/TestBatchMode.py @@ -0,0 +1,88 @@ +""" +Test that the lldb driver's batch mode works correctly. +""" + +from __future__ import print_function + +import use_lldb_suite + +import os, time +import lldb +from lldbtest import * + +class DriverBatchModeTest (TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfRemote # test not remote-ready llvm.org/pr24813 + @expectedFlakeyLinux("llvm.org/pr25172") + @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") + def test_driver_batch_mode(self): + """Test that the lldb driver's batch mode works correctly.""" + self.build() + self.setTearDownCleanup() + self.batch_mode() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.c' + + def expect_string (self, string): + import pexpect + """This expects for "string", with timeout & EOF being test fails.""" + try: + self.child.expect_exact(string) + except pexpect.EOF: + self.fail ("Got EOF waiting for '%s'"%(string)) + except pexpect.TIMEOUT: + self.fail ("Timed out waiting for '%s'"%(string)) + + def batch_mode (self): + import pexpect + exe = os.path.join(os.getcwd(), "a.out") + prompt = "(lldb) " + + # First time through, pass CRASH so the process will crash and stop in batch mode. + run_commands = ' -b -o "break set -n main" -o "run" -o "continue" -k "frame var touch_me_not"' + self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe)) + child = self.child + # Turn on logging for what the child sends back. + if self.TraceOn(): + child.logfile_read = sys.stdout + + # We should see the "run": + self.expect_string ("run") + # We should have hit the breakpoint & continued: + self.expect_string ("continue") + # The App should have crashed: + self.expect_string("About to crash") + # The -k option should have printed the frame variable once: + self.expect_string ('(char *) touch_me_not') + # Then we should have a live prompt: + self.expect_string (prompt) + self.child.sendline("frame variable touch_me_not") + self.expect_string ('(char *) touch_me_not') + + self.deletePexpectChild() + + # Now do it again, and see make sure if we don't crash, we quit: + run_commands = ' -b -o "break set -n main" -o "run" -o "continue" ' + self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (lldbtest_config.lldbExec, self.lldbOption, run_commands, exe)) + child = self.child + # Turn on logging for what the child sends back. + if self.TraceOn(): + child.logfile_read = sys.stdout + + # We should see the "run": + self.expect_string ("run") + # We should have hit the breakpoint & continued: + self.expect_string ("continue") + # The App should have not have crashed: + self.expect_string("Got there on time and it did not crash.") + # Then we should have a live prompt: + self.expect_string ("exited") + index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT]) + self.assertTrue(index == 0, "lldb didn't close on successful batch completion.") + diff --git a/lldb/packages/Python/lldbsuite/test/driver/batch_mode/main.c b/lldb/packages/Python/lldbsuite/test/driver/batch_mode/main.c new file mode 100644 index 00000000000..418160eaa36 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/driver/batch_mode/main.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <string.h> + +int +main (int argc, char **argv) +{ + if (argc >= 2 && strcmp (argv[1], "CRASH") == 0) + { + char *touch_me_not = (char *) 0; + printf ("About to crash.\n"); + touch_me_not[0] = 'a'; + } + printf ("Got there on time and it did not crash.\n"); + return 0; +} |

