コード例 #1
0
  def testImageCorrupted(self):
    """Verify error when firmware extraction corrupts SSD image.

    The primary motivator is potentially calling mount_gpt_image.sh improperly.
    """
    cb_command_lib.CheckEnvironment(self.image_name,
                                    self.firmware_dest,
                                    self.mount_point).AndReturn(True)
    cb_command_lib.RunCommand(mox.IsA(list))
    os.path.exists(self.mount_point).AndReturn(True)
    os.listdir(self.mount_point).AndReturn(['stuff', 'is', 'here'])
    cb_command_lib.ListFirmware(
        mox.IsA(str), mox.IsA(str), self.board).AndReturn(
            dict(bios='_ignore', ec='_ignore', ec2='_ignore'))
    cb_command_lib.ExtractFiles(mox.IsA(str)).AndReturn('/tmp/firmware_dir')
    for i in range(3):  # Test for alex only
      os.path.exists(mox.IsA(str)).AndReturn(True)
      shutil.copy(mox.IsA(str), mox.IsA(str))
    shutil.copy(mox.IsA(str), mox.IsA(str))
    cb_command_lib.RunCommand(mox.IsA(list))
    cb_command_lib.CheckMd5(mox.IsA(str), mox.IsA(str)).AndReturn(False)
    self.mox.ReplayAll()
    self.assertRaises(cb_constants.BundlingError,
                      cb_command_lib.ExtractFirmware,
                      self.image_name,
                      self.firmware_dest,
                      self.mount_point,
                      self.board)
コード例 #2
0
 def testEnvironmentIsGood(self):
   """Verify return value when environment is all good."""
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts')
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   self.mox.ReplayAll()
   self.assertTrue(cb_command_lib.CheckEnvironment(self.image_name,
                                                   self.firmware_dest,
                                                   self.mount_point))
コード例 #3
0
 def testNotInScriptsDirectory(self):
   """Verify return value when script not run from <cros_root/src/scripts."""
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts/lib')
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   self.mox.ReplayAll()
   self.assertFalse(cb_command_lib.CheckEnvironment(self.image_name,
                                                    self.firmware_dest,
                                                    self.mount_point))
コード例 #4
0
 def testNoMountPoint(self):
   """Verify return value when mount point not given or does not exist."""
   self.mount_point = ''
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts')
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   self.mox.ReplayAll()
   self.assertFalse(cb_command_lib.CheckEnvironment(self.image_name,
                                                    self.firmware_dest,
                                                    self.mount_point))
コード例 #5
0
 def testBadSsdName(self):
   """Verify return value when given ssd image has bad name."""
   self.image = tempfile.NamedTemporaryFile(suffix='recovery.bin')
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts')
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   self.mox.ReplayAll()
   self.assertFalse(cb_command_lib.CheckEnvironment(self.image_name,
                                                    self.firmware_dest,
                                                    self.mount_point))
コード例 #6
0
 def testNoUudecode(self):
   """Verify return value when uudecode not present."""
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts')
   self.mock_cres.output = ''
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   self.mox.ReplayAll()
   self.assertFalse(cb_command_lib.CheckEnvironment(self.image_name,
                                                    self.firmware_dest,
                                                    self.mount_point))
コード例 #7
0
 def testMountPointNotEmpty(self):
   """Verify return value when provided mount point is not empty."""
   self.mox.StubOutWithMock(os, 'listdir')
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts')
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   os.listdir(self.mount_point).AndReturn(['there_is_a_file'])
   self.mox.ReplayAll()
   self.assertFalse(cb_command_lib.CheckEnvironment(self.image_name,
                                                    self.firmware_dest,
                                                    self.mount_point))
