Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82490d3d authored by Tao Bao's avatar Tao Bao
Browse files

relesetools: Enable releasetools_test in presubmit.

About half of the testcases rely on external tools (i.e. the ones in
`otatools.zip`, which are external to releasetools module, but still
built by Android). It's WAI as releasetools scripts are mostly for
gluing purpose.

However, the current support in Soong doesn't allow packing the helper
modules as part of the built releasetools_test. This CL adds a decorator
that allows declaring external dependencies in testcases, which will be
skipped while running in presubmit. It doesn't affect local invocation
of `atest releasetools_test`.

Fixes: 112080715
Test: `atest releasetools_test`
Test: TreeHugger; check that releasetools_test is invoked (and test
      passes).
Change-Id: I8fdeb6549023cf5ddeb79d610c7c37cf9f13d3cc
parent 30e31142
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
{
  "presubmit": [
    {
      "name": "releasetools_test",
      "host": true
    }
  ]
}
+20 −12
Original line number Diff line number Diff line
@@ -34,18 +34,6 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
  def setUp(self):
    OPTIONS.input_tmp = common.MakeTempDir()

  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")

    # Calls an external binary to convert the proto message.
    cmd = ["care_map_generator", "--parse_proto", file_name, text_file]
    common.RunAndCheckOutput(cmd)

    with open(text_file, 'r') as verify_fp:
      plain_text = verify_fp.read()
    self.assertEqual('\n'.join(expected), plain_text)

  @staticmethod
  def _create_images(images, prefix):
    """Creates images under OPTIONS.input_tmp/prefix."""
@@ -164,6 +152,19 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
    }
    return image_paths

  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")

    # Calls an external binary to convert the proto message.
    cmd = ["care_map_generator", "--parse_proto", file_name, text_file]
    common.RunAndCheckOutput(cmd)

    with open(text_file) as verify_fp:
      plain_text = verify_fp.read()
    self.assertEqual('\n'.join(expected), plain_text)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta(self):
    image_paths = self._test_AddCareMapForAbOta()

@@ -179,6 +180,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):

    self._verifyCareMap(expected, care_map_file)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta_withNonCareMapPartitions(self):
    """Partitions without care_map should be ignored."""
    image_paths = self._test_AddCareMapForAbOta()
@@ -196,6 +198,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):

    self._verifyCareMap(expected, care_map_file)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta_withAvb(self):
    """Tests the case for device using AVB."""
    image_paths = self._test_AddCareMapForAbOta()
@@ -223,6 +226,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):

    self._verifyCareMap(expected, care_map_file)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta_noFingerprint(self):
    """Tests the case for partitions without fingerprint."""
    image_paths = self._test_AddCareMapForAbOta()
@@ -240,6 +244,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):

    self._verifyCareMap(expected, care_map_file)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta_withThumbprint(self):
    """Tests the case for partitions with thumbprint."""
    image_paths = self._test_AddCareMapForAbOta()
@@ -282,6 +287,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
    self.assertRaises(AssertionError, AddCareMapForAbOta, None,
                      ['system', 'vendor'], image_paths)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta_zipOutput(self):
    """Tests the case with ZIP output."""
    image_paths = self._test_AddCareMapForAbOta()
@@ -304,6 +310,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
                "google/sailfish/678:user/dev-keys"]
    self._verifyCareMap(expected, os.path.join(temp_dir, care_map_name))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AddCareMapForAbOta_zipOutput_careMapEntryExists(self):
    """Tests the case with ZIP output which already has care_map entry."""
    image_paths = self._test_AddCareMapForAbOta()
@@ -338,6 +345,7 @@ class AddImagesToTargetFilesTest(test_utils.ReleaseToolsTestCase):
    self.assertEqual(
        ['--include_descriptors_from_image', '/path/to/system.img'], cmd)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_AppendVBMetaArgsForPartition_vendorAsChainedPartition(self):
    testdata_dir = test_utils.get_testdata_dir()
    pubkey = os.path.join(testdata_dir, 'testkey.pubkey.pem')
