Exemple #1
0
    def _InsertPayloadSignatures(self, signatures):
        """Put payload signatures into the payload they sign.

    Args:
      signatures: List of signatures for the payload.
    """
        logging.info('Inserting payload signatures into %s.',
                     self.signed_payload_file)

        signature_files = [
            utils.CreateTempFileWithContents(s, base_dir=self.work_dir)
            for s in signatures
        ]
        signature_file_names = [
            path_util.ToChrootPath(f.name) for f in signature_files
        ]

        cmd = [
            'delta_generator',
            '-in_file=' + path_util.ToChrootPath(self.payload_file),
            '-signature_file=' + ':'.join(signature_file_names),
            '-out_file=' + path_util.ToChrootPath(self.signed_payload_file),
            '-out_metadata_size_file=' +
            path_util.ToChrootPath(self.metadata_size_file)
        ]

        self._RunGeneratorCmd(cmd)
        self._ReadMetadataSizeFile()

        for f in signature_files:
            f.close()
Exemple #2
0
    def _GenerateHashes(self):
        """Generate a payload hash and a metadata hash.

    Works from an unsigned update payload.

    Returns:
      payload_hash as a string, metadata_hash as a string.
    """
        logging.info('Calculating hashes on %s.', self.payload_file)

        # How big will the signatures be.
        signature_sizes = [
            str(size) for size in self.PAYLOAD_SIGNATURE_SIZES_BYTES
        ]

        with tempfile.NamedTemporaryFile(dir=self.work_dir) as \
             payload_hash_file, \
             tempfile.NamedTemporaryFile(dir=self.work_dir) as \
             metadata_hash_file:

            cmd = [
                'brillo_update_payload', 'hash', '--unsigned_payload',
                path_util.ToChrootPath(self.payload_file),
                '--payload_hash_file',
                path_util.ToChrootPath(payload_hash_file.name),
                '--metadata_hash_file',
                path_util.ToChrootPath(metadata_hash_file.name),
                '--signature_size', ':'.join(signature_sizes)
            ]

            self._RunGeneratorCmd(cmd)
            return payload_hash_file.read(), metadata_hash_file.read()
    def _InsertSignaturesIntoPayload(self, payload_signatures,
                                     metadata_signatures):
        """Put payload and metadta signatures into the payload we sign.

    Args:
      payload_signatures: List of signatures as bytes for the payload.
      metadata_signatures: List of signatures as bytes for the metadata.
    """
        logging.info('Inserting payload and metadata signatures into %s.',
                     self.signed_payload_file)

        payload_signature_file_names = self._WriteSignaturesToFile(
            payload_signatures)
        metadata_signature_file_names = self._WriteSignaturesToFile(
            metadata_signatures)

        cmd = [
            'delta_generator',
            '--in_file=' + path_util.ToChrootPath(self.payload_file),
            '--payload_signature_file=' +
            ':'.join(payload_signature_file_names),
            '--metadata_signature_file=' +
            ':'.join(metadata_signature_file_names),
            '--out_file=' + path_util.ToChrootPath(self.signed_payload_file)
        ]

        self._RunGeneratorCmd(cmd)
