ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / tests / build_artifacts_test.py
blobaa71502bf047db40414568bf9be5771c7fdd1f0f
1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import os
7 import ntpath
8 import posixpath
9 import sys
10 import collections
11 import unittest
13 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
14 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
15 CHROME_SRC = os.path.dirname(os.path.dirname(os.path.dirname(BUILD_TOOLS_DIR)))
16 MOCK_DIR = os.path.join(CHROME_SRC, 'third_party', 'pymock')
18 # For the mock library
19 sys.path.append(MOCK_DIR)
20 from mock import call, patch, Mock
22 sys.path.append(BUILD_TOOLS_DIR)
23 import build_artifacts
26 class BasePosixTestCase(unittest.TestCase):
27 def setUp(self):
28 self.addCleanup(patch.stopall)
29 patch('build_artifacts.PLATFORM', 'posix').start()
30 patch('build_artifacts.BUILD_ARCHIVE_DIR', '/archive_dir/').start()
31 patch('os.path.join', posixpath.join).start()
34 class PosixTestCase(BasePosixTestCase):
35 def setUp(self):
36 BasePosixTestCase.setUp(self)
38 def testGetToolchainNaClLib(self):
39 tests = [
40 (('newlib', 'x86_32'), 'foo/x86_64-nacl/lib32'),
41 (('newlib', 'x86_64'), 'foo/x86_64-nacl/lib'),
42 (('newlib', 'arm'), 'foo/arm-nacl/lib'),
43 (('glibc', 'x86_32'), 'foo/x86_64-nacl/lib32'),
44 (('glibc', 'x86_64'), 'foo/x86_64-nacl/lib'),
45 (('bionic', 'arm'), 'foo/arm-nacl/lib'),
46 (('pnacl', None), 'foo/le32-nacl/lib'),
49 for test in tests:
50 self.assertEqual(
51 build_artifacts.GetToolchainNaClLib(test[0][0], 'foo', test[0][1]),
52 test[1])
54 def testGetGypBuiltLib(self):
55 tests = [
56 (('newlib', 'x86_32'), 'foo/Release/gen/tc_newlib/lib32'),
57 (('newlib', 'x86_64'), 'foo/Release/gen/tc_newlib/lib64'),
58 (('newlib', 'arm'), 'foo/Release/gen/tc_newlib/libarm'),
59 (('glibc', 'x86_32'), 'foo/Release/gen/tc_glibc/lib32'),
60 (('glibc', 'x86_64'), 'foo/Release/gen/tc_glibc/lib64'),
61 (('pnacl', None), 'foo/Release/gen/tc_pnacl_newlib/lib')
64 for test in tests:
65 self.assertEqual(
66 build_artifacts.GetGypBuiltLib('foo', test[0][0], test[0][1]),
67 test[1])
69 def testGetGypToolchainLib(self):
70 tests = [
71 (('newlib', 'x86_32'),
72 'foo/Release/gen/sdk/posix_x86/nacl_x86_newlib/x86_64-nacl/lib32'),
73 (('newlib', 'x86_64'),
74 'foo/Release/gen/sdk/posix_x86/nacl_x86_newlib/x86_64-nacl/lib'),
75 (('newlib', 'arm'),
76 'foo/Release/gen/sdk/posix_x86/nacl_arm_newlib/arm-nacl/lib'),
77 (('glibc', 'x86_32'),
78 'foo/Release/gen/sdk/posix_x86/nacl_x86_glibc/x86_64-nacl/lib32'),
79 (('glibc', 'x86_64'),
80 'foo/Release/gen/sdk/posix_x86/nacl_x86_glibc/x86_64-nacl/lib'),
81 # Bionic uses the newlib toolchain lib directory
82 (('bionic', 'arm'),
83 'foo/Release/gen/sdk/posix_x86/nacl_arm_newlib/arm-nacl/lib'),
84 (('pnacl', None),
85 'foo/Release/gen/sdk/posix_x86/pnacl_newlib/le32-nacl/lib'),
88 for test in tests:
89 self.assertEqual(
90 build_artifacts.GetGypToolchainLib('foo', test[0][0], test[0][1]),
91 test[1])
93 @patch('build_artifacts.all_archives', ['foo.tar.bz2', 'bar.tar.bz2'])
94 @patch('build_version.ChromeMajorVersion', Mock(return_value='40'))
95 @patch('build_version.ChromeRevision', Mock(return_value='302630'))
96 @patch('build_version.ChromeCommitPosition', Mock(return_value=
97 '1492c3d296476fe12cafecabba6ebabe-refs/heads/master@{#302630}'))
98 @patch('buildbot_common.Archive')
99 def testUploadArchives(self, archive_mock):
100 build_artifacts.UploadArchives()
101 cwd = '/archive_dir/'
102 bucket_path = 'native-client-sdk/archives/40-302630-1492c3d29'
103 archive_mock.assert_has_calls([
104 call('foo.tar.bz2', bucket_path, cwd=cwd, step_link=False),
105 call('foo.tar.bz2.sha1', bucket_path, cwd=cwd, step_link=False),
106 call('bar.tar.bz2', bucket_path, cwd=cwd, step_link=False),
107 call('bar.tar.bz2.sha1', bucket_path, cwd=cwd, step_link=False)
111 class GypNinjaPosixTestCase(BasePosixTestCase):
112 def setUp(self):
113 BasePosixTestCase.setUp(self)
114 patch('sys.executable', 'python').start()
115 patch('build_artifacts.SRC_DIR', 'src_dir').start()
116 patch('os.environ', {}).start()
117 self.run_mock = patch('buildbot_common.Run').start()
118 self.options_mock = patch('build_artifacts.options').start()
119 self.options_mock.mac_sdk = False
120 self.options_mock.no_arm_trusted = False
121 self.gyp_defines_base = ['nacl_allow_thin_archives=0']
123 def testSimple(self):
124 build_artifacts.GypNinjaBuild(
125 None, 'gyp.py', 'foo.gyp', 'target', 'out_dir')
126 self.run_mock.assert_has_calls([
127 call(['python', 'gyp.py', 'foo.gyp', '--depth=.', '-G',
128 'output_dir=out_dir'],
129 cwd='src_dir',
130 env={'GYP_GENERATORS': 'ninja',
131 'GYP_DEFINES': ' '.join(self.gyp_defines_base)}),
132 call(['ninja', '-C', 'out_dir/Release', 'target'], cwd='src_dir')
135 def testTargetArch(self):
136 build_artifacts.GypNinjaBuild(
137 'x64', 'gyp.py', 'foo.gyp', 'target', 'out_dir')
138 self.run_mock.assert_has_calls([
139 call(['python', 'gyp.py', 'foo.gyp', '--depth=.', '-G',
140 'output_dir=out_dir'],
141 cwd='src_dir',
142 env={
143 'GYP_GENERATORS': 'ninja',
144 'GYP_DEFINES': ' '.join(self.gyp_defines_base +
145 ['target_arch=x64']),
147 call(['ninja', '-C', 'out_dir/Release', 'target'], cwd='src_dir')
150 def testMultipleTargets(self):
151 build_artifacts.GypNinjaBuild(
152 None, 'gyp.py', 'foo.gyp', ['target1', 'target2'], 'out_dir')
153 self.run_mock.assert_has_calls([
154 call(['python', 'gyp.py', 'foo.gyp', '--depth=.', '-G',
155 'output_dir=out_dir'],
156 cwd='src_dir',
157 env={'GYP_GENERATORS': 'ninja',
158 'GYP_DEFINES': ' '.join(self.gyp_defines_base)}),
159 call(['ninja', '-C', 'out_dir/Release', 'target1', 'target2'],
160 cwd='src_dir')
163 def testMacSdk(self):
164 build_artifacts.PLATFORM = 'mac'
165 self.options_mock.mac_sdk = '10.6'
166 build_artifacts.GypNinjaBuild(
167 None, 'gyp.py', 'foo.gyp', 'target', 'out_dir')
168 self.run_mock.assert_has_calls([
169 call(['python', 'gyp.py', 'foo.gyp', '--depth=.', '-G',
170 'output_dir=out_dir'],
171 cwd='src_dir',
172 env={
173 'GYP_GENERATORS': 'ninja',
174 'GYP_DEFINES': ' '.join(self.gyp_defines_base +
175 ['mac_sdk=10.6', 'clang=1']),
177 call(['ninja', '-C', 'out_dir/Release', 'target'], cwd='src_dir')
180 def testArmLinux(self):
181 build_artifacts.PLATFORM = 'linux'
182 build_artifacts.GypNinjaBuild(
183 'arm', 'gyp.py', 'foo.gyp', 'target', 'out_dir')
184 self.run_mock.assert_has_calls([
185 call(['python', 'gyp.py', 'foo.gyp', '--depth=.', '-G',
186 'output_dir=out_dir'],
187 cwd='src_dir',
188 env={
189 'GYP_CROSSCOMPILE': '1',
190 'GYP_GENERATORS': 'ninja',
191 'GYP_DEFINES': ' '.join(self.gyp_defines_base +
192 ['target_arch=arm',
193 'arm_float_abi=hard']),
195 call(['ninja', '-C', 'out_dir/Release', 'target'], cwd='src_dir')
198 def testNoArmTrusted(self):
199 build_artifacts.PLATFORM = 'linux'
200 self.options_mock.no_arm_trusted = True
201 build_artifacts.GypNinjaBuild(
202 'arm', 'gyp.py', 'foo.gyp', 'target', 'out_dir')
203 self.run_mock.assert_has_calls([
204 call(['python', 'gyp.py', 'foo.gyp', '--depth=.', '-G',
205 'output_dir=out_dir'],
206 cwd='src_dir',
207 env={
208 'GYP_CROSSCOMPILE': '1',
209 'GYP_GENERATORS': 'ninja',
210 'GYP_DEFINES': ' '.join(self.gyp_defines_base +
211 ['target_arch=arm',
212 'arm_float_abi=hard',
213 'disable_cross_trusted=1']),
215 call(['ninja', '-C', 'out_dir/Release', 'target'], cwd='src_dir')
219 class ArchivePosixTestCase(BasePosixTestCase):
220 def setUp(self):
221 BasePosixTestCase.setUp(self)
222 self.makedir_mock = patch('buildbot_common.MakeDir').start()
223 self.copyfile_mock = patch('buildbot_common.CopyFile').start()
224 self.copydir_mock = patch('buildbot_common.CopyDir').start()
225 self.isdir_mock = patch('os.path.isdir').start()
226 patch('os.path.exists', Mock(return_value=False)).start()
228 def dummy_isdir(path):
229 if path == '/archive_dir/posix_foo':
230 return True
231 return False
232 self.isdir_mock.side_effect = dummy_isdir
234 self.archive = build_artifacts.Archive('foo')
236 def testInit(self):
237 self.assertEqual(self.archive.name, 'posix_foo')
238 self.assertEqual(self.archive.archive_name, 'posix_foo.tar.bz2')
239 self.assertEqual(self.archive.archive_path,
240 '/archive_dir/posix_foo.tar.bz2')
241 self.assertEqual(self.archive.dirname, '/archive_dir/posix_foo')
242 self.makedir_mock.assert_called_once_with('/archive_dir/posix_foo')
244 @patch('glob.glob', Mock(side_effect=lambda x: [x]))
245 def testCopySimple(self):
246 self.archive.Copy('/copy_from', ['file1', 'file2'])
247 self.assertEqual(self.copydir_mock.call_count, 0)
248 self.copyfile_mock.assert_has_calls([
249 call('/copy_from/file1', '/archive_dir/posix_foo/file1'),
250 call('/copy_from/file2', '/archive_dir/posix_foo/file2')])
252 @patch('glob.glob')
253 def testCopyGlob(self, glob_mock):
254 glob_mock.return_value = ['/copy_from/foo', '/copy_from/bar']
255 self.archive.Copy('/copy_from', [('*', '')])
256 glob_mock.assert_called_once_with('/copy_from/*')
257 self.assertEqual(self.copydir_mock.call_count, 0)
258 self.copyfile_mock.assert_has_calls([
259 call('/copy_from/foo', '/archive_dir/posix_foo/'),
260 call('/copy_from/bar', '/archive_dir/posix_foo/')])
262 @patch('glob.glob', Mock(side_effect=lambda x: [x]))
263 def testCopyRename(self):
264 self.archive.Copy('/copy_from', [('file1', 'file1_renamed')])
265 self.assertEqual(self.copydir_mock.call_count, 0)
266 self.copyfile_mock.assert_called_once_with(
267 '/copy_from/file1', '/archive_dir/posix_foo/file1_renamed')
269 @patch('glob.glob', Mock(side_effect=lambda x: [x]))
270 def testCopyNewDir(self):
271 self.archive.Copy('/copy_from', [('file1', 'todir/')])
272 self.assertEqual(self.copydir_mock.call_count, 0)
273 self.copyfile_mock.assert_called_once_with(
274 '/copy_from/file1', '/archive_dir/posix_foo/todir/file1')
276 @patch('glob.glob', Mock(side_effect=lambda x: [x]))
277 def testCopyDir(self):
278 self.isdir_mock.side_effect = lambda _: True
279 self.archive.Copy('/copy_from', ['dirname'])
280 self.assertEqual(self.copyfile_mock.call_count, 0)
281 self.copydir_mock.assert_called_once_with(
282 '/copy_from/dirname', '/archive_dir/posix_foo/dirname')
285 class WinTestCase(unittest.TestCase):
286 def setUp(self):
287 patch('build_artifacts.PLATFORM', 'win').start()
288 patch('build_artifacts.BUILD_ARCHIVE_DIR', 'c:\\archive_dir\\').start()
289 patch('os.path.join', ntpath.join).start()
291 def tearDown(self):
292 patch.stopall()
294 @patch('os.path.exists', Mock(return_value=False))
295 @patch('buildbot_common.MakeDir')
296 def testArchiveInit(self, makedir_mock):
297 archive = build_artifacts.Archive('foo')
298 self.assertEqual(archive.name, 'win_foo')
299 self.assertEqual(archive.archive_name, 'win_foo.tar.bz2')
300 self.assertEqual(archive.archive_path, r'c:\archive_dir\win_foo.tar.bz2')
301 self.assertEqual(archive.dirname, r'c:\archive_dir\win_foo')
302 makedir_mock.assert_called_once_with(r'c:\archive_dir\win_foo')
305 if __name__ == '__main__':
306 unittest.main()