xref: /aosp_15_r20/external/executorch/kernels/test/custom_kernel_example/tests.bzl (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1load("@fbsource//xplat/executorch/kernels/test:util.bzl", "define_supported_features_lib", "generated_op_test")
2load(":targets.bzl", "MY_ATEN_COMPLIANT_OPS")
3
4def define_common_test_targets():
5    # Step 1: Define the function header wrapper in executorch/kernels/test/targets.bzl, like
6    # `codegen_function_header_wrapper("executorch/kernels/test/custom_kernel_example", "custom_kernel_example")`
7    # or generally `codegen_function_header_wrapper("<path-to-your-kernel>/<your-kernel-name>", "<your-kernel-name>")`
8    # This is needed because tests need to know our Functions.h target.
9    # TODO(T149423767): We should codegen this wrapper in #include, not let user define it.
10
11    # Step 2: Use the helper to produce the supported feature list for tests.
12    # Need to override some default features if different.
13    # See executorch/kernels/test/supported_features.yaml and supported_features_def_example.yaml.
14    define_supported_features_lib()
15
16    # Step 3: Use the helper generated_op_test to re-use existing tests
17    for op in MY_ATEN_COMPLIANT_OPS:
18        op_name = op["name"]
19
20        generated_op_test(
21            name = op_name + "_test",
22            op_impl_target = ":my_operators",
23            generated_lib_headers_target = ":generated_lib_headers",
24
25            # those two targets are defined in previous steps
26            supported_features_target = ":supported_features",
27            function_header_wrapper_target = "//executorch/kernels/test:function_header_wrapper_custom_kernel_example",
28        )
29