コード例 #8
0
 def testFirmwareDestinationNotWritable(self):
   """Verify return value when firmware destination directory not writable."""
   self.mox.StubOutWithMock(os, 'access')
   os.getcwd().AndReturn('/home/$USER/chromiumos/src/scripts')
   cb_command_lib.RunCommand(mox.IsA(list),
                             redirect_stdout=True).AndReturn(self.mock_cres)
   os.access(self.firmware_dest, os.W_OK).AndReturn(False)
   self.mox.ReplayAll()
   self.assertFalse(cb_command_lib.CheckEnvironment(self.image_name,
                                                    self.firmware_dest,
                                                    self.mount_point))
コード例 #9
0
 def testCheckEnvironmentBad(self):
   """Verify error when environment check fails."""
   cb_command_lib.CheckEnvironment(self.image_name,
                                   self.firmware_dest,
                                   self.mount_point).AndReturn(False)
   self.mox.ReplayAll()
   self.assertRaises(cb_constants.BundlingError,
                     cb_command_lib.ExtractFirmware,
                     self.image_name,
                     self.firmware_dest,
                     self.mount_point,
                     self.board)
コード例 #10
0
 def testMountSsdFailsMountPointNotThere(self):
   """Verify error when SSD image is not mounted."""
   cb_command_lib.CheckEnvironment(self.image_name,
                                   self.firmware_dest,
                                   self.mount_point).AndReturn(True)
   cb_command_lib.RunCommand(mox.IsA(list))
   os.path.exists(self.mount_point).AndReturn(False)
   cb_command_lib.RunCommand(mox.IsA(list))
   self.mox.ReplayAll()
   self.assertRaises(cb_constants.BundlingError,
                     cb_command_lib.ExtractFirmware,
                     self.image_name,
                     self.firmware_dest,
                     self.mount_point,
                     self.board)
コード例 #11
0
 def testFirmwareExtractionFails(self):
   """Verify error when firmware extraction fails."""
   cb_command_lib.CheckEnvironment(self.image_name,
                                   self.firmware_dest,
                                   self.mount_point).AndReturn(True)
   cb_command_lib.RunCommand(mox.IsA(list))
   os.path.exists(self.mount_point).AndReturn(True)
   os.listdir(self.mount_point).AndReturn(['stuff', 'is', 'here'])
   cb_command_lib.ListFirmware(
       mox.IsA(str), mox.IsA(str), self.board).AndReturn(
           ('_ignore', '_ignore', '_ignore'))
   cb_command_lib.ExtractFiles(mox.IsA(str))
   cb_command_lib.RunCommand(mox.IsA(list))
   self.mox.ReplayAll()
   self.assertRaises(cb_constants.BundlingError,
                     cb_command_lib.ExtractFirmware,
                     self.image_name,
                     self.firmware_dest,
                     self.mount_point,
                     self.board)
コード例 #12
0
 def testExtractFirmwareSuccess(self):
   """Verify behavior of quiet success when all goes well."""
   cb_command_lib.CheckEnvironment(self.image_name,
                                   self.firmware_dest,
                                   self.mount_point).AndReturn(True)
   cb_command_lib.RunCommand(mox.IsA(list))
   os.path.exists(self.mount_point).AndReturn(True)
   os.listdir(self.mount_point).AndReturn(['stuff', 'is', 'here'])
   cb_command_lib.ListFirmware(
       mox.IsA(str), mox.IsA(str), self.board).AndReturn(
           dict(ec='ec_name', ec2='ec2_name', bios='bios_name'))
   cb_command_lib.ExtractFiles(mox.IsA(str)).AndReturn('/tmp/firmware_dir')
   for i in range(3):  # Test for alex only
     os.path.exists(mox.IsA(str)).AndReturn(True)
     shutil.copy(mox.IsA(str), mox.IsA(str))
   shutil.copy(mox.IsA(str), mox.IsA(str))
   cb_command_lib.RunCommand(mox.IsA(list))
   cb_command_lib.CheckMd5(mox.IsA(str), mox.IsA(str)).AndReturn(True)
   self.mox.ReplayAll()
   cb_command_lib.ExtractFirmware(self.image_name,
                                  self.firmware_dest,
                                  self.mount_point,
                                  self.board)