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)
def testPackageOnly(self): """Test no version provided.""" pi = common_pb2.PackageInfo() pi.package_name = 'pkg' cpv_str = controller_util.PackageInfoToString(pi) self.assertEqual('pkg', cpv_str)
def testNoVersion(self): """Test no version provided.""" pi = common_pb2.PackageInfo() pi.package_name = 'pkg' pi.category = 'cat' cpv_str = controller_util.PackageInfoToString(pi) self.assertEqual('cat/pkg', cpv_str)
def testAllFields(self): """Test all fields present.""" pi = common_pb2.PackageInfo() pi.package_name = 'pkg' pi.category = 'cat' pi.version = '2.0.0' cpv_str = controller_util.PackageInfoToString(pi) self.assertEqual('cat/pkg-2.0.0', cpv_str)
def InstallPackages(input_proto, output_proto, _config): """Install packages into a sysroot, building as necessary and permitted.""" compile_source = input_proto.flags.compile_source event_file = input_proto.flags.event_file use_goma = input_proto.flags.use_goma target_sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path) build_target = controller_util.ParseBuildTarget( input_proto.sysroot.build_target) packages = [ controller_util.PackageInfoToString(x) for x in input_proto.packages ] if not target_sysroot.IsToolchainInstalled(): cros_build_lib.Die('Toolchain must first be installed.') _LogBinhost(build_target.name) use_flags = [u.flag for u in input_proto.use_flags] build_packages_config = sysroot.BuildPackagesRunConfig( event_file=event_file, usepkg=not compile_source, install_debug_symbols=True, packages=packages, use_flags=use_flags, use_goma=use_goma) try: sysroot.BuildPackages(build_target, target_sysroot, build_packages_config) except sysroot_lib.PackageInstallError as e: if not e.failed_packages: # No packages to report, so just exit with an error code. return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY # We need to report the failed packages. for package in e.failed_packages: package_info = output_proto.failed_packages.add() controller_util.CPVToPackageInfo(package, package_info) return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE # Read metric events log and pipe them into output_proto.events. deserialize_metrics_log(output_proto.events, prefix=build_target.name)
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)
def testNoPackageName(self): """Test no package name given.""" pi = common_pb2.PackageInfo() with self.assertRaises(ValueError): controller_util.PackageInfoToString(pi)