• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cflow/instructions_map.h"
17 
18 #include "util/range.h"
19 
20 #include "util/tests/verifier_test.h"
21 
22 #include <gtest/gtest.h>
23 
24 namespace panda::verifier::test {
25 
TEST_F(VerifierTest,InstructionsMap)26 TEST_F(VerifierTest, InstructionsMap)
27 {
28     char code[148];
29     InstructionsMap map {&code[5], &code[147]};
30 
31     // 11110010
32     EXPECT_FALSE(map.PutInstruction(&code[4], 3));
33     EXPECT_TRUE(map.PutInstruction(&code[5], 2));
34     EXPECT_TRUE(map.CanJumpTo(&code[5]));
35     EXPECT_FALSE(map.CanJumpTo(&code[6]));
36     EXPECT_TRUE(map.CanJumpTo(&code[7]));
37 
38     map.MarkCodeBlock(&code[10], 104);
39     EXPECT_TRUE(map.CanJumpTo(&code[9]));
40     EXPECT_TRUE(map.CanJumpTo(&code[114]));
41     for (auto addr : Range(10, 113)) {
42         EXPECT_FALSE(map.CanJumpTo(&code[addr]));
43     }
44 
45     EXPECT_TRUE(map.PutInstruction(&code[133], 1));
46     EXPECT_TRUE(map.CanJumpTo(&code[133]));
47 }
48 
49 }  // namespace panda::verifier::test
50