Skip to content

Commit 83a8bb8

Browse files
jeffkilpatrickGitHub Enterprise
authored andcommitted
[AISW-143208] build_and_test.py can run Android tests on local device (microsoft#181)
1 parent 11f0f4c commit 83a8bb8

File tree

5 files changed

+92
-9
lines changed

5 files changed

+92
-9
lines changed

qcom/build_and_test.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
task,
2323
)
2424
from ep_build.task import (
25+
CompositeTask,
2526
ExtractArchiveTask,
2627
ListTasksTask,
2728
NoOpTask,
29+
PyTestTask,
2830
)
2931
from ep_build.tasks.build import (
3032
BuildEpLinuxTask,
@@ -37,6 +39,7 @@
3739
REPO_ROOT,
3840
is_host_arm64,
3941
is_host_linux,
42+
is_host_mac,
4043
is_host_windows,
4144
)
4245

@@ -153,7 +156,7 @@ def to_dot(highlight: list[str] | None = None) -> str:
153156
@task
154157
@depends(["build_ort_android"])
155158
def archive_ort_android(self, plan: Plan) -> str:
156-
if is_host_linux():
159+
if is_host_linux() or is_host_mac():
157160
return plan.add_step(
158161
BuildEpLinuxTask(
159162
"Archiving ONNX Runtime for Android",
@@ -234,7 +237,7 @@ def build(self, plan: Plan) -> str:
234237
@task
235238
@depends(["create_venv"])
236239
def build_ort_android(self, plan: Plan) -> str:
237-
if is_host_linux():
240+
if is_host_linux() or is_host_mac():
238241
return plan.add_step(
239242
BuildEpLinuxTask(
240243
"Building ONNX Runtime for Android",
@@ -392,6 +395,37 @@ def test_ort_linux(self, plan: Plan) -> str:
392395
)
393396
)
394397

398+
@task
399+
@depends(["archive_ort_android"])
400+
def test_ort_local_android(self, plan: Plan) -> str:
401+
env = dict(os.environ)
402+
test_root = REPO_ROOT / "build" / "qdc_test_root"
403+
env["QDC_TEST_ROOT"] = str(test_root)
404+
405+
# This is a pretty slow way to do this, but it's easy to implement
406+
# and essentially free to maintain. If you find yourself using this
407+
# often enough that your life would be better if we didn't roundtrip
408+
# through a zip file, please open a Jira and we'll invest more here.
409+
return plan.add_step(
410+
CompositeTask(
411+
group_name=None,
412+
tasks=[
413+
ExtractArchiveTask(
414+
"Extracting ONNX Runtime for Android",
415+
REPO_ROOT / "build" / "onnxruntime-tests-android.zip",
416+
test_root,
417+
),
418+
PyTestTask(
419+
"Testing ONNX Runtime for Android with a local device",
420+
self.__venv_path,
421+
["tests"],
422+
env=env,
423+
cwd=REPO_ROOT / "qcom" / "scripts" / "linux" / "appium",
424+
),
425+
],
426+
)
427+
)
428+
395429
@task
396430
@depends(["archive_ort_android"])
397431
def test_ort_qdc_android(self, plan: Plan) -> str:

qcom/ep_build/task.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,16 @@ def run_task(self) -> None:
291291
self.true_task.run()
292292
else:
293293
self.false_task.run()
294+
295+
296+
class PyTestTask(RunExecutablesWithVenvTask):
297+
def __init__(
298+
self,
299+
group_name: str | None,
300+
venv: Path | None,
301+
files_or_dirs: list[str],
302+
env: Mapping[str, str] | None = None,
303+
cwd: Path | None = None,
304+
):
305+
cmd = [["pytest", *files_or_dirs]]
306+
super().__init__(group_name, venv, cmd, env, cwd)

qcom/packages.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ ccache_linux:
1717
url: https://github.com/ccache/ccache/releases/download/v{version}/ccache-{version}-linux-x86_64.tar.xz
1818
sha256: 7766991b91b3a5a177ab33fa043fe09e72c68586d5a86d20a563a05b74f119c0
1919
content_root: ccache-{version}-linux-x86_64
20+
ccache_macos:
21+
version: 4.11.3
22+
url: https://github.com/ccache/ccache/releases/download/v{version}/ccache-{version}-darwin.tar.gz
23+
sha256: 6f187a79fc57864d900aff28f9c3f93d020ed7a849be2f2ead6799959ccf30b0
24+
content_root: ccache-{version}-darwin
2025
ccache_windows_x86_64:
2126
version: 4.11.3
2227
url: https://github.com/ccache/ccache/releases/download/v{version}/ccache-{version}-windows-x86_64.zip
@@ -28,6 +33,12 @@ cmake_linux:
2833
sha256: 14e15d0b445dbeac686acc13fe13b3135e8307f69ccf4c5c91403996ce5aa2d4
2934
content_root: cmake-{version}-linux-x86_64
3035
bindir: bin
36+
cmake_macos:
37+
version: 3.31.7
38+
url: https://github.com/Kitware/CMake/releases/download/v{version}/cmake-{version}-macos-universal.tar.gz
39+
sha256: 1cb11aa2edae8551bb0f22807c6f5246bd0eb60ae9fa1474781eb4095d299aca
40+
content_root: cmake-{version}-macos-universal/CMake.app/Contents
41+
bindir: bin
3142
cmake_windows_x86_64:
3243
version: 3.31.7
3344
url: https://github.com/Kitware/CMake/releases/download/v{version}/cmake-{version}-windows-x86_64.zip
@@ -41,6 +52,13 @@ java_linux:
4152
sha256: 9c2f7c39e0d5b296ce50e563740694b2ebfe4a620415d1b2b848ba47bebceb47
4253
content_root: jdk-{version}
4354
bindir: bin
55+
java_macos:
56+
major_version: 21
57+
version: 21.0.5
58+
url: https://download.oracle.com/java/{major_version}/archive/jdk-{version}_macos-aarch64_bin.tar.gz
59+
sha256: 13cb8d754069fc76a2ff6eee96273cc1a96cb47ecf3afa7820407635c386dd37
60+
content_root: jdk-{version}.jdk/Contents/Home
61+
bindir: bin
4462
java_windows_x86_64:
4563
major_version: 21
4664
version: 21.0.5
@@ -52,6 +70,10 @@ ninja_linux:
5270
version: 1.12.1
5371
url: https://github.com/ninja-build/ninja/releases/download/v{version}/ninja-linux.zip
5472
sha256: 6f98805688d19672bd699fbbfa2c2cf0fc054ac3df1f0e6a47664d963d530255
73+
ninja_macos:
74+
version: 1.12.1
75+
url: https://github.com/ninja-build/ninja/releases/download/v{version}/ninja-mac.zip
76+
sha256: 89a287444b5b3e98f88a945afa50ce937b8ffd1dcc59c555ad9b1baf855298c9
5577
ninja_windows_x86_64:
5678
version: 1.12.1
5779
url: https://github.com/ninja-build/ninja/releases/download/v{version}/ninja-win.zip

qcom/scripts/linux/appium/tests/test_ort.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ def __get_test_cmd(test_cmd: list[str]) -> str:
6464
f"echo -=-=-=-=-=-=-=-=-=-=- >> {ORT_TEST_RESULTS_DEVICE_LOG} && "
6565
f"echo Running test: {test_str} >> {ORT_TEST_RESULTS_DEVICE_LOG} && "
6666
f"env ADSP_LIBRARY_PATH={QNN_ADSP_LIBRARY_PATH} LD_LIBRARY_PATH={QNN_LD_LIBRARY_PATH} "
67-
f"{test_str} >> {ORT_TEST_RESULTS_DEVICE_LOG} 2>&1"
67+
f"{test_str} 2>&1 | tee -a {ORT_TEST_RESULTS_DEVICE_LOG}"
6868
)

qcom/scripts/linux/tools.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,42 @@ function clean_tools_dir() {
2020
function get_android_ndk_root() {
2121
python \
2222
"${REPO_ROOT}/qcom/scripts/all/install_ndk.py" \
23-
"--cli-tools-root=$(get_package_contentdir android_commandlinetools_linux)"
23+
"--cli-tools-root=$(get_package_contentdir android_commandlinetools_$(get_host_platform))"
2424
}
2525

2626
#
2727
# Get the Android SDK root (ANDROID_HOME)
2828
#
2929
function get_android_sdk_root() {
30-
realpath $(get_package_contentdir android_commandlinetools_linux)/..
30+
realpath $(get_package_contentdir android_commandlinetools_$(get_host_platform))/..
3131
}
3232

3333
#
3434
# Get the directory containing ccache, installing it if necessary.
3535
#
3636
function get_ccache_bindir() {
37-
get_package_bindir ccache_linux
37+
get_package_bindir ccache_$(get_host_platform)
3838
}
3939

4040
#
4141
# Get the directory containing CMake binaries, installing them if necessary.
4242
#
4343
function get_cmake_bindir() {
44-
get_package_bindir cmake_linux
44+
get_package_bindir cmake_$(get_host_platform)
45+
}
46+
47+
function get_host_platform() {
48+
case `uname` in
49+
Darwin)
50+
echo "macos"
51+
;;
52+
Linux)
53+
echo "linux"
54+
;;
55+
*)
56+
die "Unknown host platform"
57+
;;
58+
esac
4559
}
4660

4761
#
@@ -51,15 +65,15 @@ function get_java_bindir() {
5165
if [ -n "${JAVA_HOME:-}" ]; then
5266
log_debug "JAVA_HOME found at ${JAVA_HOME}"
5367
else
54-
get_package_bindir java_linux
68+
get_package_bindir java_$(get_host_platform)
5569
fi
5670
}
5771

5872
#
5973
# Get the directory containing ninja, installing it if necessary.
6074
#
6175
function get_ninja_bindir() {
62-
get_package_bindir ninja_linux
76+
get_package_bindir ninja_$(get_host_platform)
6377
}
6478

6579
function get_package_bindir() {

0 commit comments

Comments
 (0)