Exemple #4
0
  def _RunAutotest(self):
    """Run an autotest using test_that.

    Returns:
      cros_build_lib.CommandResult object.
    """
    cmd = ['test_that']
    if self._device.board:
      cmd += ['--board', self._device.board]
    if self.results_dir:
      cmd += ['--results_dir', path_util.ToChrootPath(self.results_dir)]
    if self._device.private_key:
      cmd += ['--ssh_private_key',
              path_util.ToChrootPath(self._device.private_key)]
    if self._device.log_level == 'debug':
      cmd += ['--debug']
    if self.test_that_args:
      cmd += self.test_that_args[1:]
    cmd += [
        '--no-quickmerge',
        '--ssh_options', '-F /dev/null -i /dev/null',
    ]
    if self._device.ssh_port:
      cmd += ['%s:%d' % (self._device.device, self._device.ssh_port)]
    else:
      cmd += [self._device.device]
    cmd += self.autotest
    return cros_build_lib.run(cmd, dryrun=self.dryrun, enter_chroot=True)
    def _GenerateHashes(self):
        """Generate a payload hash and a metadata hash.

    Works from an unsigned update payload.

    Returns:
      Tuple of (payload_hash, metadata_hash) as bytes.
    """
        logging.info('Calculating hashes on %s.', self.payload_file)

        # How big will the signatures be.
        signature_sizes = [
            str(size) for size in self.PAYLOAD_SIGNATURE_SIZES_BYTES
        ]

        cmd = [
            'delta_generator',
            '--in_file=' + path_util.ToChrootPath(self.payload_file),
            '--signature_size=' + ':'.join(signature_sizes),
            '--out_hash_file=' +
            path_util.ToChrootPath(self.payload_hash_file),
            '--out_metadata_hash_file=' +
            path_util.ToChrootPath(self.metadata_hash_file)
        ]

        self._RunGeneratorCmd(cmd)

        return (osutils.ReadFile(self.payload_hash_file, mode='rb'),
                osutils.ReadFile(self.metadata_hash_file, mode='rb'))
    def GetPayloadPropertiesMap(self, payload_path):
        """Returns the payload's properties attributes in dictionary.

    The payload description contains a dictionary of key/values describing the
    characteristics of the payload. Look at
    update_engine/payload_generator/payload_properties.cc for the basic
    description of these values.

    In addition we add the following three keys to description file:

    "appid": The APP ID associated with this payload.
    "public_key": The public key the payload was signed with.

    Args:
      payload_path: The path to the payload file.

    Returns:
      A map of payload properties that can be directly used to create the
      payload.json file.
    """
        try:
            payload_path = path_util.ToChrootPath(payload_path)
        except ValueError:
            # Copy the payload inside the chroot and try with that path instead.
            logging.info(
                'The payload is not in the chroot. We will copy it there in '
                'order to get its properties.')
            copied_payload = os.path.join(self.work_dir, 'copied-payload.bin')
            shutil.copyfile(payload_path, copied_payload)
            payload_path = path_util.ToChrootPath(copied_payload)

        props_file = os.path.join(self.work_dir, 'properties.json')
        cmd = [
            'delta_generator', '--in_file=' + payload_path,
            '--properties_file=' + path_util.ToChrootPath(props_file),
            '--properties_format=json'
        ]
        self._RunGeneratorCmd(cmd)
        props_map = json.load(open(props_file))

        # delta_generator assigns empty string for signatures when the payload is
        # not signed. Replace it with 'None' so the json.dumps() writes 'null' as
        # the value to be consistent with the current scheme and not break GE.
        key = 'metadata_signature'
        if not props_map[key]:
            props_map[key] = None

        props_map['appid'] = self._appid

        # Add the public key if it exists.
        if self._public_key:
            props_map['public_key'] = base64.b64encode(
                osutils.ReadFile(self._public_key, mode='rb')).decode('utf-8')

        # We need the metadata size later for payload verification. Just grab it
        # from the properties file.
        self.metadata_size = props_map['metadata_size']

        return props_map
    def _CollectPGOProfiles(self):
        """Collect and upload PGO profiles for the board."""
        assert self.archive_path.startswith(self._build_root)

        # Look for profiles generated by instrumented LLVM
        out_chroot = os.path.abspath(os.path.join(self._build_root, 'chroot'))
        cov_data_location = 'build/%s/build/coverage_data' % self._current_board
        out_chroot_cov_data = os.path.join(out_chroot, cov_data_location)
        try:
            profiles_dirs = [
                root for root, _, _ in os.walk(out_chroot_cov_data)
                if os.path.basename(root) == 'raw_profiles'
            ]
            if not profiles_dirs:
                raise Exception('No profile directories found.')
            # Get out of chroot profile paths, and convert to in chroot paths
            profraws = [
                path_util.ToChrootPath(os.path.join(profiles_dir, f))
                for profiles_dir in profiles_dirs
                for f in os.listdir(profiles_dir)
            ]
            if not profraws:
                raise Exception(
                    'No profraw files found in profiles directory.')
        except:
            logging.info('Error: Not able to collect correct profiles.')
            raise

        # Create profdata file and make tarball
        in_chroot_path = path_util.ToChrootPath(self.archive_path)
        profdata_loc = os.path.join(in_chroot_path, self.PROFDATA)

        out_chroot_path = os.path.join(out_chroot, self.archive_path)
        out_profdata_loc = os.path.join(out_chroot_path, self.PROFDATA)

        # There can bee too many profraws to merge, put them as a list in the file
        # so that bash will not complain about arguments getting too long.
        profraw_list = os.path.join(in_chroot_path, 'profraw_list')
        out_profraw_list = os.path.join(out_chroot_path, 'profraw_list')

        with open(out_profraw_list, 'w') as f:
            f.write('\n'.join(profraws))

        self._merge_cmd = [
            'llvm-profdata', 'merge', '-output', profdata_loc, '-f',
            profraw_list
        ]
        cros_build_lib.run(self._merge_cmd,
                           cwd=self._build_root,
                           enter_chroot=True)

        cros_build_lib.CreateTarball(self.PROFDATA_TAR,
                                     cwd=out_chroot_path,
                                     inputs=[out_profdata_loc])

        # Upload profdata tarball
        self._upload_queue.put([self.PROFDATA_TAR])
  def _RunTest(self, test, remote, log_directory_base, fail_directory_base):
    """Runs a test or a suite of tests on a given remote.

    Runs a test target, whether an individual test or a suite of tests, with
    'test_that'.

    Args:
      test: The test or suite to run.
      remote: The hostname of the remote DUT.
      log_directory_base: The base directory to store test logs. A sub directory
          specific to this test will be created there.
      fail_directory_base: The base directory to store test logs in case of a
          test failure.

    Returns:
      test: Same as |test|. This is useful when the caller wants to correlate
          results to the test name.
      percent_passed: Pass rate.
      test_report: Content of the test report generated by test_that.
    """
    log_directory, _ = self._GetResultsDirectoryForTest(
        test, log_directory_base, fail_directory_base)
    log_directory_in_chroot = log_directory.rpartition('chroot')[2]

    # Copy GCE key file in a temporary file inside the chroot and
    # make sure to remove it before return.
    with tempfile.NamedTemporaryFile(
        dir=path_util.FromChrootPath('/tmp')) as gce_key_copy:
      shutil.copy(self.json_key_file, gce_key_copy.name)

      args = 'gce_project=%s gce_zone=%s gce_instance=%s gce_key_file=%s' % (
          self.gce_context.project, self.gce_context.zone, self.instances[test],
          path_util.ToChrootPath(gce_key_copy.name))

      cmd = ['test_that', '-b', self.board, '--no-quickmerge',
             '--results_dir=%s' % log_directory_in_chroot, remote, test,
             '--args=%s' % args]
      if self.ssh_private_key is not None:
        cmd.append('--ssh_private_key=%s' %
                   path_util.ToChrootPath(self.ssh_private_key))

      result = cros_build_lib.RunCommand(cmd, error_code_ok=True,
                                         enter_chroot=True,
                                         redirect_stdout=True,
                                         cwd=constants.CROSUTILS_DIR)
      percent_passed = self.ParseGeneratedTestOutput(result.output)
      test_report = self._GetTestReport(log_directory)

      # Returns the summarized test_report as it is more useful than the full
      # output, plus the entire log will always be linked in the failure report.
      return test, percent_passed, test_report
 def testPerformStage(self):
   """Tests that we correctly run test-image script."""
   stage = self.ConstructStage()
   stage.PerformStage()
   cmd = [
       'sudo', '--',
       os.path.join(self.build_root, 'chromite', 'bin', 'test_image'),
       '--board', self._current_board,
       '--test_results_root',
       path_util.ToChrootPath(os.path.join(self._test_root,
                                           'image_test_results')),
       path_util.ToChrootPath(stage.GetImageDirSymlink()),
   ]
   self.assertCommandContains(cmd)
 def testRunTestImage(self):
   """Verifies RunTestImage calls into test-image script properly."""
   commands.RunTestImage(self._build, self._board, self._image_dir,
                         self._result_dir)
   self.assertCommandContains(
       [
           'sudo', '--',
           os.path.join(self._build, 'chromite', 'bin', 'test_image'),
           '--board', self._board,
           '--test_results_root',
           path_util.ToChrootPath(self._result_dir),
           path_util.ToChrootPath(self._image_dir),
       ],
       enter_chroot=True,
   )
