diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 15:52:04 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 15:52:04 +0000 |
commit | 05a212146e5e34fc7f1b0181baa4c66b803f8b18 (patch) | |
tree | bc92e6d4eec2d28faf76d7a39007324399996c53 /tools/isolate/trace_inputs_test.py | |
parent | a5bd18f20584d35600d929e12ba728be6b7613e6 (diff) | |
download | chromium_src-05a212146e5e34fc7f1b0181baa4c66b803f8b18.zip chromium_src-05a212146e5e34fc7f1b0181baa4c66b803f8b18.tar.gz chromium_src-05a212146e5e34fc7f1b0181baa4c66b803f8b18.tar.bz2 |
Improve strace tracing and add unit tests.
Rename _Context to Context so it can be unit tested without warnings. The
classes are self-contained anyway.
Add more informative assertion print out.
R=rogerta@chromium.org
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10386094
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/isolate/trace_inputs_test.py')
-rwxr-xr-x | tools/isolate/trace_inputs_test.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tools/isolate/trace_inputs_test.py b/tools/isolate/trace_inputs_test.py index 322ef8c..d95518c 100755 --- a/tools/isolate/trace_inputs_test.py +++ b/tools/isolate/trace_inputs_test.py @@ -4,7 +4,13 @@ # found in the LICENSE file. import cStringIO +import logging +import os import unittest +import sys + +FILE_NAME = os.path.abspath(__file__) +ROOT_DIR = os.path.dirname(FILE_NAME) import trace_inputs @@ -89,5 +95,79 @@ class TraceInputs(unittest.TestCase): self._test(value, expected) +class StraceInputs(unittest.TestCase): + def _test_lines(self, lines, files, non_existent): + context = trace_inputs.Strace.Context(lambda _: False) + for line in lines: + context.on_line(line) + self.assertEquals(sorted(files), sorted(context.files)) + self.assertEquals(sorted(non_existent), sorted(context.non_existent)) + + def test_empty(self): + self._test_lines([], [], []) + + def test_close(self): + lines = [ + '31426 close(7) = 0', + ] + self._test_lines(lines, [], []) + + def test_clone(self): + # Grand-child with relative directory. + lines = [ + '86 chdir("%s") = 0' % ROOT_DIR, + '86 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID' + '|SIGCHLD, child_tidptr=0x7f5350f829d0) = 14', + ') = ? <unavailable>', + '14 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID' + '|SIGCHLD, child_tidptr=0x7f5350f829d0) = 70', + '14 close(75) = 0', + '70 open("%s", O_RDONLY) = 76' % os.path.basename(FILE_NAME), + ] + files = [ + FILE_NAME, + ] + self._test_lines(lines, files, []) + + def test_open(self): + lines = [ + '42 chdir("/home/foo_bar_user/src") = 0', + '42 execve("../out/unittests", ' + '["../out/unittests"...], [/* 44 vars */]) = 0', + '42 open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 8', + ] + files = [ + '/home/foo_bar_user/src/../out/unittests', + '/home/foo_bar_user/src/out/unittests.log', + ] + self._test_lines(lines, [], files) + + def test_open_resumed(self): + lines = [ + '42 chdir("/home/foo_bar_user/src") = 0', + '42 execve("../out/unittests", ' + '["../out/unittests"...], [/* 44 vars */]) = 0', + '42 open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND <unfinished ...>', + '42 <... open resumed> ) = 3', + ] + files = [ + '/home/foo_bar_user/src/../out/unittests', + '/home/foo_bar_user/src/out/unittests.log', + ] + self._test_lines(lines, [], files) + + def test_sig_unexpected(self): + lines = [ + '27 exit_group(0) = ?', + ] + try: + self._test_lines(lines, [], []) + self.fail() + except KeyError, e: + self.assertEqual(27, e.args[0]) + + if __name__ == '__main__': + VERBOSE = '-v' in sys.argv + logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) unittest.main() |