releasetools: add tests for check_target_files_vintf am: ccb86fe7d4

am: 96961bf94f

Change-Id: I71461cb81b58bb3c415dcf7b870b6d7cc66fb745
This commit is contained in:
Yifan Hong 2019-08-28 18:02:30 -07:00 committed by android-build-merger
commit f1bcdf5390
8 changed files with 208 additions and 1 deletions

View file

@ -155,6 +155,14 @@ python_library_host {
], ],
} }
python_library_host {
name: "releasetools_check_target_files_vintf",
defaults: [
"releasetools_library_defaults",
"releasetools_check_target_files_vintf_defaults",
],
}
python_library_host { python_library_host {
name: "releasetools_common", name: "releasetools_common",
defaults: ["releasetools_library_defaults"], defaults: ["releasetools_library_defaults"],
@ -417,13 +425,14 @@ python_defaults {
"releasetools_apex_utils", "releasetools_apex_utils",
"releasetools_build_image", "releasetools_build_image",
"releasetools_build_super_image", "releasetools_build_super_image",
"releasetools_check_target_files_vintf",
"releasetools_common", "releasetools_common",
"releasetools_img_from_target_files", "releasetools_img_from_target_files",
"releasetools_ota_from_target_files", "releasetools_ota_from_target_files",
"releasetools_verity_utils", "releasetools_verity_utils",
], ],
data: [ data: [
"testdata/*", "testdata/**/*",
], ],
required: [ required: [
"otatools", "otatools",

View file

@ -0,0 +1,143 @@
#
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os.path
import common
import test_utils
from check_target_files_vintf import CheckVintf
# A skeleton target files directory structure. This is VINTF compatible.
SKELETON_TARGET_FILE_STRUCTURE = {
# Empty files
'PRODUCT/build.prop': '',
'PRODUCT/etc/build.prop': '',
'VENDOR/etc/build.prop': '',
'ODM/build.prop': '',
'ODM/etc/build.prop': '',
'RECOVERY/RAMDISK/etc/recovery.fstab': '',
'SYSTEM/build.prop': '',
'SYSTEM/etc/build.prop': '',
'SYSTEM_EXT/build.prop': '',
'SYSTEM_EXT/etc/build.prop': '',
# Non-empty files
'SYSTEM/compatibility_matrix.xml':"""
<compatibility-matrix version="1.0" type="framework">
<sepolicy>
<sepolicy-version>0.0</sepolicy-version>
<kernel-sepolicy-version>0</kernel-sepolicy-version>
</sepolicy>
</compatibility-matrix>""",
'SYSTEM/manifest.xml':
'<manifest version="1.0" type="framework" />',
'VENDOR/build.prop': 'ro.product.first_api_level=29\n',
'VENDOR/compatibility_matrix.xml':
'<compatibility-matrix version="1.0" type="device" />',
'VENDOR/manifest.xml':
'<manifest version="1.0" type="device"/>',
'META/misc_info.txt':
'recovery_api_version=3\nfstab_version=2\nvintf_enforce=true\n',
}
def write_string_to_file(content, path, mode='w'):
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
with open(path, mode=mode) as f:
f.write(content)
class CheckTargetFilesVintfTest(test_utils.ReleaseToolsTestCase):
def setUp(self):
self.testdata_dir = test_utils.get_testdata_dir()
def prepare_test_dir(self, test_delta_rel_path):
test_delta_dir = os.path.join(self.testdata_dir, test_delta_rel_path)
test_dir = common.MakeTempDir(prefix='check_target_files_vintf')
# Create a skeleton directory structure of target files
for rel_path, content in SKELETON_TARGET_FILE_STRUCTURE.items():
write_string_to_file(content, os.path.join(test_dir, rel_path))
# Overwrite with files from test_delta_rel_path
for root, _, files in os.walk(test_delta_dir):
rel_root = os.path.relpath(root, test_delta_dir)
for f in files:
output_file = os.path.join(test_dir, rel_root, f)
with open(os.path.join(root, f)) as inp:
write_string_to_file(inp.read(), output_file)
return test_dir
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_sanity(self):
msg = 'Sanity check with skeleton target files failed.'
test_dir = self.prepare_test_dir('does-not-exist')
self.assertTrue(CheckVintf(test_dir), msg=msg)
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_matrix_incompat(self):
msg = 'vintf/matrix_incompat should be incompatible because sepolicy ' \
'version fails to match'
test_dir = self.prepare_test_dir('vintf/matrix_incompat')
self.assertFalse(CheckVintf(test_dir), msg=msg)
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_kernel_compat(self):
msg = 'vintf/kernel with 4.14.1 kernel version should be compatible'
test_dir = self.prepare_test_dir('vintf/kernel')
write_string_to_file('', os.path.join(test_dir, 'META/kernel_configs.txt'))
write_string_to_file('4.14.1',
os.path.join(test_dir, 'META/kernel_version.txt'))
self.assertTrue(CheckVintf(test_dir), msg=msg)
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_kernel_incompat(self):
msg = 'vintf/kernel with 4.14.0 kernel version should be incompatible ' \
'because 4.14.1 kernel version is required'
test_dir = self.prepare_test_dir('vintf/kernel')
write_string_to_file('', os.path.join(test_dir, 'META/kernel_configs.txt'))
write_string_to_file('4.14.0',
os.path.join(test_dir, 'META/kernel_version.txt'))
self.assertFalse(CheckVintf(test_dir), msg=msg)
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_sku_compat(self):
msg = 'vintf/sku_compat should be compatible because ' \
'ODM/etc/vintf/manifest_sku.xml has the required HALs'
test_dir = self.prepare_test_dir('vintf/sku_compat')
write_string_to_file('vintf_odm_manifest_skus=sku',
os.path.join(test_dir, 'META/misc_info.txt'), mode='a')
self.assertTrue(CheckVintf(test_dir), msg=msg)
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_sku_incompat(self):
msg = 'vintf/sku_compat should be compatible because ' \
'ODM/etc/vintf/manifest_sku.xml does not have the required HALs'
test_dir = self.prepare_test_dir('vintf/sku_incompat')
write_string_to_file('vintf_odm_manifest_skus=sku',
os.path.join(test_dir, 'META/misc_info.txt'), mode='a')
self.assertFalse(CheckVintf(test_dir), msg=msg)
@test_utils.SkipIfExternalToolsUnavailable()
def test_CheckVintf_bad_xml(self):
test_dir = self.prepare_test_dir('does-not-exist')
write_string_to_file('not an XML',
os.path.join(test_dir, 'VENDOR/manifest.xml'))
# Should raise an error because a file has invalid format.
self.assertRaises(common.ExternalError, CheckVintf, test_dir)

View file

@ -0,0 +1,7 @@
<compatibility-matrix version="1.0" type="framework">
<kernel version="4.14.1" />
<sepolicy>
<sepolicy-version>0.0</sepolicy-version>
<kernel-sepolicy-version>0</kernel-sepolicy-version>
</sepolicy>
</compatibility-matrix>

View file

@ -0,0 +1,6 @@
<compatibility-matrix version="1.0" type="framework">
<sepolicy>
<sepolicy-version>1.0</sepolicy-version>
<kernel-sepolicy-version>0</kernel-sepolicy-version>
</sepolicy>
</compatibility-matrix>

View file

@ -0,0 +1,7 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>foo</name>
<transport>hwbinder</transport>
<fqname>@1.0::IFoo/default</fqname>
</hal>
</manifest>

View file

@ -0,0 +1,14 @@
<compatibility-matrix version="1.0" type="framework">
<hal format="hidl" optional="false">
<name>foo</name>
<version>1.0</version>
<interface>
<name>IFoo</name>
<instance>default</instance>
</interface>
</hal>
<sepolicy>
<sepolicy-version>0.0</sepolicy-version>
<kernel-sepolicy-version>0</kernel-sepolicy-version>
</sepolicy>
</compatibility-matrix>

View file

@ -0,0 +1,7 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>foo</name>
<transport>hwbinder</transport>
<fqname>@1.0::IFoo/default</fqname>
</hal>
</manifest>

View file

@ -0,0 +1,14 @@
<compatibility-matrix version="1.0" type="framework">
<hal format="hidl" optional="false">
<name>foo</name>
<version>1.1</version>
<interface>
<name>IFoo</name>
<instance>default</instance>
</interface>
</hal>
<sepolicy>
<sepolicy-version>0.0</sepolicy-version>
<kernel-sepolicy-version>0</kernel-sepolicy-version>
</sepolicy>
</compatibility-matrix>