Exemple #11
0
def _CreateVMImage(src_dir, dest_dir):
    """Creates a VM image from a given chromiumos image.

  Args:
    src_dir: Path to the directory containing (non-VM) image. Defaults to None
        to use the latest image for the board.
    dest_dir: Path to the directory where the VM image should be written.

  Returns:
    The path of the created VM image.
  """
    # image_to_vm.sh only runs in chroot, but src_dir / dest_dir may not be
    # reachable from chroot. Also, image_to_vm.sh needs all the contents of
    # src_dir to work correctly (it silently does the wrong thing if some files
    # are missing).
    # So, create a tempdir reachable from chroot, copy everything to that path,
    # create vm image there and finally move it all to dest_dir.
    with chroot_util.TempDirInChroot() as tempdir:
        logging.debug('Copying images from %s to %s.', src_dir, tempdir)
        osutils.CopyDirContents(src_dir, tempdir)
        # image_to_vm.sh doesn't let us provide arbitrary names for the input image.
        # Instead, it picks the name based on whether we pass in --test_image or not
        # (and doesn't use that flag for anything else).
        cmd = [
            path_util.ToChrootPath(
                os.path.join(constants.CROSUTILS_DIR, 'image_to_vm.sh')),
            '--from=%s' % path_util.ToChrootPath(tempdir),
            '--disk_layout=16gb-rootfs',
            '--test_image',
        ]
        try:
            cros_build_lib.run(cmd,
                               enter_chroot=True,
                               cwd=constants.SOURCE_ROOT)
        except cros_build_lib.RunCommandError as e:
            raise SetupError('Failed to create VM image for %s: %s' %
                             (src_dir, e))

        # Preserve most content, although we should need only the generated VM
        # image. Other files like boot.desc might be needed elsewhere, but the
        # source images should no longer be needed.
        osutils.SafeUnlink(os.path.join(tempdir, constants.BASE_IMAGE_BIN),
                           sudo=True)
        osutils.SafeUnlink(os.path.join(tempdir, constants.TEST_IMAGE_BIN),
                           sudo=True)
        osutils.CopyDirContents(tempdir, dest_dir)
    # The exact name of the output image is hard-coded in image_to_vm.sh
    return os.path.join(dest_dir, constants.VM_IMAGE_BIN)
