chromium/base/trace_event/trace_event_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/trace_event/trace_event.h"

#include <inttypes.h>
#include <math.h>
#include <stddef.h>
#include <stdint.h>

#include <cstdlib>
#include <limits>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/singleton.h"
#include "base/process/process_handle.h"
#include "base/stl_util.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/trace_event/trace_buffer.h"
#include "base/values.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#include "third_party/perfetto/protos/perfetto/config/chrome/chrome_config.gen.h"  // nogncheck

namespace base::trace_event {

namespace {

enum CompareOp {};

struct JsonKeyValue {};

const int kAsyncId =;
const char kAsyncIdStr[] =;
const int kAsyncId2 =;
const char kAsyncId2Str[] =;

constexpr const char kRecordAllCategoryFilter[] =;
constexpr const char kAllCategory[] =;

bool IsCategoryEnabled(const char* name) {}

class TraceEventTestFixture : public testing::Test {};

void TraceEventTestFixture::OnTraceDataCollected(
    WaitableEvent* flush_complete_event,
    const scoped_refptr<base::RefCountedString>& events_str,
    bool has_more_events) {}

static bool CompareJsonValues(const std::string& lhs,
                              const std::string& rhs,
                              CompareOp op) {}

static bool IsKeyValueInDict(const JsonKeyValue* key_value,
                             const Value::Dict* dict) {}

static bool IsAllKeyValueInDict(const JsonKeyValue* key_values,
                                const Value::Dict* dict) {}

const Value::Dict* TraceEventTestFixture::FindMatchingTraceEntry(
    const JsonKeyValue* key_values) {}

void TraceEventTestFixture::DropTracedMetadataRecords() {}

const Value::Dict* TraceEventTestFixture::FindNamePhase(const char* name,
                                                        const char* phase) {}

const Value::Dict* TraceEventTestFixture::FindNamePhaseKeyValue(
    const char* name,
    const char* phase,
    const char* key,
    const char* value) {}

bool TraceEventTestFixture::FindMatchingValue(const char* key,
                                              const char* value) {}

bool TraceEventTestFixture::FindNonMatchingValue(const char* key,
                                                 const char* value) {}

bool IsStringInDict(const char* string_to_match, const Value::Dict* dict) {}

const Value::Dict* FindTraceEntry(
    const Value::List& trace_parsed,
    const char* string_to_match,
    const Value::Dict* match_after_this_item = nullptr) {}

constexpr const char kControlCharacters[] =;

void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) {}

void ValidateAllTraceMacrosCreatedData(const Value::List& trace_parsed) {}

void TraceManyInstantEvents(int thread_id, int num_events,
                            WaitableEvent* task_complete_event) {}

void ValidateInstantEventPresentOnEveryThread(const Value::List& trace_parsed,
                                              int num_threads,
                                              int num_events) {}

void CheckTraceDefaultCategoryFilters(const TraceLog& trace_log) {}

}  // namespace

// Simple Test for emitting data and validating it was received.
TEST_F(TraceEventTestFixture, DataCaptured) {}

// Emit some events and validate that only empty strings are received
// if we tell Flush() to discard events.
TEST_F(TraceEventTestFixture, DataDiscarded) {}

class MockEnabledStateChangedObserver :
      public TraceLog::EnabledStateObserver {};

TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) {}

TEST_F(TraceEventTestFixture, EnabledObserverFiresOnDisable) {}

TEST_F(TraceEventTestFixture, EnabledObserverOwnedByTraceLog) {}

// Tests the IsEnabled() state of TraceLog changes before callbacks.
class AfterStateChangeEnabledStateObserver
    : public TraceLog::EnabledStateObserver {};

TEST_F(TraceEventTestFixture, ObserversFireAfterStateChange) {}

// Tests that a state observer can remove itself during a callback.
class SelfRemovingEnabledStateObserver
    : public TraceLog::EnabledStateObserver {};

// Self removing observers are not supported at the moment.
// TODO(alph): We could add support once we have recursive locks.
TEST_F(TraceEventTestFixture, DISABLED_SelfRemovingObserver) {}

bool IsNewTrace() {}

TEST_F(TraceEventTestFixture, NewTraceRecording) {}

TEST_F(TraceEventTestFixture, AddMetadataEvent) {}

// Test that categories work.
TEST_F(TraceEventTestFixture, Categories) {}


// Test ASYNC_BEGIN/END events
TEST_F(TraceEventTestFixture, AsyncBeginEndEvents) {}

// Test ASYNC_BEGIN/END events
TEST_F(TraceEventTestFixture, AsyncBeginEndPointerNotMangled) {}

// Test that static strings are not copied.
TEST_F(TraceEventTestFixture, StaticStringVsString) {}

// Test that data sent from other threads is gathered
TEST_F(TraceEventTestFixture, DataCapturedOnThread) {}

// Test that data sent from multiple threads is gathered
TEST_F(TraceEventTestFixture, DataCapturedManyThreads) {}

// Test that the disabled trace categories are included/excluded from the
// trace output correctly.
TEST_F(TraceEventTestFixture, DisabledCategories) {}

TEST_F(TraceEventTestFixture, DeepCopy) {}

// Test that TraceResultBuffer outputs the correct result whether it is added
// in chunks or added all at once.
TEST_F(TraceEventTestFixture, TraceResultBuffer) {}

// Test that trace_event parameters are not evaluated if the tracing
// system is disabled.
TEST_F(TraceEventTestFixture, TracingIsLazy) {}

TEST_F(TraceEventTestFixture, TraceEnableDisable) {}

TEST_F(TraceEventTestFixture, TraceWithDefaultCategoryFilters) {}

TEST_F(TraceEventTestFixture, TraceWithDisabledByDefaultCategoryFilters) {}

class MyData : public ConvertableToTraceFormat {};

TEST_F(TraceEventTestFixture, ConvertableTypes) {}

TEST_F(TraceEventTestFixture, PrimitiveArgs) {}

TEST_F(TraceEventTestFixture, NameIsEscaped) {}

void BlockUntilStopped(WaitableEvent* task_start_event,
                       WaitableEvent* task_stop_event) {}

TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopBeforeTracing) {}

TEST_F(TraceEventTestFixture, ConvertTraceConfigToInternalOptions) {}

void SetBlockingFlagAndBlockUntilStopped(WaitableEvent* task_start_event,
                                         WaitableEvent* task_stop_event) {}

TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopAfterTracing) {}

TEST_F(TraceEventTestFixture, ThreadOnceBlocking) {}

std::string* g_log_buffer =;
bool MockLogMessageHandler(int, const char*, int, size_t,
                           const std::string& str) {}

TEST_F(TraceEventTestFixture, EchoToConsole) {}

bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t,
                                     const std::string&) {}

TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) {}

TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) {}

TEST_F(TraceEventTestFixture, ContextLambda) {}

class ConfigObserver : public TraceLog::EnabledStateObserver {};

// Test that GetCurrentTraceConfig() returns the correct config when tracing
// was started through Perfetto SDK.
TEST_F(TraceEventTestFixture, GetCurrentTraceConfig) {}

}  // namespace base::trace_event