chromium/third_party/perfetto/src/trace_redaction/process_thread_timeline_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 <array>
#include <cstdint>

#include "src/trace_redaction/process_thread_timeline.h"
#include "test/gtest_and_gmock.h"

namespace perfetto::trace_redaction {

namespace {

constexpr uint64_t kTimeA =;
constexpr uint64_t kTimeB =;
constexpr uint64_t kTimeC =;
constexpr uint64_t kTimeD =;
constexpr uint64_t kTimeE =;
constexpr uint64_t kTimeF =;
constexpr uint64_t kTimeG =;
constexpr uint64_t kTimeH =;

constexpr int32_t kPidA =;
constexpr int32_t kPidB =;
constexpr int32_t kPidC =;
constexpr int32_t kPidD =;

constexpr uint64_t kUidA =;
constexpr uint64_t kUidC =;

}  // namespace

// B        C        D   E   F        G        H
// *        *        *   *   *        *        *
// |----- PID B -----|   .   |----- PID B -----|
//          |--------- PID C ---------|
//          | <- PID D (no duration)
class ProcessThreadTimelineTest : public testing::Test {};

TEST_F(ProcessThreadTimelineTest, BeforeSpan) {}

TEST_F(ProcessThreadTimelineTest, StartOfSpan) {}

TEST_F(ProcessThreadTimelineTest, DuringSpan) {}

TEST_F(ProcessThreadTimelineTest, EndOfSpan) {}

// Even through its after a span, the previous open and close events should be
// openned.
TEST_F(ProcessThreadTimelineTest, AfterSpan) {}

// When a pid is reused, the new open event (for the reused pid) should be
// returned, but the close from the previous span should be returned.
TEST_F(ProcessThreadTimelineTest, StartOfSecondSpan) {}

// Now that there is a second close event, both open and close events should
// come from the same span.
TEST_F(ProcessThreadTimelineTest, CloseOfSecondSpan) {}

TEST_F(ProcessThreadTimelineTest, BeforeSpanWithZeroDuration) {}

TEST_F(ProcessThreadTimelineTest, SpanWithZeroDuration) {}

TEST_F(ProcessThreadTimelineTest, AfterSpanWithZeroDuration) {}

// |----- UID A -----| |----- UID C -----|
//  |---- PID A ----|   |---- PID C ----|
//    |-- PID B --|
//
// NOTE: The notation above does not represent time, it represent relationship.
// For example, PID B is a child of PID A.
class ProcessThreadTimelineIsConnectedTest : public testing::Test {};

// PID A is directly connected to UID A.
TEST_F(ProcessThreadTimelineIsConnectedTest, DirectPidAndUid) {}

// PID B is indirectly connected to UID A through PID A.
TEST_F(ProcessThreadTimelineIsConnectedTest, IndirectPidAndUid) {}

// UID A and UID C are valid packages. However, PID B is connected to UID A, not
// UID C.
TEST_F(ProcessThreadTimelineIsConnectedTest, NotConnectedToOtherUid) {}

// PID D is not in the timeline, so it shouldn't be connected to anything.
TEST_F(ProcessThreadTimelineIsConnectedTest, MissingPid) {}

// Even through there is a connection between PID A and UID A, the query is too
// soon (events are at TIME B, but the query is at TIME A).
TEST_F(ProcessThreadTimelineIsConnectedTest, PrematureDirectPidAndUid) {}

}  // namespace perfetto::trace_redaction