chromium/third_party/perfetto/src/trace_redaction/collect_frame_cookies_unittest.cc


/*
 * Copyright (C) 2024 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/trace_redaction/collect_frame_cookies.h"
#include "perfetto/ext/base/status_or.h"
#include "src/base/test/status_matchers.h"
#include "test/gtest_and_gmock.h"

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

namespace perfetto::trace_redaction {
namespace {

constexpr uint64_t kTimeStep =;

constexpr uint64_t kTimestampA =;
constexpr uint64_t kTimestampB =;
constexpr uint64_t kTimestampC =;
constexpr uint64_t kTimestampD =;
constexpr uint64_t kTimestampE =;

constexpr int64_t kCookieA =;
constexpr int64_t kCookieB =;

// Start at 1, amd not zero, because zero hnas special meaning (system uid).
constexpr uint64_t kUidA =;

constexpr int32_t kPidNone =;
constexpr int32_t kPidA =;

enum class FrameCookieType {};

protos::gen::TracePacket CreateExpectedSurfaceFrameStart(uint64_t ts,
                                                         int32_t pid,
                                                         int64_t cookie) {}

protos::gen::TracePacket CreateActualSurfaceFrameStart(uint64_t ts,
                                                       int32_t pid,
                                                       int64_t cookie) {}

protos::gen::TracePacket CreateExpectedDisplayFrameStart(uint64_t ts,
                                                         int32_t pid,
                                                         int64_t cookie) {}

protos::gen::TracePacket CreateActualDisplayFrameStart(uint64_t ts,
                                                       int32_t pid,
                                                       int64_t cookie) {}

protos::gen::TracePacket CreateFrameEnd(uint64_t ts, int64_t cookie) {}

protos::gen::TracePacket CreateStartPacket(FrameCookieType type,
                                           uint64_t ts,
                                           int32_t pid,
                                           int64_t cookie) {}

void CollectCookies(const std::string& packet, Context* context) {}

class FrameCookieTest : public testing::Test {};

TEST_F(FrameCookieTest, ExtractsExpectedSurfaceFrameStart) {}

TEST_F(FrameCookieTest, ExtractsActualSurfaceFrameStart) {}

TEST_F(FrameCookieTest, ExtractsExpectedDisplayFrameStart) {}

TEST_F(FrameCookieTest, ExtractsActualDisplayFrameStart) {}

// End events have no influence during the collect phase because they don't have
// a direct connection to a process. They're indirectly connected to a pid via a
// start event (via a common cookie value).
TEST_F(FrameCookieTest, IgnoresFrameEnd) {}

class ReduceFrameCookiesTest
    : public testing::Test,
      public testing::WithParamInterface<FrameCookieType> {};

TEST_P(ReduceFrameCookiesTest, RejectBeforeStart) {}

TEST_P(ReduceFrameCookiesTest, AcceptAtStart) {}

TEST_P(ReduceFrameCookiesTest, AcceptBetweenStartAndEnd) {}

TEST_P(ReduceFrameCookiesTest, AcceptAtEnd) {}

TEST_P(ReduceFrameCookiesTest, RejectAfterEnd) {}

INSTANTIATE_TEST_SUITE_P();

class TransformStartCookiesTest
    : public testing::Test,
      public testing::WithParamInterface<FrameCookieType> {};

TEST_P(TransformStartCookiesTest, RetainStartEvent) {}

TEST_P(TransformStartCookiesTest, DropStartEvent) {}

INSTANTIATE_TEST_SUITE_P();

class TransformEndFrameCookiesTest : public testing::Test {};

// An end event has no pid. The cookie connects it to a pid. If the start event
// cookie moved from the global pool into the package pool, then end the end
// event should be retained.
TEST_F(TransformStartCookiesTest, Retain) {}

TEST_F(TransformStartCookiesTest, Drop) {}

}  // namespace
}  // namespace perfetto::trace_redaction