def testTestFailsInvalidArguments(self):
     """Test invalid arguments are correctly failed."""
     with self.assertRaises(image.InvalidArgumentError):
         image.Test(None, None)
     with self.assertRaises(image.InvalidArgumentError):
         image.Test('', '')
     with self.assertRaises(image.InvalidArgumentError):
         image.Test(None, self.outside_result_dir)
     with self.assertRaises(image.InvalidArgumentError):
         image.Test(self.board, None)
Пример #2
0
def Test(input_proto, output_proto, config):
  """Run image tests.

  Args:
    input_proto (image_pb2.ImageTestRequest): The input message.
    output_proto (image_pb2.ImageTestResult): The output message.
    config (api_config.ApiConfig): The API call config.
  """
  image_path = input_proto.image.path
  board = input_proto.build_target.name
  result_directory = input_proto.result.directory

  if not os.path.isfile(image_path) or not image_path.endswith('.bin'):
    cros_build_lib.Die(
        'The image.path must be an existing image file with a .bin extension.')

  if config.validate_only:
    return controller.RETURN_CODE_VALID_INPUT

  success = image.Test(board, result_directory, image_dir=image_path)
  output_proto.success = success

  if success:
    return controller.RETURN_CODE_SUCCESS
  else:
    return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
    def testTestInsideChrootNoImageDir(self):
        """Test image dir generation inside the chroot."""
        mocked_dir = '/foo/bar'
        self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=True)
        self.PatchObject(image_lib,
                         'GetLatestImageLink',
                         return_value=mocked_dir)
        image.Test(self.board, self.outside_result_dir)

        self.assertCommandContains([
            '--board', self.board, '--test_results_root',
            self.outside_result_dir, mocked_dir
        ])
    def testTestInsideChrootAllProvided(self):
        """Test behavior when inside the chroot and all paths provided."""
        self.PatchObject(cros_build_lib, 'IsInsideChroot', return_value=True)
        image.Test(self.board,
                   self.outside_result_dir,
                   image_dir=self.image_dir_inside)

        # Inside chroot shouldn't need to do any path manipulations, so we should
        # see exactly what we called it with.
        self.assertCommandContains([
            '--board', self.board, '--test_results_root',
            self.outside_result_dir, self.image_dir_inside
        ])