xref: /aosp_15_r20/system/extras/simpleperf/read_dex_file_test.cpp (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1 /*
2  * Copyright (C) 2018 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 "read_dex_file.h"
18 
19 #include <gtest/gtest.h>
20 
21 #include <algorithm>
22 
23 #include "dso.h"
24 #include "get_test_data.h"
25 #include "test_util.h"
26 #include "utils.h"
27 
28 using namespace simpleperf;
29 
30 // @CddTest = 6.1/C-0-2
TEST(read_dex_file,smoke)31 TEST(read_dex_file, smoke) {
32   std::vector<Symbol> symbols;
33   auto symbol_callback = [&](DexFileSymbol* symbol) {
34     symbols.emplace_back(symbol->name, symbol->addr, symbol->size);
35   };
36   ASSERT_TRUE(ReadSymbolsFromDexFile(GetTestData("base.vdex"), {0x28}, symbol_callback));
37   ASSERT_EQ(12435u, symbols.size());
38   auto it = std::find_if(symbols.begin(), symbols.end(),
39                          [](const Symbol& symbol) { return symbol.addr == 0x6c77e; });
40   ASSERT_NE(it, symbols.end());
41   ASSERT_EQ(it->addr, 0x6c77e);
42   ASSERT_EQ(it->len, 0x16);
43   ASSERT_STREQ(it->Name(), "com.example.simpleperf.simpleperfexamplewithnative.MixActivity$1.run");
44 }
45