def testFirmwareExtractionScriptDoesNotExist(self): """Verify return value when firmware extraction script does not exist.""" os.path.exists(self.cros_fw).AndReturn(False) self.mox.ReplayAll() expected = None actual = cb_command_lib.ExtractFiles(self.cros_fw) self.assertEqual(expected, actual)
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)
def testExtractFilesSuccess(self): """Verify return value when all goes well.""" self.mock_cres.output = 'Files extracted to ' + self.fw_dir os.path.exists(self.cros_fw).AndReturn(True) cb_command_lib.RunCommand(mox.IsA(list), redirect_stdout=True).AndReturn(self.mock_cres) os.path.exists(self.fw_dir).AndReturn(True) self.mox.ReplayAll() self.assertEqual(self.fw_dir, cb_command_lib.ExtractFiles(self.cros_fw))
def testTmpDirectoryDoesNotExist(self): """Verify return value when extractor fails.""" self.mock_cres.output = 'Lying that files were extracted to ' + self.fw_dir os.path.exists(self.cros_fw).AndReturn(True) cb_command_lib.RunCommand(mox.IsA(list), redirect_stdout=True).AndReturn(self.mock_cres) os.path.exists(self.fw_dir).AndReturn(False) self.mox.ReplayAll() expected = None actual = cb_command_lib.ExtractFiles(self.cros_fw) self.assertEqual(expected, actual)
def testTmpDirectoryNotNamed(self): """Verify return value when extractor fails to tell where it extracted. This could be due to extraction script failing or changing output format. """ self.fw_dir = '' self.mock_cres.output = 'Not listing tmp results directory' os.path.exists(self.cros_fw).AndReturn(True) cb_command_lib.RunCommand(mox.IsA(list), redirect_stdout=True).AndReturn(self.mock_cres) self.mox.ReplayAll() expected = None actual = cb_command_lib.ExtractFiles(self.cros_fw) self.assertEqual(expected, actual)
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)
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)