-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathspe_sample_reader_test.cc
77 lines (65 loc) · 2.6 KB
/
spe_sample_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
70
71
72
73
74
75
76
77
#include "spe_sample_reader.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "util/testing/status_matchers.h"
#include "third_party/abseil/absl/status/status.h"
#include "third_party/abseil/absl/strings/str_cat.h"
#include "third_party/abseil/absl/strings/string_view.h"
namespace devtools_crosstool_autofdo {
namespace {
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::Pair;
using ::testing::SizeIs;
using ::testing::status::StatusIs;
inline constexpr absl::string_view kTestDataDir =
"//testdata/";
TEST(PerfSpeDataSampleReader, RequiresAArch64) {
PerfSpeDataSampleReader reader(
PerfSpeDataSampleReader::BranchIdStrategy::kSampling,
/*profile_file=*/
absl::StrCat(testing::SrcDir(), kTestDataDir,
"propeller_sample.arm.perfdata"),
/*mmap_regex=*/".*",
/*binary_file=*/
absl::StrCat(testing::SrcDir(), kTestDataDir, "propeller_sample.bin"));
EXPECT_THAT(
reader.GenerateAutofdoProfile(absl::StrCat(
testing::SrcDir(), kTestDataDir, "propeller_sample.arm.perfdata")),
StatusIs(absl::StatusCode::kInvalidArgument));
}
TEST(PerfSpeDataSampleReader, ComputesRangesWithSamplingOnly) {
PerfSpeDataSampleReader reader(
PerfSpeDataSampleReader::BranchIdStrategy::kSampling,
absl::StrCat(testing::SrcDir(), kTestDataDir,
"propeller_sample.arm.perfdata"),
"propeller_sample.arm.bin",
absl::StrCat(testing::SrcDir(), kTestDataDir,
"propeller_sample.arm.bin"));
EXPECT_TRUE(reader.ReadAndSetTotalCount());
EXPECT_EQ(reader.GetTotalSampleCount(), 1263256);
EXPECT_THAT(
reader.branch_count_map(),
AllOf(SizeIs(26), Contains(Pair(Pair(0x45748, 0x457d8), 224428))));
EXPECT_THAT(
reader.range_count_map(),
AllOf(SizeIs(32), Contains(Pair(Pair(0x45810, 0x4582c), 247609))));
EXPECT_EQ(reader.GetTotalCount(), 26734112);
}
TEST(PerfSpeDataSampleReader, ComputesRangesWithDisassembly) {
PerfSpeDataSampleReader reader(
PerfSpeDataSampleReader::BranchIdStrategy::kDisassembly,
absl::StrCat(testing::SrcDir(), kTestDataDir,
"propeller_sample.arm.perfdata"),
"propeller_sample.arm.bin",
absl::StrCat(testing::SrcDir(), kTestDataDir,
"propeller_sample.arm.bin"));
EXPECT_TRUE(reader.ReadAndSetTotalCount());
EXPECT_EQ(reader.GetTotalSampleCount(), 1263251);
EXPECT_THAT(
reader.range_count_map(),
AllOf(SizeIs(30), Contains(Pair(Pair(0x45810, 0x4582c), 247609))));
EXPECT_EQ(reader.GetTotalCount(), 26309075);
}
} // namespace
} // namespace devtools_crosstool_autofdo