Skip to content

Commit 3520b20

Browse files
forward fix and add additional tests for CI
Summary: Enable `test_qnn_delegate` tests to run on PR Differential Revision: D102010420
1 parent 0795efb commit 3520b20

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

.github/workflows/pull.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,45 @@ jobs:
923923
# Run QNN pass unit tests
924924
pytest -xvs backends/qualcomm/tests/test_passes.py
925925
926+
test-qnn-delegate-linux:
927+
name: test-qnn-delegate-linux
928+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
929+
permissions:
930+
id-token: write
931+
contents: read
932+
strategy:
933+
fail-fast: false
934+
with:
935+
runner: linux.2xlarge
936+
docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk
937+
submodules: 'recursive'
938+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
939+
timeout: 90
940+
script: |
941+
# The generic Linux job chooses to use base env, not the one setup by the image
942+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
943+
conda activate "${CONDA_ENV}"
944+
945+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
946+
# Source (not bash) so QNN_SDK_ROOT stays in the environment
947+
PYTHON_EXECUTABLE=python source .ci/scripts/build-qnn-sdk.sh
948+
949+
# Editable install so the PyQnnManagerAdaptor .so built by build-qnn-sdk.sh
950+
# is visible in the source tree
951+
CMAKE_ARGS="-DEXECUTORCH_BUILD_QNN=ON -DQNN_SDK_ROOT=$QNN_SDK_ROOT -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON" \
952+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool cmake --editable true
953+
954+
pip install -r requirements-examples.txt
955+
956+
# Enable conftest.py to call setup_environment() for pytest runs
957+
export QNN_DELEGATE_TEST=1
958+
export LD_LIBRARY_PATH="$QNN_SDK_ROOT/lib/x86_64-linux-clang/:$(realpath build-x86/lib/):${LD_LIBRARY_PATH:-}"
959+
960+
# Run operator and utility test classes (skip model/LLM/example tests
961+
# that need a device or large pretrained artifacts)
962+
pytest -xvs backends/qualcomm/tests/test_qnn_delegate.py \
963+
-k "TestQNNFloatingPointOperator or TestQNNQuantizedOperator or TestQNNFloatingPointUtils or TestQNNQuantizedUtils"
964+
926965
test-phi-3-mini-runner-linux:
927966
name: test-phi-3-mini-runner-linux
928967
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) Qualcomm Innovation Center, Inc.
2+
# All rights reserved
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
"""Pytest conftest for test_qnn_delegate.py.
8+
9+
When test_qnn_delegate.py is invoked via pytest (instead of as __main__),
10+
setup_environment() is never called, so TestQNN class attributes remain at
11+
their defaults (None / empty string / False). This conftest bridges the gap
12+
by calling setup_environment() with a synthetic argv built from environment
13+
variables, keeping a single source of truth for attribute assignment.
14+
15+
Required env vars for x86 simulator execution:
16+
QNN_SOC_MODEL - e.g. "SM8650"
17+
QNN_SDK_ROOT - path to QNN SDK (also used by verify_output)
18+
19+
Optional env vars (with defaults shown):
20+
QNN_BACKEND - "htp"
21+
QNN_BUILD_FOLDER - "build-x86"
22+
QNN_ENABLE_X86_64 - "1" to enable x86 simulator mode
23+
EXECUTORCH_ROOT - cwd
24+
QNN_ARTIFACT_DIR - "/tmp/qnn_test_artifacts"
25+
"""
26+
27+
import os
28+
import sys
29+
30+
31+
def pytest_configure(config):
32+
if os.environ.get("QNN_DELEGATE_TEST") != "1":
33+
return
34+
35+
argv = [
36+
"test_qnn_delegate.py",
37+
"--soc_model",
38+
os.environ.get("QNN_SOC_MODEL", "SM8650"),
39+
"--backend",
40+
os.environ.get("QNN_BACKEND", "htp"),
41+
"--build_folder",
42+
os.environ.get("QNN_BUILD_FOLDER", "build-x86"),
43+
"--executorch_root",
44+
os.environ.get("EXECUTORCH_ROOT", os.getcwd()),
45+
"--artifact_dir",
46+
os.environ.get("QNN_ARTIFACT_DIR", "/tmp/qnn_test_artifacts"),
47+
]
48+
49+
if os.environ.get("QNN_ENABLE_X86_64", "1") == "1":
50+
argv.append("--enable_x86_64")
51+
52+
original_argv = sys.argv
53+
try:
54+
sys.argv = argv
55+
from executorch.backends.qualcomm.tests.test_qnn_delegate import (
56+
setup_environment,
57+
)
58+
59+
setup_environment()
60+
finally:
61+
sys.argv = original_argv

0 commit comments

Comments
 (0)