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.
6 """Unittests for chrome stages."""
8 from __future__ import print_function
14 sys.path.insert(0, os.path.abspath('%s/../../..' % os.path.dirname(__file__)))
15 from chromite.cbuildbot import commands
16 from chromite.cbuildbot import constants
17 from chromite.cbuildbot.cbuildbot_unittest import BuilderRunMock
18 from chromite.cbuildbot.stages import chrome_stages
19 from chromite.cbuildbot.stages import generic_stages_unittest
20 from chromite.lib import cidb
21 from chromite.lib import cros_build_lib
22 from chromite.lib import cros_build_lib_unittest
23 from chromite.lib import cros_test_lib
24 from chromite.lib import osutils
25 from chromite.lib import parallel_unittest
28 # pylint: disable=R0901,W0212
29 class ChromeSDKStageTest(generic_stages_unittest.AbstractStageTest,
30 cros_test_lib.LoggingTestCase):
31 """Verify stage that creates the chrome-sdk and builds chrome with it."""
32 BOT_ID = 'link-paladin'
36 self.StartPatcher(BuilderRunMock())
37 self.StartPatcher(parallel_unittest.ParallelMock())
39 # Set up a general purpose cidb mock. Tests with more specific
40 # mock requirements can replace this with a separate call to
42 mock_cidb = mox.MockObject(cidb.CIDBConnection)
43 cidb.CIDBConnectionFactory.SetupMockCidb(mock_cidb)
47 def _Prepare(self, bot_id=None, **kwargs):
48 super(ChromeSDKStageTest, self)._Prepare(bot_id, **kwargs)
50 self._run.options.chrome_root = '/tmp/non-existent'
51 self._run.attrs.metadata.UpdateWithDict({'toolchain-tuple': ['target'],
52 'toolchain-url' : 'some-url'})
54 def ConstructStage(self):
55 self._run.GetArchive().SetupArchivePath()
56 return chrome_stages.ChromeSDKStage(self._run, self._current_board)
59 """A simple run-through test."""
60 rc_mock = self.StartPatcher(cros_build_lib_unittest.RunCommandMock())
61 rc_mock.SetDefaultCmdResult()
62 self.PatchObject(chrome_stages.ChromeSDKStage, '_ArchiveChromeEbuildEnv',
64 self.PatchObject(chrome_stages.ChromeSDKStage, '_VerifyChromeDeployed',
66 self.PatchObject(chrome_stages.ChromeSDKStage, '_VerifySDKEnvironment',
70 def testChromeEnvironment(self):
71 """Test that the Chrome environment is built."""
72 # Create the chrome environment compressed file.
73 stage = self.ConstructStage()
74 chrome_env_dir = os.path.join(
75 stage._pkg_dir, constants.CHROME_CP + '-25.3643.0_rc1')
76 env_file = os.path.join(chrome_env_dir, 'environment')
77 osutils.Touch(env_file, makedirs=True)
79 cros_build_lib.RunCommand(['bzip2', env_file])
82 stage._ArchiveChromeEbuildEnv()
84 env_tar_base = stage._upload_queue.get()[0]
85 env_tar = os.path.join(stage.archive_path, env_tar_base)
86 self.assertTrue(os.path.exists(env_tar))
87 cros_test_lib.VerifyTarball(env_tar, ['./', 'environment'])
90 class PatchChromeStageTest(generic_stages_unittest.AbstractStageTest):
91 """Tests for PatchChromeStage."""
94 self._Prepare(cmd_args=[
95 '-r', self.build_root,
96 '--rietveld-patches=1234',
97 '--rietveld-patches=555:adir',
99 self.PatchObject(commands, 'PatchChrome')
101 def ConstructStage(self):
102 return chrome_stages.PatchChromeStage(self._run)
105 """Verify requested patches are applied."""
106 stage = self.ConstructStage()
110 if __name__ == '__main__':