"""Unittests for build stages."""
+from __future__ import print_function
+
import contextlib
import os
import sys
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
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
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."""
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."""
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):
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'])
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):
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)
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."""