xref: /aosp_15_r20/external/executorch/runtime/kernel/test/test_kernel_manual_registration.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <executorch/runtime/kernel/test/RegisterKernels.h>
10 
11 #include <gtest/gtest.h>
12 
13 #include <executorch/runtime/kernel/operator_registry.h>
14 #include <executorch/runtime/platform/runtime.h>
15 
16 using namespace ::testing;
17 using executorch::runtime::Error;
18 using executorch::runtime::registry_has_op_function;
19 
20 class KernelManualRegistrationTest : public ::testing::Test {
21  public:
SetUp()22   void SetUp() override {
23     executorch::runtime::runtime_init();
24   }
25 };
26 
TEST_F(KernelManualRegistrationTest,ManualRegister)27 TEST_F(KernelManualRegistrationTest, ManualRegister) {
28   // Before registering, we can't find the add operator.
29   EXPECT_FALSE(registry_has_op_function("aten::add.out"));
30 
31   // Call the generated registration function.
32   Error result = torch::executor::register_all_kernels();
33   EXPECT_EQ(result, Error::Ok);
34 
35   // We can now find the registered add operator.
36   EXPECT_TRUE(registry_has_op_function("aten::add.out"));
37 
38   // We can't find a random other operator.
39   EXPECT_FALSE(registry_has_op_function("fpp"));
40 }
41