Upstream version 10.39.225.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 from __future__ import print_function
9
10 import mox
11 import os
12 import sys
13
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
26
27
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'
33   RELEASE_TAG = ''
34
35   def setUp(self):
36     self.StartPatcher(BuilderRunMock())
37     self.StartPatcher(parallel_unittest.ParallelMock())
38
39     # Set up a general purpose cidb mock. Tests with more specific
40     # mock requirements can replace this with a separate call to
41     # SetupMockCidb
42     mock_cidb = mox.MockObject(cidb.CIDBConnection)
43     cidb.CIDBConnectionFactory.SetupMockCidb(mock_cidb)
44
45     self._Prepare()
46
47   def _Prepare(self, bot_id=None, **kwargs):
48     super(ChromeSDKStageTest, self)._Prepare(bot_id, **kwargs)
49
50     self._run.options.chrome_root = '/tmp/non-existent'
51     self._run.attrs.metadata.UpdateWithDict({'toolchain-tuple': ['target'],
52                                             'toolchain-url' : 'some-url'})
53
54   def ConstructStage(self):
55     self._run.GetArchive().SetupArchivePath()
56     return chrome_stages.ChromeSDKStage(self._run, self._current_board)
57
58   def testIt(self):
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',
63                      autospec=True)
64     self.PatchObject(chrome_stages.ChromeSDKStage, '_VerifyChromeDeployed',
65                      autospec=True)
66     self.PatchObject(chrome_stages.ChromeSDKStage, '_VerifySDKEnvironment',
67                      autospec=True)
68     self.RunStage()
69
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)
78
79     cros_build_lib.RunCommand(['bzip2', env_file])
80
81     # Run the code.
82     stage._ArchiveChromeEbuildEnv()
83
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'])
88
89
90 class PatchChromeStageTest(generic_stages_unittest.AbstractStageTest):
91   """Tests for PatchChromeStage."""
92
93   def setUp(self):
94     self._Prepare(cmd_args=[
95         '-r', self.build_root,
96         '--rietveld-patches=1234',
97         '--rietveld-patches=555:adir',
98     ])
99     self.PatchObject(commands, 'PatchChrome')
100
101   def ConstructStage(self):
102     return chrome_stages.PatchChromeStage(self._run)
103
104   def testBasic(self):
105     """Verify requested patches are applied."""
106     stage = self.ConstructStage()
107     stage.PerformStage()
108
109
110 if __name__ == '__main__':
111   cros_test_lib.main()