Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / cbuildbot / stages / chrome_stages_unittest.py
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
6 """Unittests for chrome stages."""
7
8 import os
9 import sys
10
11 sys.path.insert(0, os.path.abspath('%s/../../..' % os.path.dirname(__file__)))
12 from chromite.cbuildbot import commands
13 from chromite.cbuildbot import constants
14 from chromite.cbuildbot.cbuildbot_unittest import BuilderRunMock
15 from chromite.cbuildbot.stages import chrome_stages
16 from chromite.cbuildbot.stages import generic_stages_unittest
17 from chromite.lib import cros_build_lib
18 from chromite.lib import cros_build_lib_unittest
19 from chromite.lib import cros_test_lib
20 from chromite.lib import osutils
21 from chromite.lib import parallel_unittest
22
23
24 # pylint: disable=R0901,W0212
25 class ChromeSDKStageTest(generic_stages_unittest.AbstractStageTest,
26                          cros_test_lib.LoggingTestCase):
27   """Verify stage that creates the chrome-sdk and builds chrome with it."""
28   BOT_ID = 'link-paladin'
29   RELEASE_TAG = ''
30
31   def setUp(self):
32     self.StartPatcher(BuilderRunMock())
33     self.StartPatcher(parallel_unittest.ParallelMock())
34
35     self._Prepare()
36
37   def _Prepare(self, bot_id=None, **kwargs):
38     super(ChromeSDKStageTest, self)._Prepare(bot_id, **kwargs)
39
40     self._run.options.chrome_root = '/tmp/non-existent'
41     self._run.attrs.metadata.UpdateWithDict({'toolchain-tuple': ['target'],
42                                             'toolchain-url' : 'some-url'})
43
44   def ConstructStage(self):
45     self._run.GetArchive().SetupArchivePath()
46     return chrome_stages.ChromeSDKStage(self._run, self._current_board)
47
48   def testIt(self):
49     """A simple run-through test."""
50     rc_mock = self.StartPatcher(cros_build_lib_unittest.RunCommandMock())
51     rc_mock.SetDefaultCmdResult()
52     self.PatchObject(chrome_stages.ChromeSDKStage, '_ArchiveChromeEbuildEnv',
53                      autospec=True)
54     self.PatchObject(chrome_stages.ChromeSDKStage, '_VerifyChromeDeployed',
55                      autospec=True)
56     self.PatchObject(chrome_stages.ChromeSDKStage, '_VerifySDKEnvironment',
57                      autospec=True)
58     self.RunStage()
59
60   def testChromeEnvironment(self):
61     """Test that the Chrome environment is built."""
62     # Create the chrome environment compressed file.
63     stage = self.ConstructStage()
64     chrome_env_dir = os.path.join(
65         stage._pkg_dir, constants.CHROME_CP + '-25.3643.0_rc1')
66     env_file = os.path.join(chrome_env_dir, 'environment')
67     osutils.Touch(env_file, makedirs=True)
68
69     cros_build_lib.RunCommand(['bzip2', env_file])
70
71     # Run the code.
72     stage._ArchiveChromeEbuildEnv()
73
74     env_tar_base = stage._upload_queue.get()[0]
75     env_tar = os.path.join(stage.archive_path, env_tar_base)
76     self.assertTrue(os.path.exists(env_tar))
77     cros_test_lib.VerifyTarball(env_tar, ['./', 'environment'])
78
79
80 class PatchChromeStageTest(generic_stages_unittest.AbstractStageTest):
81   """Tests for PatchChromeStage."""
82
83   def setUp(self):
84     self._Prepare(cmd_args=[
85         '-r', self.build_root,
86         '--rietveld-patches=1234',
87         '--rietveld-patches=555:adir',
88     ])
89     self.PatchObject(commands, 'PatchChrome')
90
91   def ConstructStage(self):
92     return chrome_stages.PatchChromeStage(self._run)
93
94   def testBasic(self):
95     """Verify requested patches are applied."""
96     stage = self.ConstructStage()
97     stage.PerformStage()
98
99
100 if __name__ == '__main__':
101   cros_test_lib.main()