+5 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ class ApexUtilsTest(test_utils.ReleaseToolsTestCase):
      payload_fp.write(os.urandom(8192))
    return payload_file

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_ParseApexPayloadInfo(self):
    payload_file = self._GetTestPayload()
    apex_utils.SignApexPayload(
@@ -48,12 +49,14 @@ class ApexUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertEqual(self.SALT, payload_info['Salt'])
    self.assertEqual('testkey', payload_info['apex.key'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_SignApexPayload(self):
    payload_file = self._GetTestPayload()
    apex_utils.SignApexPayload(
        payload_file, self.payload_key, 'testkey', 'SHA256_RSA2048', self.SALT)
    apex_utils.VerifyApexPayload(payload_file, self.payload_key)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_SignApexPayload_withSignerHelper(self):
    payload_file = self._GetTestPayload()
    signing_helper = os.path.join(self.testdata_dir, 'signing_helper.sh')
@@ -67,6 +70,7 @@ class ApexUtilsTest(test_utils.ReleaseToolsTestCase):
        payload_signer_args)
    apex_utils.VerifyApexPayload(payload_file, self.payload_key)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_SignApexPayload_invalidKey(self):
    self.assertRaises(
        apex_utils.ApexSigningError,
@@ -77,6 +81,7 @@ class ApexUtilsTest(test_utils.ReleaseToolsTestCase):
        'SHA256_RSA2048',
        self.SALT)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_VerifyApexPayload_wrongKey(self):
    payload_file = self._GetTestPayload()
    apex_utils.SignApexPayload(
+8 −4
Original line number Diff line number Diff line
@@ -18,12 +18,13 @@ import filecmp
import os.path

import common
import test_utils
from build_image import (
    BuildImageError, CheckHeadroom, GetFilesystemCharacteristics, SetUpInDirAndFsConfig)
from test_utils import ReleaseToolsTestCase
    BuildImageError, CheckHeadroom, GetFilesystemCharacteristics,
    SetUpInDirAndFsConfig)


class BuildImageTest(ReleaseToolsTestCase):
class BuildImageTest(test_utils.ReleaseToolsTestCase):

  # Available: 1000 blocks.
  EXT4FS_OUTPUT = (
@@ -48,6 +49,7 @@ class BuildImageTest(ReleaseToolsTestCase):
    self.assertRaises(
        BuildImageError, CheckHeadroom, self.EXT4FS_OUTPUT, prop_dict)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_CheckHeadroom_WrongFsType(self):
    prop_dict = {
        'fs_type' : 'f2fs',
@@ -72,6 +74,7 @@ class BuildImageTest(ReleaseToolsTestCase):
    self.assertRaises(
        AssertionError, CheckHeadroom, self.EXT4FS_OUTPUT, prop_dict)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_CheckHeadroom_WithMke2fsOutput(self):
    """Tests the result parsing from actual call to mke2fs."""
    input_dir = common.MakeTempDir()
@@ -177,13 +180,14 @@ class BuildImageTest(ReleaseToolsTestCase):
    self.assertIn('fs-config-root\n', fs_config_data)
    self.assertEqual('/', prop_dict['mount_point'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetFilesystemCharacteristics(self):
    input_dir = common.MakeTempDir()
    output_image = common.MakeTempFile(suffix='.img')
    command = ['mkuserimg_mke2fs', input_dir, output_image, 'ext4',
               '/system', '409600', '-j', '0']
    proc = common.Run(command)
    ext4fs_output, _ = proc.communicate()
    proc.communicate()
    self.assertEqual(0, proc.returncode)

    output_file = common.MakeTempFile(suffix='.img')
+26 −0
Original line number Diff line number Diff line
@@ -315,6 +315,7 @@ class CommonZipTest(test_utils.ReleaseToolsTestCase):
    finally:
      os.remove(zip_file_name)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_ZipDelete(self):
    zip_file = tempfile.NamedTemporaryFile(delete=False, suffix='.zip')
    output_zip = zipfile.ZipFile(zip_file.name, 'w',
@@ -376,6 +377,7 @@ class CommonZipTest(test_utils.ReleaseToolsTestCase):
    common.ZipClose(output_zip)
    return zip_file

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_UnzipTemp(self):
    zip_file = self._test_UnzipTemp_createZipFile()
    unzipped_dir = common.UnzipTemp(zip_file)
@@ -385,6 +387,7 @@ class CommonZipTest(test_utils.ReleaseToolsTestCase):
    self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
    self.assertTrue(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_UnzipTemp_withPatterns(self):
    zip_file = self._test_UnzipTemp_createZipFile()

@@ -425,6 +428,7 @@ class CommonZipTest(test_utils.ReleaseToolsTestCase):
    self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Bar4')))
    self.assertFalse(os.path.exists(os.path.join(unzipped_dir, 'Dir5/Baz5')))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_UnzipTemp_withPartiallyMatchingPatterns(self):
    zip_file = self._test_UnzipTemp_createZipFile()
    unzipped_dir = common.UnzipTemp(zip_file, ['Test*', 'Nonexistent*'])
@@ -575,6 +579,7 @@ class CommonApkUtilsTest(test_utils.ReleaseToolsTestCase):
    wrong_input = os.path.join(self.testdata_dir, 'testkey.pk8')
    self.assertRaises(AssertionError, common.ExtractPublicKey, wrong_input)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_ExtractAvbPublicKey(self):
    privkey = os.path.join(self.testdata_dir, 'testkey.key')
    pubkey = os.path.join(self.testdata_dir, 'testkey.pubkey.pem')
@@ -594,18 +599,22 @@ class CommonApkUtilsTest(test_utils.ReleaseToolsTestCase):
      actual = common.ParseCertificate(cert_fp.read())
    self.assertEqual(expected, actual)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetMinSdkVersion(self):
    test_app = os.path.join(self.testdata_dir, 'TestApp.apk')
    self.assertEqual('24', common.GetMinSdkVersion(test_app))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetMinSdkVersion_invalidInput(self):
    self.assertRaises(
        common.ExternalError, common.GetMinSdkVersion, 'does-not-exist.apk')

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetMinSdkVersionInt(self):
    test_app = os.path.join(self.testdata_dir, 'TestApp.apk')
    self.assertEqual(24, common.GetMinSdkVersionInt(test_app, {}))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetMinSdkVersionInt_invalidInput(self):
    self.assertRaises(
        common.ExternalError, common.GetMinSdkVersionInt, 'does-not-exist.apk',
@@ -617,6 +626,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
  def setUp(self):
    self.testdata_dir = test_utils.get_testdata_dir()

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_emptyBlockMapFile(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
@@ -649,6 +659,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
        AssertionError, common.GetSparseImage, 'unknown', self.testdata_dir,
        None, False)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_missingBlockMapFile(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
@@ -667,6 +678,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
          AssertionError, common.GetSparseImage, 'system', tempdir, input_zip,
          False)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_sharedBlocks_notAllowed(self):
    """Tests the case of having overlapping blocks but disallowed."""
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
@@ -689,6 +701,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
          AssertionError, common.GetSparseImage, 'system', tempdir, input_zip,
          False)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_sharedBlocks_allowed(self):
    """Tests the case for target using BOARD_EXT4_SHARE_DUP_BLOCKS := true."""
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
@@ -731,6 +744,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertFalse(sparse_image.file_map['__NONZERO-0'].extra)
    self.assertFalse(sparse_image.file_map['/system/file1'].extra)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_incompleteRanges(self):
    """Tests the case of ext4 images with holes."""
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
@@ -754,6 +768,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertFalse(sparse_image.file_map['/system/file1'].extra)
    self.assertTrue(sparse_image.file_map['/system/file2'].extra['incomplete'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_systemRootImage_filenameWithExtraLeadingSlash(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
@@ -781,6 +796,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertTrue(
        sparse_image.file_map['/system/app/file3'].extra['incomplete'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_systemRootImage_nonSystemFiles(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
@@ -803,6 +819,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertFalse(sparse_image.file_map['//system/file1'].extra)
    self.assertTrue(sparse_image.file_map['//init.rc'].extra['incomplete'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetSparseImage_fileNotFound(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
@@ -822,6 +839,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
          AssertionError, common.GetSparseImage, 'system', tempdir, input_zip,
          False)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetAvbChainedPartitionArg(self):
    pubkey = os.path.join(self.testdata_dir, 'testkey.pubkey.pem')
    info_dict = {
@@ -835,6 +853,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertEqual('2', args[1])
    self.assertTrue(os.path.exists(args[2]))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetAvbChainedPartitionArg_withPrivateKey(self):
    key = os.path.join(self.testdata_dir, 'testkey.key')
    info_dict = {
@@ -848,6 +867,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertEqual('2', args[1])
    self.assertTrue(os.path.exists(args[2]))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetAvbChainedPartitionArg_withSpecifiedKey(self):
    info_dict = {
        'avb_avbtool': 'avbtool',
@@ -862,6 +882,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertEqual('2', args[1])
    self.assertTrue(os.path.exists(args[2]))

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_GetAvbChainedPartitionArg_invalidKey(self):
    pubkey = os.path.join(self.testdata_dir, 'testkey_with_passwd.x509.pem')
    info_dict = {
@@ -922,6 +943,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
      self.assertIn('/', loaded_dict['fstab'])
      self.assertIn('/system', loaded_dict['fstab'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_LoadInfoDict_dirInput(self):
    target_files = self._test_LoadInfoDict_createTargetFiles(
        self.INFO_DICT_DEFAULT,
@@ -933,6 +955,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    self.assertIn('/', loaded_dict['fstab'])
    self.assertIn('/system', loaded_dict['fstab'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_LoadInfoDict_dirInput_legacyRecoveryFstabPath(self):
    target_files = self._test_LoadInfoDict_createTargetFiles(
        self.INFO_DICT_DEFAULT,
@@ -990,6 +1013,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
      self.assertEqual(2, loaded_dict['fstab_version'])
      self.assertIsNone(loaded_dict['fstab'])

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_LoadInfoDict_missingMetaMiscInfoTxt(self):
    target_files = self._test_LoadInfoDict_createTargetFiles(
        self.INFO_DICT_DEFAULT,
@@ -998,6 +1022,7 @@ class CommonUtilsTest(test_utils.ReleaseToolsTestCase):
    with zipfile.ZipFile(target_files, 'r') as target_files_zip:
      self.assertRaises(ValueError, common.LoadInfoDict, target_files_zip)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_LoadInfoDict_repacking(self):
    target_files = self._test_LoadInfoDict_createTargetFiles(
        self.INFO_DICT_DEFAULT,
@@ -1066,6 +1091,7 @@ class InstallRecoveryScriptFormatTest(test_utils.ReleaseToolsTestCase):
    validate_target_files.ValidateInstallRecoveryScript(self._tempdir,
                                                        self._info)

  @test_utils.SkipIfExternalToolsUnavailable()
  def test_recovery_from_boot(self):
    recovery_image = common.File("recovery.img", self.recovery_data)
    self._out_tmp_sink("recovery.img", recovery_image.data, "IMAGES")
Loading