load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()

runtime.python_test(
    name = "test_xnnpack_passes",
    srcs = glob([
        "passes/*.py",
    ]) + [
        "test_xnnpack_utils_classes.py",
    ],
    deps = [
        "//executorch/backends/transforms:remove_getitem_op",
        "//executorch/backends/xnnpack/_passes:xnnpack_passes",
        "//executorch/backends/xnnpack/test/tester:tester",
        "//executorch/backends/xnnpack/utils:xnnpack_utils",
        "//executorch/exir:lib",
        "//executorch/exir:pass_base",
        "//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
        "//executorch/exir/dialects:lib",
    ],
    external_deps = [
        "libtorch",
    ],
)

runtime.python_test(
    name = "test_xnnpack_ops",
    srcs = glob([
        "ops/*.py",
    ]) + [
        "test_xnnpack_utils.py",
    ],
    deps = [
        "//executorch/backends/xnnpack/partition:xnnpack_partitioner",
        "//executorch/backends/xnnpack/quantizer:xnnpack_quantizer",
        "//executorch/backends/xnnpack/test/tester:tester",
        "//executorch/devtools:lib",
        "//executorch/devtools/bundled_program:config",
        "//executorch/devtools/bundled_program/serialize:lib",
        "//executorch/exir/passes:constant_prop_pass",
        "//pytorch/ao:torchao",  # @manual
    ],
    external_deps = [
        "libtorch",
    ],
)

runtime.python_test(
    name = "test_xnnpack_models",
    srcs = glob([
        "models/*.py",
    ]),
    labels = ["long_running"],
    deps = [
        "fbsource//third-party/pypi/timm:timm",
        "fbsource//third-party/pypi/torchsr:torchsr",  # @manual
        "fbsource//third-party/pypi/transformers:transformers",  # @manual
        "//executorch/backends/xnnpack/test/tester:tester",
        "//executorch/examples/models/llama:llama2_model",
        "//pytorch/audio/src:torchaudio_core",
        "//pytorch/vision:torchvision",  # @manual
    ],
    external_deps = [
        "libtorch",
    ],
)

runtime.python_test(
    name = "test_xnnpack_serialization",
    srcs = glob([
        "serialization/*.py",
    ]),
    deps = [
        "//executorch/backends/xnnpack:xnnpack_preprocess",
    ],
)

runtime.python_test(
    name = "test_xnnpack_quantizer",
    srcs = glob([
        "quantizer/*.py",
    ]),
    deps = [
        "//executorch/backends/xnnpack:xnnpack_preprocess",
        "//executorch/backends/xnnpack/quantizer:xnnpack_quantizer",
        "//pytorch/ao:torchao",  # @manual
        "//caffe2:torch",
    ],
    external_deps = [
        "libtorch",
    ],
)

runtime.python_test(
    name = "test_xnnpack_recipes",
    srcs = glob([
        "recipes/*.py",
    ]),
    env = {
        "HTTP_PROXY": "http://fwdproxy:8080",
        "HTTPS_PROXY": "http://fwdproxy:8080",
    },
    deps = [
       "//executorch/backends/xnnpack/recipes:xnnpack_recipes",
        "//executorch/export:lib",
        "//pytorch/vision:torchvision",  # @manual
        "//executorch/backends/xnnpack/test/tester:tester",
        "//executorch/examples/models:models",  # @manual
        "//executorch/examples/xnnpack:models",  # @manual
    ],
)
