blob: 8ca51e48516d6a231cc9bae3ea37057a72162334 [file] [log] [blame]
Dragos Sbirlea597e46b2013-08-07 18:15:44 -07001/*
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_test.h"
18#include "sea_ir/ir/sea.h"
19
20using utils::ScopedHashtable;
21
22namespace sea_ir {
23
24class RegionsTest : public art::CommonTest {
25};
26
27TEST_F(RegionsTest, Basics) {
28 sea_ir::SeaGraph sg(*java_lang_dex_file_);
29 sea_ir::Region* root = sg.GetNewRegion();
30 sea_ir::Region* then_region = sg.GetNewRegion();
31 sea_ir::Region* else_region = sg.GetNewRegion();
32 std::vector<sea_ir::Region*>* regions = sg.GetRegions();
33 // Test that regions have been registered correctly as children of the graph.
34 EXPECT_TRUE(std::find(regions->begin(), regions->end(), root) != regions->end());
35 EXPECT_TRUE(std::find(regions->begin(), regions->end(), then_region) != regions->end());
36 EXPECT_TRUE(std::find(regions->begin(), regions->end(), else_region) != regions->end());
37 // Check that an edge recorded correctly in both the head and the tail.
38 sg.AddEdge(root, then_region);
39 std::vector<sea_ir::Region*>* succs = root->GetSuccessors();
40 EXPECT_EQ(1U, succs->size());
41 EXPECT_EQ(then_region, succs->at(0));
42 std::vector<sea_ir::Region*>* preds = then_region->GetPredecessors();
43 EXPECT_EQ(1U, preds->size());
44 EXPECT_EQ(root, preds->at(0));
45 // Check that two edges are recorded properly for both head and tail.
46 sg.AddEdge(root, else_region);
47 succs = root->GetSuccessors();
48 EXPECT_EQ(2U, succs->size());
49 EXPECT_TRUE(std::find(succs->begin(), succs->end(), then_region) != succs->end());
50 EXPECT_TRUE(std::find(succs->begin(), succs->end(), else_region) != succs->end());
51 preds = then_region->GetPredecessors();
52 EXPECT_EQ(1U, preds->size());
53 EXPECT_EQ(root, preds->at(0));
54 preds = else_region->GetPredecessors();
55 EXPECT_EQ(1U, preds->size());
56 EXPECT_EQ(root, preds->at(0));
57}
58
Mathieu Chartier02e25112013-08-14 16:14:24 -070059} // namespace sea_ir