|
| 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