Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / LessEqual.test.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4  *
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
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/test_models/less_equal/FloatLessEqualKernel.h"
20
21 #include "loader/ModuleLoader.h"
22
23 namespace luci_interpreter
24 {
25 namespace
26 {
27
28 using namespace testing;
29
30 class LessEqualTest : public ::testing::Test
31 {
32   // Do nothing
33 };
34
35 template <typename T, typename U>
36 std::vector<U> checkLessEqualKernel(test_kernel::TestDataBase<T, U> *test_data_base)
37 {
38   MemoryManager memory_manager{};
39   RuntimeModule runtime_module{};
40   bool dealloc_input = true;
41
42   // Load model with single op
43   auto *model_data_raw = reinterpret_cast<const char *>(test_data_base->get_model_ptr());
44   ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input);
45
46   auto *main_runtime_graph = runtime_module.getMainGraph();
47   assert(main_runtime_graph->getNumOfInputTensors() == 2);
48
49   // set left input data
50   {
51     auto *input_tensor_data = reinterpret_cast<T *>(main_runtime_graph->configureGraphInput(0));
52     std::copy(test_data_base->get_input_data_by_index(0).begin(),
53               test_data_base->get_input_data_by_index(0).end(), input_tensor_data);
54   }
55
56   // set right input data
57   {
58     auto *input_tensor_data = reinterpret_cast<T *>(main_runtime_graph->configureGraphInput(1));
59     std::copy(test_data_base->get_input_data_by_index(1).begin(),
60               test_data_base->get_input_data_by_index(1).end(), input_tensor_data);
61   }
62
63   runtime_module.execute();
64
65   assert(main_runtime_graph->getNumOfOutputTensors() == 1);
66
67   U *output_data = reinterpret_cast<U *>(main_runtime_graph->getOutputDataByIndex(0));
68   const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(U));
69   std::vector<U> output_data_vector(output_data, output_data + num_elements);
70   return output_data_vector;
71 }
72
73 TEST_F(LessEqualTest, FloatNoBroadcast_P)
74 {
75   const bool is_with_broadcast = false;
76   test_kernel::TestDataFloatLessEqual test_data_kernel(is_with_broadcast, false);
77   std::vector<bool> output_data_vector = checkLessEqualKernel<float, bool>(&test_data_kernel);
78   EXPECT_THAT(output_data_vector, test_data_kernel.get_output_data_by_index(0));
79 }
80
81 TEST_F(LessEqualTest, FloatNoBroadcast_NEG)
82 {
83   const bool is_with_broadcast = false;
84   test_kernel::TestDataFloatLessEqual test_data_kernel(is_with_broadcast, true);
85   EXPECT_DEATH(checkLessEqualKernel(&test_data_kernel), "");
86 }
87
88 } // namespace
89 } // namespace luci_interpreter