aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/memory/heapprofd_end_to_end_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/profiling/memory/heapprofd_end_to_end_test.cc')
-rw-r--r--src/profiling/memory/heapprofd_end_to_end_test.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/profiling/memory/heapprofd_end_to_end_test.cc b/src/profiling/memory/heapprofd_end_to_end_test.cc
index 97c9876dc..df08bd96e 100644
--- a/src/profiling/memory/heapprofd_end_to_end_test.cc
+++ b/src/profiling/memory/heapprofd_end_to_end_test.cc
@@ -19,6 +19,7 @@
#include <vector>
#include <fcntl.h>
+#include <stdint.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -311,6 +312,9 @@ void __attribute__((constructor(1024))) RunAccurateMalloc() {
// Wait around so we can verify it did't crash.
for (;;) {
+ // Call sleep, otherwise an empty busy loop is undefined behavior:
+ // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+ sleep(1);
}
}
@@ -350,6 +354,9 @@ void __attribute__((noreturn)) RunAccurateMallocWithVforkCommon() {
// Wait around so we can verify it did't crash.
for (;;) {
+ // Call sleep, otherwise an empty busy loop is undefined behavior:
+ // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+ sleep(1);
}
}
@@ -386,6 +393,9 @@ void __attribute__((constructor(1024))) RunAccurateSample() {
// Wait around so we can verify it did't crash.
for (;;) {
+ // Call sleep, otherwise an empty busy loop is undefined behavior:
+ // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+ sleep(1);
}
}
@@ -454,6 +464,7 @@ void __attribute__((constructor(1024))) RunCustomLifetime() {
static std::atomic<bool> disabled{false};
static std::atomic<uint64_t> sampling_interval;
+ static uint32_t other_heap_id = 0;
auto enabled_callback = [](void*,
const AHeapProfileEnableCallbackInfo* info) {
sampling_interval =
@@ -461,6 +472,8 @@ void __attribute__((constructor(1024))) RunCustomLifetime() {
initialized = true;
};
auto disabled_callback = [](void*, const AHeapProfileDisableCallbackInfo*) {
+ PERFETTO_CHECK(other_heap_id);
+ AHeapProfile_reportFree(other_heap_id, 0);
disabled = true;
};
static uint32_t heap_id =
@@ -469,6 +482,7 @@ void __attribute__((constructor(1024))) RunCustomLifetime() {
enabled_callback, nullptr),
disabled_callback, nullptr));
+ other_heap_id = AHeapProfile_registerHeap(AHeapInfo_create("othertest"));
ChildFinishHandshake();
// heapprofd_client needs malloc to see the signal.
@@ -488,6 +502,9 @@ void __attribute__((constructor(1024))) RunCustomLifetime() {
// Wait around so we can verify it didn't crash.
for (;;) {
+ // Call sleep, otherwise an empty busy loop is undefined behavior:
+ // http://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee
+ sleep(1);
}
}
@@ -1136,6 +1153,7 @@ TEST_P(HeapprofdEndToEnd, CustomLifetime) {
cfg->set_sampling_interval_bytes(1000000);
cfg->add_pid(pid);
cfg->add_heaps("test");
+ cfg->add_heaps("othertest");
});
auto helper = Trace(trace_config);
@@ -1744,6 +1762,10 @@ TEST_P(HeapprofdEndToEnd, NativeProfilingActiveAtProcessExit) {
EXPECT_GT(total_allocated, 0u);
}
+// Disable these tests when running with sanitizers. They (double) fork and that
+// seems to cause flaky crashes with sanitizers.
+#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
+ !defined(MEMORY_SANITIZER) && !defined(LEAK_SANITIZER)
// On in-tree Android, we use the system heapprofd in fork or central mode.
// For Linux and out-of-tree Android, we statically include a copy of
// heapprofd and use that. This one does not support intercepting malloc.
@@ -1752,7 +1774,7 @@ TEST_P(HeapprofdEndToEnd, NativeProfilingActiveAtProcessExit) {
#error "Need to start daemons for Linux test."
#endif
-INSTANTIATE_TEST_CASE_P(DISABLED_Run,
+INSTANTIATE_TEST_CASE_P(Run,
HeapprofdEndToEnd,
Values(std::make_tuple(TestMode::kStatic,
AllocatorMode::kCustom)),
@@ -1765,6 +1787,8 @@ INSTANTIATE_TEST_CASE_P(
std::make_tuple(TestMode::kCentral, AllocatorMode::kCustom)),
TestSuffix);
#endif
+#endif
+
} // namespace
} // namespace profiling