Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions .ci/scripts/tests/test_cortex_m_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
ROOT = Path(__file__).resolve().parents[3]
CONFIG = "backends/arm/test/pytest.ini"
SUITE = "backends/cortex_m/test"
HELPER = ".ci/scripts/torchci-report-args.sh"


@unittest.skipUnless(
sys.platform == "linux" and shutil.which("bash"),
"Cortex-M reporting uses Linux Bash",
os.name == "posix" and shutil.which("bash"), "Cortex-M workflows use Bash"
)
class CortexMReportingTest(unittest.TestCase):
def test_workflows_keep_the_arm_config_and_repo_relative_test_ids(self):
Expand All @@ -34,10 +32,19 @@ def test_workflows_keep_the_arm_config_and_repo_relative_test_ids(self):
)
with tempfile.TemporaryDirectory() as directory:
repo = Path(directory)
for name in (CONFIG, HELPER):
for name in (CONFIG, "tools/__init__.py", "tools/pytest_torchci.py"):
target = repo / name
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(ROOT / name, target)
torchci = repo / "torch/testing/_internal/torchci"
torchci.mkdir(parents=True)
(repo / "torch/__init__.py").touch()
(torchci / "report.py").write_text("SCHEMA_VERSION = '1.0'\n")
(torchci / "plugin.py").write_text(
"from pathlib import Path\n"
"def pytest_sessionstart(session):\n"
" Path(session.config.option.torchci_report_prefix).touch()\n"
)
# Widening confcutdir would also load ExecuTorch's root seed hook.
(repo / "conftest.py").write_text(
"raise RuntimeError('root hook loaded')\n"
Expand All @@ -60,30 +67,30 @@ def test_workflows_keep_the_arm_config_and_repo_relative_test_ids(self):
" assert target == os.environ['EXPECTED_TARGET']\n"
)
env = dict(
os.environ, PYTEST_DISABLE_PLUGIN_AUTOLOAD="1", PYTHON=sys.executable
os.environ,
PATH=os.pathsep.join(
(str(Path(sys.executable).parent), os.environ["PATH"])
),
PYTEST_DISABLE_PLUGIN_AUTOLOAD="1",
PYTEST_ADDOPTS="-v",
RUNNER_TEST_RUN_REPORTS_DIR=str(repo),
JOB_ID="1",
GITHUB_REPOSITORY="pytorch/executorch",
)
for name in (
"PYTEST_ADDOPTS",
"PYTEST_PLUGINS",
"RUNNER_TEST_RUN_REPORTS_DIR",
):
env.pop(name, None)
env.pop("PYTEST_PLUGINS", None)
for workflow, job, target in jobs:
with self.subTest(target=target):
path = ROOT / ".github/workflows" / workflow
inputs = yaml.safe_load(path.read_text(encoding="utf-8"))["jobs"][
job
]["with"]
self.assertIs(inputs["upload-test-run-reports"], True)
tail = inputs["script"].split(f"source {HELPER} ", 1)[1]
tail = tail.replace("${{ matrix.target }}", target)
script = inputs["script"]
command = script[script.index("TORCHCI_REPORT_NAME=") :].replace(
"${{ matrix.target }}", target
)
result = subprocess.run(
[
"bash",
"-eu",
"-c",
f'pytest() {{ "$PYTHON" -m pytest -v "$@"; }}\nsource {HELPER} {tail}',
],
["bash", "-eu", "-c", command],
cwd=repo,
env=dict(env, EXPECTED_TARGET=target),
capture_output=True,
Expand All @@ -96,3 +103,9 @@ def test_workflows_keep_the_arm_config_and_repo_relative_test_ids(self):
self.assertIn(
f"{SUITE}/ops/test_smoke.py::test_target PASSED", result.stdout
)
prefix = (
"cortex-m"
if workflow == "pull.yml"
else f"cortex-m-ops-{target}"
)
self.assertTrue((repo / prefix).is_file(), result.stdout)
3 changes: 3 additions & 0 deletions .ci/scripts/tests/test_torchci_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def configure(env, config=None, **stubs):
with contextlib.ExitStack() as stack:
stack.enter_context(mock.patch.dict(sys.modules, stub_modules(**stubs)))
stack.enter_context(mock.patch.dict(os.environ, env, clear=True))
stack.enter_context(mock.patch.object(sys, "path", [str(ROOT), *sys.path]))
sys.modules.pop("tools", None)
sys.modules.pop("tools.pytest_torchci", None)
spec.loader.exec_module(module)
module.pytest_configure(config)
return module, config
Expand Down
188 changes: 0 additions & 188 deletions .ci/scripts/tests/test_torchci_report_args.py

This file was deleted.

38 changes: 0 additions & 38 deletions .ci/scripts/torchci-report-args.sh

This file was deleted.

5 changes: 1 addition & 4 deletions .ci/scripts/unittest-linux-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ fi

bash .ci/scripts/tests/vulkan/test_vulkan_cmake_package.sh

source .ci/scripts/torchci-report-args.sh unittest-linux-cmake

source .ci/scripts/setup-hf-cache.sh

# Run pytest with coverage
pytest -n auto --cov=./ --cov-report=xml \
${TORCHCI_REPORT_ARGS[@]+"${TORCHCI_REPORT_ARGS[@]}"}
pytest -n auto --cov=./ --cov-report=xml
# Run gtest
LLVM_PROFDATA=llvm-profdata-12 LLVM_COV=llvm-cov-12 \
test/run_oss_cpp_tests.sh
4 changes: 2 additions & 2 deletions .github/workflows/_test_cortex_m_ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ jobs:
# op set, implementation tests check FVP numerics. Both are parametrized
# over --cortex-m-target, so a future target-dependent lowering change is
# caught here. (cortex-m55 runs on pull via the full-suite job.)
source .ci/scripts/torchci-report-args.sh cortex-m-ops-${{ matrix.target }}
pytest ${TORCHCI_REPORT_ARGS[@]+"${TORCHCI_REPORT_ARGS[@]}"} --rootdir=. \
TORCHCI_REPORT_NAME=cortex-m-ops-${{ matrix.target }} \
python -m pytest -p tools.pytest_torchci --rootdir=. \
-c backends/arm/test/pytest.ini \
backends/cortex_m/test/ops \
--cortex-m-target=${{ matrix.target }}
4 changes: 2 additions & 2 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,8 @@ jobs:
backends/cortex_m/test/build_test_runner.sh

# Use repo-relative report identities without loading the root seed hook.
source .ci/scripts/torchci-report-args.sh cortex-m
pytest ${TORCHCI_REPORT_ARGS[@]+"${TORCHCI_REPORT_ARGS[@]}"} --rootdir=. \
TORCHCI_REPORT_NAME=cortex-m \
python -m pytest -p tools.pytest_torchci --rootdir=. \
-c backends/arm/test/pytest.ini backends/cortex_m/test

android:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ TEST_F(
EXPECT_TENSOR_EQ(out_pc, out_pt);
}

// The uint8 typed entry, on the first row of the linear test's input.
// Expected values are aot/ref_implementations.py's with the multiplier negated,
// for the reason test_op_quantized_linear.cpp gives.
// The uint8 typed entry, on the first row of the linear test's input, with
// the scale test_op_quantized_linear.cpp works out.
TEST_F(GenericQuantizedFullyConnectedPerChannelTest, Asym8uPerTensor) {
TensorFactory<ScalarType::Byte> tf_uint8;
TensorFactory<ScalarType::Int> tf_int32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ TEST_F(GenericQuantizedLinearPerChannelTest, LengthOneMatchesPerTensor) {

// The uint8 typed entry. The kernel computes -out_multiplier / (1 << 31), and
// 1 << 31 is INT_MIN, so the scale is +out_multiplier / 2^31, as
// quantize_tensor_multiplier produces. aot/ref_implementations.py computes
// -out_multiplier / 2^31, so the expected values come from it with the
// multiplier negated: (src - 128) @ (weight - 128)^T + bias =
// quantize_tensor_multiplier produces and aot/ref_implementations.py
// computes: (src - 128) @ (weight - 128)^T + bias =
// [[-3, 80], [-4, 0]], times 1/4, plus 100.
TEST_F(GenericQuantizedLinearPerChannelTest, Asym8uPerTensor) {
TensorFactory<ScalarType::Byte> tf_uint8;
Expand Down
Loading
Loading