Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / cbuildbot / stages / build_stages_unittest.py
index 2bf2a34..6b0bbe3 100755 (executable)
@@ -5,6 +5,8 @@
 
 """Unittests for build stages."""
 
+from __future__ import print_function
+
 import contextlib
 import os
 import sys
@@ -13,6 +15,7 @@ sys.path.insert(0, os.path.abspath('%s/../../..' % os.path.dirname(__file__)))
 from chromite.cbuildbot import cbuildbot_config as config
 from chromite.cbuildbot import commands
 from chromite.cbuildbot import constants
+from chromite.cbuildbot.cbuildbot_unittest import BuilderRunMock
 from chromite.cbuildbot.stages import build_stages
 from chromite.cbuildbot.stages import generic_stages_unittest
 from chromite.lib import cros_build_lib
@@ -22,10 +25,10 @@ from chromite.lib import git
 from chromite.lib import parallel
 from chromite.lib import parallel_unittest
 from chromite.lib import partial_mock
+from chromite.lib import portage_util
 
 from chromite.cbuildbot.stages.generic_stages_unittest import patch
 from chromite.cbuildbot.stages.generic_stages_unittest import patches
-from chromite.cbuildbot.stages.generic_stages_unittest import BuilderRunMock
 
 
 # pylint: disable=W0212,R0901
@@ -82,10 +85,11 @@ class SetupBoardTest(generic_stages_unittest.RunCommandAbstractStageTest):
   def _RunFull(self, dir_exists=False):
     """Helper for testing a full builder."""
     self._Run(dir_exists)
+    self.assertCommandContains(['./update_chroot', '--nousepkg'])
     cmd = ['./setup_board', '--board=%s' % self._current_board, '--nousepkg']
     self.assertCommandContains(cmd, expected=not dir_exists)
     cmd = ['./setup_board', '--skip_chroot_upgrade']
-    self.assertCommandContains(cmd, expected=False)
+    self.assertCommandContains(cmd)
 
   def testFullBuildWithProfile(self):
     """Tests whether full builds add profile flag when requested."""
@@ -107,11 +111,17 @@ class SetupBoardTest(generic_stages_unittest.RunCommandAbstractStageTest):
   def _RunBin(self, dir_exists):
     """Helper for testing a binary builder."""
     self._Run(dir_exists)
-    self.assertCommandContains(['./setup_board'])
-    cmd = ['./setup_board', '--nousepkg']
-    self.assertCommandContains(cmd, expected=self._run.options.latest_toolchain)
+    usepkg_toolchain = (self._run.config.usepkg_toolchain and not
+                        self._run.options.latest_toolchain)
+    self.assertCommandContains(['./update_chroot', '--nousepkg'],
+                               expected=not usepkg_toolchain)
+    run_setup_board = not dir_exists or self._run.options.latest_toolchain
+    self.assertCommandContains(['./setup_board'], expected=run_setup_board)
     cmd = ['./setup_board', '--skip_chroot_upgrade']
-    self.assertCommandContains(cmd, expected=False)
+    self.assertCommandContains(cmd, expected=run_setup_board)
+    cmd = ['./setup_board', '--nousepkg'],
+    self.assertCommandContains(cmd,
+        expected=run_setup_board and not self._run.config.usepkg_build_packages)
 
   def testBinBuildWithBoard(self):
     """Tests whether we don't create the board when it's there."""
@@ -126,6 +136,13 @@ class SetupBoardTest(generic_stages_unittest.RunCommandAbstractStageTest):
   def testBinBuildWithLatestToolchain(self):
     """Tests whether we use --nousepkg for creating the board."""
     self._PrepareBin()
+    self._run.options.latest_toolchain = True
+    self._RunBin(dir_exists=False)
+
+  def testBinBuildWithNoToolchainPackages(self):
+    """Tests whether we use --nousepkg for creating the board."""
+    self._PrepareBin()
+    self._run.config.usepkg_toolchain = False
     self._RunBin(dir_exists=False)
 
   def testSDKBuild(self):
