| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import cStringIO | 6 import cStringIO |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import unittest | 9 import unittest |
| 10 import sys | 10 import sys |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 " },\n" | 88 " },\n" |
| 89 " }, {\n" | 89 " }, {\n" |
| 90 " 'variables': {\n" | 90 " 'variables': {\n" |
| 91 " },\n" | 91 " },\n" |
| 92 " }],\n" | 92 " }],\n" |
| 93 " ],\n" | 93 " ],\n" |
| 94 "}\n") | 94 "}\n") |
| 95 self._test(value, expected) | 95 self._test(value, expected) |
| 96 | 96 |
| 97 | 97 |
| 98 class StraceInputs(unittest.TestCase): | 98 if trace_inputs.get_flavor() == 'linux': |
| 99 def _test_lines(self, lines, files, non_existent): | 99 class StraceInputs(unittest.TestCase): |
| 100 context = trace_inputs.Strace.Context(lambda _: False) | 100 def _test_lines(self, lines, files, non_existent): |
| 101 for line in lines: | 101 context = trace_inputs.Strace.Context(lambda _: False) |
| 102 context.on_line(line) | 102 for line in lines: |
| 103 self.assertEquals(sorted(files), sorted(context.files)) | 103 context.on_line(line) |
| 104 self.assertEquals(sorted(non_existent), sorted(context.non_existent)) | 104 self.assertEquals(sorted(files), sorted(context.files)) |
| 105 self.assertEquals(sorted(non_existent), sorted(context.non_existent)) |
| 105 | 106 |
| 106 def test_empty(self): | 107 def test_empty(self): |
| 107 self._test_lines([], [], []) | 108 self._test_lines([], [], []) |
| 108 | 109 |
| 109 def test_close(self): | 110 def test_close(self): |
| 110 lines = [ | 111 lines = [ |
| 111 '31426 close(7) = 0', | 112 '31426 close(7) = 0', |
| 112 ] | 113 ] |
| 113 self._test_lines(lines, [], []) | 114 self._test_lines(lines, [], []) |
| 114 | 115 |
| 115 def test_clone(self): | 116 def test_clone(self): |
| 116 # Grand-child with relative directory. | 117 # Grand-child with relative directory. |
| 117 lines = [ | 118 lines = [ |
| 118 '86 chdir("%s") = 0' % ROOT_DIR, | 119 '86 chdir("%s") = 0' % ROOT_DIR, |
| 119 '86 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID' | 120 '86 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID' |
| 120 '|SIGCHLD, child_tidptr=0x7f5350f829d0) = 14', | 121 '|SIGCHLD, child_tidptr=0x7f5350f829d0) = 14', |
| 121 ') = ? <unavailable>', | 122 ') = ? <unavailable>', |
| 122 '14 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID' | 123 '14 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID' |
| 123 '|SIGCHLD, child_tidptr=0x7f5350f829d0) = 70', | 124 '|SIGCHLD, child_tidptr=0x7f5350f829d0) = 70', |
| 124 '14 close(75) = 0', | 125 '14 close(75) = 0', |
| 125 '70 open("%s", O_RDONLY) = 76' % os.path.basename(FILE_NAME), | 126 '70 open("%s", O_RDONLY) = 76' % os.path.basename(FILE_NAME), |
| 126 ] | 127 ] |
| 127 files = [ | 128 files = [ |
| 128 FILE_NAME, | 129 FILE_NAME, |
| 129 ] | 130 ] |
| 130 self._test_lines(lines, files, []) | 131 self._test_lines(lines, files, []) |
| 131 | 132 |
| 132 def test_open(self): | 133 def test_open(self): |
| 133 lines = [ | 134 lines = [ |
| 134 '42 chdir("/home/foo_bar_user/src") = 0', | 135 '42 chdir("/home/foo_bar_user/src") = 0', |
| 135 '42 execve("../out/unittests", ' | 136 '42 execve("../out/unittests", ' |
| 136 '["../out/unittests"...], [/* 44 vars */]) = 0', | 137 '["../out/unittests"...], [/* 44 vars */]) = 0', |
| 137 '42 open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 8', | 138 '42 open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 8', |
| 138 ] | 139 ] |
| 139 files = [ | 140 files = [ |
| 140 '/home/foo_bar_user/src/../out/unittests', | 141 '/home/foo_bar_user/src/../out/unittests', |
| 141 '/home/foo_bar_user/src/out/unittests.log', | 142 '/home/foo_bar_user/src/out/unittests.log', |
| 142 ] | 143 ] |
| 143 self._test_lines(lines, [], files) | 144 self._test_lines(lines, [], files) |
| 144 | 145 |
| 145 def test_open_resumed(self): | 146 def test_open_resumed(self): |
| 146 lines = [ | 147 lines = [ |
| 147 '42 chdir("/home/foo_bar_user/src") = 0', | 148 '42 chdir("/home/foo_bar_user/src") = 0', |
| 148 '42 execve("../out/unittests", ' | 149 '42 execve("../out/unittests", ' |
| 149 '["../out/unittests"...], [/* 44 vars */]) = 0', | 150 '["../out/unittests"...], [/* 44 vars */]) = 0', |
| 150 '42 open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND <unfinished ...>', | 151 '42 open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND ' |
| 151 '42 <... open resumed> ) = 3', | 152 '<unfinished ...>', |
| 152 ] | 153 '42 <... open resumed> ) = 3', |
| 153 files = [ | 154 ] |
| 154 '/home/foo_bar_user/src/../out/unittests', | 155 files = [ |
| 155 '/home/foo_bar_user/src/out/unittests.log', | 156 '/home/foo_bar_user/src/../out/unittests', |
| 156 ] | 157 '/home/foo_bar_user/src/out/unittests.log', |
| 157 self._test_lines(lines, [], files) | 158 ] |
| 159 self._test_lines(lines, [], files) |
| 158 | 160 |
| 159 def test_sig_unexpected(self): | 161 def test_sig_unexpected(self): |
| 160 lines = [ | 162 lines = [ |
| 161 '27 exit_group(0) = ?', | 163 '27 exit_group(0) = ?', |
| 162 ] | 164 ] |
| 163 try: | 165 try: |
| 164 self._test_lines(lines, [], []) | 166 self._test_lines(lines, [], []) |
| 165 self.fail() | 167 self.fail() |
| 166 except KeyError, e: | 168 except KeyError, e: |
| 167 self.assertEqual(27, e.args[0]) | 169 self.assertEqual(27, e.args[0]) |
| 168 | 170 |
| 169 | 171 |
| 170 if __name__ == '__main__': | 172 if __name__ == '__main__': |
| 171 VERBOSE = '-v' in sys.argv | 173 VERBOSE = '-v' in sys.argv |
| 172 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 174 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 173 unittest.main() | 175 unittest.main() |
| OLD | NEW |