Chromium Code Reviews| Index: tests/untrusted_crash_dump/untrusted_crash_dump_test.py |
| diff --git a/tests/untrusted_crash_dump/untrusted_crash_dump_test.py b/tests/untrusted_crash_dump/untrusted_crash_dump_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..ec29b469e137f224dec76d7e4d629d56dbeb79bb |
| --- /dev/null |
| +++ b/tests/untrusted_crash_dump/untrusted_crash_dump_test.py |
| @@ -0,0 +1,67 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import linecache |
| +import os |
| +import sys |
| + |
| + |
| +# Import decode_dump for small testing. |
| +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| +TESTS_DIR = os.path.dirname(SCRIPT_DIR) |
| +NACL_DIR = os.path.dirname(TESTS_DIR) |
| +CRASH_DUMP_DIR = os.path.join(NACL_DIR, 'src', 'untrusted', 'crash_dump') |
| +sys.path.insert(0, CRASH_DUMP_DIR) |
| +import decode_dump |
| + |
| + |
| +def CheckStackTrace(core, main_nexe, nmf, addr2line, nacl_sdk_lib): |
| + """Check that a core dump yields an expected stack trace. |
| + |
| + Args: |
| + core: the core.json file emitted on crash. |
| + main_nexe: the main nexe in question. |
| + nmf: the manifest for main_nexe. |
| + addr2line: location of addr2line for the relevant toolchain. |
| + nacl_sdk_lib: location of the system dylibs for this nexe. |
| + """ |
| + class Options: |
|
Mark Seaborn
2012/02/16 18:42:50
If you change decode_dump to split the the parser
bradn
2012/02/16 20:13:10
Done.
|
| + pass |
| + options = Options() |
| + options.addr2line = addr2line |
| + options.toolchain_libs = nacl_sdk_lib |
| + options.main_nexe = main_nexe |
| + if nmf == '-': |
| + options.nmf = None |
| + else: |
| + options.nmf = nmf |
| + info = decode_dump.LoadAndDecode(options, core) |
| + trace = decode_dump.StackTrace(info) |
| + expected = [ |
| + ('layer5', '*(volatile int *) x = y;'), |
| + ('layer4', 'layer5(x, 1);'), |
| + ('CallMe', 'func(arg);'), |
| + ('layer3', 'CallMe(layer4, a + b + c);'), |
| + ('layer2', 'layer3(i, j, 7);'), |
| + ('layer1', 'layer2(junk[0], t + 1);'), |
| + ] |
| + for i in range(len(expected)): |
| + scope = trace[i] |
| + lineno = int(scope['lineno']) |
| + # Line prior to return is more interested in all but the innermost scope. |
| + if i != 0: |
| + lineno -= 1 |
|
Mark Seaborn
2012/02/16 18:42:50
The line textually before isn't necessarily where
bradn
2012/02/16 20:13:10
Done.
|
| + line = linecache.getline(scope['filename'], lineno).strip() |
| + actual = (scope['function'], line) |
| + assert expected[i] == actual |
| + |
| + |
| +if __name__ == '__main__': |
| + if len(sys.argv) != 6: |
| + print >>sys.stderr, ( |
|
Mark Seaborn
2012/02/16 18:42:50
Prefer sys.stderr.write() over print>>
bradn
2012/02/16 20:13:10
Done.
|
| + 'USAGE: %s <core.json> <nexe> <nmf> <addr2line> <nacl_sdk_lib>' % |
| + sys.argv[0]) |
| + sys.exit(1) |
| + CheckStackTrace(*sys.argv[1:]) |