diff options
author | Nathan Slingerland <slingn@gmail.com> | 2015-12-16 21:45:43 +0000 |
---|---|---|
committer | Nathan Slingerland <slingn@gmail.com> | 2015-12-16 21:45:43 +0000 |
commit | 48dd080c77c6a6398906b6db73d015fee15d8591 (patch) | |
tree | 4ecca36c8ea7d92f85c74274579a16d277b75e13 /llvm/unittests/ProfileData/SampleProfTest.cpp | |
parent | 031bed291ee7feccd2272efac2f7fce98c8353de (diff) | |
download | bcm5719-llvm-48dd080c77c6a6398906b6db73d015fee15d8591.tar.gz bcm5719-llvm-48dd080c77c6a6398906b6db73d015fee15d8591.zip |
[PGO] Handle and report overflow during profile merge for all types of data
Summary: Surface counter overflow when merging profile data. Merging still occurs on overflow but counts saturate to the maximum representable value. Overflow is reported to the user.
Reviewers: davidxl, dnovillo, silvas
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D15547
llvm-svn: 255825
Diffstat (limited to 'llvm/unittests/ProfileData/SampleProfTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/SampleProfTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp index aa1144d7913..cc3c2f5306e 100644 --- a/llvm/unittests/ProfileData/SampleProfTest.cpp +++ b/llvm/unittests/ProfileData/SampleProfTest.cpp @@ -99,4 +99,34 @@ TEST_F(SampleProfTest, roundtrip_binary_profile) { testRoundTrip(SampleProfileFormat::SPF_Binary); } +TEST_F(SampleProfTest, sample_overflow_saturation) { + const uint64_t Max = std::numeric_limits<uint64_t>::max(); + sampleprof_error Result; + + StringRef FooName("_Z3fooi"); + FunctionSamples FooSamples; + Result = FooSamples.addTotalSamples(1); + ASSERT_EQ(Result, sampleprof_error::success); + + Result = FooSamples.addHeadSamples(1); + ASSERT_EQ(Result, sampleprof_error::success); + + Result = FooSamples.addBodySamples(10, 0, 1); + ASSERT_EQ(Result, sampleprof_error::success); + + Result = FooSamples.addTotalSamples(Max); + ASSERT_EQ(Result, sampleprof_error::counter_overflow); + ASSERT_EQ(FooSamples.getTotalSamples(), Max); + + Result = FooSamples.addHeadSamples(Max); + ASSERT_EQ(Result, sampleprof_error::counter_overflow); + ASSERT_EQ(FooSamples.getHeadSamples(), Max); + + Result = FooSamples.addBodySamples(10, 0, Max); + ASSERT_EQ(Result, sampleprof_error::counter_overflow); + ErrorOr<uint64_t> BodySamples = FooSamples.findSamplesAt(10, 0); + ASSERT_FALSE(BodySamples.getError()); + ASSERT_EQ(BodySamples.get(), Max); +} + } // end anonymous namespace |