diff --git a/runtime/kernel/test/CMakeLists.txt b/runtime/kernel/test/CMakeLists.txt new file mode 100644 index 0000000000..189cb87f6c --- /dev/null +++ b/runtime/kernel/test/CMakeLists.txt @@ -0,0 +1,65 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# +# This file should be formatted with +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ +# It should also be cmake-lint clean. +# + +cmake_minimum_required(VERSION 3.19) +project(runtime_kernel_test) + +# Use C++17 for test. +set(CMAKE_CXX_STANDARD 17) + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) + +include(${EXECUTORCH_ROOT}/build/Test.cmake) + +add_executable(operator_registry_test operator_registry_test.cpp) +target_link_libraries( + operator_registry_test GTest::gtest GTest::gtest_main GTest::gmock executorch +) +target_include_directories(operator_registry_test PRIVATE ${EXECUTORCH_ROOT}/..) +add_test(ExecuTorchTest operator_registry_test) + +add_executable(kernel_runtime_context_test kernel_runtime_context_test.cpp) +target_link_libraries( + kernel_runtime_context_test GTest::gtest GTest::gtest_main GTest::gmock + executorch +) +target_include_directories( + kernel_runtime_context_test PRIVATE ${EXECUTORCH_ROOT}/.. +) +add_test(ExecuTorchTest kernel_runtime_context_test) + +add_executable( + operator_registry_max_kernel_num_test + operator_registry_max_kernel_num_test.cpp + ../operator_registry.cpp + ../../core/evalue.cpp + ../../platform/abort.cpp + ../../platform/log.cpp + ../../platform/runtime.cpp + ../../platform/target/Posix.cpp +) +target_link_libraries( + operator_registry_max_kernel_num_test GTest::gtest GTest::gtest_main + GTest::gmock +) +target_compile_definitions( + operator_registry_max_kernel_num_test PRIVATE "-DMAX_KERNEL_NUM=1" +) +target_include_directories( + operator_registry_max_kernel_num_test PRIVATE ${EXECUTORCH_ROOT}/.. +) +add_test(ExecuTorchTest operator_registry_max_kernel_num_test) + +# TODO: Migrate kernel_double_registration_test and +# test_kernel_manual_registration. Make sure dtype selective build is working. diff --git a/runtime/kernel/test/operator_registry_test.cpp b/runtime/kernel/test/operator_registry_test.cpp index e3b99c1241..0aee13896b 100644 --- a/runtime/kernel/test/operator_registry_test.cpp +++ b/runtime/kernel/test/operator_registry_test.cpp @@ -112,12 +112,12 @@ TEST_F(OperatorRegistryTest, RegisterTwoKernels) { make_kernel_key({{ScalarType::Float, {0, 1, 2, 3}}}, buf_float_contiguous); KernelKey key_2 = KernelKey(buf_float_contiguous); Kernel kernel_1 = - Kernel("test::boo", key_1, [](RuntimeContext& context, EValue** stack) { + Kernel("test::bar", key_1, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(100); }); Kernel kernel_2 = - Kernel("test::boo", key_2, [](RuntimeContext& context, EValue** stack) { + Kernel("test::bar", key_2, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(50); }); @@ -132,11 +132,11 @@ TEST_F(OperatorRegistryTest, RegisterTwoKernels) { TensorMeta meta_2[] = {TensorMeta(ScalarType::Float, dim_order_type)}; ArrayRef user_kernel_key_2 = ArrayRef(meta_2, 1); - EXPECT_TRUE(hasOpsFn("test::boo", user_kernel_key_1)); - EXPECT_TRUE(hasOpsFn("test::boo", user_kernel_key_2)); + EXPECT_TRUE(hasOpsFn("test::bar", user_kernel_key_1)); + EXPECT_TRUE(hasOpsFn("test::bar", user_kernel_key_2)); // no fallback kernel is registered - EXPECT_FALSE(hasOpsFn("test::boo", {})); + EXPECT_FALSE(hasOpsFn("test::bar", {})); EValue values[1]; values[0] = Scalar(0); @@ -145,7 +145,7 @@ TEST_F(OperatorRegistryTest, RegisterTwoKernels) { RuntimeContext context{}; // test kernel_1 - OpFunction func_1 = getOpsFn("test::boo", user_kernel_key_1); + OpFunction func_1 = getOpsFn("test::bar", user_kernel_key_1); func_1(context, evalues); auto val_1 = values[0].toScalar().to(); @@ -153,7 +153,7 @@ TEST_F(OperatorRegistryTest, RegisterTwoKernels) { // test kernel_2 values[0] = Scalar(0); - OpFunction func_2 = getOpsFn("test::boo", user_kernel_key_2); + OpFunction func_2 = getOpsFn("test::bar", user_kernel_key_2); func_2(context, evalues); auto val_2 = values[0].toScalar().to(); @@ -166,12 +166,12 @@ TEST_F(OperatorRegistryTest, DoubleRegisterKernelsDies) { KernelKey key = KernelKey(buf_long_contiguous); Kernel kernel_1 = - Kernel("test::boo", key, [](RuntimeContext& context, EValue** stack) { + Kernel("test::baz", key, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(100); }); Kernel kernel_2 = - Kernel("test::boo", key, [](RuntimeContext& context, EValue** stack) { + Kernel("test::baz", key, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(50); }); @@ -187,7 +187,7 @@ TEST_F(OperatorRegistryTest, ExecutorChecksKernel) { KernelKey key = KernelKey(buf_long_contiguous); Kernel kernel_1 = - Kernel("test::boo", key, [](RuntimeContext& context, EValue** stack) { + Kernel("test::qux", key, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(100); }); @@ -198,7 +198,7 @@ TEST_F(OperatorRegistryTest, ExecutorChecksKernel) { auto dim_order_type = ArrayRef(dims, 4); TensorMeta meta[] = {TensorMeta(ScalarType::Long, dim_order_type)}; ArrayRef user_kernel_key_1 = ArrayRef(meta, 1); - EXPECT_TRUE(hasOpsFn("test::boo", user_kernel_key_1)); + EXPECT_TRUE(hasOpsFn("test::qux", user_kernel_key_1)); Tensor::DimOrderType dims_channel_first[] = {0, 3, 1, 2}; auto dim_order_type_channel_first = @@ -207,11 +207,11 @@ TEST_F(OperatorRegistryTest, ExecutorChecksKernel) { TensorMeta(ScalarType::Long, dim_order_type_channel_first)}; ArrayRef user_kernel_key_2 = ArrayRef(meta_channel_first, 1); - EXPECT_FALSE(hasOpsFn("test::boo", user_kernel_key_2)); + EXPECT_FALSE(hasOpsFn("test::qux", user_kernel_key_2)); TensorMeta meta_float[] = {TensorMeta(ScalarType::Float, dim_order_type)}; ArrayRef user_kernel_key_3 = ArrayRef(meta_float, 1); - EXPECT_FALSE(hasOpsFn("test::boo", ArrayRef(user_kernel_key_3))); + EXPECT_FALSE(hasOpsFn("test::qux", ArrayRef(user_kernel_key_3))); } TEST_F(OperatorRegistryTest, ExecutorUsesKernel) { @@ -220,7 +220,7 @@ TEST_F(OperatorRegistryTest, ExecutorUsesKernel) { KernelKey key = KernelKey(buf_long_contiguous); Kernel kernel_1 = - Kernel("test::boo", key, [](RuntimeContext& context, EValue** stack) { + Kernel("test::quux", key, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(100); }); @@ -231,9 +231,9 @@ TEST_F(OperatorRegistryTest, ExecutorUsesKernel) { auto dim_order_type = ArrayRef(dims, 4); TensorMeta meta[] = {TensorMeta(ScalarType::Long, dim_order_type)}; ArrayRef user_kernel_key_1 = ArrayRef(meta, 1); - EXPECT_TRUE(hasOpsFn("test::boo", ArrayRef(meta))); + EXPECT_TRUE(hasOpsFn("test::quux", ArrayRef(meta))); - OpFunction func = getOpsFn("test::boo", ArrayRef(meta)); + OpFunction func = getOpsFn("test::quux", ArrayRef(meta)); EValue values[1]; values[0] = Scalar(0); @@ -248,17 +248,17 @@ TEST_F(OperatorRegistryTest, ExecutorUsesKernel) { TEST_F(OperatorRegistryTest, ExecutorUsesFallbackKernel) { Kernel kernel_1 = Kernel( - "test::boo", KernelKey{}, [](RuntimeContext& context, EValue** stack) { + "test::corge", KernelKey{}, [](RuntimeContext& context, EValue** stack) { (void)context; *(stack[0]) = Scalar(100); }); auto s1 = register_kernels({kernel_1}); EXPECT_EQ(s1, torch::executor::Error::Ok); - EXPECT_TRUE(hasOpsFn("test::boo")); - EXPECT_TRUE(hasOpsFn("test::boo", ArrayRef())); + EXPECT_TRUE(hasOpsFn("test::corge")); + EXPECT_TRUE(hasOpsFn("test::corge", ArrayRef())); - OpFunction func = getOpsFn("test::boo", ArrayRef()); + OpFunction func = getOpsFn("test::corge", ArrayRef()); EValue values[1]; values[0] = Scalar(0); diff --git a/runtime/kernel/test/targets.bzl b/runtime/kernel/test/targets.bzl index f7bbfc21e4..96e0c8c557 100644 --- a/runtime/kernel/test/targets.bzl +++ b/runtime/kernel/test/targets.bzl @@ -37,18 +37,6 @@ def define_common_targets(): define_static_targets = True, ) - executorch_generated_lib( - name = "test_generated_lib_1", - deps = [ - ":executorch_all_ops", - "//executorch/kernels/portable:operators", - ], - functions_yaml_target = "//executorch/kernels/portable:functions.yaml", - visibility = [ - "//executorch/...", - ], - ) - runtime.export_file( name = "functions.yaml", )