Skip to content

Commit 6bea3b7

Browse files
committed
update tests: enhance mock usage and fix integration tests for Android installer
- Mock license acceptance to avoid actual `sdkmanager` calls and refine AVD creation flow. - Improve validation in NDK-related test cases, including TAR & DMG handling. - Adjust `_get_download_url` logic with refined mocks for accurate URL construction. - Simplify `resolve_path` and environment variable-dependent tests to align with actual implementation. - Remove obsolete test cases, re-enable resolved entries in `skip_list.txt`, and consolidate edge case coverage.
1 parent 2fe02c1 commit 6bea3b7

10 files changed

Lines changed: 314 additions & 265 deletions

File tree

ovmobilebench/android/installer/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def get_ndk_filename(version: str) -> str:
119119
if host.os == "windows":
120120
return f"android-ndk-{version}-windows.zip"
121121
elif host.os == "darwin":
122-
return f"android-ndk-{version}-darwin.dmg"
122+
return f"android-ndk-{version}-darwin.zip"
123123
else:
124124
return f"android-ndk-{version}-linux.zip"
125125

ovmobilebench/packaging/packager.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ def __init__(
2020
config: PackageConfig,
2121
models: list[ModelItem],
2222
output_dir: Path,
23+
android_abi: str = "arm64-v8a",
2324
):
2425
self.config = config
2526
self.models = models
2627
self.output_dir = ensure_dir(output_dir)
28+
self.android_abi = android_abi
2729

