2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "kernels/TestUtils.h"
19 #include "loader/ModuleLoader.h"
20 #include "luci_interpreter/test_models/resize_bilinear/FloatResizeBilinearKernel.h"
21 #include "luci_interpreter/test_models/resize_bilinear/U8ResizeBilinearKernel.h"
22 #include "luci_interpreter/test_models/resize_bilinear/NegResizeBilinearKernel.h"
24 namespace luci_interpreter
31 using namespace testing;
33 class ResizeBilinearTest : public ::testing::Test
39 std::vector<T> checkResizeBilinearKernel(test_kernel::TestDataBase<T> *test_data_base)
41 MemoryManager memory_manager{};
42 RuntimeModule runtime_module{};
43 bool dealloc_input = true;
45 // Load model with single op
46 auto *model_data_raw = reinterpret_cast<const char *>(test_data_base->get_model_ptr());
47 ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input);
49 auto *main_runtime_graph = runtime_module.getMainGraph();
50 assert(main_runtime_graph->getNumOfInputTensors() == 1);
54 auto *input_tensor_data = reinterpret_cast<T *>(main_runtime_graph->configureGraphInput(0));
55 std::copy(test_data_base->get_input_data_by_index(0).begin(),
56 test_data_base->get_input_data_by_index(0).end(), input_tensor_data);
59 runtime_module.execute();
61 assert(main_runtime_graph->getNumOfOutputTensors() == 1);
63 T *output_data = reinterpret_cast<T *>(main_runtime_graph->getOutputDataByIndex(0));
64 const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T));
65 std::vector<T> output_data_vector(output_data, output_data + num_elements);
66 return output_data_vector;
69 TEST_F(ResizeBilinearTest, Float_P)
71 test_kernel::TestDataFloatResizeBilinear test_data_kernel(false);
72 std::vector<float> output_data_vector = checkResizeBilinearKernel(&test_data_kernel);
74 EXPECT_THAT(output_data_vector,
75 FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f));
78 TEST_F(ResizeBilinearTest, HalfPixelCenter_Float_P)
81 test_kernel::TestDataFloatResizeBilinear test_data_kernel(true);
82 std::vector<float> output_data_vector = checkResizeBilinearKernel(&test_data_kernel);
84 EXPECT_THAT(output_data_vector,
85 FloatArrayNear(test_data_kernel.get_output_data_by_index(0), 0.0001f));
88 TEST_F(ResizeBilinearTest, Uint8_P)
90 test_kernel::TestDataUint8ResizeBilinear test_data_kernel(false);
91 std::vector<uint8_t> output_data_vector = checkResizeBilinearKernel<uint8_t>(&test_data_kernel);
93 EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0));
96 TEST_F(ResizeBilinearTest, HalfPixelCenter_Uint8_P)
98 test_kernel::TestDataUint8ResizeBilinear test_data_kernel(true);
99 std::vector<uint8_t> output_data_vector = checkResizeBilinearKernel<uint8_t>(&test_data_kernel);
101 EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0));
104 TEST_F(ResizeBilinearTest, InvalidInputShape_Float_NEG)
107 test_kernel::NegTestDataInvalidInputShapeFloatResizeBilinearKernel test_data_kernel;
109 MemoryManager memory_manager{};
110 RuntimeModule runtime_module{};
111 bool dealloc_input = true;
112 // Load model with single op
113 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
114 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
118 TEST_F(ResizeBilinearTest, InvalidParams_Float_NEG)
121 test_kernel::NegTestDataInvalidParamFloatResizeBilinearKernel test_data_kernel;
123 MemoryManager memory_manager{};
124 RuntimeModule runtime_module{};
125 bool dealloc_input = true;
126 // Load model with single op
127 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
128 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
132 TEST_F(ResizeBilinearTest, InvalidSizeShape_Float_NEG)
135 test_kernel::NegTestDataInvalidSizeShapeDimensionsFloatResizeBilinearKernel test_data_kernel;
137 MemoryManager memory_manager{};
138 RuntimeModule runtime_module{};
139 bool dealloc_input = true;
140 // Load model with single op
141 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
142 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
146 TEST_F(ResizeBilinearTest, InvalidInputShape_uint8_NEG)
149 test_kernel::NegTestDataInvalidInputShapeUint8ResizeBilinearKernel test_data_kernel;
151 MemoryManager memory_manager{};
152 RuntimeModule runtime_module{};
153 bool dealloc_input = true;
154 // Load model with single op
155 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
156 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
160 TEST_F(ResizeBilinearTest, InvalidParams_uint8_NEG)
163 test_kernel::NegTestDataInvalidParamUint8ResizeBilinearKernel test_data_kernel;
165 MemoryManager memory_manager{};
166 RuntimeModule runtime_module{};
167 bool dealloc_input = true;
168 // Load model with single op
169 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
170 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
174 TEST_F(ResizeBilinearTest, InvalidSizeShape_uint8_NEG)
177 test_kernel::NegTestDataInvalidSizeShapeDimensionsUint8ResizeBilinearKernel test_data_kernel;
179 MemoryManager memory_manager{};
180 RuntimeModule runtime_module{};
181 bool dealloc_input = true;
182 // Load model with single op
183 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
184 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
189 } // namespace kernels
190 } // namespace luci_interpreter