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

#include "src/base/test/status_matchers.h"
#include "src/trace_redaction/find_package_uid.h"
#include "test/gtest_and_gmock.h"

#include "protos/perfetto/trace/android/packages_list.gen.h"
#include "protos/perfetto/trace/ps/process_tree.gen.h"
#include "protos/perfetto/trace/trace_packet.gen.h"

namespace perfetto::trace_redaction {

namespace {

// packet {
//   trusted_uid: 9999
//   trusted_packet_sequence_id: 2
//   previous_packet_dropped: true
//   packages_list {
//     packages {
//       name: "com.shannon.qualifiednetworksservice"
//       uid: 10201
//       debuggable: false
//       profileable_from_shell: false
//       version_code: 131
//     }
//     packages {
//       name: "com.google.android.uvexposurereporter"
//       uid: 10205
//       debuggable: false
//       profileable_from_shell: false
//       version_code: 34
//     }
//     packages {
//       name: "com.android.internal.display.cutout.emulation.noCutout"
//       uid: 10007
//       debuggable: false
//       profileable_from_shell: false
//       version_code: 1
//     }
//     packages {
//       name: "com.google.android.networkstack.tethering"
//       uid: 1073
//       debuggable: false
//       profileable_from_shell: false
//       version_code: 34
//     }
//     packages {
//       name: "com.amazon.mShop.android.shopping"
//       uid: 10303
//       debuggable: false
//       profileable_from_shell: false
//       version_code: 1241261011
//     }
//   }
//   trusted_pid: 1085
//   first_packet_on_sequence: true
// }
//
// packet {
//   process_tree {
//     processes {
//       pid: 23022
//       ppid: 1
//       cmdline: "/vendor/bin/hw/wpa_supplicant"
//       cmdline: "-O/data/vendor/wifi/wpa/sockets"
//       cmdline: "-dd"
//       cmdline: "-g@android:wpa_wlan0"
//       uid: 1010
//     }
//     threads {
//       tid: 6382
//       tgid: 18176
//     }
//     threads {
//      tid: 18419
//       tgid: 18176
//     }
//     threads {
//       tid: 18434
//       tgid: 18176
//     }
//     collection_end_timestamp: 333724398314653
//   }
//   trusted_uid: 9999
//   timestamp: 333724396714922
//   trusted_packet_sequence_id: 3
//   trusted_pid: 1085
// }

void AddPackage(const std::string& name,
                uint64_t uid,
                int version_code,
                protos::gen::PackagesList* list) {}

void AddProcess(protos::gen::ProcessTree* process_tree) {}

void AddThread(int32_t tid,
               int32_t ttid,
               protos::gen::ProcessTree* process_tree) {}

std::string CreatePackageListPacket() {}

std::string CreateProcessTreePacket() {}
}  // namespace

TEST(FindPackageUidTest, FindsUidInPackageList) {}

TEST(FindPackageUidTest, ContinuesOverNonPackageList) {}

TEST(FindPackageUidTest, ContinuesOverPackageListWithOutPackageName) {}

TEST(FindPackageUidTest, MissingPackageNameReturnsError) {}

TEST(FindPackageUidTest, FailsIfUidStartsInitialized) {}

}  // namespace perfetto::trace_redaction