Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: prebuilt_unittest.py

Issue 3858003: Update prebuilt to modify make.conf files for the board/host targets. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils
Patch Set: Address sosa comments Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « prebuilt.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium OS 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 mox 6 import mox
7 import os 7 import os
8 import prebuilt 8 import prebuilt
9 import shutil 9 import shutil
10 import tempfile 10 import tempfile
11 import unittest 11 import unittest
12 from chromite.lib import cros_build_lib 12 from chromite.lib import cros_build_lib
13 13
14 class TestUpdateFile(unittest.TestCase): 14 class TestUpdateFile(unittest.TestCase):
15 15
16 def setUp(self): 16 def setUp(self):
17 self.contents_str = ['stage 20100309/stage3-amd64-20100309.tar.bz2', 17 self.contents_str = ['# comment that should be skipped',
18 'PKGDIR="/var/lib/portage/pkgs"',
19 'PORTAGE_BINHOST="http://no.thanks.com"',
18 'portage portage-20100310.tar.bz2'] 20 'portage portage-20100310.tar.bz2']
19 temp_fd, self.version_file = tempfile.mkstemp() 21 temp_fd, self.version_file = tempfile.mkstemp()
20 os.write(temp_fd, '\n'.join(self.contents_str)) 22 os.write(temp_fd, '\n'.join(self.contents_str))
21 os.close(temp_fd) 23 os.close(temp_fd)
22 24
23 def tearDown(self): 25 def tearDown(self):
24 os.remove(self.version_file) 26 os.remove(self.version_file)
25 27
26 def _read_version_file(self): 28 def _read_version_file(self):
27 """Read the contents of self.version_file and return as a list.""" 29 """Read the contents of self.version_file and return as a list."""
28 version_fh = open(self.version_file) 30 version_fh = open(self.version_file)
29 try: 31 try:
30 return [line.strip() for line in version_fh.readlines()] 32 return [line.strip() for line in version_fh.readlines()]
31 finally: 33 finally:
32 version_fh.close() 34 version_fh.close()
33 35
34 def _verify_key_pair(self, key, val): 36 def _verify_key_pair(self, key, val):
35 file_contents = self._read_version_file() 37 file_contents = self._read_version_file()
38 # ensure key for verify is wrapped on quotes
39 if '"' not in val:
40 val = '"%s"' % val
36 for entry in file_contents: 41 for entry in file_contents:
37 file_key, file_val = entry.split() 42 if '=' not in entry:
43 continue
44 file_key, file_val = entry.split('=')
38 if file_key == key: 45 if file_key == key:
39 if val == file_val: 46 if val == file_val:
40 break 47 break
41 else: 48 else:
42 self.fail('Could not find "%s %s" in version file' % (key, val)) 49 self.fail('Could not find "%s=%s" in version file' % (key, val))
43 50
44 def testAddVariableThatDoesNotExist(self): 51 def testAddVariableThatDoesNotExist(self):
45 """Add in a new variable that was no present in the file.""" 52 """Add in a new variable that was no present in the file."""
46 key = 'x86-testcase' 53 key = 'PORTAGE_BINHOST'
47 value = '1234567' 54 value = '1234567'
48 prebuilt.UpdateLocalFile(self.version_file, key, value) 55 prebuilt.UpdateLocalFile(self.version_file, value)
56 print self.version_file
49 current_version_str = self._read_version_file() 57 current_version_str = self._read_version_file()
50 self._verify_key_pair(key, value) 58 self._verify_key_pair(key, value)
59 print self.version_file
51 60
52 def testUpdateVariable(self): 61 def testUpdateVariable(self):
53 """Test updating a variable that already exists.""" 62 """Test updating a variable that already exists."""
54 # take first entry in contents 63 key, val = self.contents_str[2].split('=')
55 key, val = self.contents_str[0].split()
56 new_val = 'test_update' 64 new_val = 'test_update'
57 self._verify_key_pair(key, val) 65 self._verify_key_pair(key, val)
58 prebuilt.UpdateLocalFile(self.version_file, key, new_val) 66 prebuilt.UpdateLocalFile(self.version_file, new_val)
59 self._verify_key_pair(key, new_val) 67 self._verify_key_pair(key, new_val)
60 68
61 69
62 class TestPrebuiltFilters(unittest.TestCase): 70 class TestPrebuiltFilters(unittest.TestCase):
63 71
64 def setUp(self): 72 def setUp(self):
65 self.tmp_dir = tempfile.mkdtemp() 73 self.tmp_dir = tempfile.mkdtemp()
66 self.private_dir = os.path.join(self.tmp_dir, 74 self.private_dir = os.path.join(self.tmp_dir,
67 prebuilt._PRIVATE_OVERLAY_DIR) 75 prebuilt._PRIVATE_OVERLAY_DIR)
68 self.private_structure_base = 'chromeos-overlay/chromeos-base' 76 self.private_structure_base = 'chromeos-overlay/chromeos-base'
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 gs_bucket_path = 'gs://chromeos-prebuilt/host/version' 165 gs_bucket_path = 'gs://chromeos-prebuilt/host/version'
158 self.mox.StubOutWithMock(cros_build_lib, 'ListFiles') 166 self.mox.StubOutWithMock(cros_build_lib, 'ListFiles')
159 cros_build_lib.ListFiles(' ').AndReturn(self.files_to_sync) 167 cros_build_lib.ListFiles(' ').AndReturn(self.files_to_sync)
160 self.mox.ReplayAll() 168 self.mox.ReplayAll()
161 result = prebuilt.GenerateUploadDict(' ', gs_bucket_path, self.fake_path) 169 result = prebuilt.GenerateUploadDict(' ', gs_bucket_path, self.fake_path)
162 self.assertEqual(result, self._generate_dict_results(gs_bucket_path)) 170 self.assertEqual(result, self._generate_dict_results(gs_bucket_path))
163 171
164 def testFailonUploadFail(self): 172 def testFailonUploadFail(self):
165 """Make sure we fail if one of the upload processes fail.""" 173 """Make sure we fail if one of the upload processes fail."""
166 files = {'test': '/uasd'} 174 files = {'test': '/uasd'}
167 self.assertEqual(prebuilt.RemoteUpload(files), [('test', '/uasd')]) 175 self.assertEqual(prebuilt.RemoteUpload(files), set([('test', '/uasd')]))
176
177 def testDetermineMakeConf(self):
178 """Test the different known variants of boards for proper path discovery."""
179 targets = {'amd64': os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']),
180 'x86-generic': os.path.join(prebuilt._BINHOST_BASE_DIR,
181 'overlay-x86-generic', 'make.conf'),
182 'arm-tegra2_vogue': os.path.join(
183 prebuilt._BINHOST_BASE_DIR,
184 'overlay-variant-arm-tegra2-vogue', 'make.conf'),}
185 for target in targets:
186 self.assertEqual(prebuilt.DetermineMakeConfFile(target), targets[target])
187
188 def testDetermineMakeConfGarbage(self):
189 """Ensure an exception is raised on bad input."""
190 self.assertRaises(prebuilt.UnknownBoardFormat, prebuilt.DetermineMakeConfFil e,
191 'asdfasdf')
168 192
169 193
170 if __name__ == '__main__': 194 if __name__ == '__main__':
171 unittest.main() 195 unittest.main()
OLDNEW
« no previous file with comments | « prebuilt.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698