Exemple #12
0
def RunInsideChroot(command=None, chroot_args=None):
    """Restart the current command inside the chroot.

  This method is only valid for any code that is run via ScriptWrapperMain.
  It allows proper cleanup of the local context by raising an exception handled
  in ScriptWrapperMain.

  Args:
    command: An instance of CliCommand to be restarted inside the chroot.
             |command| can be None if you do not wish to modify the log_level.
    chroot_args: List of command-line arguments to pass to cros_sdk, if invoked.
  """
    if cros_build_lib.IsInsideChroot():
        return

    # Produce the command line to execute inside the chroot.
    argv = sys.argv[:]
    argv[0] = path_util.ToChrootPath(argv[0])

    # Set log-level of cros_sdk to be same as log-level of command entering the
    # chroot.
    if chroot_args is None:
        chroot_args = []
    if command is not None:
        chroot_args += ['--log-level', command.options.log_level]

    raise ChrootRequiredError(argv, chroot_args)
Exemple #13
0
def CreateVMImage(image, board=None, full=True):
    """Returns the path of the image built to run in a VM.

  VM returned is a test image that can run full update testing on it.  This
  method does not return a new image if one already existed before.

  Args:
    image: Path to the image.
    board: Board that the image was built with. If None, attempts to use the
           configured default board.
    full: If the vm image doesn't exist, create a "full" one which supports AU.
  """
    vm_image_path = '%s/chromiumos_qemu_image.bin' % os.path.dirname(image)
    if not os.path.exists(vm_image_path):
        logging.info('Creating %s', vm_image_path)
        cmd = [
            './image_to_vm.sh',
            '--from=%s' % path_util.ToChrootPath(os.path.dirname(image)),
            '--test_image'
        ]
        if full:
            cmd.extend(['--disk_layout', '2gb-rootfs-updatable'])
        if board:
            cmd.extend(['--board', board])

        cros_build_lib.RunCommand(cmd,
                                  enter_chroot=True,
                                  cwd=constants.SOURCE_ROOT)

    assert os.path.exists(vm_image_path), 'Failed to create the VM image.'
    return vm_image_path
    def WipePayloadCache(cls,
                         devserver_bin='start_devserver',
                         static_dir=None):
        """Cleans up devserver cache of payloads.

    This isn't necessary for chrome checkouts.

    Args:
      devserver_bin: path to the devserver binary.
      static_dir: path to use as the static directory of the devserver instance.
    """
        if path_util.DetermineCheckout(
        ).type == path_util.CHECKOUT_TYPE_GCLIENT:
            return

        logging.info('Cleaning up previously generated payloads.')
        cmd = [devserver_bin, '--clear_cache', '--exit']
        if static_dir:
            cmd.append('--static_dir=%s' % path_util.ToChrootPath(static_dir))

        cros_build_lib.sudo_run(cmd,
                                enter_chroot=True,
                                print_cmd=False,
                                stderr=subprocess.STDOUT,
                                stdout=True,
                                cwd=constants.SOURCE_ROOT)
        def GeneratePayload(payload, log_file):
            """Returns the error code from generating an update with the devserver."""
            # Base command.
            command = ['start_devserver', '--pregenerate_update', '--exit']

            in_chroot_key = in_chroot_base = None
            in_chroot_target = path_util.ToChrootPath(payload.target)
            if payload.base:
                in_chroot_base = path_util.ToChrootPath(payload.base)

            if payload.key:
                in_chroot_key = path_util.ToChrootPath(payload.key)

            command.append('--image=%s' % in_chroot_target)
            if payload.base:
                command.append('--src_image=%s' % in_chroot_base)
            if payload.key:
                command.append('--private_key=%s' % in_chroot_key)

            if payload.base:
                debug_message = 'delta payload from %s to %s' % (
                    payload.base, payload.target)
            else:
                debug_message = 'full payload to %s' % payload.target

            if payload.for_vm:
                debug_message += ' and not patching the kernel.'

            if in_chroot_key:
                debug_message = 'Generating a signed %s' % debug_message
            else:
                debug_message = 'Generating an unsigned %s' % debug_message

            logging.info(debug_message)
            try:
                with timeout_util.Timeout(constants.MAX_TIMEOUT_SECONDS):
                    cros_build_lib.SudoRunCommand(command,
                                                  log_stdout_to_file=log_file,
                                                  combine_stdout_stderr=True,
                                                  enter_chroot=True,
                                                  print_cmd=False,
                                                  cwd=constants.SOURCE_ROOT)
            except (timeout_util.TimeoutError, cros_build_lib.RunCommandError):
                # Print output first, then re-raise the exception.
                if os.path.isfile(log_file):
                    logging.error(osutils.ReadFile(log_file))
                raise
    def _VerifyPayload(self):
        """Checks the integrity of the generated payload.

    Raises:
      PayloadVerificationError when the payload fails to verify.
    """
        if self.signer:
            payload_file_name = self.signed_payload_file
            metadata_sig_file_name = self.metadata_signature_file
        else:
            payload_file_name = self.payload_file
            metadata_sig_file_name = None

        is_delta = bool(self.payload.src_image)

        logging.info('Applying %s payload and verifying result',
                     'delta' if is_delta else 'full')

        # This command checks both the payload integrity and applies the payload
        # to source and target partitions.
        cmd = [
            'check_update_payload',
            path_util.ToChrootPath(payload_file_name), '--check', '--type',
            'delta' if is_delta else 'full', '--disabled_tests',
            'move-same-src-dst-block', '--part_names'
        ]
        cmd.extend(self.partition_names)
        cmd += ['--dst_part_paths']
        cmd.extend(path_util.ToChrootPath(x) for x in self.tgt_partitions)
        if metadata_sig_file_name:
            cmd += [
                '--meta-sig',
                path_util.ToChrootPath(metadata_sig_file_name)
            ]

        cmd += ['--metadata-size', str(self.metadata_size)]

        if is_delta:
            cmd += ['--src_part_paths']
            cmd.extend(path_util.ToChrootPath(x) for x in self.src_partitions)

        # We signed it with the private key, now verify it with the public key.
        if self._public_key:
            cmd += ['--key', path_util.ToChrootPath(self._public_key)]

        self._RunGeneratorCmd(cmd)
