#include "services/tracing/perfetto/test_utils.h"
#include <utility>
#include "base/containers/heap_array.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/tracing/perfetto_platform.h"
#include "services/tracing/public/cpp/perfetto/shared_memory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/commit_data_request.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_packet.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_writer.h"
#include "third_party/perfetto/include/perfetto/tracing/core/trace_config.h"
#include "third_party/perfetto/protos/perfetto/trace/test_event.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet.pb.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet.pbzero.h"
namespace tracing {
namespace {
perfetto::TraceConfig GetDefaultTraceConfig(
const std::vector<std::string>& data_sources) { … }
}
std::unique_ptr<TestDataSource> TestDataSource::CreateAndRegisterDataSource(
const std::string& data_source_name,
size_t send_packet_count) { … }
TestDataSource::TestDataSource(const std::string& data_source_name,
size_t send_packet_count)
: … { … }
TestDataSource::~TestDataSource() = default;
void TestDataSource::WritePacketBigly() { … }
void TestDataSource::StartTracingImpl(
PerfettoProducer* producer,
const perfetto::DataSourceConfig& data_source_config) { … }
void TestDataSource::StopTracingImpl(base::OnceClosure stop_complete_callback) { … }
void TestDataSource::Flush(base::RepeatingClosure flush_complete_callback) { … }
void TestDataSource::set_start_tracing_callback(
base::OnceClosure start_tracing_callback) { … }
MockProducerClient::MockProducerClient(
uint32_t num_data_sources,
base::OnceClosure client_enabled_callback,
base::OnceClosure client_disabled_callback)
: … { … }
MockProducerClient::~MockProducerClient() = default;
std::unique_ptr<MockProducerClient::Handle> MockProducerClient::Create(
uint32_t num_data_sources,
base::OnceClosure client_enabled_callback,
base::OnceClosure client_disabled_callback) { … }
MockProducerClient::Handle::~Handle() { … }
void MockProducerClient::SetupDataSource(const std::string& data_source_name) { … }
void MockProducerClient::StartDataSource(
uint64_t id,
const perfetto::DataSourceConfig& data_source_config,
StartDataSourceCallback callback) { … }
void MockProducerClient::StopDataSource(uint64_t id,
StopDataSourceCallback callback) { … }
void MockProducerClient::CommitData(const perfetto::CommitDataRequest& commit,
CommitDataCallback callback) { … }
void MockProducerClient::SetAgentEnabledCallback(
base::OnceClosure client_enabled_callback) { … }
void MockProducerClient::SetAgentDisabledCallback(
base::OnceClosure client_disabled_callback) { … }
MockConsumer::MockConsumer(std::vector<std::string> data_source_names,
perfetto::TracingService* service,
PacketReceivedCallback packet_received_callback)
: … { … }
MockConsumer::MockConsumer(std::vector<std::string> data_source_names,
perfetto::TracingService* service,
PacketReceivedCallback packet_received_callback,
const perfetto::TraceConfig& config)
: … { … }
MockConsumer::~MockConsumer() = default;
void MockConsumer::ReadBuffers() { … }
void MockConsumer::StopTracing() { … }
void MockConsumer::StartTracing() { … }
void MockConsumer::FreeBuffers() { … }
void MockConsumer::OnConnect() { … }
void MockConsumer::OnDisconnect() { … }
void MockConsumer::OnTracingDisabled(const std::string& error) { … }
void MockConsumer::OnTraceData(std::vector<perfetto::TracePacket> packets,
bool has_more) { … }
void MockConsumer::OnDetach(bool ) { … }
void MockConsumer::OnAttach(bool , const perfetto::TraceConfig&) { … }
void MockConsumer::OnTraceStats(bool , const perfetto::TraceStats&) { … }
void MockConsumer::OnSessionCloned(const OnSessionClonedArgs&) { … }
void MockConsumer::OnObservableEvents(
const perfetto::ObservableEvents& events) { … }
void MockConsumer::WaitForAllDataSourcesStarted() { … }
void MockConsumer::WaitForAllDataSourcesStopped() { … }
void MockConsumer::CheckForAllDataSourcesStarted() { … }
void MockConsumer::CheckForAllDataSourcesStopped() { … }
MockProducerHost::MockProducerHost(
const std::string& producer_name,
const std::string& data_source_name,
PerfettoService* service,
MockProducerClient* producer_client,
base::OnceClosure datasource_registered_callback)
: … { … }
MockProducerHost::~MockProducerHost() = default;
void MockProducerHost::RegisterDataSource(
const perfetto::DataSourceDescriptor& registration_info) { … }
void MockProducerHost::OnConnect() { … }
void MockProducerHost::OnCommit(
const perfetto::CommitDataRequest& commit_data_request) { … }
MockProducer::MockProducer(const std::string& producer_name,
const std::string& data_source_name,
PerfettoService* service,
base::OnceClosure on_datasource_registered,
base::OnceClosure on_tracing_started,
size_t num_packets) { … }
MockProducer::~MockProducer() = default;
void MockProducer::WritePacketBigly(base::OnceClosure on_write_complete) { … }
TracingUnitTest::TracingUnitTest()
: … { … }
TracingUnitTest::~TracingUnitTest() { … }
void TracingUnitTest::SetUp() { … }
void TracingUnitTest::TearDown() { … }
}