@@ -133,6 +150,7 @@ class SetupBoardTest(generic_stages_unittest.RunCommandAbstractStageTest):
     extra_config = {'build_type': constants.CHROOT_BUILDER_TYPE}
     self._PrepareFull(extra_config=extra_config)
     self._Run(dir_exists=False)
+    self.assertCommandContains(['./update_chroot'], expected=False)
     self.assertCommandContains(['./setup_board', '--skip_chroot_upgrade'])
 
 
@@ -163,17 +181,12 @@ class UprevStageTest(generic_stages_unittest.AbstractStageTest):
     self.mox.VerifyAll()
 
 
-class BuildPackagesStageTest(generic_stages_unittest.AbstractStageTest):
-  """Tests BuildPackagesStage."""
-
-  def setUp(self):
-    self._release_tag = None
-
-    self.StartPatcher(BuilderRunMock())
+class AllConfigsTestCase(generic_stages_unittest.AbstractStageTest):
+  """Test case for testing against all bot configs."""
 
   def ConstructStage(self):
-    self._run.attrs.release_tag = self._release_tag
-    return build_stages.BuildPackagesStage(self._run, self._current_board)
+    """Bypass lint warning"""
+    generic_stages_unittest.AbstractStageTest.ConstructStage(self)
 
   @contextlib.contextmanager
   def RunStageWithConfig(self, mock_configurator=None):
@@ -193,6 +206,42 @@ class BuildPackagesStageTest(generic_stages_unittest.AbstractStageTest):
       msg = '%s failed the following test:\n%s' % (self._bot_id, ex)
       raise AssertionError(msg)
 
+  def RunAllConfigs(self, task, skip_missing=False):
+    """Run |task| against all major configurations"""
+    with parallel.BackgroundTaskRunner(task) as queue:
+      # Loop through all major configuration types and pick one from each.
+      for bot_type in config.CONFIG_TYPE_DUMP_ORDER:
+        for bot_id in config.config:
+          if bot_id.endswith(bot_type):
+            # Skip any config without a board, since those configs do not
+            # build packages.
+            cfg = config.config[bot_id]
+            if cfg.boards:
+              # Skip boards w/out a local overlay.  Like when running a
+              # public manifest and testing private-only boards.
+              if skip_missing:
+                try:
+                  for b in cfg.boards:
+                    portage_util.FindPrimaryOverlay(constants.BOTH_OVERLAYS, b)
+                except portage_util.MissingOverlayException:
+                  continue
+
+              queue.put([bot_id])
+              break
+
+
+class BuildPackagesStageTest(AllConfigsTestCase):
+  """Tests BuildPackagesStage."""
+
+  def setUp(self):
+    self._release_tag = None
+
+    self.StartPatcher(BuilderRunMock())
+
+  def ConstructStage(self):
+    self._run.attrs.release_tag = self._release_tag
+    return build_stages.BuildPackagesStage(self._run, self._current_board)
+
   def RunTestsWithBotId(self, bot_id, options_tests=True):
     """Test with the config for the specified bot_id."""
     self._Prepare(bot_id)
@@ -210,18 +259,7 @@ class BuildPackagesStageTest(generic_stages_unittest.AbstractStageTest):
 
   def testAllConfigs(self):
     """Test all major configurations"""
-    task = self.RunTestsWithBotId
-    with parallel.BackgroundTaskRunner(task) as queue:
-      # Loop through all major configuration types and pick one from each.
-      for bot_type in config.CONFIG_TYPE_DUMP_ORDER:
-        for bot_id in config.config:
-          if bot_id.endswith(bot_type):
-            # Skip any config without a board, since those configs do not
-            # build packages.
-            cfg = config.config[bot_id]
-            if cfg.boards:
-              queue.put([bot_id])
-              break
+    self.RunAllConfigs(self.RunTestsWithBotId)
 
   def testNoTests(self):
     """Test that self.options.tests = False works."""