Commit b48ce50b authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Move unwind through library tests earlier

Coalesces all the unwinding scenario tests into the same part of the
file.

Bug: 909957
Change-Id: I5cc7cd00dc298e1c5adf1d9ad4d1585f5495b256
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580142
Auto-Submit: Mike Wittman <wittman@chromium.org>
Commit-Queue: Charlie Andrews <charliea@chromium.org>
Reviewed-by: default avatarCharlie Andrews <charliea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653586}
parent a306236a
...@@ -855,6 +855,76 @@ PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_Alloca) { ...@@ -855,6 +855,76 @@ PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_Alloca) {
scenario.GetOuterFunctionAddressRange()}); scenario.GetOuterFunctionAddressRange()});
} }
// Checks that a stack that runs through another library produces a stack with
// the expected functions.
// macOS ASAN is not yet supported - crbug.com/718628.
#if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
#define MAYBE_OtherLibrary OtherLibrary
#else
#define MAYBE_OtherLibrary DISABLED_OtherLibrary
#endif
PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_OtherLibrary) {
SamplingParams params;
params.sampling_interval = TimeDelta::FromMilliseconds(0);
params.samples_per_profile = 1;
Profile profile;
ScopedNativeLibrary other_library(LoadOtherLibrary());
UnwindScenario scenario(
BindRepeating(&CallThroughOtherLibrary, Unretained(other_library.get())));
WithTargetThread(&scenario, [&, this](PlatformThreadId target_thread_id) {
WaitableEvent sampling_thread_completed(
WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED);
StackSamplingProfiler profiler(
target_thread_id, params,
std::make_unique<TestProfileBuilder>(
module_cache(),
BindLambdaForTesting(
[&profile, &sampling_thread_completed](Profile result_profile) {
profile = std::move(result_profile);
sampling_thread_completed.Signal();
})));
profiler.Start();
sampling_thread_completed.Wait();
});
// Look up the frames.
ASSERT_EQ(1u, profile.frame_sets.size());
const Frames& frames = profile.frame_sets[0];
// The stack should contain a full unwind.
ExpectStackContains(frames, {scenario.GetWaitForSampleAddressRange(),
scenario.GetSetupFunctionAddressRange(),
scenario.GetOuterFunctionAddressRange()});
}
// Checks that a stack that runs through a library that is unloading produces a
// stack, and doesn't crash.
// Unloading is synchronous on the Mac, so this test is inapplicable.
#if !defined(OS_MACOSX)
#define MAYBE_UnloadingLibrary UnloadingLibrary
#else
#define MAYBE_UnloadingLibrary DISABLED_UnloadingLibrary
#endif
PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_UnloadingLibrary) {
TestLibraryUnload(false, module_cache());
}
// Checks that a stack that runs through a library that has been unloaded
// produces a stack, and doesn't crash.
// macOS ASAN is not yet supported - crbug.com/718628.
#if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
#define MAYBE_UnloadedLibrary UnloadedLibrary
#else
#define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary
#endif
PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) {
TestLibraryUnload(true, module_cache());
}
// Checks that a profiler can stop/destruct without ever having started. // Checks that a profiler can stop/destruct without ever having started.
PROFILER_TEST_F(StackSamplingProfilerTest, StopWithoutStarting) { PROFILER_TEST_F(StackSamplingProfilerTest, StopWithoutStarting) {
WithTargetThread([this](PlatformThreadId target_thread_id) { WithTargetThread([this](PlatformThreadId target_thread_id) {
...@@ -1309,76 +1379,6 @@ PROFILER_TEST_F(StackSamplingProfilerTest, ConcurrentProfiling_Mixed) { ...@@ -1309,76 +1379,6 @@ PROFILER_TEST_F(StackSamplingProfilerTest, ConcurrentProfiling_Mixed) {
}); });
} }
// Checks that a stack that runs through another library produces a stack with
// the expected functions.
// macOS ASAN is not yet supported - crbug.com/718628.
#if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
#define MAYBE_OtherLibrary OtherLibrary
#else
#define MAYBE_OtherLibrary DISABLED_OtherLibrary
#endif
PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_OtherLibrary) {
SamplingParams params;
params.sampling_interval = TimeDelta::FromMilliseconds(0);
params.samples_per_profile = 1;
Profile profile;
ScopedNativeLibrary other_library(LoadOtherLibrary());
UnwindScenario scenario(
BindRepeating(&CallThroughOtherLibrary, Unretained(other_library.get())));
WithTargetThread(&scenario, [&, this](PlatformThreadId target_thread_id) {
WaitableEvent sampling_thread_completed(
WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED);
StackSamplingProfiler profiler(
target_thread_id, params,
std::make_unique<TestProfileBuilder>(
module_cache(),
BindLambdaForTesting(
[&profile, &sampling_thread_completed](Profile result_profile) {
profile = std::move(result_profile);
sampling_thread_completed.Signal();
})));
profiler.Start();
sampling_thread_completed.Wait();
});
// Look up the frames.
ASSERT_EQ(1u, profile.frame_sets.size());
const Frames& frames = profile.frame_sets[0];
// The stack should contain a full unwind.
ExpectStackContains(frames, {scenario.GetWaitForSampleAddressRange(),
scenario.GetSetupFunctionAddressRange(),
scenario.GetOuterFunctionAddressRange()});
}
// Checks that a stack that runs through a library that is unloading produces a
// stack, and doesn't crash.
// Unloading is synchronous on the Mac, so this test is inapplicable.
#if !defined(OS_MACOSX)
#define MAYBE_UnloadingLibrary UnloadingLibrary
#else
#define MAYBE_UnloadingLibrary DISABLED_UnloadingLibrary
#endif
PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_UnloadingLibrary) {
TestLibraryUnload(false, module_cache());
}
// Checks that a stack that runs through a library that has been unloaded
// produces a stack, and doesn't crash.
// macOS ASAN is not yet supported - crbug.com/718628.
#if !(defined(ADDRESS_SANITIZER) && defined(OS_MACOSX))
#define MAYBE_UnloadedLibrary UnloadedLibrary
#else
#define MAYBE_UnloadedLibrary DISABLED_UnloadedLibrary
#endif
PROFILER_TEST_F(StackSamplingProfilerTest, MAYBE_UnloadedLibrary) {
TestLibraryUnload(true, module_cache());
}
// Checks that different threads can be sampled in parallel. // Checks that different threads can be sampled in parallel.
PROFILER_TEST_F(StackSamplingProfilerTest, MultipleSampledThreads) { PROFILER_TEST_F(StackSamplingProfilerTest, MultipleSampledThreads) {
UnwindScenario scenario1(BindRepeating(&CallWithPlainFunction)); UnwindScenario scenario1(BindRepeating(&CallWithPlainFunction));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment