def test_AddCareMapTxtForAbOta_zipOutput_careMapEntryExists(self): """Tests the case with ZIP output which already has care_map entry.""" image_paths = self._test_AddCareMapTxtForAbOta() output_file = common.MakeTempFile(suffix='.zip') with zipfile.ZipFile(output_file, 'w') as output_zip: # Create an existing META/care_map.txt entry. common.ZipWriteStr(output_zip, 'META/care_map.txt', 'dummy care_map.txt') # Request to add META/care_map.txt again. AddCareMapTxtForAbOta(output_zip, ['system', 'vendor'], image_paths) # The one under OPTIONS.input_tmp must have been replaced. care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') with open(care_map_file, 'r') as verify_fp: care_map = verify_fp.read() lines = care_map.split('\n') self.assertEqual(4, len(lines)) self.assertEqual('system', lines[0]) self.assertEqual(RangeSet("0-5 10-15").to_string_raw(), lines[1]) self.assertEqual('vendor', lines[2]) self.assertEqual(RangeSet("0-9").to_string_raw(), lines[3]) # The existing entry should be scheduled to be replaced. self.assertIn('META/care_map.txt', OPTIONS.replace_updated_files_list)
def test_AddCareMapTxtForAbOta_verityNotEnabled(self): """No care_map.txt should be generated if verity not enabled.""" image_paths = self._test_AddCareMapTxtForAbOta() OPTIONS.info_dict = {} AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') self.assertFalse(os.path.exists(care_map_file))
def test_AddCareMapTxtForAbOta(self): image_paths = self._test_AddCareMapTxtForAbOta() AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') expected = [ 'system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', RangeSet("0-9").to_string_raw() ] self._verifyCareMap(expected, care_map_file)
def test_AddCareMapTxtForAbOta(self): image_paths = self._test_AddCareMapTxtForAbOta() AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') with open(care_map_file, 'r') as verify_fp: care_map = verify_fp.read() lines = care_map.split('\n') self.assertEqual(4, len(lines)) self.assertEqual('system', lines[0]) self.assertEqual(RangeSet("0-5 10-15").to_string_raw(), lines[1]) self.assertEqual('vendor', lines[2]) self.assertEqual(RangeSet("0-9").to_string_raw(), lines[3])
def test_AddCareMapTxtForAbOta_withNonCareMapPartitions(self): """Partitions without care_map should be ignored.""" image_paths = self._test_AddCareMapTxtForAbOta() AddCareMapTxtForAbOta(None, ['boot', 'system', 'vendor', 'vbmeta'], image_paths) care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') expected = [ 'system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', RangeSet("0-9").to_string_raw() ] self._verifyCareMap(expected, care_map_file)
def test_AddCareMapTxtForAbOta_zipOutput(self): """Tests the case with ZIP output.""" image_paths = self._test_AddCareMapTxtForAbOta() output_file = common.MakeTempFile(suffix='.zip') with zipfile.ZipFile(output_file, 'w') as output_zip: AddCareMapTxtForAbOta(output_zip, ['system', 'vendor'], image_paths) with zipfile.ZipFile(output_file, 'r') as verify_zip: care_map = verify_zip.read('META/care_map.txt').decode('ascii') lines = care_map.split('\n') self.assertEqual(4, len(lines)) self.assertEqual('system', lines[0]) self.assertEqual(RangeSet("0-5 10-15").to_string_raw(), lines[1]) self.assertEqual('vendor', lines[2]) self.assertEqual(RangeSet("0-9").to_string_raw(), lines[3])
def test_AddCareMapTxtForAbOta_withAvb(self): """Tests the case for device using AVB.""" image_paths = self._test_AddCareMapTxtForAbOta() OPTIONS.info_dict = { 'avb_system_hashtree_enable': 'true', 'avb_vendor_hashtree_enable': 'true', } AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') expected = [ 'system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', RangeSet("0-9").to_string_raw() ] self._verifyCareMap(expected, care_map_file)
def test_AddCareMapTxtForAbOta_withAvb(self): """Tests the case for device using AVB.""" image_paths = self._test_AddCareMapTxtForAbOta() OPTIONS.info_dict = { 'avb_system_hashtree_enable': 'true', 'avb_vendor_hashtree_enable': 'true', } AddCareMapTxtForAbOta(None, ['system', 'vendor'], image_paths) care_map_file = os.path.join(OPTIONS.input_tmp, 'META', 'care_map.txt') with open(care_map_file, 'r') as verify_fp: care_map = verify_fp.read() lines = care_map.split('\n') self.assertEqual(4, len(lines)) self.assertEqual('system', lines[0]) self.assertEqual(RangeSet("0-5 10-15").to_string_raw(), lines[1]) self.assertEqual('vendor', lines[2]) self.assertEqual(RangeSet("0-9").to_string_raw(), lines[3])
def test_AddCareMapTxtForAbOta_zipOutput(self): """Tests the case with ZIP output.""" image_paths = self._test_AddCareMapTxtForAbOta() output_file = common.MakeTempFile(suffix='.zip') with zipfile.ZipFile(output_file, 'w') as output_zip: AddCareMapTxtForAbOta(output_zip, ['system', 'vendor'], image_paths) care_map_name = "META/care_map.txt" temp_dir = common.MakeTempDir() with zipfile.ZipFile(output_file, 'r') as verify_zip: self.assertTrue(care_map_name in verify_zip.namelist()) verify_zip.extract(care_map_name, path=temp_dir) expected = [ 'system', RangeSet("0-5 10-15").to_string_raw(), 'vendor', RangeSet("0-9").to_string_raw() ] self._verifyCareMap(expected, os.path.join(temp_dir, care_map_name))