forked from openkylin/platform_build
Merge "releasetools: Add a common base class for unittests."
This commit is contained in:
commit
e95680a60f
|
@ -16,7 +16,6 @@
|
|||
|
||||
import os
|
||||
import os.path
|
||||
import unittest
|
||||
import zipfile
|
||||
|
||||
import common
|
||||
|
@ -30,14 +29,11 @@ from rangelib import RangeSet
|
|||
OPTIONS = common.OPTIONS
|
||||
|
||||
|
||||
class AddImagesToTargetFilesTest(unittest.TestCase):
|
||||
class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
OPTIONS.input_tmp = common.MakeTempDir()
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def _verifyCareMap(self, expected, file_name):
|
||||
"""Parses the care_map.pb; and checks the content in plain text."""
|
||||
text_file = common.MakeTempFile(prefix="caremap-", suffix=".txt")
|
||||
|
|
|
@ -14,17 +14,14 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
|
||||
import common
|
||||
from blockimgdiff import (BlockImageDiff, EmptyImage, HeapItem, ImgdiffStats,
|
||||
Transfer)
|
||||
from blockimgdiff import (
|
||||
BlockImageDiff, EmptyImage, HeapItem, ImgdiffStats, Transfer)
|
||||
from rangelib import RangeSet
|
||||
from test_utils import ReleaseToolsTestCase
|
||||
|
||||
|
||||
class HealpItemTest(unittest.TestCase):
|
||||
class HealpItemTest(ReleaseToolsTestCase):
|
||||
|
||||
class Item(object):
|
||||
def __init__(self, score):
|
||||
|
@ -54,7 +51,7 @@ class HealpItemTest(unittest.TestCase):
|
|||
self.assertFalse(item)
|
||||
|
||||
|
||||
class BlockImageDiffTest(unittest.TestCase):
|
||||
class BlockImageDiffTest(ReleaseToolsTestCase):
|
||||
|
||||
def test_GenerateDigraphOrder(self):
|
||||
"""Make sure GenerateDigraph preserves the order.
|
||||
|
@ -245,7 +242,7 @@ class BlockImageDiffTest(unittest.TestCase):
|
|||
block_image_diff.imgdiff_stats.stats)
|
||||
|
||||
|
||||
class ImgdiffStatsTest(unittest.TestCase):
|
||||
class ImgdiffStatsTest(ReleaseToolsTestCase):
|
||||
|
||||
def test_Log(self):
|
||||
imgdiff_stats = ImgdiffStats()
|
||||
|
|
|
@ -18,15 +18,15 @@ import filecmp
|
|||
import math
|
||||
import os.path
|
||||
import random
|
||||
import unittest
|
||||
|
||||
import common
|
||||
from build_image import (
|
||||
AVBCalcMinPartitionSize, BLOCK_SIZE, BuildImageError, CheckHeadroom,
|
||||
SetUpInDirAndFsConfig)
|
||||
from test_utils import ReleaseToolsTestCase
|
||||
|
||||
|
||||
class BuildImageTest(unittest.TestCase):
|
||||
class BuildImageTest(ReleaseToolsTestCase):
|
||||
|
||||
# Available: 1000 blocks.
|
||||
EXT4FS_OUTPUT = (
|
||||
|
@ -39,9 +39,6 @@ class BuildImageTest(unittest.TestCase):
|
|||
self._image_sizes = [BLOCK_SIZE * random.randint(51200, 524288) + offset
|
||||
for offset in range(BLOCK_SIZE)]
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def test_CheckHeadroom_SizeUnderLimit(self):
|
||||
# Required headroom: 1000 blocks.
|
||||
prop_dict = {
|
||||
|
|
|
@ -19,7 +19,6 @@ import os
|
|||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
import zipfile
|
||||
from hashlib import sha1
|
||||
|
||||
|
@ -44,7 +43,8 @@ def get_2gb_string():
|
|||
yield '\0' * (step_size - block_size)
|
||||
|
||||
|
||||
class CommonZipTest(unittest.TestCase):
|
||||
class CommonZipTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def _verify(self, zip_file, zip_file_name, arcname, expected_hash,
|
||||
test_file_name=None, expected_stat=None, expected_mode=0o644,
|
||||
expected_compress_type=zipfile.ZIP_STORED):
|
||||
|
@ -359,7 +359,7 @@ class CommonZipTest(unittest.TestCase):
|
|||
os.remove(zip_file.name)
|
||||
|
||||
|
||||
class CommonApkUtilsTest(unittest.TestCase):
|
||||
class CommonApkUtilsTest(test_utils.ReleaseToolsTestCase):
|
||||
"""Tests the APK utils related functions."""
|
||||
|
||||
APKCERTS_TXT1 = (
|
||||
|
@ -407,9 +407,6 @@ class CommonApkUtilsTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.testdata_dir = test_utils.get_testdata_dir()
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
@staticmethod
|
||||
def _write_apkcerts_txt(apkcerts_txt, additional=None):
|
||||
if additional is None:
|
||||
|
@ -523,14 +520,11 @@ class CommonApkUtilsTest(unittest.TestCase):
|
|||
{})
|
||||
|
||||
|
||||
class CommonUtilsTest(unittest.TestCase):
|
||||
class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.testdata_dir = test_utils.get_testdata_dir()
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def test_GetSparseImage_emptyBlockMapFile(self):
|
||||
target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
|
||||
with zipfile.ZipFile(target_files, 'w') as target_files_zip:
|
||||
|
@ -935,7 +929,7 @@ class CommonUtilsTest(unittest.TestCase):
|
|||
AssertionError, common.LoadInfoDict, target_files_zip, True)
|
||||
|
||||
|
||||
class InstallRecoveryScriptFormatTest(unittest.TestCase):
|
||||
class InstallRecoveryScriptFormatTest(test_utils.ReleaseToolsTestCase):
|
||||
"""Checks the format of install-recovery.sh.
|
||||
|
||||
Its format should match between common.py and validate_target_files.py.
|
||||
|
@ -994,6 +988,3 @@ class InstallRecoveryScriptFormatTest(unittest.TestCase):
|
|||
recovery_image, boot_image, self._info)
|
||||
validate_target_files.ValidateInstallRecoveryScript(self._tempdir,
|
||||
self._info)
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
import copy
|
||||
import os
|
||||
import os.path
|
||||
import unittest
|
||||
import zipfile
|
||||
|
||||
import common
|
||||
|
@ -104,7 +103,7 @@ class MockScriptWriter(object):
|
|||
self.script.append(('AssertSomeThumbprint',) + args)
|
||||
|
||||
|
||||
class BuildInfoTest(unittest.TestCase):
|
||||
class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
TEST_INFO_DICT = {
|
||||
'build.prop' : {
|
||||
|
@ -352,10 +351,7 @@ class BuildInfoTest(unittest.TestCase):
|
|||
script_writer.script)
|
||||
|
||||
|
||||
class LoadOemDictsTest(unittest.TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
class LoadOemDictsTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def test_NoneDict(self):
|
||||
self.assertIsNone(_LoadOemDicts(None))
|
||||
|
@ -388,7 +384,7 @@ class LoadOemDictsTest(unittest.TestCase):
|
|||
self.assertEqual('{}'.format(i), oem_dict['ro.build.index'])
|
||||
|
||||
|
||||
class OtaFromTargetFilesTest(unittest.TestCase):
|
||||
class OtaFromTargetFilesTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
TEST_TARGET_INFO_DICT = {
|
||||
'build.prop' : {
|
||||
|
@ -430,9 +426,6 @@ class OtaFromTargetFilesTest(unittest.TestCase):
|
|||
common.OPTIONS.search_path = test_utils.get_search_path()
|
||||
self.assertIsNotNone(common.OPTIONS.search_path)
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def test_GetPackageMetadata_abOta_full(self):
|
||||
target_info_dict = copy.deepcopy(self.TEST_TARGET_INFO_DICT)
|
||||
target_info_dict['ab_update'] = 'true'
|
||||
|
@ -720,14 +713,11 @@ class TestPropertyFiles(PropertyFiles):
|
|||
)
|
||||
|
||||
|
||||
class PropertyFilesTest(unittest.TestCase):
|
||||
class PropertyFilesTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
common.OPTIONS.no_signing = False
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
@staticmethod
|
||||
def construct_zip_package(entries):
|
||||
zip_file = common.MakeTempFile(suffix='.zip')
|
||||
|
@ -1151,7 +1141,7 @@ class NonAbOtaPropertyFilesTest(PropertyFilesTest):
|
|||
property_files.Verify(zip_fp, raw_metadata)
|
||||
|
||||
|
||||
class PayloadSignerTest(unittest.TestCase):
|
||||
class PayloadSignerTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
SIGFILE = 'sigfile.bin'
|
||||
SIGNED_SIGFILE = 'signed-sigfile.bin'
|
||||
|
@ -1167,9 +1157,6 @@ class PayloadSignerTest(unittest.TestCase):
|
|||
common.OPTIONS.package_key : None,
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def _assertFilesEqual(self, file1, file2):
|
||||
with open(file1, 'rb') as fp1, open(file2, 'rb') as fp2:
|
||||
self.assertEqual(fp1.read(), fp2.read())
|
||||
|
@ -1230,7 +1217,7 @@ class PayloadSignerTest(unittest.TestCase):
|
|||
self._assertFilesEqual(verify_file, signed_file)
|
||||
|
||||
|
||||
class PayloadTest(unittest.TestCase):
|
||||
class PayloadTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.testdata_dir = test_utils.get_testdata_dir()
|
||||
|
@ -1244,9 +1231,6 @@ class PayloadTest(unittest.TestCase):
|
|||
common.OPTIONS.package_key : None,
|
||||
}
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
@staticmethod
|
||||
def _create_payload_full(secondary=False):
|
||||
target_file = construct_target_files(secondary)
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from rangelib import RangeSet
|
||||
from test_utils import ReleaseToolsTestCase
|
||||
|
||||
class RangeSetTest(unittest.TestCase):
|
||||
|
||||
class RangeSetTest(ReleaseToolsTestCase):
|
||||
|
||||
def test_union(self):
|
||||
self.assertEqual(RangeSet("10-19 30-34").union(RangeSet("18-29")),
|
||||
|
@ -129,8 +129,8 @@ class RangeSetTest(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
RangeSet.parse_raw(RangeSet("0-9").to_string_raw()),
|
||||
RangeSet("0-9"))
|
||||
self.assertEqual(RangeSet.parse_raw(
|
||||
RangeSet("2-10 12").to_string_raw()),
|
||||
self.assertEqual(
|
||||
RangeSet.parse_raw(RangeSet("2-10 12").to_string_raw()),
|
||||
RangeSet("2-10 12"))
|
||||
self.assertEqual(
|
||||
RangeSet.parse_raw(RangeSet("11 2-10 12 1 0").to_string_raw()),
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import base64
|
||||
import os.path
|
||||
import unittest
|
||||
import zipfile
|
||||
|
||||
import common
|
||||
|
@ -28,7 +25,7 @@ from sign_target_files_apks import (
|
|||
ReplaceVerityKeyId, RewriteProps)
|
||||
|
||||
|
||||
class SignTargetFilesApksTest(unittest.TestCase):
|
||||
class SignTargetFilesApksTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
MAC_PERMISSIONS_XML = """<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<policy>
|
||||
|
@ -39,9 +36,6 @@ class SignTargetFilesApksTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.testdata_dir = test_utils.get_testdata_dir()
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def test_EditTags(self):
|
||||
self.assertEqual(EditTags('dev-keys'), ('release-keys'))
|
||||
self.assertEqual(EditTags('test-keys'), ('release-keys'))
|
||||
|
|
|
@ -21,6 +21,7 @@ Utils for running unittests.
|
|||
import os
|
||||
import os.path
|
||||
import struct
|
||||
import unittest
|
||||
|
||||
import common
|
||||
|
||||
|
@ -110,3 +111,10 @@ def construct_sparse_image(chunks):
|
|||
fp.write(os.urandom(data_size))
|
||||
|
||||
return sparse_image
|
||||
|
||||
|
||||
class ReleaseToolsTestCase(unittest.TestCase):
|
||||
"""A common base class for all the releasetools unittests."""
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
|
|
@ -16,12 +16,9 @@
|
|||
|
||||
"""Unittests for validate_target_files.py."""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
import build_image
|
||||
import common
|
||||
|
@ -29,14 +26,11 @@ import test_utils
|
|||
from validate_target_files import ValidateVerifiedBootImages
|
||||
|
||||
|
||||
class ValidateTargetFilesTest(unittest.TestCase):
|
||||
class ValidateTargetFilesTest(test_utils.ReleaseToolsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.testdata_dir = test_utils.get_testdata_dir()
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def _generate_boot_image(self, output_file):
|
||||
kernel = common.MakeTempFile(prefix='kernel-')
|
||||
with open(kernel, 'wb') as kernel_fp:
|
||||
|
|
|
@ -16,25 +16,22 @@
|
|||
|
||||
"""Unittests for verity_utils.py."""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
import build_image
|
||||
import common
|
||||
import sparse_img
|
||||
import test_utils
|
||||
from rangelib import RangeSet
|
||||
from test_utils import get_testdata_dir, ReleaseToolsTestCase
|
||||
from verity_utils import (
|
||||
CreateHashtreeInfoGenerator, HashtreeInfo,
|
||||
VerifiedBootVersion1HashtreeInfoGenerator)
|
||||
|
||||
|
||||
class VerifiedBootVersion1HashtreeInfoGeneratorTest(unittest.TestCase):
|
||||
class VerifiedBootVersion1HashtreeInfoGeneratorTest(ReleaseToolsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.testdata_dir = test_utils.get_testdata_dir()
|
||||
self.testdata_dir = get_testdata_dir()
|
||||
|
||||
self.partition_size = 1024 * 1024
|
||||
self.prop_dict = {
|
||||
|
@ -50,9 +47,6 @@ class VerifiedBootVersion1HashtreeInfoGeneratorTest(unittest.TestCase):
|
|||
self.expected_root_hash = \
|
||||
"0b7c4565e87b1026e11fbab91c0bc29e185c847a5b44d40e6e86e461e8adf80d"
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
def _create_simg(self, raw_data):
|
||||
output_file = common.MakeTempFile()
|
||||
raw_image = common.MakeTempFile()
|
||||
|
|
Loading…
Reference in New Issue