Exemple #17
0
def _RunTestSuiteUsingChromite(board,
                               image_path,
                               results_dir,
                               test_config,
                               allow_chrome_crashes,
                               ssh_private_key=None,
                               ssh_port=9228):
    """Runs the test harness suite using the chromite code path."""
    image_dir = os.path.dirname(image_path)
    vm_image_path = os.path.join(image_dir, constants.VM_IMAGE_BIN)

    cmd = [
        'cros_run_test',
        '--debug',
        '--board=%s' % board,
        '--image-path=%s' % path_util.ToChrootPath(vm_image_path),
        '--ssh-port=%s' % ssh_port,
        '--autotest=suite:%s' % test_config.test_suite,
        '--results-dir=%s' % results_dir,
    ]

    if allow_chrome_crashes:
        cmd.append('--test_that-args=--allow-chrome-crashes')

    if ssh_private_key is not None:
        cmd.append('--private-key=%s' %
                   path_util.ToChrootPath(ssh_private_key))

    # Give tests 10 minutes to clean up before shutting down.
    result = cros_build_lib.run(cmd,
                                check=False,
                                kill_timeout=10 * 60,
                                enter_chroot=True)
    if result.returncode:
        results_dir_in_chroot = os.path.join(constants.SOURCE_ROOT,
                                             constants.DEFAULT_CHROOT_DIR,
                                             results_dir.lstrip('/'))
        if os.path.exists(results_dir_in_chroot):
            error = '%s exited with code %d' % (' '.join(cmd),
                                                result.returncode)
            with open(results_dir_in_chroot + '/failed_test_command',
                      'w') as failed:
                failed.write(error)

        raise failures_lib.TestFailure('** VMTests failed with code %d **' %
                                       result.returncode)
