1 /*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include "common_compiler_test.h"
18 #include "sea_ir/ir/sea.h"
19
20 using utils::ScopedHashtable;
21
22 namespace sea_ir {
23
24 class RegionsTest : public art::CommonCompilerTest {};
25
TEST_F(RegionsTest,Basics)26 TEST_F(RegionsTest, Basics) {
27 sea_ir::SeaGraph sg(*java_lang_dex_file_);
28 sea_ir::Region* root = sg.GetNewRegion();
29 sea_ir::Region* then_region = sg.GetNewRegion();
30 sea_ir::Region* else_region = sg.GetNewRegion();
31 std::vector<sea_ir::Region*>* regions = sg.GetRegions();
32 // Test that regions have been registered correctly as children of the graph.
33 EXPECT_TRUE(std::find(regions->begin(), regions->end(), root) != regions->end());
34 EXPECT_TRUE(std::find(regions->begin(), regions->end(), then_region) != regions->end());
35 EXPECT_TRUE(std::find(regions->begin(), regions->end(), else_region) != regions->end());
36 // Check that an edge recorded correctly in both the head and the tail.
37 sg.AddEdge(root, then_region);
38 std::vector<sea_ir::Region*>* succs = root->GetSuccessors();
39 EXPECT_EQ(1U, succs->size());
40 EXPECT_EQ(then_region, succs->at(0));
41 std::vector<sea_ir::Region*>* preds = then_region->GetPredecessors();
42 EXPECT_EQ(1U, preds->size());
43 EXPECT_EQ(root, preds->at(0));
44 // Check that two edges are recorded properly for both head and tail.
45 sg.AddEdge(root, else_region);
46 succs = root->GetSuccessors();
47 EXPECT_EQ(2U, succs->size());
48 EXPECT_TRUE(std::find(succs->begin(), succs->end(), then_region) != succs->end());
49 EXPECT_TRUE(std::find(succs->begin(), succs->end(), else_region) != succs->end());
50 preds = then_region->GetPredecessors();
51 EXPECT_EQ(1U, preds->size());
52 EXPECT_EQ(root, preds->at(0));
53 preds = else_region->GetPredecessors();
54 EXPECT_EQ(1U, preds->size());
55 EXPECT_EQ(root, preds->at(0));
56 }
57
58 } // namespace sea_ir
59