-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathllvm_profile_reader_test.cc
69 lines (55 loc) · 2.35 KB
/
llvm_profile_reader_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Checks that llvm profile reader reads in profiles correctly.
#include "llvm_profile_reader.h"
#include <string>
#include "base/commandlineflags.h"
#include "symbol_map.h"
#include "gtest/gtest.h"
#include "third_party/abseil/absl/container/node_hash_set.h"
#include "third_party/abseil/absl/flags/flag.h"
#define FLAGS_test_tmpdir std::string(testing::UnitTest::GetInstance()->original_working_dir())
#define FLAGS_test_srcdir std::string(testing::UnitTest::GetInstance()->original_working_dir())
namespace {
void VerifySymbolMap(const devtools_crosstool_autofdo::SymbolMap &symbol_map) {
const auto *data = symbol_map.map().at("_Z11compute_noii");
constexpr uint16_t kLine = 3;
constexpr uint16_t kDisc = 2;
constexpr uint64_t kLookup =
devtools_crosstool_autofdo::SourceInfo::GenerateOffset(kLine, kDisc);
EXPECT_EQ(data->callsites.size(), 0);
EXPECT_EQ(data->pos_counts.size(), 16);
EXPECT_EQ(data->pos_counts.at(kLookup).count, 1941);
data = symbol_map.map().at("main");
EXPECT_EQ(data->pos_counts.size(), 16);
EXPECT_EQ(data->callsites.size(), 1);
}
TEST(LLVMProfileReaderTest, ReadBinaryTest) {
devtools_crosstool_autofdo::SymbolMap symbol_map;
absl::node_hash_set<std::string> names;
devtools_crosstool_autofdo::LLVMProfileReader reader(&symbol_map, names);
reader.ReadFromFile(FLAGS_test_srcdir +
"/testdata/"
"llvm_autoprof.golden.binprof");
VerifySymbolMap(symbol_map);
}
TEST(LLVMProfileReaderTest, ReadTextTest) {
devtools_crosstool_autofdo::SymbolMap symbol_map;
absl::node_hash_set<std::string> names;
devtools_crosstool_autofdo::LLVMProfileReader reader(&symbol_map, names);
EXPECT_TRUE(
reader.ReadFromFile(FLAGS_test_srcdir +
"/testdata/"
"llvm_autoprof.golden.textprof"));
VerifySymbolMap(symbol_map);
}
TEST(LLVMProfileReaderTest, ReadEmptyBodyNonZeroFunctionTotalTest) {
devtools_crosstool_autofdo::SymbolMap symbol_map;
absl::node_hash_set<std::string> names;
devtools_crosstool_autofdo::LLVMProfileReader reader(&symbol_map, names);
reader.ReadFromFile(FLAGS_test_srcdir +
"/testdata/"
"llvm_testzero.golden.textprof");
const auto *data =
symbol_map.map().at("_Z11EmptyBodyNonZeroTotalCount_noii");
EXPECT_EQ(data->total_count, 1000);
}
} // namespace