Merge "relesetools: Support running all the unittests with atest."

This commit is contained in:
Tao Bao 2019-04-13 01:50:09 +00:00 committed by Gerrit Code Review
commit 2bb1380ee5
4 changed files with 98 additions and 4 deletions

View File

@ -0,0 +1,72 @@
// 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.
python_defaults {
name: "releasetools_test_defaults",
version: {
py2: {
enabled: true,
embedded_launcher: false,
},
py3: {
enabled: false,
},
},
}
python_library_host {
name: "releasetools_lib",
defaults: ["releasetools_test_defaults"],
srcs: [
"add_img_to_target_files.py",
"apex_utils.py",
"blockimgdiff.py",
"build_image.py",
"build_super_image.py",
"check_ota_package_signature.py",
"check_target_files_signatures.py",
"common.py",
"edify_generator.py",
"img_from_target_files.py",
"make_recovery_patch.py",
"merge_target_files.py",
"ota_from_target_files.py",
"ota_package_parser.py",
"rangelib.py",
"sign_target_files_apks.py",
"sparse_img.py",
"target_files_diff.py",
"validate_target_files.py",
"verity_utils.py",
],
}
python_test_host {
name: "releasetools_test",
defaults: ["releasetools_test_defaults"],
main: "test_utils.py",
srcs: [
"test_*.py",
],
libs: [
"releasetools_lib",
],
data: [
"testdata/*",
],
required: [
"otatools",
],
test_suites: ["general-tests"],
}

View File

@ -56,8 +56,10 @@ class ApexUtilsTest(test_utils.ReleaseToolsTestCase):
def test_SignApexPayload_withSignerHelper(self):
payload_file = self._GetTestPayload()
signing_helper = os.path.join(self.testdata_dir, 'signing_helper.sh')
os.chmod(signing_helper, 0o700)
payload_signer_args = '--signing_helper_with_files {}'.format(
os.path.join(self.testdata_dir, 'signing_helper.sh'))
signing_helper)
apex_utils.SignApexPayload(
payload_file,
self.payload_key,

View File

@ -1233,6 +1233,7 @@ class PayloadSignerTest(test_utils.ReleaseToolsTestCase):
"""Uses testdata/payload_signer.sh as the external payload signer."""
common.OPTIONS.payload_signer = os.path.join(
self.testdata_dir, 'payload_signer.sh')
os.chmod(common.OPTIONS.payload_signer, 0o700)
common.OPTIONS.payload_signer_args = [
os.path.join(self.testdata_dir, 'testkey.pk8')]
payload_signer = PayloadSigner()

25
tools/releasetools/test_utils.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
#
# Copyright (C) 2018 The Android Open Source Project
#
@ -40,6 +41,19 @@ def get_testdata_dir():
def get_search_path():
"""Returns the search path that has 'framework/signapk.jar' under."""
def signapk_exists(path):
signapk_path = os.path.realpath(
os.path.join(path, 'framework', 'signapk.jar'))
return os.path.exists(signapk_path)
# Try with ANDROID_BUILD_TOP first.
full_path = os.path.realpath(os.path.join(
os.environ.get('ANDROID_BUILD_TOP', ''), 'out', 'host', 'linux-x86'))
if signapk_exists(full_path):
return full_path
# Otherwise try going with relative pathes.
current_dir = os.path.dirname(os.path.realpath(__file__))
for path in (
# In relative to 'build/make/tools/releasetools' in the Android source.
@ -47,9 +61,7 @@ def get_search_path():
# Or running the script unpacked from otatools.zip.
['..']):
full_path = os.path.realpath(os.path.join(current_dir, *path))
signapk_path = os.path.realpath(
os.path.join(full_path, 'framework', 'signapk.jar'))
if os.path.exists(signapk_path):
if signapk_exists(full_path):
return full_path
return None
@ -123,3 +135,10 @@ class ReleaseToolsTestCase(unittest.TestCase):
def tearDown(self):
common.Cleanup()
if __name__ == '__main__':
testsuite = unittest.TestLoader().discover(
os.path.dirname(os.path.realpath(__file__)))
# atest needs a verbosity level of >= 2 to correctly parse the result.
unittest.TextTestRunner(verbosity=2).run(testsuite)