diff options
Diffstat (limited to 'build/mainline_modules_sdks_test.py')
-rw-r--r-- | build/mainline_modules_sdks_test.py | 88 |
1 files changed, 79 insertions, 9 deletions
diff --git a/build/mainline_modules_sdks_test.py b/build/mainline_modules_sdks_test.py index e66b3bb2..2131a602 100644 --- a/build/mainline_modules_sdks_test.py +++ b/build/mainline_modules_sdks_test.py @@ -23,6 +23,7 @@ import shutil import tempfile import unittest import zipfile +import json from unittest import mock import mainline_modules_sdks as mm @@ -108,6 +109,10 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder): # For rest of the modules, generate an empty .info file. self.write_data_to_file(sdk_info_file, "[]") + def get_module_extension_version(self): + # Return any integer value indicating the module extension version for testing. + return 5 + def build_sdk_scope_targets(self, build_release, modules): target_paths = [] target_dict = {} @@ -199,14 +204,18 @@ class TestProduceDist(unittest.TestCase): "mainline-sdks/for-S-build/current/com.android.ipsec/sdk/ipsec-module-sdk-current.zip", "mainline-sdks/for-S-build/current/com.android.tethering/sdk/tethering-module-sdk-current.zip", "mainline-sdks/for-S-build/current/com.google.android.wifi/sdk/wifi-module-sdk-current.zip", + "mainline-sdks/for-latest-build/current/com.android.art/gantry-metadata.json", "mainline-sdks/for-latest-build/current/com.android.art/host-exports/art-module-host-exports-current.zip", "mainline-sdks/for-latest-build/current/com.android.art/sdk/art-module-sdk-current-api-diff.txt", "mainline-sdks/for-latest-build/current/com.android.art/sdk/art-module-sdk-current.zip", "mainline-sdks/for-latest-build/current/com.android.art/test-exports/art-module-test-exports-current.zip", + "mainline-sdks/for-latest-build/current/com.android.ipsec/gantry-metadata.json", "mainline-sdks/for-latest-build/current/com.android.ipsec/sdk/ipsec-module-sdk-current-api-diff.txt", "mainline-sdks/for-latest-build/current/com.android.ipsec/sdk/ipsec-module-sdk-current.zip", + "mainline-sdks/for-latest-build/current/com.android.tethering/gantry-metadata.json", "mainline-sdks/for-latest-build/current/com.android.tethering/sdk/tethering-module-sdk-current-api-diff.txt", "mainline-sdks/for-latest-build/current/com.android.tethering/sdk/tethering-module-sdk-current.zip", + "mainline-sdks/for-latest-build/current/com.google.android.wifi/gantry-metadata.json", "mainline-sdks/for-latest-build/current/com.google.android.wifi/sdk/wifi-module-sdk-current-api-diff.txt", "mainline-sdks/for-latest-build/current/com.google.android.wifi/sdk/wifi-module-sdk-current.zip", ], @@ -295,6 +304,7 @@ class TestProduceDist(unittest.TestCase): "bundled-mainline-sdks/platform-mainline/sdk/platform-mainline-sdk-current.zip", "bundled-mainline-sdks/platform-mainline/test-exports/platform-mainline-test-exports-current.zip", # Unbundled (normal) modules. + "mainline-sdks/for-latest-build/current/com.android.art/gantry-metadata.json", "mainline-sdks/for-latest-build/current/com.android.art/host-exports/art-module-host-exports-current.zip", "mainline-sdks/for-latest-build/current/com.android.art/sdk/art-module-sdk-current-api-diff.txt", "mainline-sdks/for-latest-build/current/com.android.art/sdk/art-module-sdk-current.zip", @@ -311,6 +321,29 @@ class TestProduceDist(unittest.TestCase): 0, msg="Api diff file should not be empty for the art module") + art_gantry_metadata_json_file = os.path.join( + self.tmp_dist_dir, + "mainline-sdks/for-latest-build/current/com.android.art/gantry-metadata.json" + ) + + with open(art_gantry_metadata_json_file, "r", + encoding="utf8") as gantry_metadata_json_file_object: + json_data = json.load(gantry_metadata_json_file_object) + + self.assertEqual( + json_data["api_diff_file"], + "art-module-sdk-current-api-diff.txt", + msg="Incorrect api-diff file name.") + self.assertEqual( + json_data["api_diff_file_size"], + 267, + msg="Incorrect api-diff file size.") + self.assertEqual( + json_data["module_extension_version"], + 5, + msg="The module extension version does not match the expected value." + ) + def create_build_number_file(self): soong_dir = os.path.join(self.tmp_out_dir, "soong") os.makedirs(soong_dir, exist_ok=True) @@ -405,7 +438,7 @@ def read_test_data(relative_path): class TestAndroidBpTransformations(unittest.TestCase): - def apply_transformations(self, src, transformations, expected): + def apply_transformations(self, src, transformations, build_release, expected): producer = mm.SdkDistProducer( subprocess_runner=mock.Mock(mm.SubprocessRunner), snapshot_builder=mock.Mock(mm.SnapshotBuilder), @@ -417,7 +450,8 @@ class TestAndroidBpTransformations(unittest.TestCase): with open(path, "w", encoding="utf8") as f: f.write(src) - mm.apply_transformations(producer, tmp_dir, transformations) + mm.apply_transformations( + producer, tmp_dir, transformations, build_release) with open(path, "r", encoding="utf8") as f: result = f.read() @@ -438,7 +472,7 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] transformations = module.transformations(mm.S, mm.Sdk) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.S, expected) def test_common_mainline_module_tiramisu(self): """Tests the transformations applied to a common mainline sdk on T. @@ -453,7 +487,7 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] transformations = module.transformations(mm.Tiramisu, mm.Sdk) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.Tiramisu, expected) def test_optional_mainline_module(self): """Tests the transformations applied to an optional mainline sdk on S. @@ -469,7 +503,7 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.wifi"] transformations = module.transformations(mm.S, mm.Sdk) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.S, expected) def test_optional_mainline_module_tiramisu(self): """Tests the transformations applied to an optional mainline sdk on T. @@ -484,7 +518,7 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.wifi"] transformations = module.transformations(mm.Tiramisu, mm.Sdk) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.Tiramisu, expected) def test_art(self): """Tests the transformations applied to a the ART mainline module. @@ -500,7 +534,7 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.art"] transformations = module.transformations(mm.S, mm.Sdk) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.S, expected) def test_art_module_exports(self): """Tests the transformations applied to a the ART mainline module. @@ -516,7 +550,7 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.art"] transformations = module.transformations(mm.S, mm.HostExports) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.S, expected) def test_r_build(self): """Tests the transformations that are applied for the R build. @@ -534,7 +568,43 @@ class TestAndroidBpTransformations(unittest.TestCase): module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] transformations = module.transformations(mm.R, mm.Sdk) - self.apply_transformations(src, transformations, expected) + self.apply_transformations(src, transformations, mm.R, expected) + + def test_additional_transformation(self): + """Tests additional transformation. + + This uses ipsec as an example of a common case for adding information + in Android.bp file. + This checks will append the information in Android.bp for a regular module. + """ + + @dataclasses.dataclass(frozen=True) + class TestTransformation(mm.FileTransformation): + """Transforms an Android.bp file by appending testing message.""" + + test_content: str = "" + + def apply(self, producer, path, build_release): + with open(path, "a+", encoding="utf8") as file: + self._apply_transformation(producer, file, build_release) + + def _apply_transformation(self, producer, file, build_release): + if build_release >= mm.Tiramisu: + file.write(self.test_content) + + src = read_test_data("ipsec_Android.bp.input") + + expected = read_test_data( + "ipsec_tiramisu_Android.bp.additional.expected") + test_transformation = TestTransformation( + "Android.bp", test_content="\n// Adding by test") + module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] + module = dataclasses.replace( + module, apex=module.apex, + first_release=module.first_release, + additional_transformations=[test_transformation]) + transformations = module.transformations(mm.Tiramisu, mm.Sdk) + self.apply_transformations(src, transformations, mm.Tiramisu, expected) class TestFilterModules(unittest.TestCase): |