def testArgumentValidationNoBuildTarget(self): """Test missing build target name.""" out_proto = self._OutputProto() in_proto = self._InputProto(sysroot_path=self.sysroot) with self.assertRaises(cros_build_lib.DieSystemExit): sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config)
def testFailureOutputHandling(self): """Test failed package handling.""" # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot) out_proto = self._OutputProto() # Failed package info and expected list for verification. err_pkgs = ['cat/pkg', 'cat2/pkg2'] err_cpvs = [ portage_util.SplitCPV(cpv, strict=False) for cpv in err_pkgs ] expected = [('cat', 'pkg'), ('cat2', 'pkg2')] # Force error to be raised with the packages. error = sysroot_lib.PackageInstallError('Error', cros_build_lib.CommandResult(), packages=err_cpvs) self.PatchObject(sysroot_service, 'BuildPackages', side_effect=error) rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) # This needs to return 2 to indicate the available error response. self.assertEqual( controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc) for package in out_proto.failed_packages: cat_pkg = (package.category, package.package_name) self.assertIn(cat_pkg, expected)
def testSuccessWithGomaLogs(self): """Test successful call with goma.""" self._CreateGomaLogFile(self.goma_dir, 'compiler_proxy', datetime.datetime(2018, 9, 21, 12, 0, 0)) self._CreateGomaLogFile(self.goma_dir, 'compiler_proxy-subproc', datetime.datetime(2018, 9, 21, 12, 1, 0)) self._CreateGomaLogFile(self.goma_dir, 'gomacc', datetime.datetime(2018, 9, 21, 12, 2, 0)) # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot, goma_dir=self.goma_dir, goma_log_dir=self.goma_out_dir) out_proto = self._OutputProto() self.PatchObject(sysroot_service, 'BuildPackages') rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) self.assertFalse(rc) self.assertFalse(out_proto.failed_packages) self.assertCountEqual(out_proto.goma_artifacts.log_files, [ 'compiler_proxy-subproc.host.log.INFO.20180921-120100.000000.gz', 'compiler_proxy.host.log.INFO.20180921-120000.000000.gz', 'gomacc.host.log.INFO.20180921-120200.000000.tar.gz' ])
def testArgumentValidationAllMissing(self): """Test missing all arguments.""" out_proto = self._OutputProto() in_proto = self._InputProto() with self.assertRaises(cros_build_lib.DieSystemExit): sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config)
def testArgumentValidationInvalidPackage(self): out_proto = self._OutputProto() in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot, packages=['package-1.0.0-r2']) with self.assertRaises(cros_build_lib.DieSystemExit): sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config)
def testValidateOnly(self): """Sanity check that a validate only call does not execute any logic.""" patch = self.PatchObject(sysroot_service, 'BuildPackages') in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot) sysroot_controller.InstallPackages(in_proto, self._OutputProto(), self.validate_only_config) patch.assert_not_called()
def testArgumentValidationInvalidSysroot(self): """Test sysroot that hasn't had the toolchain installed.""" out_proto = self._OutputProto() in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot) self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=False) with self.assertRaises(cros_build_lib.DieSystemExit): sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config)
def testMockCall(self): """Sanity check that a mock call does not execute any logic.""" patch = self.PatchObject(sysroot_service, 'BuildPackages') request = self._InputProto() response = self._OutputProto() rc = sysroot_controller.InstallPackages(request, response, self.mock_call_config) patch.assert_not_called() self.assertEqual(controller.RETURN_CODE_SUCCESS, rc)
def testMockError(self): """Sanity check that a mock error does not execute any logic.""" patch = self.PatchObject(sysroot_service, 'BuildPackages') request = self._InputProto() response = self._OutputProto() rc = sysroot_controller.InstallPackages(request, response, self.mock_error_config) patch.assert_not_called() self.assertEqual( controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc) self.assertTrue(response.failed_packages)
def testSuccessWithGomaLogsAndStatsCounterzFiles(self): """Test successful call with goma including stats and counterz files.""" self._CreateGomaLogFile(self.goma_dir, 'compiler_proxy', datetime.datetime(2018, 9, 21, 12, 0, 0)) self._CreateGomaLogFile(self.goma_dir, 'compiler_proxy-subproc', datetime.datetime(2018, 9, 21, 12, 1, 0)) self._CreateGomaLogFile(self.goma_dir, 'gomacc', datetime.datetime(2018, 9, 21, 12, 2, 0)) # Create stats and counterz files. osutils.WriteFile(os.path.join(self.goma_dir, 'stats.binaryproto'), 'File: stats.binaryproto') osutils.WriteFile(os.path.join(self.goma_dir, 'counterz.binaryproto'), 'File: counterz.binaryproto') # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot, goma_dir=self.goma_dir, goma_log_dir=self.goma_out_dir, goma_stats_file='stats.binaryproto', goma_counterz_file='counterz.binaryproto') out_proto = self._OutputProto() self.PatchObject(sysroot_service, 'BuildPackages') rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) self.assertFalse(rc) self.assertFalse(out_proto.failed_packages) self.assertCountEqual(out_proto.goma_artifacts.log_files, [ 'compiler_proxy-subproc.host.log.INFO.20180921-120100.000000.gz', 'compiler_proxy.host.log.INFO.20180921-120000.000000.gz', 'gomacc.host.log.INFO.20180921-120200.000000.tar.gz' ]) # Verify that the output dir has 5 files -- since there should be 3 log # files, the stats file, and the counterz file. output_files = os.listdir(self.goma_out_dir) self.assertCountEqual(output_files, [ 'stats.binaryproto', 'counterz.binaryproto', 'compiler_proxy-subproc.host.log.INFO.20180921-120100.000000.gz', 'compiler_proxy.host.log.INFO.20180921-120000.000000.gz', 'gomacc.host.log.INFO.20180921-120200.000000.tar.gz' ]) self.assertEqual(out_proto.goma_artifacts.counterz_file, 'counterz.binaryproto') self.assertEqual(out_proto.goma_artifacts.stats_file, 'stats.binaryproto')
def testSuccessOutputHandling(self): """Test successful call output handling.""" # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot) out_proto = self._OutputProto() self.PatchObject(sysroot_service, 'BuildPackages') rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) self.assertFalse(rc) self.assertFalse(out_proto.failed_packages)
def testSuccessPackageIndexes(self): """Test successful call with package_indexes.""" # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) package_indexes = [ common_pb2.PackageIndexInfo( snapshot_sha='SHA', snapshot_number=5, build_target=common_pb2.BuildTarget(name='board'), location='LOCATION', profile=common_pb2.Profile(name='profile')), common_pb2.PackageIndexInfo( snapshot_sha='SHA2', snapshot_number=4, build_target=common_pb2.BuildTarget(name='board'), location='LOCATION2', profile=common_pb2.Profile(name='profile')) ] in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot, package_indexes=package_indexes) out_proto = self._OutputProto() rc_patch = self.PatchObject(sysroot_service, 'BuildPackagesRunConfig') self.PatchObject(sysroot_service, 'BuildPackages') rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) self.assertFalse(rc) rc_patch.assert_called_with( usepkg=True, install_debug_symbols=True, packages=[], package_indexes=[ binpkg.PackageIndexInfo.from_protobuf(x) for x in package_indexes ], use_flags=[], use_goma=False, incremental_build=False)
def testFailureMissingGomaStatsCounterzFiles(self): """Test successful call with goma including stats and counterz files.""" self._CreateGomaLogFile(self.goma_dir, 'compiler_proxy', datetime.datetime(2018, 9, 21, 12, 0, 0)) self._CreateGomaLogFile(self.goma_dir, 'compiler_proxy-subproc', datetime.datetime(2018, 9, 21, 12, 1, 0)) self._CreateGomaLogFile(self.goma_dir, 'gomacc', datetime.datetime(2018, 9, 21, 12, 2, 0)) # Note that stats and counterz files are not created, but are specified in # the proto below. # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot, goma_dir=self.goma_dir, goma_log_dir=self.goma_out_dir, goma_stats_file='stats.binaryproto', goma_counterz_file='counterz.binaryproto') out_proto = self._OutputProto() self.PatchObject(sysroot_service, 'BuildPackages') rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) self.assertFalse(rc) self.assertFalse(out_proto.failed_packages) self.assertCountEqual(out_proto.goma_artifacts.log_files, [ 'compiler_proxy-subproc.host.log.INFO.20180921-120100.000000.gz', 'compiler_proxy.host.log.INFO.20180921-120000.000000.gz', 'gomacc.host.log.INFO.20180921-120200.000000.tar.gz' ]) self.assertFalse(out_proto.goma_artifacts.counterz_file) self.assertFalse(out_proto.goma_artifacts.stats_file)
def testNoPackageFailureOutputHandling(self): """Test failure handling without packages to report.""" # Prevent argument validation error. self.PatchObject(sysroot_lib.Sysroot, 'IsToolchainInstalled', return_value=True) in_proto = self._InputProto(build_target=self.build_target, sysroot_path=self.sysroot) out_proto = self._OutputProto() # Force error to be raised with no packages. error = sysroot_lib.PackageInstallError('Error', cros_build_lib.CommandResult(), packages=[]) self.PatchObject(sysroot_service, 'BuildPackages', side_effect=error) rc = sysroot_controller.InstallPackages(in_proto, out_proto, self.api_config) # All we really care about is it's not 0 or 2 (response available), so # test for that rather than a specific return code. self.assertTrue(rc) self.assertNotEqual( controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)