Merge "releasetools: Rename test names in test_verity_utils.py."

This commit is contained in:
Treehugger Robot 2018-10-12 05:58:24 +00:00 committed by Gerrit Code Review
commit f77560ec12
2 changed files with 21 additions and 26 deletions

View File

@ -18,7 +18,6 @@
from __future__ import print_function from __future__ import print_function
import os
import os.path import os.path
import unittest import unittest
@ -26,11 +25,14 @@ import build_image
import common import common
import sparse_img import sparse_img
import test_utils import test_utils
import verity_utils
from rangelib import RangeSet from rangelib import RangeSet
from verity_utils import (
CreateHashtreeInfoGenerator, HashtreeInfo,
VerifiedBootVersion1HashtreeInfoGenerator)
class VerityUtilsTest(unittest.TestCase): class VerifiedBootVersion1HashtreeInfoGeneratorTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.testdata_dir = test_utils.get_testdata_dir() self.testdata_dir = test_utils.get_testdata_dir()
@ -88,33 +90,33 @@ class VerityUtilsTest(unittest.TestCase):
return output_file return output_file
def test_VerifiedBootVersion1HashtreeInfoGenerator_create(self): def test_CreateHashtreeInfoGenerator(self):
image_file = sparse_img.SparseImage(self._generate_image()) image_file = sparse_img.SparseImage(self._generate_image())
generator = verity_utils.CreateHashtreeInfoGenerator( generator = CreateHashtreeInfoGenerator(
'system', image_file, self.prop_dict) 'system', image_file, self.prop_dict)
self.assertEqual( self.assertEqual(
verity_utils.VerifiedBootVersion1HashtreeInfoGenerator, type(generator)) VerifiedBootVersion1HashtreeInfoGenerator, type(generator))
self.assertEqual(self.partition_size, generator.partition_size) self.assertEqual(self.partition_size, generator.partition_size)
self.assertTrue(generator.fec_supported) self.assertTrue(generator.fec_supported)
def test_VerifiedBootVersion1HashtreeInfoGenerator_decomposeImage(self): def test_DecomposeSparseImage(self):
image_file = sparse_img.SparseImage(self._generate_image()) image_file = sparse_img.SparseImage(self._generate_image())
generator = verity_utils.VerifiedBootVersion1HashtreeInfoGenerator( generator = VerifiedBootVersion1HashtreeInfoGenerator(
self.partition_size, 4096, True) self.partition_size, 4096, True)
generator.DecomposeSparseImage(image_file) generator.DecomposeSparseImage(image_file)
self.assertEqual(991232, generator.filesystem_size) self.assertEqual(991232, generator.filesystem_size)
self.assertEqual(12288, generator.hashtree_size) self.assertEqual(12288, generator.hashtree_size)
self.assertEqual(32768, generator.metadata_size) self.assertEqual(32768, generator.metadata_size)
def test_VerifiedBootVersion1HashtreeInfoGenerator_parseHashtreeMetadata( def test_ParseHashtreeMetadata(self):
self):
image_file = sparse_img.SparseImage(self._generate_image()) image_file = sparse_img.SparseImage(self._generate_image())
generator = verity_utils.VerifiedBootVersion1HashtreeInfoGenerator( generator = VerifiedBootVersion1HashtreeInfoGenerator(
self.partition_size, 4096, True) self.partition_size, 4096, True)
generator.DecomposeSparseImage(image_file) generator.DecomposeSparseImage(image_file)
# pylint: disable=protected-access
generator._ParseHashtreeMetadata() generator._ParseHashtreeMetadata()
self.assertEqual( self.assertEqual(
@ -122,13 +124,12 @@ class VerityUtilsTest(unittest.TestCase):
self.assertEqual(self.fixed_salt, generator.hashtree_info.salt) self.assertEqual(self.fixed_salt, generator.hashtree_info.salt)
self.assertEqual(self.expected_root_hash, generator.hashtree_info.root_hash) self.assertEqual(self.expected_root_hash, generator.hashtree_info.root_hash)
def test_VerifiedBootVersion1HashtreeInfoGenerator_validateHashtree_smoke( def test_ValidateHashtree_smoke(self):
self): generator = VerifiedBootVersion1HashtreeInfoGenerator(
generator = verity_utils.VerifiedBootVersion1HashtreeInfoGenerator(
self.partition_size, 4096, True) self.partition_size, 4096, True)
generator.image = sparse_img.SparseImage(self._generate_image()) generator.image = sparse_img.SparseImage(self._generate_image())
generator.hashtree_info = info = verity_utils.HashtreeInfo() generator.hashtree_info = info = HashtreeInfo()
info.filesystem_range = RangeSet(data=[0, 991232 / 4096]) info.filesystem_range = RangeSet(data=[0, 991232 / 4096])
info.hashtree_range = RangeSet( info.hashtree_range = RangeSet(
data=[991232 / 4096, (991232 + 12288) / 4096]) data=[991232 / 4096, (991232 + 12288) / 4096])
@ -138,13 +139,12 @@ class VerityUtilsTest(unittest.TestCase):
self.assertTrue(generator.ValidateHashtree()) self.assertTrue(generator.ValidateHashtree())
def test_VerifiedBootVersion1HashtreeInfoGenerator_validateHashtree_failure( def test_ValidateHashtree_failure(self):
self): generator = VerifiedBootVersion1HashtreeInfoGenerator(
generator = verity_utils.VerifiedBootVersion1HashtreeInfoGenerator(
self.partition_size, 4096, True) self.partition_size, 4096, True)
generator.image = sparse_img.SparseImage(self._generate_image()) generator.image = sparse_img.SparseImage(self._generate_image())
generator.hashtree_info = info = verity_utils.HashtreeInfo() generator.hashtree_info = info = HashtreeInfo()
info.filesystem_range = RangeSet(data=[0, 991232 / 4096]) info.filesystem_range = RangeSet(data=[0, 991232 / 4096])
info.hashtree_range = RangeSet( info.hashtree_range = RangeSet(
data=[991232 / 4096, (991232 + 12288) / 4096]) data=[991232 / 4096, (991232 + 12288) / 4096])
@ -154,10 +154,9 @@ class VerityUtilsTest(unittest.TestCase):
self.assertFalse(generator.ValidateHashtree()) self.assertFalse(generator.ValidateHashtree())
def test_VerifiedBootVersion1HashtreeInfoGenerator_generate(self): def test_Generate(self):
image_file = sparse_img.SparseImage(self._generate_image()) image_file = sparse_img.SparseImage(self._generate_image())
generator = verity_utils.CreateHashtreeInfoGenerator( generator = CreateHashtreeInfoGenerator('system', 4096, self.prop_dict)
'system', 4096, self.prop_dict)
info = generator.Generate(image_file) info = generator.Generate(image_file)
self.assertEqual(RangeSet(data=[0, 991232 / 4096]), info.filesystem_range) self.assertEqual(RangeSet(data=[0, 991232 / 4096]), info.filesystem_range)

View File

@ -63,10 +63,6 @@ class HashtreeInfoGenerator(object):
raise NotImplementedError raise NotImplementedError
class VerifiedBootVersion2HashtreeInfoGenerator(HashtreeInfoGenerator):
pass
class VerifiedBootVersion1HashtreeInfoGenerator(HashtreeInfoGenerator): class VerifiedBootVersion1HashtreeInfoGenerator(HashtreeInfoGenerator):
"""A class that parses the metadata of hashtree for a given partition.""" """A class that parses the metadata of hashtree for a given partition."""