OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 os | 6 import os |
7 import sys | 7 import sys |
8 import unittest | 8 import unittest |
9 | 9 |
10 from pylib import cmd_helper | 10 from pylib import cmd_helper |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 def testCalculateDeviceMd5Sums_singlePath(self): | 86 def testCalculateDeviceMd5Sums_singlePath(self): |
87 test_path = '/storage/emulated/legacy/test/file.dat' | 87 test_path = '/storage/emulated/legacy/test/file.dat' |
88 | 88 |
89 device = mock.NonCallableMock() | 89 device = mock.NonCallableMock() |
90 device_md5sum_output = [ | 90 device_md5sum_output = [ |
91 '0123456789abcdeffedcba9876543210 ' | 91 '0123456789abcdeffedcba9876543210 ' |
92 '/storage/emulated/legacy/test/file.dat', | 92 '/storage/emulated/legacy/test/file.dat', |
93 ] | 93 ] |
94 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) | 94 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
95 | 95 |
96 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 96 with mock.patch('os.path.getsize', return_value=1337): |
97 self.assertEquals(1, len(out)) | 97 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
98 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) | 98 self.assertEquals(1, len(out)) |
99 self.assertEquals('0123456789abcdeffedcba9876543210', | 99 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) |
100 out['/storage/emulated/legacy/test/file.dat']) | 100 self.assertEquals('0123456789abcdeffedcba9876543210', |
101 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) | 101 out['/storage/emulated/legacy/test/file.dat']) |
| 102 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) |
102 | 103 |
103 def testCalculateDeviceMd5Sums_list(self): | 104 def testCalculateDeviceMd5Sums_list(self): |
104 test_path = ['/storage/emulated/legacy/test/file0.dat', | 105 test_path = ['/storage/emulated/legacy/test/file0.dat', |
105 '/storage/emulated/legacy/test/file1.dat'] | 106 '/storage/emulated/legacy/test/file1.dat'] |
106 device = mock.NonCallableMock() | 107 device = mock.NonCallableMock() |
107 device_md5sum_output = [ | 108 device_md5sum_output = [ |
108 '0123456789abcdeffedcba9876543210 ' | 109 '0123456789abcdeffedcba9876543210 ' |
109 '/storage/emulated/legacy/test/file0.dat', | 110 '/storage/emulated/legacy/test/file0.dat', |
110 '123456789abcdef00fedcba987654321 ' | 111 '123456789abcdef00fedcba987654321 ' |
111 '/storage/emulated/legacy/test/file1.dat', | 112 '/storage/emulated/legacy/test/file1.dat', |
112 ] | 113 ] |
113 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) | 114 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
114 | 115 |
115 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 116 with mock.patch('os.path.getsize', return_value=1337): |
116 self.assertEquals(2, len(out)) | 117 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
117 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) | 118 self.assertEquals(2, len(out)) |
118 self.assertEquals('0123456789abcdeffedcba9876543210', | 119 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) |
119 out['/storage/emulated/legacy/test/file0.dat']) | 120 self.assertEquals('0123456789abcdeffedcba9876543210', |
120 self.assertTrue('/storage/emulated/legacy/test/file1.dat' in out) | 121 out['/storage/emulated/legacy/test/file0.dat']) |
121 self.assertEquals('123456789abcdef00fedcba987654321', | 122 self.assertTrue('/storage/emulated/legacy/test/file1.dat' in out) |
122 out['/storage/emulated/legacy/test/file1.dat']) | 123 self.assertEquals('123456789abcdef00fedcba987654321', |
123 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) | 124 out['/storage/emulated/legacy/test/file1.dat']) |
| 125 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) |
124 | 126 |
125 def testCalculateDeviceMd5Sums_generator(self): | 127 def testCalculateDeviceMd5Sums_generator(self): |
126 test_path = ('/storage/emulated/legacy/test/file%d.dat' % n | 128 test_path = ('/storage/emulated/legacy/test/file%d.dat' % n |
127 for n in xrange(0, 2)) | 129 for n in xrange(0, 2)) |
128 | 130 |
129 device = mock.NonCallableMock() | 131 device = mock.NonCallableMock() |
130 device_md5sum_output = [ | 132 device_md5sum_output = [ |
131 '0123456789abcdeffedcba9876543210 ' | 133 '0123456789abcdeffedcba9876543210 ' |
132 '/storage/emulated/legacy/test/file0.dat', | 134 '/storage/emulated/legacy/test/file0.dat', |
133 '123456789abcdef00fedcba987654321 ' | 135 '123456789abcdef00fedcba987654321 ' |
134 '/storage/emulated/legacy/test/file1.dat', | 136 '/storage/emulated/legacy/test/file1.dat', |
135 ] | 137 ] |
136 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) | 138 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
137 | 139 |
138 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 140 with mock.patch('os.path.getsize', return_value=1337): |
139 self.assertEquals(2, len(out)) | 141 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
140 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) | 142 self.assertEquals(2, len(out)) |
141 self.assertEquals('0123456789abcdeffedcba9876543210', | 143 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) |
142 out['/storage/emulated/legacy/test/file0.dat']) | 144 self.assertEquals('0123456789abcdeffedcba9876543210', |
143 self.assertTrue('/storage/emulated/legacy/test/file1.dat' in out) | 145 out['/storage/emulated/legacy/test/file0.dat']) |
144 self.assertEquals('123456789abcdef00fedcba987654321', | 146 self.assertTrue('/storage/emulated/legacy/test/file1.dat' in out) |
145 out['/storage/emulated/legacy/test/file1.dat']) | 147 self.assertEquals('123456789abcdef00fedcba987654321', |
146 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) | 148 out['/storage/emulated/legacy/test/file1.dat']) |
| 149 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) |
147 | 150 |
148 def testCalculateDeviceMd5Sums_singlePath_linkerWarning(self): | 151 def testCalculateDeviceMd5Sums_singlePath_linkerWarning(self): |
149 # See crbug/479966 | 152 # See crbug/479966 |
150 test_path = '/storage/emulated/legacy/test/file.dat' | 153 test_path = '/storage/emulated/legacy/test/file.dat' |
151 | 154 |
152 device = mock.NonCallableMock() | 155 device = mock.NonCallableMock() |
153 device_md5sum_output = [ | 156 device_md5sum_output = [ |
154 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' | 157 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' |
155 'unused DT entry: type 0x1d arg 0x15db', | 158 'unused DT entry: type 0x1d arg 0x15db', |
156 'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text', | 159 'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text', |
157 '0123456789abcdeffedcba9876543210 ' | 160 '0123456789abcdeffedcba9876543210 ' |
158 '/storage/emulated/legacy/test/file.dat', | 161 '/storage/emulated/legacy/test/file.dat', |
159 ] | 162 ] |
160 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) | 163 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
161 | 164 |
162 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 165 with mock.patch('os.path.getsize', return_value=1337): |
163 self.assertEquals(1, len(out)) | 166 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
164 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) | 167 self.assertEquals(1, len(out)) |
165 self.assertEquals('0123456789abcdeffedcba9876543210', | 168 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) |
166 out['/storage/emulated/legacy/test/file.dat']) | 169 self.assertEquals('0123456789abcdeffedcba9876543210', |
167 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) | 170 out['/storage/emulated/legacy/test/file.dat']) |
| 171 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) |
168 | 172 |
169 def testCalculateDeviceMd5Sums_list_fileMissing(self): | 173 def testCalculateDeviceMd5Sums_list_fileMissing(self): |
170 test_path = ['/storage/emulated/legacy/test/file0.dat', | 174 test_path = ['/storage/emulated/legacy/test/file0.dat', |
171 '/storage/emulated/legacy/test/file1.dat'] | 175 '/storage/emulated/legacy/test/file1.dat'] |
172 device = mock.NonCallableMock() | 176 device = mock.NonCallableMock() |
173 device_md5sum_output = [ | 177 device_md5sum_output = [ |
174 '0123456789abcdeffedcba9876543210 ' | 178 '0123456789abcdeffedcba9876543210 ' |
175 '/storage/emulated/legacy/test/file0.dat', | 179 '/storage/emulated/legacy/test/file0.dat', |
176 '[0819/203513:ERROR:md5sum.cc(25)] Could not open file asdf', | 180 '[0819/203513:ERROR:md5sum.cc(25)] Could not open file asdf', |
177 '', | 181 '', |
178 ] | 182 ] |
179 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) | 183 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
180 | 184 |
181 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 185 with mock.patch('os.path.getsize', return_value=1337): |
182 self.assertEquals(1, len(out)) | 186 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
183 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) | 187 self.assertEquals(1, len(out)) |
184 self.assertEquals('0123456789abcdeffedcba9876543210', | 188 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) |
185 out['/storage/emulated/legacy/test/file0.dat']) | 189 self.assertEquals('0123456789abcdeffedcba9876543210', |
186 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) | 190 out['/storage/emulated/legacy/test/file0.dat']) |
| 191 self.assertEquals(1, len(device.RunShellCommand.call_args_list)) |
187 | 192 |
188 | 193 |
189 def testCalculateDeviceMd5Sums_requiresBinary(self): | 194 def testCalculateDeviceMd5Sums_requiresBinary(self): |
190 test_path = '/storage/emulated/legacy/test/file.dat' | 195 test_path = '/storage/emulated/legacy/test/file.dat' |
191 | 196 |
192 device = mock.NonCallableMock() | 197 device = mock.NonCallableMock() |
193 device.adb = mock.NonCallableMock() | 198 device.adb = mock.NonCallableMock() |
194 device.adb.Push = mock.Mock() | 199 device.adb.Push = mock.Mock() |
195 device_md5sum_output = [ | 200 device_md5sum_output = [ |
196 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' | 201 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' |
197 'unused DT entry: type 0x1d arg 0x15db', | 202 'unused DT entry: type 0x1d arg 0x15db', |
198 'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text', | 203 'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text', |
199 '0123456789abcdeffedcba9876543210 ' | 204 '0123456789abcdeffedcba9876543210 ' |
200 '/storage/emulated/legacy/test/file.dat', | 205 '/storage/emulated/legacy/test/file.dat', |
201 ] | 206 ] |
202 error = device_errors.AdbShellCommandFailedError('cmd', 'out', 2) | 207 error = device_errors.AdbShellCommandFailedError('cmd', 'out', 2) |
203 device.RunShellCommand = mock.Mock( | 208 device.RunShellCommand = mock.Mock( |
204 side_effect=(error, device_md5sum_output)) | 209 side_effect=(error, device_md5sum_output)) |
205 | 210 |
206 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 211 with mock.patch('os.path.getsize', return_value=1337): |
207 self.assertEquals(1, len(out)) | 212 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
208 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) | 213 self.assertEquals(1, len(out)) |
209 self.assertEquals('0123456789abcdeffedcba9876543210', | 214 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) |
210 out['/storage/emulated/legacy/test/file.dat']) | 215 self.assertEquals('0123456789abcdeffedcba9876543210', |
211 self.assertEquals(2, len(device.RunShellCommand.call_args_list)) | 216 out['/storage/emulated/legacy/test/file.dat']) |
212 device.adb.Push.assert_called_once_with( | 217 self.assertEquals(2, len(device.RunShellCommand.call_args_list)) |
213 'test/out/directory/md5sum_dist', '/data/local/tmp/md5sum/') | 218 device.adb.Push.assert_called_once_with( |
| 219 'test/out/directory/md5sum_dist', '/data/local/tmp/md5sum/') |
214 | 220 |
215 | 221 |
216 if __name__ == '__main__': | 222 if __name__ == '__main__': |
217 unittest.main(verbosity=2) | 223 unittest.main(verbosity=2) |
218 | 224 |
OLD | NEW |