• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <cstdlib>
17 #include "disassembler.h"
18 #include <gtest/gtest.h>
19 #include <string>
20 
21 using namespace testing::ext;
22 namespace panda::disasm {
23 
24 static const std::string MODULE_REQUEST_FILE_NAME = GRAPH_TEST_ABC_DIR "module-requests-annotation-import.abc";
25 static const std::string SLOT_NUMBER_FILE_NAME = GRAPH_TEST_ABC_DIR "slot-number-annotation.abc";
26 
27 class DisassemblerAnnotationTest : public testing::Test {
28 public:
SetUpTestCase(void)29     static void SetUpTestCase(void) {};
TearDownTestCase(void)30     static void TearDownTestCase(void) {};
SetUp()31     void SetUp() {};
TearDown()32     void TearDown() {};
33 
ValidateAnnotation(std::optional<std::vector<std::string>> & annotations,const std::string & annotation_name)34     bool ValidateAnnotation(std::optional<std::vector<std::string>> &annotations, const std::string &annotation_name)
35     {
36         std::vector<std::string> ann = annotations.value();
37         const auto ann_iter = std::find(ann.begin(), ann.end(), annotation_name);
38         if (ann_iter != ann.end()) {
39             return true;
40         }
41 
42         return false;
43     }
44 };
45 
46 /**
47 * @tc.name: disassembler_annotation_test_001
48 * @tc.desc: get module request annotation of abc file.
49 * @tc.type: FUNC
50 * @tc.require: file path and name
51 */
52 HWTEST_F(DisassemblerAnnotationTest, disassembler_annotation_test_001, TestSize.Level1)
53 {
54     static const std::string METHOD_NAME = "module-requests-annotation-import.funcD";
55     static const std::string ANNOTATION_NAME = "L_ESConcurrentModuleRequestsAnnotation";
56     panda::disasm::Disassembler disasm {};
57     disasm.Disassemble(MODULE_REQUEST_FILE_NAME, false, false);
58     std::optional<std::vector<std::string>> annotations = disasm.GetAnnotationByMethodName(METHOD_NAME);
59     ASSERT_NE(annotations, std::nullopt);
60     bool has_annotation = ValidateAnnotation(annotations, ANNOTATION_NAME);
61     EXPECT_TRUE(has_annotation);
62 }
63 
64 /**
65 * @tc.name: disassembler_annotation_test_002
66 * @tc.desc: get solt number annotation of abc file.
67 * @tc.type: FUNC
68 * @tc.require: file path and name
69 */
70 HWTEST_F(DisassemblerAnnotationTest, disassembler_annotation_test_002, TestSize.Level1)
71 {
72     static const std::string METHOD_NAME = "funcA";
73     static const std::string ANNOTATION_NAME = "L_ESSlotNumberAnnotation";
74     panda::disasm::Disassembler disasm {};
75     disasm.Disassemble(SLOT_NUMBER_FILE_NAME, false, false);
76     std::optional<std::vector<std::string>> annotations = disasm.GetAnnotationByMethodName(METHOD_NAME);
77     ASSERT_NE(annotations, std::nullopt);
78     bool has_annotation = ValidateAnnotation(annotations, ANNOTATION_NAME);
79     EXPECT_TRUE(has_annotation);
80 }
81 };
82