Exemple #18
0
  def GetChrootExtraEnv(self):
    """Extra env vars set to use goma inside chroot."""
    # Note: GOMA_DIR and GOMA_SERVICE_ACCOUNT_JSON_FILE in chroot is hardcoded.
    # Please see also enter_chroot.sh.
    goma_dir = os.path.join('/home', os.environ.get('USER'), 'goma')
    result = dict(
        Goma._DEFAULT_ENV_VARS,
        GOMA_DIR=goma_dir,
        GOMA_TMP_DIR=path_util.ToChrootPath(self.goma_tmp_dir),
        GLOG_log_dir=path_util.ToChrootPath(self.goma_log_dir))
    if self.goma_client_json:
      result['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = (
          '/creds/service_accounts/service-account-goma-client.json')

    if self.goma_cache:
      result['GOMA_CACHE_DIR'] = os.path.join(
          goma_dir, os.path.relpath(self.goma_cache, self.goma_dir))
    return result
 def _RunUnitTest(self):
     """Run chromeos_config_unittest to confirm a clean scheduler config."""
     logging.debug(
         'Running chromeos_config_unittest, to confirm sane state.')
     test_path = path_util.ToChrootPath(
         os.path.join(constants.CHROMITE_DIR, 'config',
                      'chromeos_config_unittest'))
     cmd = ['cros_sdk', '--', test_path]
     cros_build_lib.run(cmd, cwd=constants.CHROMITE_DIR)
