Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2012 The Chromium OS 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. |
| 5 | |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 6 | """Unit tests for the deploy_chrome script.""" |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 7 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 8 | import os |
| 9 | import sys |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 10 | import time |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 11 | |
| 12 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 13 | '..', '..')) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 14 | |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 15 | from chromite.cros.commands import cros_chrome_sdk_unittest |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 16 | from chromite.lib import chrome_util |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 17 | from chromite.lib import cros_build_lib |
| 18 | from chromite.lib import cros_test_lib |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 19 | from chromite.lib import osutils |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 20 | from chromite.lib import partial_mock |
| 21 | from chromite.lib import remote_access_unittest |
Ryan Cui | cbd9bb6 | 2013-04-30 11:17:02 -0700 | [diff] [blame] | 22 | from chromite.lib import stats |
| 23 | from chromite.lib import stats_unittest |
| 24 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 25 | from chromite.scripts import deploy_chrome |
| 26 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 27 | |
Brian Harring | e752437 | 2012-12-23 02:02:56 -0800 | [diff] [blame] | 28 | # TODO(build): Finish test wrapper (http://crosbug.com/37517). |
| 29 | # Until then, this has to be after the chromite imports. |
| 30 | import mock |
| 31 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 32 | |
| 33 | # pylint: disable=W0212 |
| 34 | |
| 35 | _REGULAR_TO = ('--to', 'monkey') |
| 36 | _GS_PATH = 'gs://foon' |
| 37 | |
| 38 | |
| 39 | def _ParseCommandLine(argv): |
| 40 | return deploy_chrome._ParseCommandLine(['--log-level', 'debug'] + argv) |
| 41 | |
| 42 | |
| 43 | class InterfaceTest(cros_test_lib.OutputTestCase): |
| 44 | """Tests the commandline interface of the script.""" |
| 45 | |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 46 | BOARD = 'lumpy' |
| 47 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 48 | def testGsLocalPathUnSpecified(self): |
| 49 | """Test no chrome path specified.""" |
| 50 | with self.OutputCapturer(): |
| 51 | self.assertRaises2(SystemExit, _ParseCommandLine, list(_REGULAR_TO), |
| 52 | check_attrs={'code': 2}) |
| 53 | |
| 54 | def testGsPathSpecified(self): |
| 55 | """Test case of GS path specified.""" |
| 56 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH] |
| 57 | _ParseCommandLine(argv) |
| 58 | |
| 59 | def testLocalPathSpecified(self): |
| 60 | """Test case of local path specified.""" |
Ryan Cui | a56a71e | 2012-10-18 18:40:35 -0700 | [diff] [blame] | 61 | argv = list(_REGULAR_TO) + ['--local-pkg-path', '/path/to/chrome'] |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 62 | _ParseCommandLine(argv) |
| 63 | |
| 64 | def testNoTarget(self): |
| 65 | """Test no target specified.""" |
| 66 | argv = ['--gs-path', _GS_PATH] |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 67 | self.assertParseError(argv) |
| 68 | |
| 69 | def assertParseError(self, argv): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 70 | with self.OutputCapturer(): |
| 71 | self.assertRaises2(SystemExit, _ParseCommandLine, argv, |
| 72 | check_attrs={'code': 2}) |
| 73 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 74 | def testStagingFlagsNoStrict(self): |
| 75 | """Errors out when --staging-flags is set without --strict.""" |
| 76 | argv = ['--staging-only', '--build-dir=/path/to/nowhere', |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 77 | '--board=%s' % self.BOARD, '--staging-flags=highdpi'] |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 78 | self.assertParseError(argv) |
| 79 | |
| 80 | def testStrictNoBuildDir(self): |
| 81 | """Errors out when --strict is set without --build-dir.""" |
| 82 | argv = ['--staging-only', '--strict', '--gs-path', _GS_PATH] |
| 83 | self.assertParseError(argv) |
| 84 | |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 85 | def testNoBoardBuildDir(self): |
| 86 | argv = ['--staging-only', '--build-dir=/path/to/nowhere'] |
| 87 | self.assertParseError(argv) |
| 88 | |
Thiago Goncales | 1279331 | 2013-05-23 11:26:17 -0700 | [diff] [blame] | 89 | def testMountOptionSetsTargetDir(self): |
| 90 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount'] |
| 91 | options, _ = _ParseCommandLine(argv) |
| 92 | self.assertIsNot(options.target_dir, None) |
| 93 | |
| 94 | def testMountOptionSetsMountDir(self): |
| 95 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount'] |
| 96 | options, _ = _ParseCommandLine(argv) |
| 97 | self.assertIsNot(options.mount_dir, None) |
| 98 | |
| 99 | def testMountOptionDoesNotOverrideTargetDir(self): |
| 100 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount', |
| 101 | '--target-dir', '/foo/bar/cow'] |
| 102 | options, _ = _ParseCommandLine(argv) |
| 103 | self.assertEqual(options.target_dir, '/foo/bar/cow') |
| 104 | |
| 105 | def testMountOptionDoesNotOverrideMountDir(self): |
| 106 | argv = list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--mount', |
| 107 | '--mount-dir', '/foo/bar/cow'] |
| 108 | options, _ = _ParseCommandLine(argv) |
| 109 | self.assertEqual(options.mount_dir, '/foo/bar/cow') |
| 110 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 111 | |
| 112 | class DeployChromeMock(partial_mock.PartialMock): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 113 | """Deploy Chrome Mock Class.""" |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 114 | |
| 115 | TARGET = 'chromite.scripts.deploy_chrome.DeployChrome' |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 116 | ATTRS = ('_KillProcsIfNeeded', '_DisableRootfsVerification') |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 117 | |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 118 | def __init__(self): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 119 | partial_mock.PartialMock.__init__(self) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 120 | # Target starts off as having rootfs verification enabled. |
Ryan Cui | e18f24f | 2012-12-03 18:39:55 -0800 | [diff] [blame] | 121 | self.rsh_mock = remote_access_unittest.RemoteShMock() |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 122 | self.rsh_mock.SetDefaultCmdResult(0) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 123 | self.MockMountCmd(1) |
Pawel Osciak | 577773a | 2013-03-05 10:52:12 -0800 | [diff] [blame] | 124 | self.rsh_mock.AddCmdResult( |
| 125 | deploy_chrome.LSOF_COMMAND % (deploy_chrome._CHROME_DIR,), 1) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 126 | |
| 127 | def MockMountCmd(self, returnvalue): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 128 | self.rsh_mock.AddCmdResult(deploy_chrome.MOUNT_RW_COMMAND, |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 129 | returnvalue) |
| 130 | |
| 131 | def _DisableRootfsVerification(self, inst): |
| 132 | with mock.patch.object(time, 'sleep'): |
| 133 | self.backup['_DisableRootfsVerification'](inst) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 134 | |
Ryan Cui | 4d6fca9 | 2012-12-13 16:41:56 -0800 | [diff] [blame] | 135 | def PreStart(self): |
| 136 | self.rsh_mock.start() |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 137 | |
Ryan Cui | 4d6fca9 | 2012-12-13 16:41:56 -0800 | [diff] [blame] | 138 | def PreStop(self): |
| 139 | self.rsh_mock.stop() |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 140 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 141 | def _KillProcsIfNeeded(self, _inst): |
| 142 | # Fully stub out for now. |
| 143 | pass |
| 144 | |
| 145 | |
Ryan Cui | cbd9bb6 | 2013-04-30 11:17:02 -0700 | [diff] [blame] | 146 | class MainTest(cros_test_lib.MockLoggingTestCase): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 147 | """Main tests.""" |
Ryan Cui | cbd9bb6 | 2013-04-30 11:17:02 -0700 | [diff] [blame] | 148 | |
| 149 | def setUp(self): |
| 150 | self.PatchObject(deploy_chrome.DeployChrome, 'Perform', autospec=True) |
| 151 | self.stats_module_mock = stats_unittest.StatsModuleMock() |
| 152 | self.StartPatcher(self.stats_module_mock) |
| 153 | |
| 154 | def testStatsUpload(self, call_count=1): |
| 155 | """The stats upload path.""" |
| 156 | deploy_chrome.main(['--board=lumpy', '--staging-only', |
| 157 | '--build-dir=/tmp/abc']) |
| 158 | self.assertEquals(stats.StatsUploader._Upload.call_count, call_count) |
| 159 | |
| 160 | def testStatsUploadError(self): |
| 161 | """Don't upload stats if we fail to create it.""" |
| 162 | self.stats_module_mock.stats_mock.init_exception = True |
| 163 | with cros_test_lib.LoggingCapturer(): |
| 164 | self.testStatsUpload(call_count=0) |
| 165 | |
| 166 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 167 | class DeployTest(cros_test_lib.MockTempDirTestCase): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 168 | """Setup a deploy object with a GS-path for use in tests.""" |
| 169 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 170 | def _GetDeployChrome(self, args): |
| 171 | options, _ = _ParseCommandLine(args) |
Ryan Cui | a56a71e | 2012-10-18 18:40:35 -0700 | [diff] [blame] | 172 | return deploy_chrome.DeployChrome( |
| 173 | options, self.tempdir, os.path.join(self.tempdir, 'staging')) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 174 | |
| 175 | def setUp(self): |
Ryan Cui | f1416f3 | 2013-01-22 18:43:41 -0800 | [diff] [blame] | 176 | self.deploy_mock = self.StartPatcher(DeployChromeMock()) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 177 | self.deploy = self._GetDeployChrome( |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 178 | list(_REGULAR_TO) + ['--gs-path', _GS_PATH, '--force']) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 179 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 180 | |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 181 | class TestDisableRootfsVerification(DeployTest): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 182 | """Testing disabling of rootfs verification and RO mode.""" |
| 183 | |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 184 | def testDisableRootfsVerificationSuccess(self): |
| 185 | """Test the working case, disabling rootfs verification.""" |
| 186 | self.deploy_mock.MockMountCmd(0) |
| 187 | self.deploy._DisableRootfsVerification() |
| 188 | self.assertFalse(self.deploy._rootfs_is_still_readonly.is_set()) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 189 | |
| 190 | def testDisableRootfsVerificationFailure(self): |
| 191 | """Test failure to disable rootfs verification.""" |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 192 | self.assertRaises(cros_build_lib.RunCommandError, |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 193 | self.deploy._DisableRootfsVerification) |
| 194 | self.assertFalse(self.deploy._rootfs_is_still_readonly.is_set()) |
| 195 | |
| 196 | |
| 197 | class TestMount(DeployTest): |
| 198 | """Testing mount success and failure.""" |
| 199 | |
| 200 | def testSuccess(self): |
| 201 | """Test case where we are able to mount as writable.""" |
| 202 | self.assertFalse(self.deploy._rootfs_is_still_readonly.is_set()) |
| 203 | self.deploy_mock.MockMountCmd(0) |
| 204 | self.deploy._MountRootfsAsWritable() |
| 205 | self.assertFalse(self.deploy._rootfs_is_still_readonly.is_set()) |
| 206 | |
| 207 | def testMountError(self): |
| 208 | """Test that mount failure doesn't raise an exception by default.""" |
| 209 | self.assertFalse(self.deploy._rootfs_is_still_readonly.is_set()) |
| 210 | self.deploy._MountRootfsAsWritable() |
| 211 | self.assertTrue(self.deploy._rootfs_is_still_readonly.is_set()) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 212 | |
| 213 | def testMountRwFailure(self): |
David James | 88e6f03 | 2013-03-02 08:13:20 -0800 | [diff] [blame] | 214 | """Test that mount failure raises an exception if error_code_ok=False.""" |
| 215 | self.assertRaises(cros_build_lib.RunCommandError, |
| 216 | self.deploy._MountRootfsAsWritable, error_code_ok=False) |
| 217 | self.assertFalse(self.deploy._rootfs_is_still_readonly.is_set()) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 218 | |
| 219 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 220 | class TestUiJobStarted(DeployTest): |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 221 | """Test detection of a running 'ui' job.""" |
| 222 | |
Ryan Cui | f2d1a58 | 2013-02-19 14:08:13 -0800 | [diff] [blame] | 223 | def MockStatusUiCmd(self, **kwargs): |
| 224 | self.deploy_mock.rsh_mock.AddCmdResult('status ui', **kwargs) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 225 | |
| 226 | def testUiJobStartedFalse(self): |
| 227 | """Correct results with a stopped job.""" |
Ryan Cui | f2d1a58 | 2013-02-19 14:08:13 -0800 | [diff] [blame] | 228 | self.MockStatusUiCmd(output='ui stop/waiting') |
| 229 | self.assertFalse(self.deploy._CheckUiJobStarted()) |
| 230 | |
| 231 | def testNoUiJob(self): |
| 232 | """Correct results when the job doesn't exist.""" |
| 233 | self.MockStatusUiCmd(error='start: Unknown job: ui', returncode=1) |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 234 | self.assertFalse(self.deploy._CheckUiJobStarted()) |
| 235 | |
| 236 | def testCheckRootfsWriteableTrue(self): |
| 237 | """Correct results with a running job.""" |
Ryan Cui | f2d1a58 | 2013-02-19 14:08:13 -0800 | [diff] [blame] | 238 | self.MockStatusUiCmd(output='ui start/running, process 297') |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 239 | self.assertTrue(self.deploy._CheckUiJobStarted()) |
| 240 | |
| 241 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 242 | class StagingTest(cros_test_lib.MockTempDirTestCase): |
| 243 | """Test user-mode and ebuild-mode staging functionality.""" |
| 244 | |
| 245 | def setUp(self): |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 246 | self.staging_dir = os.path.join(self.tempdir, 'staging') |
| 247 | self.build_dir = os.path.join(self.tempdir, 'build_dir') |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 248 | self.common_flags = ['--build-dir', self.build_dir, |
| 249 | '--board=lumpy', '--staging-only', '--cache-dir', |
| 250 | self.tempdir] |
Ryan Cui | a0215a7 | 2013-02-14 16:20:45 -0800 | [diff] [blame] | 251 | self.sdk_mock = self.StartPatcher(cros_chrome_sdk_unittest.SDKFetcherMock()) |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 252 | self.PatchObject( |
| 253 | osutils, 'SourceEnvironment', autospec=True, |
| 254 | return_value={'STRIP': 'x86_64-cros-linux-gnu-strip'}) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 255 | |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 256 | def testSingleFileDeployFailure(self): |
| 257 | """Default staging enforces that mandatory files are copied""" |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 258 | options, _ = _ParseCommandLine(self.common_flags) |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 259 | osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True) |
| 260 | self.assertRaises( |
| 261 | chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 262 | options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 263 | |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 264 | def testSloppyDeployFailure(self): |
| 265 | """Sloppy staging enforces that at least one file is copied.""" |
| 266 | options, _ = _ParseCommandLine(self.common_flags + ['--sloppy']) |
| 267 | self.assertRaises( |
| 268 | chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 269 | options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME) |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 270 | |
| 271 | def testSloppyDeploySuccess(self): |
| 272 | """Sloppy staging - stage one file.""" |
| 273 | options, _ = _ParseCommandLine(self.common_flags + ['--sloppy']) |
| 274 | osutils.Touch(os.path.join(self.build_dir, 'chrome'), makedirs=True) |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 275 | deploy_chrome._PrepareStagingDir(options, self.tempdir, self.staging_dir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 276 | chrome_util._COPY_PATHS_CHROME) |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 277 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 278 | def testEmptyDeployStrict(self): |
David James | a6e0889 | 2013-03-01 13:34:11 -0800 | [diff] [blame] | 279 | """Strict staging fails when there are no files.""" |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 280 | options, _ = _ParseCommandLine( |
| 281 | self.common_flags + ['--gyp-defines', 'chromeos=1', '--strict']) |
Ryan Cui | 686ec05 | 2013-02-12 16:39:41 -0800 | [diff] [blame] | 282 | |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 283 | self.assertRaises( |
| 284 | chrome_util.MissingPathError, deploy_chrome._PrepareStagingDir, |
Daniel Erat | c89829c | 2014-05-12 17:24:21 -0700 | [diff] [blame] | 285 | options, self.tempdir, self.staging_dir, chrome_util._COPY_PATHS_CHROME) |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 286 | |
| 287 | |
| 288 | class DeployTestBuildDir(cros_test_lib.MockTempDirTestCase): |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 289 | """Set up a deploy object with a build-dir for use in deployment type tests""" |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 290 | |
| 291 | def _GetDeployChrome(self, args): |
| 292 | options, _ = _ParseCommandLine(args) |
| 293 | return deploy_chrome.DeployChrome( |
| 294 | options, self.tempdir, os.path.join(self.tempdir, 'staging')) |
| 295 | |
| 296 | def setUp(self): |
| 297 | self.staging_dir = os.path.join(self.tempdir, 'staging') |
| 298 | self.build_dir = os.path.join(self.tempdir, 'build_dir') |
| 299 | self.deploy_mock = self.StartPatcher(DeployChromeMock()) |
| 300 | self.deploy = self._GetDeployChrome( |
| 301 | list(_REGULAR_TO) + ['--build-dir', self.build_dir, |
| 302 | '--board=lumpy', '--staging-only', '--cache-dir', |
| 303 | self.tempdir, '--sloppy']) |
| 304 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 305 | def getCopyPath(self, source_path): |
| 306 | """Return a chrome_util.Path or None if not present.""" |
| 307 | paths = [p for p in self.deploy.copy_paths if p.src == source_path] |
| 308 | return paths[0] if paths else None |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 309 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 310 | class TestDeploymentType(DeployTestBuildDir): |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 311 | """Test detection of deployment type using build dir.""" |
| 312 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 313 | def testAppShellDetection(self): |
| 314 | """Check for an app_shell deployment""" |
| 315 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'), |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 316 | makedirs=True) |
| 317 | self.deploy._CheckDeployType() |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 318 | self.assertTrue(self.getCopyPath('app_shell')) |
| 319 | self.assertFalse(self.getCopyPath('chrome')) |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 320 | |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 321 | def testChromeAndAppShellDetection(self): |
| 322 | """Check for a regular chrome deployment when app_shell also exists.""" |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 323 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'), |
| 324 | makedirs=True) |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 325 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'app_shell'), |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 326 | makedirs=True) |
| 327 | self.deploy._CheckDeployType() |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 328 | self.assertFalse(self.getCopyPath('app_shell')) |
| 329 | self.assertTrue(self.getCopyPath('chrome')) |
Steve Fung | 63d705d | 2014-03-16 03:14:03 -0700 | [diff] [blame] | 330 | |
Steve Fung | e984a53 | 2013-11-25 17:09:25 -0800 | [diff] [blame] | 331 | def testChromeDetection(self): |
| 332 | """Check for a regular chrome deployment""" |
| 333 | osutils.Touch(os.path.join(self.deploy.options.build_dir, 'chrome'), |
| 334 | makedirs=True) |
| 335 | self.deploy._CheckDeployType() |
Daniel Erat | 1ae4638 | 2014-08-14 10:23:39 -0700 | [diff] [blame^] | 336 | self.assertFalse(self.getCopyPath('app_shell')) |
| 337 | self.assertTrue(self.getCopyPath('chrome')) |
Ryan Cui | ef91e70 | 2013-02-04 12:06:36 -0800 | [diff] [blame] | 338 | |
Ryan Cui | afd6c5c | 2012-07-30 17:48:22 -0700 | [diff] [blame] | 339 | if __name__ == '__main__': |
| 340 | cros_test_lib.main() |