chromium/services/resource_coordinator/memory_instrumentation/coordinator_impl_unittest.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/resource_coordinator/memory_instrumentation/coordinator_impl.h"

#include <memory>

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/test/trace_test_utils.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/trace_event/memory_dump_request_args.h"
#include "build/build_config.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/tracing_observer_proto.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
#include "services/tracing/public/cpp/perfetto/producer_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

RunOnceClosure;
_;
AllOf;
Contains;
Eq;
Field;
Invoke;
IsEmpty;
Ne;
NiceMock;
NotNull;
Pointee;
Property;
Return;
UnorderedElementsAre;

GetVmRegionsForHeapProfilerCallback;
RequestGlobalMemoryDumpAndAppendToTraceCallback;
RequestGlobalMemoryDumpCallback;
RequestGlobalMemoryDumpForPidCallback;
MemoryAllocatorDump;
MemoryDumpArgs;
MemoryDumpLevelOfDetail;
MemoryDumpManager;
MemoryDumpRequestArgs;
MemoryDumpType;
ProcessMemoryDump;
TraceLog;
GlobalMemoryDump;
GlobalMemoryDumpPtr;

namespace memory_instrumentation {

class FakeCoordinatorImpl : public CoordinatorImpl {};

class CoordinatorImplTest : public testing::Test {};

class MockClientProcess : public mojom::ClientProcess {};

class MockGlobalMemoryDumpCallback {};

class MockGlobalMemoryDumpAndAppendToTraceCallback {};

class MockGetVmRegionsForHeapProfilerCallback {};

uint64_t GetFakeAddrForVmRegion(int pid, int region_index) {}

uint64_t GetFakeSizeForVmRegion(int pid, int region_index) {}

mojom::RawOSMemDumpPtr FillRawOSDump(int pid) {}

// Tests that the global dump is acked even in absence of clients.
TEST_F(CoordinatorImplTest, NoClients) {}

// Nominal behavior: several clients contributing to the global dump.
TEST_F(CoordinatorImplTest, SeveralClients) {}

// Issuing two requests will cause the second one to be queued.
TEST_F(CoordinatorImplTest, QueuedRequest) {}

TEST_F(CoordinatorImplTest, MissingChromeDump) {}

TEST_F(CoordinatorImplTest, MissingOsDump) {}

TEST_F(CoordinatorImplTest, TimeOutStuckChild) {}

TEST_F(CoordinatorImplTest, TimeOutStuckChildMultiProcess) {}

// Tests that a global dump is completed even if a client disconnects (e.g. due
// to a crash) while a global dump is happening.
TEST_F(CoordinatorImplTest, ClientCrashDuringGlobalDump) {}

// Like ClientCrashDuringGlobalDump but covers the case of having only one
// client. Regression testing for crbug.com/742265.
TEST_F(CoordinatorImplTest, SingleClientCrashDuringGlobalDump) {}

TEST_F(CoordinatorImplTest, GlobalMemoryDumpStruct) {}

TEST_F(CoordinatorImplTest, VmRegionsForHeapProfiler) {}

// RequestGlobalMemoryDump, as opposite to RequestGlobalMemoryDumpAndAddToTrace,
// shouldn't add anything into the trace
TEST_F(CoordinatorImplTest, DumpsArentAddedToTraceUnlessRequested) {}

// TODO(crbug.com/40281135): Test is flaky across platforms.
TEST_F(CoordinatorImplTest, DISABLED_DumpsAreAddedToTraceWhenRequested) {}

TEST_F(CoordinatorImplTest, DumpByPidSuccess) {}

TEST_F(CoordinatorImplTest, DumpByPidFailure) {}

TEST_F(CoordinatorImplTest, GlobalDumpWithSubTrees) {}

}  // namespace memory_instrumentation