2 * Copyright (c) 2018 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 <gtest/gtest.h>
20 #include "ir/verifier/Verifier.h"
22 #include "../MockNode.h"
29 using IndexSet = onert::ir::OperandIndexSequence;
30 using Mock = onert_test::ir::SimpleMock;
34 TEST(graph_operand_usedef, usedef_test)
36 onert::ir::Graph graph;
37 onert::ir::verifier::DAGChecker verifier;
39 onert::ir::Shape shape(3);
40 onert::ir::TypeInfo type{onert::ir::DataType::INT32};
43 auto input_operand = graph.addOperand(shape, type);
44 auto output_operand = graph.addOperand(shape, type);
46 graph.addInput(input_operand);
47 graph.addOutput(output_operand);
50 auto operand_index1 = graph.addOperand(shape, type);
51 auto mocknode_index1 =
52 graph.addOperation(std::make_unique<Mock>(IndexSet{input_operand}, IndexSet{operand_index1}));
55 auto operand_index2 = graph.addOperand(shape, type);
56 auto mocknode_index2 =
57 graph.addOperation(std::make_unique<Mock>(IndexSet{input_operand}, IndexSet{operand_index2}));
59 // MockNode3(two input)
60 auto multiinput_index = graph.addOperation(
61 std::make_unique<Mock>(IndexSet{operand_index1, operand_index2}, IndexSet{output_operand}));
63 graph.finishBuilding();
65 ASSERT_EQ(verifier.verify(graph), true);
68 ASSERT_EQ(graph.operands().at(operand_index1).getDef(), mocknode_index1);
69 ASSERT_EQ(graph.operands().at(operand_index2).getDef(), mocknode_index2);
70 ASSERT_EQ(graph.operands().at(output_operand).getDef(), multiinput_index);
72 ASSERT_NE(graph.operands().at(operand_index1).getDef(), mocknode_index2);
73 ASSERT_NE(graph.operands().at(operand_index1).getDef(), multiinput_index);
76 ASSERT_EQ(graph.operands().at(input_operand).getUses().contains(mocknode_index1), true);
77 ASSERT_EQ(graph.operands().at(input_operand).getUses().contains(mocknode_index2), true);
78 ASSERT_EQ(graph.operands().at(input_operand).getUses().contains(multiinput_index), false);
79 ASSERT_EQ(graph.operands().at(operand_index1).getUses().contains(multiinput_index), true);
80 ASSERT_EQ(graph.operands().at(operand_index2).getUses().contains(multiinput_index), true);
82 ASSERT_EQ(graph.operands().at(input_operand).getUses().size(), 2);
83 ASSERT_EQ(graph.operands().at(operand_index1).getUses().size(), 1);
84 ASSERT_EQ(graph.operands().at(output_operand).getUses().size(), 0);