diff options
author | Tao Bao <tbao@google.com> | 2018-10-12 18:33:56 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-10-12 18:33:56 +0000 |
commit | e95680a60f74d4208a59fd23396baf79d1dfc229 (patch) | |
tree | 2cf1cafa0999bc5e20021b90eae5c8c7927958de | |
parent | d772deb65342cb5384d1f68c9d650365310a1b18 (diff) | |
parent | 65b94e92be900b995f9f8ae8412acabfa9e62996 (diff) | |
download | platform_build-oreo-mr1-1.2-iot-release.tar.gz platform_build-oreo-mr1-1.2-iot-release.tar.bz2 platform_build-oreo-mr1-1.2-iot-release.zip |
Merge "releasetools: Add a common base class for unittests."android-o-mr1-iot-release-smart-display-r3oreo-mr1-1.2-iot-release
-rw-r--r-- | tools/releasetools/test_add_img_to_target_files.py | 6 | ||||
-rw-r--r-- | tools/releasetools/test_blockimgdiff.py | 15 | ||||
-rw-r--r-- | tools/releasetools/test_build_image.py | 7 | ||||
-rw-r--r-- | tools/releasetools/test_common.py | 19 | ||||
-rw-r--r-- | tools/releasetools/test_ota_from_target_files.py | 28 | ||||
-rw-r--r-- | tools/releasetools/test_rangelib.py | 10 | ||||
-rw-r--r-- | tools/releasetools/test_sign_target_files_apks.py | 8 | ||||
-rw-r--r-- | tools/releasetools/test_utils.py | 8 | ||||
-rw-r--r-- | tools/releasetools/test_validate_target_files.py | 8 | ||||
-rw-r--r-- | tools/releasetools/test_verity_utils.py | 12 |
10 files changed, 38 insertions, 83 deletions
diff --git a/tools/releasetools/test_add_img_to_target_files.py b/tools/releasetools/test_add_img_to_target_files.py index cc7b887db5..ad22b7252f 100644 --- a/tools/releasetools/test_add_img_to_target_files.py +++ b/tools/releasetools/test_add_img_to_target_files.py @@ -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") diff --git a/tools/releasetools/test_blockimgdiff.py b/tools/releasetools/test_blockimgdiff.py index 124b4d54e8..857026e34a 100644 --- a/tools/releasetools/test_blockimgdiff.py +++ b/tools/releasetools/test_blockimgdiff.py @@ -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() diff --git a/tools/releasetools/test_build_image.py b/tools/releasetools/test_build_image.py index a2df27886a..6f853e8592 100644 --- a/tools/releasetools/test_build_image.py +++ b/tools/releasetools/test_build_image.py @@ -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 = { diff --git a/tools/releasetools/test_common.py b/tools/releasetools/test_common.py index ec86eb2675..c99049adef 100644 --- a/tools/releasetools/test_common.py +++ b/tools/releasetools/test_common.py @@ -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() diff --git a/tools/releasetools/test_ota_from_target_files.py b/tools/releasetools/test_ota_from_target_files.py index 29e0d83dfc..f75b3a75be 100644 --- a/tools/releasetools/test_ota_from_target_files.py +++ b/tools/releasetools/test_ota_from_target_files.py @@ -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) diff --git a/tools/releasetools/test_rangelib.py b/tools/releasetools/test_rangelib.py index e1811870fe..1251e11f0d 100644 --- a/tools/releasetools/test_rangelib.py +++ b/tools/releasetools/test_rangelib.py @@ -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()), diff --git a/tools/releasetools/test_sign_target_files_apks.py b/tools/releasetools/test_sign_target_files_apks.py index ac1b567ca9..18762eebad 100644 --- a/tools/releasetools/test_sign_target_files_apks.py +++ b/tools/releasetools/test_sign_target_files_apks.py @@ -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')) diff --git a/tools/releasetools/test_utils.py b/tools/releasetools/test_utils.py index a15ff5b2a5..b9c8dc7261 100644 --- a/tools/releasetools/test_utils.py +++ b/tools/releasetools/test_utils.py @@ -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() diff --git a/tools/releasetools/test_validate_target_files.py b/tools/releasetools/test_validate_target_files.py index ecb7fde22d..7b29ef8e82 100644 --- a/tools/releasetools/test_validate_target_files.py +++ b/tools/releasetools/test_validate_target_files.py @@ -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: diff --git a/tools/releasetools/test_verity_utils.py b/tools/releasetools/test_verity_utils.py index f318b02b99..a9cd17b1fc 100644 --- a/tools/releasetools/test_verity_utils.py +++ b/tools/releasetools/test_verity_utils.py @@ -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() |