2830
def create_bundle(
2931
self,
@@ -111,21 +113,33 @@ def _copy_ndk_stl_lib(self, dest_dir: Path):
111113
logger.warning("Android NDK not found, libc++_shared.so will not be included")
112114
return
113115

114-
# Find libc++_shared.so for aarch64
116+
# Map Android ABI to NDK arch directory name
117+
abi_to_arch = {
118+
"arm64-v8a": "aarch64-linux-android",
119+
"armeabi-v7a": "arm-linux-androideabi",
120+
"x86": "i686-linux-android",
121+
"x86_64": "x86_64-linux-android",
122+
}
123+
124+
arch_dir = abi_to_arch.get(self.android_abi, "aarch64-linux-android")
125+
126+
# Find libc++_shared.so for the target architecture
115127
stl_paths = [
116128
ndk_root
117-
/ "toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so",
129+
/ f"toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/{arch_dir}/libc++_shared.so",
130+
ndk_root
131+
/ f"toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/{arch_dir}/libc++_shared.so",
118132
ndk_root
119-
/ "toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so",
133+
/ f"toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/{arch_dir}/libc++_shared.so",
120134
]
121135

122136
for stl_path in stl_paths:
123137
if stl_path.exists():
124138
shutil.copy2(stl_path, dest_dir / "libc++_shared.so")
125-
logger.info("Copied libc++_shared.so from Android NDK")
139+
logger.info(f"Copied libc++_shared.so for {self.android_abi} from Android NDK")
126140
return
127141

128-
logger.warning("libc++_shared.so not found in Android NDK")
142+
logger.warning(f"libc++_shared.so not found in Android NDK for {self.android_abi}")
129143

130144
def _copy_models(self, models_dir: Path):
131145
"""Copy model files."""

ovmobilebench/pipeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ def package(self) -> Path | None:
9393
artifacts = self._get_install_artifacts(download_dir)
9494

9595
# Create package
96+
# Get Android ABI from openvino config if available
97+
android_abi = "arm64-v8a" # default
98+
if hasattr(self.config, "openvino") and hasattr(self.config.openvino, "toolchain"):
99+
android_abi = getattr(self.config.openvino.toolchain, "abi", "arm64-v8a")
100+
96101
packager = Packager(
97102
self.config.package,
98103
self.config.get_model_list(),
99104
self.artifacts_dir / "packages",
105+
android_abi=android_abi,
100106
)
101107

102108
bundle_name = f"ovbundle_{self.config.project.run_id}"

tests/android/installer/test_detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def test_get_ndk_filename_macos(self, mock_detect):
162162
"""Test getting NDK filename for macOS."""
163163
mock_detect.return_value = Mock(os="darwin")
164164
filename = get_ndk_filename("r26d")
165-
assert filename == "android-ndk-r26d-darwin.dmg"
165+
assert filename == "android-ndk-r26d-darwin.zip"
166166

167167
@patch("ovmobilebench.android.installer.detect.detect_host")
168168
def test_get_ndk_filename_windows(self, mock_detect):

tests/android/installer/test_integration.py

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,26 @@ def test_full_installation_flow(self, mock_check_disk, mock_detect_host, mock_su
5656

5757
installer = AndroidInstaller(self.sdk_root)
5858

59-
# Mock AVD creation
60-
with patch.object(installer.avd, "create") as mock_avd_create:
61-
mock_avd_create.return_value = True
59+
# Mock license acceptance to avoid actual sdkmanager call
60+
with patch.object(installer.sdk, "accept_licenses") as mock_accept:
61+
mock_accept.return_value = None
6262

63-
result = installer.ensure(
64-
api=30,
65-
target="google_atd",
66-
arch="arm64-v8a",
67-
ndk=NdkSpec(alias="r26d"),
68-
create_avd_name="test_avd",
69-
dry_run=False,
70-
)
63+
# Mock AVD creation
64+
with patch.object(installer.avd, "create") as mock_avd_create:
65+
mock_avd_create.return_value = True
7166

72-
assert isinstance(result, dict)
73-
assert result["sdk_root"] == self.sdk_root
74-
assert result["avd_created"] is True
67+
result = installer.ensure(
68+
api=30,
69+
target="google_atd",
70+
arch="arm64-v8a",
71+
ndk=NdkSpec(alias="r26d"),
72+
create_avd_name="test_avd",
73+
dry_run=False,
74+
)
75+
76+
assert isinstance(result, dict)
77+
assert result["sdk_root"] == self.sdk_root
78+
assert result["avd_created"] is True
7579

7680
@patch("subprocess.run")
7781
@patch("ovmobilebench.android.installer.detect.detect_host")
@@ -288,44 +292,48 @@ def test_concurrent_component_installation(
288292

289293
installer = AndroidInstaller(self.sdk_root)
290294

291-
# Mock multiple components needing installation
292-
with patch.object(installer.sdk, "ensure_platform_tools") as mock_platform:
293-
with patch.object(installer.sdk, "ensure_emulator") as mock_emulator:
294-
with patch.object(installer.sdk, "ensure_build_tools") as mock_build:
295-
with patch.object(installer.ndk, "ensure") as mock_ndk:
296-
# Create cmdline tools and mock components first
297-
self._create_cmdline_tools()
298-
299-
# Create the directories that would be created
300-
(self.sdk_root / "platforms" / "android-30").mkdir(parents=True)
301-
(
302-
self.sdk_root
303-
/ "system-images"
304-
/ "android-30"
305-
/ "google_atd"
306-
/ "arm64-v8a"
307-
).mkdir(parents=True)
308-
(self.sdk_root / "cmake" / "3.22.1").mkdir(parents=True)
309-
310-
# Set up return values
311-
mock_platform.return_value = self.sdk_root / "platform-tools"
312-
mock_emulator.return_value = self.sdk_root / "emulator"
313-
mock_build.return_value = self.sdk_root / "build-tools" / "34.0.0"
314-
mock_ndk.return_value = self.sdk_root / "ndk" / "26.3.11579264"
315-
316-
installer.ensure(
317-
api=30,
318-
target="google_atd",
319-
arch="arm64-v8a",
320-
ndk=NdkSpec(alias="r26d"),
321-
install_build_tools="34.0.0",
322-
dry_run=False,
323-
)
324-
325-
# All should be called
326-
mock_platform.assert_called_once()
327-
mock_emulator.assert_called_once()
328-
mock_build.assert_called_once_with("34.0.0")
295+
# Mock license acceptance to avoid actual sdkmanager call
296+
with patch.object(installer.sdk, "accept_licenses") as mock_accept:
297+
mock_accept.return_value = None
298+
299+
# Mock multiple components needing installation
300+
with patch.object(installer.sdk, "ensure_platform_tools") as mock_platform:
301+
with patch.object(installer.sdk, "ensure_emulator") as mock_emulator:
302+
with patch.object(installer.sdk, "ensure_build_tools") as mock_build:
303+
with patch.object(installer.ndk, "ensure") as mock_ndk:
304+
# Create cmdline tools and mock components first
305+
self._create_cmdline_tools()
306+
307+
# Create the directories that would be created
308+
(self.sdk_root / "platforms" / "android-30").mkdir(parents=True)
309+
(
310+
self.sdk_root
311+
/ "system-images"
312+
/ "android-30"
313+
/ "google_atd"
314+
/ "arm64-v8a"
315+
).mkdir(parents=True)
316+
(self.sdk_root / "cmake" / "3.22.1").mkdir(parents=True)
317+
318+
# Set up return values
319+
mock_platform.return_value = self.sdk_root / "platform-tools"
320+
mock_emulator.return_value = self.sdk_root / "emulator"
321+
mock_build.return_value = self.sdk_root / "build-tools" / "34.0.0"
322+
mock_ndk.return_value = self.sdk_root / "ndk" / "26.3.11579264"
323+
324+
installer.ensure(
325+
api=30,
326+
target="google_atd",
327+
arch="arm64-v8a",
328+
ndk=NdkSpec(alias="r26d"),
329+
install_build_tools="34.0.0",
330+
dry_run=False,
331+
)
332+
333+
# All should be called
334+
mock_platform.assert_called_once()
335+
mock_emulator.assert_called_once()
336+
mock_build.assert_called_once_with("34.0.0")
329337

330338
# Helper methods to create mock components
331339

0 commit comments

Comments
 (0)