[Test] Consolidate kernel tests under plural kernels tree (#39966)

This commit is contained in:
Xiaoyu Zhang
2026-09-18 07:37:48 +08:00
committed by GitHub
parent b98a2d1096
commit 7bc9152447
53 changed files with 113 additions and 53 deletions
@@ -4,11 +4,12 @@ Pre-commit hook: reject CI-registered tests that live inside the importable
`sglang` package (python/sglang/).
Registered tests and benchmarks must live under test/registered/ (e.g.
test/registered/jit/ for JIT kernel tests and test/registered/jit/benchmark/
for JIT kernel benchmarks) so they are not shipped in the wheel and are
collected by run_suite.py's registered glob. A registered file placed inside
the package would be shipped to users AND silently dropped by run_suite.py
(which no longer globs the package) -- it would never run in CI. This guard
test/registered/kernels/ops/ for kernel tests and
test/registered/kernels/benchmark/ for kernel benchmarks) so they are not
shipped in the wheel and are collected by run_suite.py's registered glob. A
registered file placed inside the package would be shipped to users AND
silently dropped by run_suite.py (which no longer globs the package) -- it
would never run in CI. This guard
turns that silent skip into a hard failure.
Reuses ut_parse_one_file() from ci_register.py (AST-based) so the registry
@@ -65,8 +66,8 @@ def main() -> int:
)
print(
" Registered tests and benchmarks must live under test/registered/\n"
" (e.g. test/registered/jit/ for JIT kernel tests and\n"
" test/registered/jit/benchmark/ for JIT kernel benchmarks) so they\n"
" (e.g. test/registered/kernels/ops/ for kernel tests and\n"
" test/registered/kernels/benchmark/ for kernel benchmarks) so they\n"
" are not shipped in the wheel and are collected by run_suite.py.\n"
)
for f in offenders:
+14 -5
View File
@@ -39,10 +39,11 @@ _MODERN_SHAPE = re.compile(r"^(.+)-test-(.+)$")
# no suite any workflow invokes and the test silently never runs.
_LEGACY_CUDA_PREFIXES = ("stress",)
_TEST_KINDS = {"unit", "kernel", "e2e", "accuracy", "perf", "stress"}
_TEST_KINDS = {"unit", "e2e", "accuracy", "perf", "stress"}
_KERNEL_ROOT = "kernels"
# Flat vendor trees. Vendor-only coverage fits no kind above: no XPU/NPU suite
# carries the `-kernel-` infix `kernel` needs, and these launch device work.
# carries the `-kernel-` infix the kernel tree needs, and these launch device work.
_VENDOR_DIRS = {"amd", "mlx", "musa", "npu", "xpu"}
@@ -132,11 +133,22 @@ def taxonomy_errors(path: str, registries: list, tree: ast.AST) -> list[str]:
relative_parts = parts[2:] if parts[:2] == ["test", "registered"] else []
if relative_parts and relative_parts[0] in _VENDOR_DIRS:
return []
if relative_parts and relative_parts[0] == _KERNEL_ROOT:
errors = []
if len(relative_parts) < 4 or relative_parts[1] not in {"ops", "benchmark"}:
errors.append(
f"{path}: kernel tests must live under "
"test/registered/kernels/{ops,benchmark}/<group>/"
)
if any("-kernel-" not in (r.effective_suite or "") for r in registries):
errors.append(f"{path}: kernel tests must use a *-kernel-* suite")
return errors
if len(relative_parts) < 3 or relative_parts[0] not in _TEST_KINDS:
return [
f"{path}: registered tests must live under "
"test/registered/<kind>/<subsystem>/; kind must be one of "
+ ", ".join(sorted(_TEST_KINDS))
+ "; kernel tests use test/registered/kernels/{ops,benchmark}/<group>/"
]
kind = relative_parts[0]
@@ -153,9 +165,6 @@ def taxonomy_errors(path: str, registries: list, tree: ast.AST) -> list[str]:
errors.append(f"{path}: unit test est_time must be <= 60 seconds")
if _contains_call(tree, "popen_launch_server"):
errors.append(f"{path}: unit tests may not launch a server")
elif kind == "kernel":
if any("-kernel-" not in (r.effective_suite or "") for r in registries):
errors.append(f"{path}: kernel tests must use a *-kernel-* suite")
elif kind in {"accuracy", "perf"}:
invalid = [
r
@@ -0,0 +1,51 @@
import ast
import unittest
from types import SimpleNamespace
from scripts.lint.check_registered_tests import taxonomy_errors
def _registry(suite: str):
return SimpleNamespace(effective_suite=suite, est_time=1)
class TestRegisteredTestTaxonomy(unittest.TestCase):
def setUp(self):
self.tree = ast.parse("")
self.kernel_registry = [_registry("base-b-kernel-unit-test-1-gpu-large")]
def test_plural_kernel_ops_layout_is_accepted(self):
errors = taxonomy_errors(
"test/registered/kernels/ops/attention/test_example.py",
self.kernel_registry,
self.tree,
)
self.assertEqual(errors, [])
def test_plural_kernel_benchmark_layout_is_accepted(self):
errors = taxonomy_errors(
"test/registered/kernels/benchmark/attention/bench_example.py",
[_registry("base-b-kernel-benchmark-test-1-gpu-large")],
self.tree,
)
self.assertEqual(errors, [])
def test_singular_kernel_root_is_rejected(self):
errors = taxonomy_errors(
"test/registered/kernel/attention/test_example.py",
self.kernel_registry,
self.tree,
)
self.assertTrue(errors)
def test_kernel_group_is_required(self):
errors = taxonomy_errors(
"test/registered/kernels/ops/test_example.py",
self.kernel_registry,
self.tree,
)
self.assertTrue(errors)
if __name__ == "__main__":
unittest.main()