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 21 matching lines...) Expand all Loading... |
32 for p in self._patchers: | 32 for p in self._patchers: |
33 p.stop() | 33 p.stop() |
34 | 34 |
35 def testCalculateHostMd5Sums_singlePath(self): | 35 def testCalculateHostMd5Sums_singlePath(self): |
36 test_path = '/test/host/file.dat' | 36 test_path = '/test/host/file.dat' |
37 mock_get_cmd_output = mock.Mock( | 37 mock_get_cmd_output = mock.Mock( |
38 return_value='0123456789abcdeffedcba9876543210 /test/host/file.dat') | 38 return_value='0123456789abcdeffedcba9876543210 /test/host/file.dat') |
39 with mock.patch('pylib.cmd_helper.GetCmdOutput', new=mock_get_cmd_output): | 39 with mock.patch('pylib.cmd_helper.GetCmdOutput', new=mock_get_cmd_output): |
40 out = md5sum.CalculateHostMd5Sums(test_path) | 40 out = md5sum.CalculateHostMd5Sums(test_path) |
41 self.assertEquals(1, len(out)) | 41 self.assertEquals(1, len(out)) |
42 self.assertEquals('0123456789abcdeffedcba9876543210', out[0].hash) | 42 self.assertTrue('/test/host/file.dat' in out) |
43 self.assertEquals('/test/host/file.dat', out[0].path) | 43 self.assertEquals('0123456789abcdeffedcba9876543210', |
| 44 out['/test/host/file.dat']) |
44 mock_get_cmd_output.assert_called_once_with( | 45 mock_get_cmd_output.assert_called_once_with( |
45 [HOST_MD5_EXECUTABLE, '/test/host/file.dat']) | 46 [HOST_MD5_EXECUTABLE, '/test/host/file.dat']) |
46 | 47 |
47 def testCalculateHostMd5Sums_list(self): | 48 def testCalculateHostMd5Sums_list(self): |
48 test_paths = ['/test/host/file0.dat', '/test/host/file1.dat'] | 49 test_paths = ['/test/host/file0.dat', '/test/host/file1.dat'] |
49 mock_get_cmd_output = mock.Mock( | 50 mock_get_cmd_output = mock.Mock( |
50 return_value='0123456789abcdeffedcba9876543210 /test/host/file0.dat\n' | 51 return_value='0123456789abcdeffedcba9876543210 /test/host/file0.dat\n' |
51 '123456789abcdef00fedcba987654321 /test/host/file1.dat\n') | 52 '123456789abcdef00fedcba987654321 /test/host/file1.dat\n') |
52 with mock.patch('pylib.cmd_helper.GetCmdOutput', new=mock_get_cmd_output): | 53 with mock.patch('pylib.cmd_helper.GetCmdOutput', new=mock_get_cmd_output): |
53 out = md5sum.CalculateHostMd5Sums(test_paths) | 54 out = md5sum.CalculateHostMd5Sums(test_paths) |
54 self.assertEquals(2, len(out)) | 55 self.assertEquals(2, len(out)) |
55 self.assertEquals('0123456789abcdeffedcba9876543210', out[0].hash) | 56 self.assertTrue('/test/host/file0.dat' in out) |
56 self.assertEquals('/test/host/file0.dat', out[0].path) | 57 self.assertEquals('0123456789abcdeffedcba9876543210', |
57 self.assertEquals('123456789abcdef00fedcba987654321', out[1].hash) | 58 out['/test/host/file0.dat']) |
58 self.assertEquals('/test/host/file1.dat', out[1].path) | 59 self.assertTrue('/test/host/file1.dat' in out) |
| 60 self.assertEquals('123456789abcdef00fedcba987654321', |
| 61 out['/test/host/file1.dat']) |
59 mock_get_cmd_output.assert_called_once_with( | 62 mock_get_cmd_output.assert_called_once_with( |
60 [HOST_MD5_EXECUTABLE, '/test/host/file0.dat', | 63 [HOST_MD5_EXECUTABLE, '/test/host/file0.dat', |
61 '/test/host/file1.dat']) | 64 '/test/host/file1.dat']) |
62 | 65 |
63 def testCalculateHostMd5Sums_generator(self): | 66 def testCalculateHostMd5Sums_generator(self): |
64 test_paths = ('/test/host/' + p for p in ['file0.dat', 'file1.dat']) | 67 test_paths = ('/test/host/' + p for p in ['file0.dat', 'file1.dat']) |
65 mock_get_cmd_output = mock.Mock( | 68 mock_get_cmd_output = mock.Mock( |
66 return_value='0123456789abcdeffedcba9876543210 /test/host/file0.dat\n' | 69 return_value='0123456789abcdeffedcba9876543210 /test/host/file0.dat\n' |
67 '123456789abcdef00fedcba987654321 /test/host/file1.dat\n') | 70 '123456789abcdef00fedcba987654321 /test/host/file1.dat\n') |
68 with mock.patch('pylib.cmd_helper.GetCmdOutput', new=mock_get_cmd_output): | 71 with mock.patch('pylib.cmd_helper.GetCmdOutput', new=mock_get_cmd_output): |
69 out = md5sum.CalculateHostMd5Sums(test_paths) | 72 out = md5sum.CalculateHostMd5Sums(test_paths) |
70 self.assertEquals(2, len(out)) | 73 self.assertEquals(2, len(out)) |
71 self.assertEquals('0123456789abcdeffedcba9876543210', out[0].hash) | 74 self.assertTrue('/test/host/file0.dat' in out) |
72 self.assertEquals('/test/host/file0.dat', out[0].path) | 75 self.assertEquals('0123456789abcdeffedcba9876543210', |
73 self.assertEquals('123456789abcdef00fedcba987654321', out[1].hash) | 76 out['/test/host/file0.dat']) |
74 self.assertEquals('/test/host/file1.dat', out[1].path) | 77 self.assertTrue('/test/host/file1.dat' in out) |
| 78 self.assertEquals('123456789abcdef00fedcba987654321', |
| 79 out['/test/host/file1.dat']) |
75 mock_get_cmd_output.assert_called_once_with( | 80 mock_get_cmd_output.assert_called_once_with( |
76 [HOST_MD5_EXECUTABLE, '/test/host/file0.dat', '/test/host/file1.dat']) | 81 [HOST_MD5_EXECUTABLE, '/test/host/file0.dat', '/test/host/file1.dat']) |
77 | 82 |
78 def testCalculateDeviceMd5Sums_singlePath(self): | 83 def testCalculateDeviceMd5Sums_singlePath(self): |
79 test_path = '/storage/emulated/legacy/test/file.dat' | 84 test_path = '/storage/emulated/legacy/test/file.dat' |
80 | 85 |
81 device = mock.NonCallableMock() | 86 device = mock.NonCallableMock() |
82 device.adb = mock.NonCallableMock() | 87 device.adb = mock.NonCallableMock() |
83 device.adb.Push = mock.Mock() | 88 device.adb.Push = mock.Mock() |
84 device_md5sum_output = [ | 89 device_md5sum_output = [ |
85 '0123456789abcdeffedcba9876543210 ' | 90 '0123456789abcdeffedcba9876543210 ' |
86 '/storage/emulated/legacy/test/file.dat', | 91 '/storage/emulated/legacy/test/file.dat', |
87 ] | 92 ] |
88 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) | 93 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
89 | 94 |
90 mock_temp_file = mock.mock_open() | 95 mock_temp_file = mock.mock_open() |
91 mock_temp_file.return_value.name = '/tmp/test/script/file.sh' | 96 mock_temp_file.return_value.name = '/tmp/test/script/file.sh' |
92 | 97 |
93 mock_device_temp_file = mock.mock_open() | 98 mock_device_temp_file = mock.mock_open() |
94 mock_device_temp_file.return_value.name = ( | 99 mock_device_temp_file.return_value.name = ( |
95 '/data/local/tmp/test/script/file.sh') | 100 '/data/local/tmp/test/script/file.sh') |
96 | 101 |
97 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( | 102 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( |
98 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', | 103 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', |
99 new=mock_device_temp_file)): | 104 new=mock_device_temp_file)): |
100 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 105 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
101 self.assertEquals(1, len(out)) | 106 self.assertEquals(1, len(out)) |
102 self.assertEquals('0123456789abcdeffedcba9876543210', out[0].hash) | 107 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) |
103 self.assertEquals('/storage/emulated/legacy/test/file.dat', out[0].path) | 108 self.assertEquals('0123456789abcdeffedcba9876543210', |
| 109 out['/storage/emulated/legacy/test/file.dat']) |
104 device.adb.Push.assert_called_once_with( | 110 device.adb.Push.assert_called_once_with( |
105 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') | 111 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') |
106 device.RunShellCommand.assert_called_once_with( | 112 device.RunShellCommand.assert_called_once_with( |
107 ['sh', '/data/local/tmp/test/script/file.sh']) | 113 ['sh', '/data/local/tmp/test/script/file.sh']) |
108 | 114 |
109 def testCalculateDeviceMd5Sums_list(self): | 115 def testCalculateDeviceMd5Sums_list(self): |
110 test_path = ['/storage/emulated/legacy/test/file0.dat', | 116 test_path = ['/storage/emulated/legacy/test/file0.dat', |
111 '/storage/emulated/legacy/test/file1.dat'] | 117 '/storage/emulated/legacy/test/file1.dat'] |
112 device = mock.NonCallableMock() | 118 device = mock.NonCallableMock() |
113 device.adb = mock.NonCallableMock() | 119 device.adb = mock.NonCallableMock() |
(...skipping 11 matching lines...) Expand all Loading... |
125 | 131 |
126 mock_device_temp_file = mock.mock_open() | 132 mock_device_temp_file = mock.mock_open() |
127 mock_device_temp_file.return_value.name = ( | 133 mock_device_temp_file.return_value.name = ( |
128 '/data/local/tmp/test/script/file.sh') | 134 '/data/local/tmp/test/script/file.sh') |
129 | 135 |
130 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( | 136 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( |
131 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', | 137 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', |
132 new=mock_device_temp_file)): | 138 new=mock_device_temp_file)): |
133 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 139 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
134 self.assertEquals(2, len(out)) | 140 self.assertEquals(2, len(out)) |
135 self.assertEquals('0123456789abcdeffedcba9876543210', out[0].hash) | 141 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) |
136 self.assertEquals('/storage/emulated/legacy/test/file0.dat', out[0].path) | 142 self.assertEquals('0123456789abcdeffedcba9876543210', |
137 self.assertEquals('123456789abcdef00fedcba987654321', out[1].hash) | 143 out['/storage/emulated/legacy/test/file0.dat']) |
138 self.assertEquals('/storage/emulated/legacy/test/file1.dat', out[1].path) | 144 self.assertTrue('/storage/emulated/legacy/test/file1.dat' in out) |
| 145 self.assertEquals('123456789abcdef00fedcba987654321', |
| 146 out['/storage/emulated/legacy/test/file1.dat']) |
139 device.adb.Push.assert_called_once_with( | 147 device.adb.Push.assert_called_once_with( |
140 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') | 148 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') |
141 device.RunShellCommand.assert_called_once_with( | 149 device.RunShellCommand.assert_called_once_with( |
142 ['sh', '/data/local/tmp/test/script/file.sh']) | 150 ['sh', '/data/local/tmp/test/script/file.sh']) |
143 | 151 |
144 def testCalculateDeviceMd5Sums_generator(self): | 152 def testCalculateDeviceMd5Sums_generator(self): |
145 test_path = ('/storage/emulated/legacy/test/file%d.dat' % n | 153 test_path = ('/storage/emulated/legacy/test/file%d.dat' % n |
146 for n in xrange(0, 2)) | 154 for n in xrange(0, 2)) |
147 | 155 |
148 device = mock.NonCallableMock() | 156 device = mock.NonCallableMock() |
(...skipping 12 matching lines...) Expand all Loading... |
161 | 169 |
162 mock_device_temp_file = mock.mock_open() | 170 mock_device_temp_file = mock.mock_open() |
163 mock_device_temp_file.return_value.name = ( | 171 mock_device_temp_file.return_value.name = ( |
164 '/data/local/tmp/test/script/file.sh') | 172 '/data/local/tmp/test/script/file.sh') |
165 | 173 |
166 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( | 174 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( |
167 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', | 175 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', |
168 new=mock_device_temp_file)): | 176 new=mock_device_temp_file)): |
169 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 177 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
170 self.assertEquals(2, len(out)) | 178 self.assertEquals(2, len(out)) |
171 self.assertEquals('0123456789abcdeffedcba9876543210', out[0].hash) | 179 self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out) |
172 self.assertEquals('/storage/emulated/legacy/test/file0.dat', out[0].path) | 180 self.assertEquals('0123456789abcdeffedcba9876543210', |
173 self.assertEquals('123456789abcdef00fedcba987654321', out[1].hash) | 181 out['/storage/emulated/legacy/test/file0.dat']) |
174 self.assertEquals('/storage/emulated/legacy/test/file1.dat', out[1].path) | 182 self.assertTrue('/storage/emulated/legacy/test/file1.dat' in out) |
| 183 self.assertEquals('123456789abcdef00fedcba987654321', |
| 184 out['/storage/emulated/legacy/test/file1.dat']) |
175 device.adb.Push.assert_called_once_with( | 185 device.adb.Push.assert_called_once_with( |
176 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') | 186 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') |
177 device.RunShellCommand.assert_called_once_with( | 187 device.RunShellCommand.assert_called_once_with( |
| 188 ['sh', '/data/local/tmp/test/script/file.sh']) |
| 189 |
| 190 def testCalculateDeviceMd5Sums_singlePath_linkerWarning(self): |
| 191 # See crbug/479966 |
| 192 test_path = '/storage/emulated/legacy/test/file.dat' |
| 193 |
| 194 device = mock.NonCallableMock() |
| 195 device.adb = mock.NonCallableMock() |
| 196 device.adb.Push = mock.Mock() |
| 197 device_md5sum_output = [ |
| 198 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' |
| 199 'unused DT entry: type 0x1d arg 0x15db', |
| 200 '0123456789abcdeffedcba9876543210 ' |
| 201 '/storage/emulated/legacy/test/file.dat', |
| 202 ] |
| 203 device.RunShellCommand = mock.Mock(return_value=device_md5sum_output) |
| 204 |
| 205 mock_temp_file = mock.mock_open() |
| 206 mock_temp_file.return_value.name = '/tmp/test/script/file.sh' |
| 207 |
| 208 mock_device_temp_file = mock.mock_open() |
| 209 mock_device_temp_file.return_value.name = ( |
| 210 '/data/local/tmp/test/script/file.sh') |
| 211 |
| 212 with mock.patch('tempfile.NamedTemporaryFile', new=mock_temp_file), ( |
| 213 mock.patch('pylib.utils.device_temp_file.DeviceTempFile', |
| 214 new=mock_device_temp_file)): |
| 215 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
| 216 self.assertEquals(1, len(out)) |
| 217 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) |
| 218 self.assertEquals('0123456789abcdeffedcba9876543210', |
| 219 out['/storage/emulated/legacy/test/file.dat']) |
| 220 device.adb.Push.assert_called_once_with( |
| 221 '/tmp/test/script/file.sh', '/data/local/tmp/test/script/file.sh') |
| 222 device.RunShellCommand.assert_called_once_with( |
178 ['sh', '/data/local/tmp/test/script/file.sh']) | 223 ['sh', '/data/local/tmp/test/script/file.sh']) |
179 | 224 |
180 | 225 |
181 if __name__ == '__main__': | 226 if __name__ == '__main__': |
182 unittest.main(verbosity=2) | 227 unittest.main(verbosity=2) |
183 | 228 |
OLD | NEW |