2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "mio_circle/Helper.h"
19 #include <flatbuffers/flatbuffers.h>
20 #include <gtest/gtest.h>
24 class mio_circle06_helper_test : public ::testing::Test
27 void initialization_finish(void)
29 _fbb.Finish(circle::CreateModelDirect(_fbb, 0, &_opcodes_vec));
33 void add_operator_code(int8_t deprecated_builtin_code, const char *custom_code,
34 circle::BuiltinOperator builtin_code)
36 _opcodes_vec.push_back(circle::CreateOperatorCodeDirect(
37 _fbb, deprecated_builtin_code, custom_code, 1 /* version */, builtin_code));
40 const circle::OperatorCode *get_operator_code(uint8_t idx)
42 return circle::GetModel(_fbb.GetBufferPointer())->operator_codes()->Get(idx);
46 flatbuffers::FlatBufferBuilder _fbb;
47 std::vector<flatbuffers::Offset<circle::OperatorCode>> _opcodes_vec;
50 TEST_F(mio_circle06_helper_test, v06)
52 // BuiltinOperator_ADD = 0
53 // BuiltinOperator_CONV_2D = 3
54 add_operator_code(3, "", circle::BuiltinOperator_ADD);
55 initialization_finish();
57 ASSERT_TRUE(mio::circle::is_valid(get_operator_code(0)));
58 ASSERT_EQ(mio::circle::builtin_code_neutral(get_operator_code(0)),
59 circle::BuiltinOperator_CONV_2D);
60 ASSERT_FALSE(mio::circle::is_custom(get_operator_code(0)));
63 TEST_F(mio_circle06_helper_test, v06_custom_old)
65 // BuiltinOperator_ADD = 0
66 // BuiltinOperator_CUSTOM = 32
67 add_operator_code(32, "custom", circle::BuiltinOperator_ADD);
68 initialization_finish();
70 ASSERT_TRUE(mio::circle::is_valid(get_operator_code(0)));
71 ASSERT_EQ(mio::circle::builtin_code_neutral(get_operator_code(0)),
72 circle::BuiltinOperator_CUSTOM);
73 ASSERT_TRUE(mio::circle::is_custom(get_operator_code(0)));
76 TEST_F(mio_circle06_helper_test, v06_NEG)
78 // BuiltinOperator_ADD = 0
79 // BuiltinOperator_CUMSUM = 128
80 // deprecated_builtin_code cannot be negative value
81 add_operator_code(128, "", circle::BuiltinOperator_ADD);
82 initialization_finish();
84 ASSERT_FALSE(mio::circle::is_valid(get_operator_code(0)));
87 TEST_F(mio_circle06_helper_test, v06_under127)
89 // BuiltinOperator_CONV_2D = 3
90 add_operator_code(3, "", circle::BuiltinOperator_CONV_2D);
91 initialization_finish();
93 ASSERT_TRUE(mio::circle::is_valid(get_operator_code(0)));
94 ASSERT_EQ(mio::circle::builtin_code_neutral(get_operator_code(0)),
95 circle::BuiltinOperator_CONV_2D);
96 ASSERT_FALSE(mio::circle::is_custom(get_operator_code(0)));
99 TEST_F(mio_circle06_helper_test, v06_under127_NEG)
101 // BuiltinOperator_CONV_2D = 3
102 // BuiltinOperator_CUMSUM = 128
103 // deprecated_builtin_code cannot be negative value
104 add_operator_code(128, "", circle::BuiltinOperator_CONV_2D);
105 initialization_finish();
107 ASSERT_FALSE(mio::circle::is_valid(get_operator_code(0)));
110 TEST_F(mio_circle06_helper_test, v06_custom)
112 // BuiltinOperator_CUSTOM = 32
113 add_operator_code(32, "custom", circle::BuiltinOperator_CUSTOM);
114 initialization_finish();
116 ASSERT_TRUE(mio::circle::is_valid(get_operator_code(0)));
117 ASSERT_EQ(mio::circle::builtin_code_neutral(get_operator_code(0)),
118 circle::BuiltinOperator_CUSTOM);
119 ASSERT_TRUE(mio::circle::is_custom(get_operator_code(0)));
122 TEST_F(mio_circle06_helper_test, v06_custom_NEG)
124 // BuiltinOperator_CUMSUM = 128
125 // deprecated_builtin_code cannot be negative value
126 add_operator_code(128, "custom", circle::BuiltinOperator_CUSTOM);
127 initialization_finish();
129 ASSERT_FALSE(mio::circle::is_valid(get_operator_code(0)));
132 TEST_F(mio_circle06_helper_test, v06_over127)
134 // BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES = 127
135 // BuiltinOperator_CUMSUM = 128
136 add_operator_code(127, "", circle::BuiltinOperator_CUMSUM);
137 initialization_finish();
139 ASSERT_TRUE(mio::circle::is_valid(get_operator_code(0)));
140 ASSERT_EQ(mio::circle::builtin_code_neutral(get_operator_code(0)),
141 circle::BuiltinOperator_CUMSUM);
142 ASSERT_FALSE(mio::circle::is_custom(get_operator_code(0)));
145 TEST_F(mio_circle06_helper_test, v06_over127_NEG)
147 // BuiltinOperator_CUMSUM = 128
148 // deprecated_builtin_code cannot be negative value
149 add_operator_code(128, "", circle::BuiltinOperator_CUMSUM);
150 initialization_finish();
152 ASSERT_FALSE(mio::circle::is_valid(get_operator_code(0)));