def UpdateManifest(ebuild):
  """Update the manifest for an ebuild.

  Args:
    ebuild: Path to the ebuild to update the manifest for.
  """
  ebuild = path_util.ToChrootPath(os.path.realpath(ebuild))
  cros_build_lib.RunCommand(['ebuild', ebuild, 'manifest'], quiet=True,
                            enter_chroot=True)
    def GetHashSignatures(self, hashes, keysets=('update_signer', )):
        """See SignerPayloadsClientGoogleStorage._GetHashsignatures().

    Instead of waiting for the signers to sign the hashes, we just sign then and
    copy them to the requested files. It doesn't really support keysets at this
    point.

    Args:
      Look at SignerPayloadsClientGoogleStorage.GetHashsignatures()

    Returns:
      Look at SignerPayloadsClientGoogleStorage.GetHashsignatures()
    """
        logging.info('Signing the hashes with unoffical keys.')

        key_path = os.path.join(self._work_dir, 'update_key.pem')
        filelib.Copy(self._private_key, key_path)

        signatures = []
        for h in hashes:
            hash_hex = binascii.hexlify(h)
            hash_file = os.path.join(self._work_dir, 'hash-%s.bin' % hash_hex)
            signature_file = os.path.join(self._work_dir,
                                          'signature-%s.bin' % hash_hex)
            osutils.WriteFile(hash_file, h, mode='wb')

            sign_script = path_util.ToChrootPath(
                os.path.join(
                    constants.SOURCE_ROOT,
                    'src/platform/vboot_reference/scripts/image_signing/',
                    'sign_official_build.sh'))

            cros_build_lib.run([
                sign_script, 'update_payload',
                path_util.ToChrootPath(hash_file),
                path_util.ToChrootPath(self._work_dir),
                path_util.ToChrootPath(signature_file)
            ],
                               enter_chroot=True)

            signatures.append([osutils.ReadFile(signature_file, mode='rb')])

        return signatures
    def _RunLegacyUnitTest(self):
        """Run chromeos_config_unittest on top of the changes."""
        logging.debug('Running chromeos_config_unittest')
        test_path = path_util.ToChrootPath(
            os.path.join(self.chromite_dir, self.config_dir,
                         'chromeos_config_unittest'))

        # Because of --update, this updates our generated files.
        cmd = ['cros_sdk', '--', test_path, '--update']
        cros_build_lib.run(cmd, cwd=os.path.dirname(self.chromite_dir))
Exemple #23
0
def IsExt4Image(image):
  """Returns true if the image is detected to be ext2/ext3/ext4."""
  try:
    # -l: Listing the content of the superblock structure.
    cros_build_lib.sudo_run(
        ['tune2fs', '-l', path_util.ToChrootPath(image)], stdout=True,
        enter_chroot=True)
    return True
  except cros_build_lib.RunCommandError:
    return False
Exemple #24
0
  def PerformStage(self):
    """Run the CIDB integration tests."""
    buildroot_chromite = path_util.ToChrootPath(
        os.path.join(self._build_root, 'chromite'))

    cmd = [
        os.path.join(buildroot_chromite, 'lib', 'cidb_integration_test'),
        '-v',
        # '--network'  Doesn't work in a build, yet.
    ]
    cros_build_lib.RunCommand(cmd, enter_chroot=True)
Exemple #25
0
def IsSquashfsImage(image):
    """Returns true if the image is detected to be Squashfs."""
    try:
        # -s: Display file system superblock.
        cros_build_lib.run(['unsquashfs', '-s',
                            path_util.ToChrootPath(image)],
                           redirect_stdout=True,
                           enter_chroot=True)
        return True
    except cros_build_lib.RunCommandError:
        return False
Exemple #26
0
 def _BuildAndArchiveChromeSysroot(self):
   """Generate and upload sysroot for building Chrome."""
   assert self.archive_path.startswith(self._build_root)
   extra_env = {}
   if self._run.config.useflags:
     extra_env['USE'] = ' '.join(self._run.config.useflags)
   in_chroot_path = path_util.ToChrootPath(self.archive_path)
   cmd = ['cros_generate_sysroot', '--out-dir', in_chroot_path, '--board',
          self._current_board, '--package', constants.CHROME_CP]
   cros_build_lib.RunCommand(cmd, cwd=self._build_root, enter_chroot=True,
                             extra_env=extra_env)
   self._upload_queue.put([constants.CHROME_SYSROOT_TAR])
Exemple #27
0
  def PerformStage(self):
    """Run the chromite unittests."""
    buildroot_chromite = path_util.ToChrootPath(
        os.path.join(self._build_root, 'chromite'))

    cmd = [
        os.path.join(buildroot_chromite, 'cbuildbot', 'run_tests'),
        # TODO(crbug.com/682381): When tests can pass, add '--network',
    ]
    # TODO: Remove enter_chroot=True when we have virtualenv support.
    # Until then, we skip all chromite tests outside the chroot.
    cros_build_lib.RunCommand(cmd, enter_chroot=True)
