Add test for snapshot build order
This test is added to show the current order so that the impact of a
follow up change that changes the order can be assessed.
Test: atest --host mainline_modules_sdks_test
pyformat -s 4 --force_quote_type double -i build/mainline_modules_sdks*.py
/usr/bin/pylint --rcfile $ANDROID_BUILD_TOP/tools/repohooks/tools/pylintrc build/mainline_modules_sdks*.py
Change-Id: I738cc90024ebc2bec59a7193e1b1f42956763ef8
This commit is contained in:
@@ -14,7 +14,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""Unit tests for mainline_modules_sdks.py."""
|
"""Unit tests for mainline_modules_sdks.py."""
|
||||||
|
import dataclasses
|
||||||
import re
|
import re
|
||||||
|
import typing
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@@ -30,6 +32,7 @@ MAINLINE_MODULES_BY_APEX = dict(
|
|||||||
mm.PLATFORM_SDKS_FOR_MAINLINE))
|
mm.PLATFORM_SDKS_FOR_MAINLINE))
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass()
|
||||||
class FakeSnapshotBuilder(mm.SnapshotBuilder):
|
class FakeSnapshotBuilder(mm.SnapshotBuilder):
|
||||||
"""A fake snapshot builder that does not run the build.
|
"""A fake snapshot builder that does not run the build.
|
||||||
|
|
||||||
@@ -37,6 +40,8 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder):
|
|||||||
modules.
|
modules.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
snapshots: typing.List[typing.Any] = dataclasses.field(default_factory=list)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_sdk_library_files(z, name):
|
def create_sdk_library_files(z, name):
|
||||||
z.writestr(f"sdk_library/public/{name}-removed.txt", "")
|
z.writestr(f"sdk_library/public/{name}-removed.txt", "")
|
||||||
@@ -56,6 +61,8 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder):
|
|||||||
self.create_sdk_library_files(z, re.sub(r"-.*$", "", name))
|
self.create_sdk_library_files(z, re.sub(r"-.*$", "", name))
|
||||||
|
|
||||||
def build_snapshots(self, build_release, sdk_versions, modules):
|
def build_snapshots(self, build_release, sdk_versions, modules):
|
||||||
|
self.snapshots.append((build_release.name, build_release.soong_env,
|
||||||
|
sdk_versions, [m.apex for m in modules]))
|
||||||
# Create input file structure.
|
# Create input file structure.
|
||||||
sdks_out_dir = Path(self.mainline_sdks_dir).joinpath("test")
|
sdks_out_dir = Path(self.mainline_sdks_dir).joinpath("test")
|
||||||
sdks_out_dir.mkdir(parents=True, exist_ok=True)
|
sdks_out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -256,6 +263,75 @@ class TestProduceDist(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
sorted(self.list_files_in_dir(self.tmp_dist_dir)))
|
sorted(self.list_files_in_dir(self.tmp_dist_dir)))
|
||||||
|
|
||||||
|
def test_snapshot_build_order(self):
|
||||||
|
subprocess_runner = unittest.mock.Mock(mm.SubprocessRunner)
|
||||||
|
snapshot_builder = FakeSnapshotBuilder(
|
||||||
|
tool_path="path/to/mainline_modules_sdks.sh",
|
||||||
|
subprocess_runner=subprocess_runner,
|
||||||
|
out_dir=self.tmp_out_dir,
|
||||||
|
)
|
||||||
|
producer = mm.SdkDistProducer(
|
||||||
|
subprocess_runner=subprocess_runner,
|
||||||
|
snapshot_builder=snapshot_builder,
|
||||||
|
dist_dir=self.tmp_dist_dir,
|
||||||
|
)
|
||||||
|
|
||||||
|
modules = [
|
||||||
|
MAINLINE_MODULES_BY_APEX["com.android.art"],
|
||||||
|
MAINLINE_MODULES_BY_APEX["com.android.ipsec"],
|
||||||
|
# Create a google specific module.
|
||||||
|
mm.aosp_to_google(MAINLINE_MODULES_BY_APEX["com.android.wifi"]),
|
||||||
|
]
|
||||||
|
build_releases = [
|
||||||
|
mm.Q,
|
||||||
|
mm.R,
|
||||||
|
mm.S,
|
||||||
|
mm.LATEST,
|
||||||
|
mm.LEGACY_BUILD_RELEASE,
|
||||||
|
]
|
||||||
|
|
||||||
|
producer.produce_dist(modules, build_releases)
|
||||||
|
|
||||||
|
# Check the order in which the snapshots are built.
|
||||||
|
self.assertEqual([
|
||||||
|
(
|
||||||
|
"R",
|
||||||
|
{},
|
||||||
|
["current"],
|
||||||
|
["com.android.ipsec", "com.google.android.wifi"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"S",
|
||||||
|
{
|
||||||
|
"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S"
|
||||||
|
},
|
||||||
|
["current"],
|
||||||
|
[
|
||||||
|
"com.android.art", "com.android.ipsec",
|
||||||
|
"com.google.android.wifi"
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"latest",
|
||||||
|
{},
|
||||||
|
["current"],
|
||||||
|
[
|
||||||
|
"com.android.art", "com.android.ipsec",
|
||||||
|
"com.google.android.wifi"
|
||||||
|
],
|
||||||
|
),
|
||||||
|
('latest', {}, ['current'], []),
|
||||||
|
(
|
||||||
|
"legacy",
|
||||||
|
{},
|
||||||
|
["current"],
|
||||||
|
[
|
||||||
|
"com.android.art", "com.android.ipsec",
|
||||||
|
"com.google.android.wifi"
|
||||||
|
],
|
||||||
|
),
|
||||||
|
], snapshot_builder.snapshots)
|
||||||
|
|
||||||
|
|
||||||
def path_to_test_data(relative_path):
|
def path_to_test_data(relative_path):
|
||||||
"""Construct a path to a test data file.
|
"""Construct a path to a test data file.
|
||||||
|
|||||||
Reference in New Issue
Block a user