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/kernels/portable/cpu/scalar_utils.h>
10 #include <executorch/test/utils/DeathTest.h>
11 #include <gtest/gtest.h>
12
13 using namespace ::testing;
14 using exec_aten::ScalarType;
15 using torch::executor::ScalarTypeToCppType;
16
TEST(DtypeSelectiveBuildTest,UnknownOp)17 TEST(DtypeSelectiveBuildTest, UnknownOp) {
18 ET_EXPECT_DEATH(
19 ET_SWITCH_TWO_TYPES(
20 Float,
21 Int,
22 exec_aten::ScalarType::Float,
23 ctx,
24 "unknown.out",
25 // @lint-ignore CLANGTIDY clang-diagnostic-unused-local-typedef
26 CTYPE_OUT,
27 [&] { return true; }),
28 "");
29 }
30
TEST(DtypeSelectiveBuildTest,OpWithoutDtype)31 TEST(DtypeSelectiveBuildTest, OpWithoutDtype) {
32 ET_EXPECT_DEATH(
33 ET_SWITCH_TWO_TYPES(
34 Float,
35 Int,
36 exec_aten::ScalarType::Int,
37 ctx,
38 "add.out",
39 // @lint-ignore CLANGTIDY clang-diagnostic-unused-local-typedef
40 CTYPE_OUT,
41 [&] { return true; }),
42 "");
43 }
44
TEST(DtypeSelectiveBuildTest,OpWithDtype)45 TEST(DtypeSelectiveBuildTest, OpWithDtype) {
46 ASSERT_EQ(
47 ET_SWITCH_TWO_TYPES(
48 Float,
49 Int,
50 exec_aten::ScalarType::Float,
51 ctx,
52 "add.out",
53 // @lint-ignore CLANGTIDY clang-diagnostic-unused-local-typedef
54 CTYPE_OUT,
55 [&] { return true; }),
56 true);
57 }
58