2 * Copyright (c) 2020 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 "kernels/TestUtils.h"
18 #include "luci_interpreter/test_models/transpose/TransposeKernel.h"
20 #include "loader/ModuleLoader.h"
22 namespace luci_interpreter
27 using namespace testing;
29 class TransposeTest : public ::testing::Test
35 std::vector<T> checkTransposeKernel(test_kernel::TestDataBase<T> *test_data_base)
37 MemoryManager memory_manager{};
38 RuntimeModule runtime_module{};
39 bool dealloc_input = true;
41 // Load model with single op
42 auto *model_data_raw = reinterpret_cast<const char *>(test_data_base->get_model_ptr());
43 ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input);
45 auto *main_runtime_graph = runtime_module.getMainGraph();
46 assert(main_runtime_graph->getNumOfInputTensors() == 1);
50 auto *input_tensor_data = reinterpret_cast<T *>(main_runtime_graph->configureGraphInput(0));
51 std::copy(test_data_base->get_input_data_by_index(0).begin(),
52 test_data_base->get_input_data_by_index(0).end(), input_tensor_data);
55 runtime_module.execute();
57 assert(main_runtime_graph->getNumOfOutputTensors() == 1);
59 T *output_data = reinterpret_cast<T *>(main_runtime_graph->getOutputDataByIndex(0));
60 const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T));
61 std::vector<T> output_data_vector(output_data, output_data + num_elements);
62 return output_data_vector;
65 TEST_F(TransposeTest, MainTest_P)
67 test_kernel::TestDataTransposeKernel<float> test_data_kernel;
68 std::vector<float> output_data_vector = checkTransposeKernel(&test_data_kernel);
69 EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0));
72 // TODO: add negative tests?
75 } // namespace luci_interpreter