chromium/third_party/perfetto/src/tracing/core/trace_writer_impl_unittest.cc

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "src/tracing/core/trace_writer_impl.h"

#include <vector>

#include "perfetto/ext/base/utils.h"
#include "perfetto/ext/tracing/core/commit_data_request.h"
#include "perfetto/ext/tracing/core/shared_memory_abi.h"
#include "perfetto/ext/tracing/core/trace_writer.h"
#include "perfetto/ext/tracing/core/tracing_service.h"
#include "perfetto/protozero/message.h"
#include "perfetto/protozero/proto_utils.h"
#include "perfetto/protozero/scattered_stream_writer.h"
#include "src/base/test/gtest_test_suite.h"
#include "src/base/test/test_task_runner.h"
#include "src/tracing/core/shared_memory_arbiter_impl.h"
#include "src/tracing/test/aligned_buffer_test.h"
#include "src/tracing/test/mock_producer_endpoint.h"
#include "test/gtest_and_gmock.h"

#include "protos/perfetto/trace/test_event.gen.h"
#include "protos/perfetto/trace/test_event.pbzero.h"
#include "protos/perfetto/trace/trace_packet.gen.h"
#include "protos/perfetto/trace/trace_packet.pbzero.h"

namespace perfetto {
namespace {

ChunkHeader;
ShmemMode;
ScatteredStreamWriter;
AllOf;
ElementsAre;
IsEmpty;
IsNull;
MockFunction;
Ne;
NiceMock;
Not;
NotNull;
Optional;
SizeIs;
ValuesIn;

class TraceWriterImplTest : public AlignedBufferTest {};

size_t const kPageSizes[] =;
INSTANTIATE_TEST_SUITE_P();

TEST_P(TraceWriterImplTest, NewTracePacket) {}

TEST_P(TraceWriterImplTest, NewTracePacketLargePackets) {}

// A prefix corresponding to first_packet_on_sequence = true in a serialized
// TracePacket proto.
constexpr char kFirstPacketOnSequenceFlagPrefix[] =;

TEST_P(TraceWriterImplTest, NewTracePacketTakeWriter) {}

#if defined(GTEST_HAS_DEATH_TEST)
TraceWriterImplDeathTest;
INSTANTIATE_TEST_SUITE_P();

TEST_P(TraceWriterImplDeathTest, NewTracePacketTakeWriterNoFinish) {}
#endif  // defined(GTEST_HAS_DEATH_TEST)

TEST_P(TraceWriterImplTest, AnnotatePatch) {}

TEST_P(TraceWriterImplTest, MixManualTakeAndMessage) {}

TEST_P(TraceWriterImplTest, MessageHandleDestroyedPacketScrapable) {}

TEST_P(TraceWriterImplTest, FinishTracePacketScrapable) {}

TEST_P(TraceWriterImplTest,
       MessageHandleDestroyedAndFinishTracePacketScrapable) {}

TEST_P(TraceWriterImplTest, MessageHandleDestroyedPacketFullChunk) {}

TEST_P(TraceWriterImplTest, FinishTracePacketFullChunk) {}

TEST_P(TraceWriterImplTest, FragmentingPacketWithProducerAndServicePatching) {}

TEST_P(TraceWriterImplTest, FragmentingPacketWithoutEnablingProducerPatching) {}

// Sets up a scenario in which the SMB is exhausted and TraceWriter fails to
// get a new chunk while fragmenting a packet. Verifies that data is dropped
// until the SMB is freed up and TraceWriter can get a new chunk.
TEST_P(TraceWriterImplTest, FragmentingPacketWhileBufferExhausted) {}

// Verifies that a TraceWriter that is flushed before the SMB is full and then
// acquires a garbage chunk later recovers and writes a
// previous_packet_dropped marker into the trace.
TEST_P(TraceWriterImplTest, FlushBeforeBufferExhausted) {}

// Regression test that verifies that flushing a TraceWriter while a
// fragmented packet still has uncommitted patches doesn't hit a DCHECK /
// crash the writer thread.
TEST_P(TraceWriterImplTest, FlushAfterFragmentingPacketWhileBufferExhausted) {}

TEST_P(TraceWriterImplTest, GarbageChunkWrap) {}

TEST_P(TraceWriterImplTest, AnnotatePatchWhileBufferExhausted) {}

TEST_P(TraceWriterImplTest, Flush) {}

TEST_P(TraceWriterImplTest, NestedMsgsPatches) {}

// TODO(primiano): add multi-writer test.

}  // namespace
}  // namespace perfetto