Commit a548a739 authored by Gabriel Marin's avatar Gabriel Marin Committed by Commit Bot

Don't run tcmalloc dependent unit tests with sanitizers

Sanitizers replace the default memory allocator with a custom one.
Unit tests that depend on tcmalloc functionality should not execute in
such cases. These cases are identified by compile macro
MEMORY_TOOL_REPLACES_ALLOCATOR being defined.

While we are at it, don't instantiate the heap profiler when
tcmalloc is not used, as the collector depends on tcmalloc too and it
may result in flakiness. We can enable it for sanitizers once we
remove dependency on tcmalloc.

BUG=chromium:724399,b:70905156

Change-Id: I4ded0301e6ef190b6b45c7f01405005765f3c5e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636611Reviewed-by: default avatarGabriel Marin <gmx@chromium.org>
Reviewed-by: default avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664568}
parent 5f6d6a2c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/sampling_heap_profiler/poisson_allocation_sampler.h" #include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#include "base/sampling_heap_profiler/sampling_heap_profiler.h" #include "base/sampling_heap_profiler/sampling_heap_profiler.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/test_simple_task_runner.h" #include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -146,6 +147,7 @@ class TestHeapCollector : public HeapCollector { ...@@ -146,6 +147,7 @@ class TestHeapCollector : public HeapCollector {
DISALLOW_COPY_AND_ASSIGN(TestHeapCollector); DISALLOW_COPY_AND_ASSIGN(TestHeapCollector);
}; };
#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
size_t HeapSamplingPeriod(const TestHeapCollector& collector) { size_t HeapSamplingPeriod(const TestHeapCollector& collector) {
CHECK_EQ(collector.Mode(), HeapCollectionMode::kTcmalloc) CHECK_EQ(collector.Mode(), HeapCollectionMode::kTcmalloc)
<< "Reading heap sampling period works only with tcmalloc sampling"; << "Reading heap sampling period works only with tcmalloc sampling";
...@@ -155,6 +157,7 @@ size_t HeapSamplingPeriod(const TestHeapCollector& collector) { ...@@ -155,6 +157,7 @@ size_t HeapSamplingPeriod(const TestHeapCollector& collector) {
<< "Failed to read heap sampling period"; << "Failed to read heap sampling period";
return sampling_period; return sampling_period;
} }
#endif
} // namespace } // namespace
...@@ -225,6 +228,7 @@ class HeapCollectorTest : public testing::Test { ...@@ -225,6 +228,7 @@ class HeapCollectorTest : public testing::Test {
size_t HeapCollectorTest::next_browser_id = 1; size_t HeapCollectorTest::next_browser_id = 1;
#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
TEST_F(HeapCollectorTest, CheckSetup_Tcmalloc) { TEST_F(HeapCollectorTest, CheckSetup_Tcmalloc) {
MakeHeapCollector(HeapCollectionMode::kTcmalloc); MakeHeapCollector(HeapCollectionMode::kTcmalloc);
heap_collector_->Init(); heap_collector_->Init();
...@@ -239,18 +243,6 @@ TEST_F(HeapCollectorTest, CheckSetup_Tcmalloc) { ...@@ -239,18 +243,6 @@ TEST_F(HeapCollectorTest, CheckSetup_Tcmalloc) {
EXPECT_GT(sampling_period, 0u); EXPECT_GT(sampling_period, 0u);
} }
TEST_F(HeapCollectorTest, CheckSetup_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
heap_collector_->Init();
// No profiles are cached on start.
std::vector<SampledProfile> stored_profiles;
EXPECT_FALSE(heap_collector_->GetSampledProfiles(&stored_profiles));
EXPECT_TRUE(stored_profiles.empty());
EXPECT_TRUE(heap_collector_->IsEnabled());
}
TEST_F(HeapCollectorTest, IncognitoWindowDisablesSamplingOnInit_Tcmalloc) { TEST_F(HeapCollectorTest, IncognitoWindowDisablesSamplingOnInit_Tcmalloc) {
MakeHeapCollector(HeapCollectionMode::kTcmalloc); MakeHeapCollector(HeapCollectionMode::kTcmalloc);
OpenBrowserWindow(/*incognito=*/true); OpenBrowserWindow(/*incognito=*/true);
...@@ -261,15 +253,6 @@ TEST_F(HeapCollectorTest, IncognitoWindowDisablesSamplingOnInit_Tcmalloc) { ...@@ -261,15 +253,6 @@ TEST_F(HeapCollectorTest, IncognitoWindowDisablesSamplingOnInit_Tcmalloc) {
EXPECT_EQ(sampling_period, 0u); EXPECT_EQ(sampling_period, 0u);
} }
TEST_F(HeapCollectorTest, IncognitoWindowDisablesSamplingOnInit_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
OpenBrowserWindow(/*incognito=*/true);
heap_collector_->Init();
// Heap sampling is disabled when an incognito session is active.
EXPECT_FALSE(heap_collector_->IsEnabled());
}
TEST_F(HeapCollectorTest, IncognitoWindowPausesSampling_Tcmalloc) { TEST_F(HeapCollectorTest, IncognitoWindowPausesSampling_Tcmalloc) {
MakeHeapCollector(HeapCollectionMode::kTcmalloc); MakeHeapCollector(HeapCollectionMode::kTcmalloc);
heap_collector_->Init(); heap_collector_->Init();
...@@ -303,32 +286,6 @@ TEST_F(HeapCollectorTest, IncognitoWindowPausesSampling_Tcmalloc) { ...@@ -303,32 +286,6 @@ TEST_F(HeapCollectorTest, IncognitoWindowPausesSampling_Tcmalloc) {
EXPECT_GT(sampling_period, 0u); EXPECT_GT(sampling_period, 0u);
} }
TEST_F(HeapCollectorTest, IncognitoWindowPausesSampling_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
heap_collector_->Init();
// Heap sampling is enabled.
EXPECT_TRUE(heap_collector_->IsEnabled());
// Opening an incognito window disables sampling and doesn't crash the test.
auto win1 = OpenBrowserWindow(/*incognito=*/true);
EXPECT_FALSE(heap_collector_->IsEnabled());
// Open also a regular window. Sampling still disabled.
OpenBrowserWindow(/*incognito=*/false);
EXPECT_FALSE(heap_collector_->IsEnabled());
// Open another incognito window and close the first one.
auto win3 = OpenBrowserWindow(/*incognito=*/true);
CloseBrowserWindow(win1);
EXPECT_FALSE(heap_collector_->IsEnabled());
// Closing the last incognito window resumes heap sampling, without
// crashing the test.
CloseBrowserWindow(win3);
EXPECT_TRUE(heap_collector_->IsEnabled());
}
TEST_F(HeapCollectorTest, DumpProfileToTempFile_Tcmalloc) { TEST_F(HeapCollectorTest, DumpProfileToTempFile_Tcmalloc) {
MakeHeapCollector(HeapCollectionMode::kTcmalloc); MakeHeapCollector(HeapCollectionMode::kTcmalloc);
base::Optional<base::FilePath> got_path = base::Optional<base::FilePath> got_path =
...@@ -345,39 +302,6 @@ TEST_F(HeapCollectorTest, DumpProfileToTempFile_Tcmalloc) { ...@@ -345,39 +302,6 @@ TEST_F(HeapCollectorTest, DumpProfileToTempFile_Tcmalloc) {
ASSERT_TRUE(base::DeleteFile(got_path.value(), false)); ASSERT_TRUE(base::DeleteFile(got_path.value(), false));
} }
TEST_F(HeapCollectorTest, DumpProfileToTempFile_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
base::Optional<base::FilePath> got_path =
heap_collector_->DumpProfileToTempFile();
// Check that we got a path.
ASSERT_TRUE(got_path);
// Check that the file is readable and not empty.
base::File temp(got_path.value(),
base::File::FLAG_OPEN | base::File::FLAG_READ);
ASSERT_TRUE(temp.IsValid());
EXPECT_GT(temp.GetLength(), 0);
temp.Close();
// We must be able to remove the temp file.
ASSERT_TRUE(base::DeleteFile(got_path.value(), false));
}
TEST_F(HeapCollectorTest, MakeQuipperCommand) {
const base::FilePath kTempProfile(
FILE_PATH_LITERAL("/tmp/MakeQuipperCommand.test"));
base::CommandLine got = heap_collector_->MakeQuipperCommand(kTempProfile);
// Check that we got the correct two switch names.
ASSERT_EQ(got.GetSwitches().size(), 2u);
EXPECT_TRUE(got.HasSwitch("input_heap_profile"));
EXPECT_TRUE(got.HasSwitch("pid"));
// Check that we got the correct program name and switch values.
EXPECT_EQ(got.GetProgram().value(), "/usr/bin/quipper");
EXPECT_EQ(got.GetSwitchValuePath("input_heap_profile"), kTempProfile);
EXPECT_EQ(got.GetSwitchValueASCII("pid"),
std::to_string(base::GetCurrentProcId()));
}
TEST_F(HeapCollectorTest, ParseAndSaveProfile_Tcmalloc) { TEST_F(HeapCollectorTest, ParseAndSaveProfile_Tcmalloc) {
MakeHeapCollector(HeapCollectionMode::kTcmalloc); MakeHeapCollector(HeapCollectionMode::kTcmalloc);
// Write a sample perf data proto to a temp file. // Write a sample perf data proto to a temp file.
...@@ -428,6 +352,87 @@ TEST_F(HeapCollectorTest, ParseAndSaveProfile_Tcmalloc) { ...@@ -428,6 +352,87 @@ TEST_F(HeapCollectorTest, ParseAndSaveProfile_Tcmalloc) {
base::File(kTempProfile, base::File::FLAG_OPEN | base::File::FLAG_READ); base::File(kTempProfile, base::File::FLAG_OPEN | base::File::FLAG_READ);
ASSERT_FALSE(temp.IsValid()); ASSERT_FALSE(temp.IsValid());
} }
#endif
TEST_F(HeapCollectorTest, CheckSetup_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
heap_collector_->Init();
// No profiles are cached on start.
std::vector<SampledProfile> stored_profiles;
EXPECT_FALSE(heap_collector_->GetSampledProfiles(&stored_profiles));
EXPECT_TRUE(stored_profiles.empty());
EXPECT_TRUE(heap_collector_->IsEnabled());
}
TEST_F(HeapCollectorTest, IncognitoWindowDisablesSamplingOnInit_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
OpenBrowserWindow(/*incognito=*/true);
heap_collector_->Init();
// Heap sampling is disabled when an incognito session is active.
EXPECT_FALSE(heap_collector_->IsEnabled());
}
TEST_F(HeapCollectorTest, IncognitoWindowPausesSampling_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
heap_collector_->Init();
// Heap sampling is enabled.
EXPECT_TRUE(heap_collector_->IsEnabled());
// Opening an incognito window disables sampling and doesn't crash the test.
auto win1 = OpenBrowserWindow(/*incognito=*/true);
EXPECT_FALSE(heap_collector_->IsEnabled());
// Open also a regular window. Sampling still disabled.
OpenBrowserWindow(/*incognito=*/false);
EXPECT_FALSE(heap_collector_->IsEnabled());
// Open another incognito window and close the first one.
auto win3 = OpenBrowserWindow(/*incognito=*/true);
CloseBrowserWindow(win1);
EXPECT_FALSE(heap_collector_->IsEnabled());
// Closing the last incognito window resumes heap sampling, without
// crashing the test.
CloseBrowserWindow(win3);
EXPECT_TRUE(heap_collector_->IsEnabled());
}
TEST_F(HeapCollectorTest, DumpProfileToTempFile_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer);
base::Optional<base::FilePath> got_path =
heap_collector_->DumpProfileToTempFile();
// Check that we got a path.
ASSERT_TRUE(got_path);
// Check that the file is readable and not empty.
base::File temp(got_path.value(),
base::File::FLAG_OPEN | base::File::FLAG_READ);
ASSERT_TRUE(temp.IsValid());
EXPECT_GT(temp.GetLength(), 0);
temp.Close();
// We must be able to remove the temp file.
ASSERT_TRUE(base::DeleteFile(got_path.value(), false));
}
TEST_F(HeapCollectorTest, MakeQuipperCommand) {
const base::FilePath kTempProfile(
FILE_PATH_LITERAL("/tmp/MakeQuipperCommand.test"));
base::CommandLine got = heap_collector_->MakeQuipperCommand(kTempProfile);
// Check that we got the correct two switch names.
ASSERT_EQ(got.GetSwitches().size(), 2u);
EXPECT_TRUE(got.HasSwitch("input_heap_profile"));
EXPECT_TRUE(got.HasSwitch("pid"));
// Check that we got the correct program name and switch values.
EXPECT_EQ(got.GetProgram().value(), "/usr/bin/quipper");
EXPECT_EQ(got.GetSwitchValuePath("input_heap_profile"), kTempProfile);
EXPECT_EQ(got.GetSwitchValueASCII("pid"),
base::NumberToString(base::GetCurrentProcId()));
}
TEST_F(HeapCollectorTest, ParseAndSaveProfile_ShimLayer) { TEST_F(HeapCollectorTest, ParseAndSaveProfile_ShimLayer) {
MakeHeapCollector(HeapCollectionMode::kShimLayer); MakeHeapCollector(HeapCollectionMode::kShimLayer);
...@@ -493,6 +498,7 @@ class HeapCollectorCollectionParamsTest : public testing::Test { ...@@ -493,6 +498,7 @@ class HeapCollectorCollectionParamsTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(HeapCollectorCollectionParamsTest); DISALLOW_COPY_AND_ASSIGN(HeapCollectorCollectionParamsTest);
}; };
#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
TEST_F(HeapCollectorCollectionParamsTest, ParametersOverride_Tcmalloc) { TEST_F(HeapCollectorCollectionParamsTest, ParametersOverride_Tcmalloc) {
std::map<std::string, std::string> params; std::map<std::string, std::string> params;
params.insert(std::make_pair("SamplingIntervalBytes", "800000")); params.insert(std::make_pair("SamplingIntervalBytes", "800000"));
...@@ -532,6 +538,7 @@ TEST_F(HeapCollectorCollectionParamsTest, ParametersOverride_Tcmalloc) { ...@@ -532,6 +538,7 @@ TEST_F(HeapCollectorCollectionParamsTest, ParametersOverride_Tcmalloc) {
EXPECT_EQ(base::TimeDelta::FromSeconds(20), EXPECT_EQ(base::TimeDelta::FromSeconds(20),
parsed_params.restore_session.max_collection_delay); parsed_params.restore_session.max_collection_delay);
} }
#endif
TEST_F(HeapCollectorCollectionParamsTest, ParametersOverride_ShimLayer) { TEST_F(HeapCollectorCollectionParamsTest, ParametersOverride_ShimLayer) {
std::map<std::string, std::string> params; std::map<std::string, std::string> params;
......
...@@ -39,7 +39,7 @@ ProfileProvider::~ProfileProvider() { ...@@ -39,7 +39,7 @@ ProfileProvider::~ProfileProvider() {
} }
void ProfileProvider::Init() { void ProfileProvider::Init() {
#if BUILDFLAG(USE_NEW_TCMALLOC) #if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) && BUILDFLAG(USE_NEW_TCMALLOC)
if (base::FeatureList::IsEnabled(heap_profiling::kOOPHeapProfilingFeature)) { if (base::FeatureList::IsEnabled(heap_profiling::kOOPHeapProfilingFeature)) {
HeapCollectionMode mode = HeapCollector::CollectionModeFromString( HeapCollectionMode mode = HeapCollector::CollectionModeFromString(
base::GetFieldTrialParamValueByFeature( base::GetFieldTrialParamValueByFeature(
......
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