diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/gdb/lib-for-tests | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/gdb/lib-for-tests')
-rw-r--r-- | js/src/gdb/lib-for-tests/catcher.py | 22 | ||||
-rw-r--r-- | js/src/gdb/lib-for-tests/prologue.py | 90 |
2 files changed, 112 insertions, 0 deletions
diff --git a/js/src/gdb/lib-for-tests/catcher.py b/js/src/gdb/lib-for-tests/catcher.py new file mode 100644 index 000000000..4bac2a025 --- /dev/null +++ b/js/src/gdb/lib-for-tests/catcher.py @@ -0,0 +1,22 @@ +# Apparently, there's simply no way to ask GDB to exit with a non-zero +# status when the script run with the --eval-command option fails. Thus, if +# we have --eval-command run prologue.py directly, syntax errors there will +# lead GDB to exit with no indication anything went wrong. +# +# To avert that, we use this very small launcher script to run prologue.py +# and catch errors. +# +# Remember, errors in this file will cause spurious passes, so keep this as +# simple as possible! + +import os +import sys +import traceback +try: + # testlibdir is set on the GDB command line, via: + # --eval-command python testlibdir=... + exec(open(os.path.join(testlibdir, 'prologue.py')).read()) +except Exception as err: + sys.stderr.write('Error running GDB prologue:\n') + traceback.print_exc() + sys.exit(1) diff --git a/js/src/gdb/lib-for-tests/prologue.py b/js/src/gdb/lib-for-tests/prologue.py new file mode 100644 index 000000000..c54d2a674 --- /dev/null +++ b/js/src/gdb/lib-for-tests/prologue.py @@ -0,0 +1,90 @@ +import gdb +import os +import re +import sys +import traceback + +# testlibdir is set on the GDB command line, via --eval-command python testlibdir=... +sys.path[0:0] = [testlibdir] + +# Run the C++ fragment named |fragment|, stopping on entry to |function| +# ('breakpoint', by default) and then select the calling frame. +def run_fragment(fragment, function='breakpoint'): + # Arrange to stop at a reasonable place in the test program. + bp = gdb.Breakpoint(function); + try: + gdb.execute("run %s" % (fragment,)) + # Check that we did indeed stop by hitting the breakpoint we set. + assert bp.hit_count == 1 + finally: + bp.delete() + gdb.execute('frame 1') + +# Assert that |actual| is equal to |expected|; if not, complain in a helpful way. +def assert_eq(actual, expected): + if actual != expected: + raise AssertionError("""Unexpected result: +expected: %r +actual: %r""" % (expected, actual)) + +# Assert that |expected| regex matches |actual| result; if not, complain in a helpful way. +def assert_match(actual, expected): + if re.match(expected, actual, re.MULTILINE) == None: + raise AssertionError("""Unexpected result: +expected pattern: %r +actual: %r""" % (expected, actual)) + +# Assert that |value|'s pretty-printed form is |form|. If |value| is a +# string, then evaluate it with gdb.parse_and_eval to produce a value. +def assert_pretty(value, form): + if isinstance(value, str): + value = gdb.parse_and_eval(value) + assert_eq(str(value), form) + +# Assert that |value|'s pretty-printed form match the pattern |pattern|. If +# |value| is a string, then evaluate it with gdb.parse_and_eval to produce a +# value. +def assert_regexp_pretty(value, form): + if isinstance(value, str): + value = gdb.parse_and_eval(value) + assert_match(str(value), form) + +# Check that the list of registered pretty-printers includes one named +# |printer|, with a subprinter named |subprinter|. +def assert_subprinter_registered(printer, subprinter): + # Match a line containing |printer| followed by a colon, and then a + # series of more-indented lines containing |subprinter|. + + names = { 'printer': re.escape(printer), 'subprinter': re.escape(subprinter) } + pat = r'^( +)%(printer)s *\n(\1 +.*\n)*\1 +%(subprinter)s *\n' % names + output = gdb.execute('info pretty-printer', to_string=True) + if not re.search(pat, output, re.MULTILINE): + raise AssertionError("assert_subprinter_registered failed to find pretty-printer:\n" + " %s:%s\n" + "'info pretty-printer' says:\n" + "%s" % (printer, subprinter, output)) + +# Request full stack traces for Python errors. +gdb.execute('set python print-stack full') + +# Tell GDB not to ask the user about the things we tell it to do. +gdb.execute('set confirm off', False) + +# Some print settings that make testing easier. +gdb.execute('set print static-members off') +gdb.execute('set print address off') +gdb.execute('set print pretty off') +gdb.execute('set width 0') + +try: + # testscript is set on the GDB command line, via: + # --eval-command python testscript=... + exec(open(testscript).read()) +except AssertionError as err: + sys.stderr.write('\nAssertion traceback:\n') + (t, v, tb) = sys.exc_info() + traceback.print_tb(tb) + sys.stderr.write('\nTest assertion failed:\n') + sys.stderr.write(str(err)) + sys.exit(1) + |