Add OWNERS to content/browser/quota
[chromium-blink-merge.git] / tools / auto_bisect / fetch_build_test.py
blobf559b1ebea3712017fb1582cc3af9d6d3747712d
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Unit tests for the fetch_builds module."""
7 import errno
8 import unittest
10 # The third-party mock module is expected to be available in PYTHONPATH.
11 import mock
13 import fetch_build
16 # The tests below test private functions (W0212).
17 # Some methods don't reference self because they use the mock module (R0201).
18 # pylint: disable=R0201,W0212
19 class FetchBuildTest(unittest.TestCase):
21 def setUp(self):
22 # Mocks of the os and bisect_utils modules are used in the methods below.
23 cloud_storage_patcher = mock.patch('fetch_build.cloud_storage')
24 self.mock_cloud_storage = cloud_storage_patcher.start()
25 self.addCleanup(cloud_storage_patcher.stop)
27 @mock.patch('fetch_build.os.path.exists')
28 def test_FetchFromCloudStorage_FileFound(self, mock_os_path_exists):
29 self.mock_cloud_storage.Exists.return_value = True
30 mock_os_path_exists.return_value = True
31 local_path = fetch_build.FetchFromCloudStorage(
32 'my_bucket', 'remote/foo.zip', 'local')
33 self.assertEqual('local/foo.zip', local_path)
34 self.mock_cloud_storage.Get.assert_called_with(
35 'my_bucket', 'remote/foo.zip', 'local/foo.zip')
37 def test_FetchFromCloudStorage_FileNotFound(self):
38 self.mock_cloud_storage.Exists.return_value = False
39 local_path = fetch_build.FetchFromCloudStorage(
40 'my_bucket', 'remote/foo.zip', 'local')
41 self.assertIsNone(local_path)
42 self.assertFalse(self.mock_cloud_storage.Get.called)
45 class BuildArchiveTest(unittest.TestCase):
47 def test_CreatePerfBuildArchive(self):
48 archive = fetch_build.BuildArchive.Create(fetch_build.PERF_BUILDER)
49 self.assertEqual('chrome-perf', archive.BucketName())
50 self.assertTrue(isinstance(archive, fetch_build.PerfBuildArchive))
52 def test_CreateFullBuildArchive(self):
53 archive = fetch_build.BuildArchive.Create(fetch_build.FULL_BUILDER)
54 archive._platform = 'linux'
55 self.assertEqual('chromium-linux-archive', archive.BucketName())
56 self.assertTrue(isinstance(archive, fetch_build.FullBuildArchive))
58 def test_BuildArchive_NonExistentType(self):
59 self.assertRaises(
60 NotImplementedError, fetch_build.BuildArchive.Create, 'other')
62 def test_FullBuildArchive_Linux(self):
63 archive = fetch_build.FullBuildArchive()
64 archive._platform = 'linux'
65 self.assertEqual('chromium-linux-archive', archive.BucketName())
66 self.assertEqual(
67 'chromium.linux/Linux Builder/full-build-linux_1234567890abcdef.zip',
68 archive.FilePath('1234567890abcdef'))
70 def test_FullBuildArchive_Android(self):
71 archive = fetch_build.FullBuildArchive()
72 archive._platform = 'android'
73 self.assertEqual('chromium-android', archive.BucketName())
74 self.assertEqual(
75 'android_main_rel/full-build-linux_1234567890abcdef.zip',
76 archive.FilePath('1234567890abcdef'))
78 def test_FullBuildArchive_Linux_BuilderName(self):
79 archive = fetch_build.FullBuildArchive()
80 archive._platform = 'linux'
81 self.assertEqual('linux_full_bisect_builder', archive.GetBuilderName())
83 def test_FullBuildArchive_Windows_BuildTime(self):
84 archive = fetch_build.FullBuildArchive()
85 archive._platform = 'win'
86 self.assertEqual(14400, archive.GetBuilderBuildTime())
88 def test_PerfBuildArchive_Linux(self):
89 archive = fetch_build.PerfBuildArchive()
90 archive._platform = 'linux'
91 self.assertEqual('chrome-perf', archive.BucketName())
92 self.assertEqual(
93 'Linux Builder/full-build-linux_1234567890abcdef.zip',
94 archive.FilePath('1234567890abcdef'))
96 def test_PerfBuildArchive_Android(self):
97 archive = fetch_build.PerfBuildArchive()
98 archive._platform = 'android'
99 self.assertEqual('chrome-perf', archive.BucketName())
100 self.assertEqual(
101 'android_perf_rel/full-build-linux_123456.zip',
102 archive.FilePath('123456'))
104 def test_PerfBuildArchive_AndroidArm64(self):
105 archive = fetch_build.PerfBuildArchive()
106 archive._platform = 'android_arm64'
107 self.assertEqual('chrome-perf', archive.BucketName())
108 self.assertEqual(
109 'android_perf_rel_arm64/full-build-linux_123456.zip',
110 archive.FilePath('123456'))
112 def test_PerfBuildArchive_64BitWindows(self):
113 archive = fetch_build.PerfBuildArchive(target_arch='x64')
114 archive._platform = 'win64'
115 self.assertEqual('chrome-perf', archive.BucketName())
116 self.assertEqual(
117 'Win x64 Builder/full-build-win32_123456.zip',
118 archive.FilePath('123456'))
120 def test_PerfBuildArchive_WithDepsPatchSha(self):
121 archive = fetch_build.PerfBuildArchive()
122 archive._platform = 'linux'
123 self.assertEqual(
124 'Linux Builder/full-build-linux_123456'
125 '_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.zip',
126 archive.FilePath(123456, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'))
128 def test_PerfBuildArchive_64BitWindows_BuilderName(self):
129 archive = fetch_build.PerfBuildArchive()
130 archive._platform = 'win64'
131 self.assertEqual('winx64_bisect_builder', archive.GetBuilderName())
133 def test_PerfBuildArchive_64BitWindows_BuildTime(self):
134 archive = fetch_build.PerfBuildArchive()
135 archive._platform = 'win64'
136 self.assertEqual(14400, archive.GetBuilderBuildTime())
138 def test_PerfBuildArchive_Windows_BuilderName(self):
139 archive = fetch_build.PerfBuildArchive()
140 archive._platform = 'win'
141 self.assertEqual('win_perf_bisect_builder', archive.GetBuilderName())
143 def test_PerfBuildArchive_Windows_BuildTime(self):
144 archive = fetch_build.PerfBuildArchive()
145 archive._platform = 'win'
146 self.assertEqual(14400, archive.GetBuilderBuildTime())
148 def test_PerfBuildArchive_Linux_BuilderName(self):
149 archive = fetch_build.PerfBuildArchive()
150 archive._platform = 'linux'
151 self.assertEqual('linux_perf_bisect_builder', archive.GetBuilderName())
153 def test_PerfBuildArchive_Linux_BuildTime(self):
154 archive = fetch_build.PerfBuildArchive()
155 archive._platform = 'linux'
156 self.assertEqual(14400, archive.GetBuilderBuildTime())
158 def test_PerfBuildArchive_Android_BuilderName(self):
159 archive = fetch_build.PerfBuildArchive()
160 archive._platform = 'android'
161 self.assertEqual('android_perf_bisect_builder', archive.GetBuilderName())
163 def test_PerfBuildArchive_Android_BuildTime(self):
164 archive = fetch_build.PerfBuildArchive()
165 archive._platform = 'android'
166 self.assertEqual(14400, archive.GetBuilderBuildTime())
168 def test_PerfBuildArchive_Mac_BuilderName(self):
169 archive = fetch_build.PerfBuildArchive()
170 archive._platform = 'mac'
171 self.assertEqual('mac_perf_bisect_builder', archive.GetBuilderName())
173 def test_PerfBuildArchive_mac_BuildTime(self):
174 archive = fetch_build.PerfBuildArchive()
175 archive._platform = 'mac'
176 self.assertEqual(14400, archive.GetBuilderBuildTime())
178 def test_GetBuildBotUrl_Perf(self):
179 self.assertEqual(
180 fetch_build.PERF_TRY_SERVER_URL,
181 fetch_build.GetBuildBotUrl(fetch_build.PERF_BUILDER))
183 def test_GetBuildBotUrl_full(self):
184 self.assertEqual(
185 fetch_build.LINUX_TRY_SERVER_URL,
186 fetch_build.GetBuildBotUrl(fetch_build.FULL_BUILDER))
189 class UnzipTest(unittest.TestCase):
191 def setUp(self):
192 # Mocks of the os and bisect_utils modules are used in the methods below.
193 os_patcher = mock.patch('fetch_build.os')
194 self.mock_os = os_patcher.start()
195 self.addCleanup(os_patcher.stop)
197 bisect_utils_patcher = mock.patch('fetch_build.bisect_utils')
198 self.mock_bisect_utils = bisect_utils_patcher.start()
199 self.addCleanup(bisect_utils_patcher.stop)
201 @mock.patch('fetch_build._MakeDirectory')
202 @mock.patch('fetch_build._UnzipUsingCommand')
203 def test_Unzip_Linux(self, mock_UnzipUsingCommand, mock_MakeDirectory):
204 self.mock_bisect_utils.IsLinuxHost.return_value = True
205 self.mock_bisect_utils.IsMacHost.return_value = False
206 self.mock_bisect_utils.IsWindowsHost.return_value = False
207 fetch_build.Unzip('x.zip', 'out_dir', verbose=False)
208 mock_MakeDirectory.assert_called_with('out_dir')
209 mock_UnzipUsingCommand.assert_called_with(
210 ['unzip', '-o'], 'x.zip', 'out_dir')
212 @mock.patch('fetch_build._MakeDirectory')
213 @mock.patch('fetch_build._UnzipUsingZipFile')
214 def test_Unzip_Mac_LargeFile(
215 self, mock_UnzipUsingZipFile, mock_MakeDirectory):
216 # The zipfile module is used to unzip on mac when the file is > 4GB.
217 self.mock_bisect_utils.IsLinuxHost.return_value = False
218 self.mock_bisect_utils.IsMacHost.return_value = True
219 self.mock_bisect_utils.IsWindowsHost.return_value = False
220 self.mock_os.path.getsize.return_value = 2 ** 33 # 8GB
221 fetch_build.Unzip('x.zip', 'out_dir', verbose=False)
222 mock_MakeDirectory.assert_called_with('out_dir')
223 mock_UnzipUsingZipFile.assert_called_with('x.zip', 'out_dir', False)
225 def test_UnzipUsingCommand(self):
226 # The _UnzipUsingCommand function should move to the output
227 # directory and run the command with the file's absolute path.
228 self.mock_os.path.abspath.return_value = '/foo/some/path/x.zip'
229 self.mock_os.getcwd.return_value = 'curr_dir'
230 self.mock_bisect_utils.RunProcess.return_value = 0
231 fetch_build._UnzipUsingCommand(['unzip'], 'x.zip', 'out_dir')
232 self.mock_os.chdir.assert_has_calls(
233 [mock.call('out_dir'), mock.call('curr_dir')])
234 self.mock_bisect_utils.RunProcess.assert_called_with(
235 ['unzip', '/foo/some/path/x.zip'])
237 def test_MakeDirectory(self):
238 # _MakeDirectory uses os.makedirs.
239 fetch_build._MakeDirectory('some/path')
240 self.mock_os.makedirs.assert_called_with('some/path')
242 def test_MakeDirectory_RaisesError(self):
243 self.mock_os.makedirs.side_effect = OSError()
244 self.assertRaises(OSError, fetch_build._MakeDirectory, 'some/path')
246 def test_MakeDirectory_NoErrorIfDirectoryAlreadyExists(self):
247 already_exists = OSError()
248 already_exists.errno = errno.EEXIST
249 self.mock_os.makedirs.side_effect = already_exists
250 fetch_build._MakeDirectory('some/path')
252 @mock.patch('fetch_build.shutil')
253 def test_RemoveDirectoryTree(self, mock_shutil):
254 # _RemoveDirectoryTree uses shutil.rmtree.
255 fetch_build._RemoveDirectoryTree('some/path')
256 mock_shutil.rmtree.assert_called_with('some/path')
259 if __name__ == '__main__':
260 unittest.main()