chromium/third_party/perfetto/src/trace_redaction/redact_sched_events_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/redact_sched_events.h"
#include "src/base/test/status_matchers.h"
#include "test/gtest_and_gmock.h"

#include "protos/perfetto/trace/ftrace/ftrace_event.gen.h"
#include "protos/perfetto/trace/ftrace/ftrace_event_bundle.gen.h"
#include "protos/perfetto/trace/ftrace/sched.gen.h"
#include "protos/perfetto/trace/trace.gen.h"
#include "protos/perfetto/trace/trace_packet.gen.h"

namespace perfetto::trace_redaction {

namespace {
constexpr uint64_t kUidA =;
constexpr uint64_t kUidB =;
constexpr uint64_t kUidC =;

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

constexpr int32_t kCpuA =;
constexpr int32_t kCpuB =;
constexpr int32_t kCpuC =;

constexpr uint64_t kHalfStep =;
constexpr uint64_t kFullStep =;

constexpr uint64_t kTimeA =;
constexpr uint64_t kTimeB =;
constexpr uint64_t kTimeC =;

constexpr auto kCommA =;
constexpr auto kCommB =;
constexpr auto kCommC =;
constexpr auto kCommNone =;

template <int32_t new_pid>
class ChangePidTo : public PidCommModifier {};
}  // namespace

class RedactSchedSwitchFtraceEventTest : public testing::Test {};

// In this case, the target uid will be UID A. That means the comm values for
// PID B should be removed, and the comm values for PID A should remain.
TEST_F(RedactSchedSwitchFtraceEventTest, KeepsTargetCommValues) {}

// This case is very similar to the "some are connected", expect that it
// verifies all comm values will be removed when testing against an unused
// uid.
TEST_F(RedactSchedSwitchFtraceEventTest, RemovesAllCommsIfPackageDoesntExist) {}

class RedactCompactSchedSwitchTest : public testing::Test {};

TEST_F(RedactCompactSchedSwitchTest, KeepsTargetCommValues) {}

// If two pids use the same comm, but one pid changes, the shared comm should
// still be available.
TEST_F(RedactCompactSchedSwitchTest, ChangingSharedCommonRetainsComm) {}

TEST_F(RedactCompactSchedSwitchTest, RemovesAllCommsIfPackageDoesntExist) {}

TEST_F(RedactCompactSchedSwitchTest, CanChangePid) {}

class RedactSchedWakingFtraceEventTest : public testing::Test {};

TEST_F(RedactSchedWakingFtraceEventTest, WakeeKeepsCommWhenConnectedToPackage) {}

TEST_F(RedactSchedWakingFtraceEventTest,
       WakeeLosesCommWhenNotConnectedToPackage) {}

TEST_F(RedactSchedWakingFtraceEventTest, WakeeKeepsPidWhenConnectedToPackage) {}

TEST_F(RedactSchedWakingFtraceEventTest,
       WakeeLosesPidWhenNotConnectedToPackage) {}

TEST_F(RedactSchedWakingFtraceEventTest, WakerPidIsLeftUnaffected) {}

class FilterCompactSchedWakingEventsTest : public testing::Test {};

// Builds a simple ftrace bundle that contains two ftrace events:
//
//  - Pid A wakes up pid B
//  - Pid A wakes up pid C
//
// Because compact sched uses associative arrays, the data will look like:
//
//  - Time | PID   | CPU   | *
//    -----+-------+-------+---
//    0.5  | kPidB | kCpuB |
//    1.5  | kPidC | kCpuB |
//
// Because the filter will only keep events where pid is being waked, only the
// first of the two events should remain.
TEST_F(FilterCompactSchedWakingEventsTest, FilterCompactSched) {}

// Timing information is based off delta-time values. When a row is removed
// from the compact sched arrays, downstream timing data is corrupted. The
// delta value of removed rows should be rolled into the next row.
TEST_F(FilterCompactSchedWakingEventsTest,
       CorrectsTimeWhenRemovingWakingEvents) {}

// This is an implementation detail. When an event is removed, the gap is
// collapsed into the next event by tracking the error created by removing the
// event. If implemented incorrectly, flipping between keep and remove will
// break as the error will not be reset correctly.
TEST_F(FilterCompactSchedWakingEventsTest, RemovingWakingEventsThrashing) {}

}  // namespace perfetto::trace_redaction