Exemple #28
0
    def testCollectPGOProfiles(self):
        """Test that the sysroot generation was called correctly."""
        stage = self.ConstructStage()

        # No profiles directory
        with self.assertRaises(Exception) as msg:
            stage._CollectPGOProfiles()
        self.assertEqual('No profile directories found.', str(msg.exception))

        # Create profiles directory
        cov_path = 'build/%s/build/coverage_data' % stage._current_board
        out_cov_path = os.path.abspath(
            os.path.join(self.build_root, 'chroot', cov_path))
        os.makedirs(os.path.join(out_cov_path, 'raw_profiles'))

        # No profraw files
        with self.assertRaises(Exception) as msg:
            stage._CollectPGOProfiles()
        self.assertEqual('No profraw files found in profiles directory.',
                         str(msg.exception))

        # Create profraw file
        profraw = os.path.join(out_cov_path, 'raw_profiles', 'a.profraw')
        with open(profraw, 'a') as f:
            f.write('123')

        # Check uploading tarball
        self.PatchObject(stage._upload_queue, 'put', autospec=True)
        stage._CollectPGOProfiles()
        llvm_profdata = path_util.ToChrootPath(
            os.path.join(stage.archive_path, 'llvm.profdata'))
        profraw_list = path_util.ToChrootPath(
            os.path.join(stage.archive_path, 'profraw_list'))
        self.assertEqual([
            'llvm-profdata', 'merge', '-output', llvm_profdata, '-f',
            profraw_list
        ], stage._merge_cmd)
        tarball = stage.PROFDATA_TAR
        stage._upload_queue.put.assert_called_with([tarball])
Exemple #29
0
    def _GenerateUnsignedPayload(self):
        """Generate the unsigned delta into self.payload_file."""
        # Note that the command run here requires sudo access.

        logging.info('Generating unsigned payload as %s', self.payload_file)

        tgt_image = self.payload.tgt_image
        cmd = [
            'cros_generate_update_payload', '--output',
            path_util.ToChrootPath(self.payload_file), '--image',
            path_util.ToChrootPath(self.tgt_image_file), '--channel',
            tgt_image.channel, '--board', tgt_image.board, '--version',
            tgt_image.version, '--kern_path',
            path_util.ToChrootPath(self.tgt_partitions[self._KERNEL]),
            '--root_path',
            path_util.ToChrootPath(self.tgt_partitions[self._ROOTFS])
        ]
        cmd += self._BuildArg('--key', tgt_image, 'key', default='test')
        cmd += self._BuildArg('--build_channel',
                              tgt_image,
                              'image_channel',
                              default=tgt_image.channel)
        cmd += self._BuildArg('--build_version',
                              tgt_image,
                              'image_version',
                              default=tgt_image.version)

        if self.payload.src_image:
            src_image = self.payload.src_image
            cmd += [
                '--src_image',
                path_util.ToChrootPath(self.src_image_file), '--src_channel',
                src_image.channel, '--src_board', src_image.board,
                '--src_version', src_image.version, '--src_kern_path',
                path_util.ToChrootPath(self.src_partitions[self._KERNEL]),
                '--src_root_path',
                path_util.ToChrootPath(self.src_partitions[self._ROOTFS])
            ]
            cmd += self._BuildArg('--src_key',
                                  src_image,
                                  'key',
                                  default='test')
            cmd += self._BuildArg('--src_build_channel',
                                  src_image,
                                  'image_channel',
                                  default=src_image.channel)
            cmd += self._BuildArg('--src_build_version',
                                  src_image,
                                  'image_version',
                                  default=src_image.version)

        self._RunGeneratorCmd(cmd)
        self._CheckPartitionFiles()
 def BuildAndArchiveDeltaSysroot(self):
   """Generate and upload delta sysroot for initial build_packages."""
   extra_env = {}
   if self._run.config.useflags:
     extra_env['USE'] = ' '.join(self._run.config.useflags)
   in_chroot_path = path_util.ToChrootPath(self.archive_path)
   cmd = ['generate_delta_sysroot', '--out-dir', in_chroot_path,
          '--board', self._current_board]
   # TODO(mtennant): Make this condition into one run param.
   if not self._run.options.tests:
     cmd.append('--skip-tests')
   cros_build_lib.RunCommand(cmd, cwd=self._build_root, enter_chroot=True,
                             extra_env=extra_env)
   self._upload_queue.put([constants.DELTA_SYSROOT_TAR])