예제 #1
0
 def testBlacklist(self):
     """Test the blacklist argument."""
     blacklist = ['foo/bar', 'cat/pkg']
     test.BuildTargetUnitTest(self.build_target,
                              self.chroot,
                              blacklist=blacklist)
     self.assertCommandContains(['--blacklist_packages', 'foo/bar cat/pkg'])
예제 #2
0
    def testSuccess(self):
        """Test simple success case."""
        result = test.BuildTargetUnitTest(self.build_target, self.chroot)

        self.assertCommandContains(
            ['cros_run_unit_tests', '--board', self.board])
        self.assertTrue(result.success)
예제 #3
0
 def testPackages(self):
     """Test the packages argument."""
     packages = ['foo/bar', 'cat/pkg']
     test.BuildTargetUnitTest(self.build_target,
                              self.chroot,
                              packages=packages)
     self.assertCommandContains(['--packages', 'foo/bar cat/pkg'])
예제 #4
0
def BuildTargetUnitTest(input_proto, output_proto, _config):
    """Run a build target's ebuild unit tests."""
    # Required args.
    result_path = input_proto.result_path

    # Method flags.
    # An empty sysroot means build packages was not run. This is used for
    # certain boards that need to use prebuilts (e.g. grunt's unittest-only).
    was_built = not input_proto.flags.empty_sysroot

    # Packages to be tested.
    packages_package_info = input_proto.packages
    packages = []
    for package_info_msg in packages_package_info:
        packages.append(controller_util.PackageInfoToString(package_info_msg))

    # Skipped tests.
    # TODO: Remove blacklist when we fully switch to blocklist.
    blocklisted_package_info = (input_proto.package_blacklist
                                or input_proto.package_blocklist)
    blocklist = []
    for package_info_msg in blocklisted_package_info:
        blocklist.append(controller_util.PackageInfoToString(package_info_msg))

    # Allow call to succeed if no tests were found.
    testable_packages_optional = input_proto.flags.testable_packages_optional

    build_target = controller_util.ParseBuildTarget(input_proto.build_target)
    chroot = controller_util.ParseChroot(input_proto.chroot)

    code_coverage = input_proto.flags.code_coverage

    result = test.BuildTargetUnitTest(
        build_target,
        chroot,
        packages=packages,
        blocklist=blocklist,
        was_built=was_built,
        code_coverage=code_coverage,
        testable_packages_optional=testable_packages_optional)

    if not result.success:
        # Failed to run tests or some tests failed.
        # Record all failed packages.
        for cpv in result.failed_cpvs:
            package_info_msg = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(cpv, package_info_msg)
        if result.failed_cpvs:
            return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
        else:
            return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY

    sysroot = sysroot_lib.Sysroot(build_target.root)
    tarball = test.BuildTargetUnitTestTarball(chroot, sysroot, result_path)
    if tarball:
        output_proto.tarball_path = tarball
    deserialize_metrics_log(output_proto.events, prefix=build_target.name)
예제 #5
0
    def testCodeCoverage(self):
        """Test adding use flags for coverage when requested."""
        result = test.BuildTargetUnitTest(self.build_target,
                                          self.chroot,
                                          code_coverage=True)

        self.assertCommandContains(
            ['cros_run_unit_tests', '--board', self.board],
            extra_env=PartialDict('USE', 'coverage'))
        self.assertTrue(result.success)
예제 #6
0
    def testCodeCoverageExistingFlags(self):
        """Test adding use flags for coverage when existing flags."""
        chroot = chroot_lib.Chroot(path=self.tempdir, env={'USE': 'foo bar'})
        result = test.BuildTargetUnitTest(self.build_target,
                                          chroot,
                                          code_coverage=True)

        self.assertCommandContains(
            ['cros_run_unit_tests', '--board', self.board],
            extra_env=PartialDict('USE', 'foo bar coverage'))
        self.assertTrue(result.success)
예제 #7
0
    def testFailure(self):
        """Test non-zero return code and failed package handling."""
        packages = ['foo/bar', 'cat/pkg']
        cpvs = [portage_util.SplitCPV(p, strict=False) for p in packages]
        self.PatchObject(portage_util,
                         'ParseDieHookStatusFile',
                         return_value=cpvs)
        expected_rc = 1
        self.rc.SetDefaultCmdResult(returncode=expected_rc)

        result = test.BuildTargetUnitTest(self.build_target, self.chroot)

        self.assertFalse(result.success)
        self.assertEqual(expected_rc, result.return_code)
        self.assertCountEqual(cpvs, result.failed_cpvs)
예제 #8
0
def BuildTargetUnitTest(input_proto, output_proto, _config):
    """Run a build target's ebuild unit tests."""
    # Required args.
    board = input_proto.build_target.name
    result_path = input_proto.result_path

    # Method flags.
    # An empty sysroot means build packages was not run. This is used for
    # certain boards that need to use prebuilts (e.g. grunt's unittest-only).
    was_built = not input_proto.flags.empty_sysroot

    # Skipped tests.
    blacklisted_package_info = input_proto.package_blacklist
    blacklist = []
    for package_info in blacklisted_package_info:
        blacklist.append(controller_util.PackageInfoToString(package_info))

    build_target = build_target_util.BuildTarget(board)
    chroot = controller_util.ParseChroot(input_proto.chroot)

    result = test.BuildTargetUnitTest(build_target,
                                      chroot,
                                      blacklist=blacklist,
                                      was_built=was_built)

    if not result.success:
        # Failed to run tests or some tests failed.
        # Record all failed packages.
        for cpv in result.failed_cpvs:
            package_info = output_proto.failed_packages.add()
            controller_util.CPVToPackageInfo(cpv, package_info)
        if result.failed_cpvs:
            return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
        else:
            return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY

    sysroot = sysroot_lib.Sysroot(build_target.root)
    tarball = test.BuildTargetUnitTestTarball(chroot, sysroot, result_path)
    if tarball:
        output_proto.tarball_path = tarball
    deserialize_metrics_log(output_proto.events, prefix=build_target.name)
예제 #9
0
 def testTestablePackagesOptional(self):
     """Test the testable packages optional argument."""
     test.BuildTargetUnitTest(self.build_target,
                              self.chroot,
                              testable_packages_optional=True)
     self.assertCommandContains(['--no-testable-packages-ok'])