#ifdef UNSAFE_BUFFERS_BUILD
#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"
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) { … }
}
TEST_F(TraceEventTestFixture, DataCaptured) { … }
TEST_F(TraceEventTestFixture, DataDiscarded) { … }
class MockEnabledStateChangedObserver :
public TraceLog::EnabledStateObserver { … };
TEST_F(TraceEventTestFixture, EnabledObserverFiresOnEnable) { … }
TEST_F(TraceEventTestFixture, EnabledObserverFiresOnDisable) { … }
TEST_F(TraceEventTestFixture, EnabledObserverOwnedByTraceLog) { … }
class AfterStateChangeEnabledStateObserver
: public TraceLog::EnabledStateObserver { … };
TEST_F(TraceEventTestFixture, ObserversFireAfterStateChange) { … }
class SelfRemovingEnabledStateObserver
: public TraceLog::EnabledStateObserver { … };
TEST_F(TraceEventTestFixture, DISABLED_SelfRemovingObserver) { … }
bool IsNewTrace() { … }
TEST_F(TraceEventTestFixture, NewTraceRecording) { … }
TEST_F(TraceEventTestFixture, AddMetadataEvent) { … }
TEST_F(TraceEventTestFixture, Categories) { … }
TEST_F(TraceEventTestFixture, AsyncBeginEndEvents) { … }
TEST_F(TraceEventTestFixture, AsyncBeginEndPointerNotMangled) { … }
TEST_F(TraceEventTestFixture, StaticStringVsString) { … }
TEST_F(TraceEventTestFixture, DataCapturedOnThread) { … }
TEST_F(TraceEventTestFixture, DataCapturedManyThreads) { … }
TEST_F(TraceEventTestFixture, DisabledCategories) { … }
TEST_F(TraceEventTestFixture, DeepCopy) { … }
TEST_F(TraceEventTestFixture, TraceResultBuffer) { … }
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_F(TraceEventTestFixture, GetCurrentTraceConfig) { … }
}