chromium/net/base/address_tracker_linux_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/base/address_tracker_linux.h"

#include <linux/if.h>
#include <linux/rtnetlink.h>
#include <sched.h>

#include <memory>
#include <unordered_set>
#include <vector>

#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/bind.h"
#include "base/test/multiprocess_test.h"
#include "base/test/spin_wait.h"
#include "base/test/task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/simple_thread.h"
#include "build/build_config.h"
#include "net/base/address_map_cache_linux.h"
#include "net/base/address_map_linux.h"
#include "net/base/address_tracker_linux_test_util.h"
#include "net/base/ip_address.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif

#ifndef IFA_F_HOMEADDRESS
#define IFA_F_HOMEADDRESS
#endif

AddressTrackerLinux;

namespace net::test {
namespace {

const int kTestInterfaceEth =;
const int kTestInterfaceWifi =;
const int kTestInterfaceTun =;
const int kTestInterfaceAp =;

const char kIgnoredInterfaceName[] =;

char* TestGetInterfaceName(int interface_index, char* buf) {}

}  // namespace

class AddressTrackerLinuxTest : public testing::Test {};

namespace {

const unsigned char kAddress0[] =;
const unsigned char kAddress1[] =;
const unsigned char kAddress2[] =;
const unsigned char kAddress3[] =;

TEST_F(AddressTrackerLinuxTest, NewAddress) {}

TEST_F(AddressTrackerLinuxTest, NewAddressChange) {}

TEST_F(AddressTrackerLinuxTest, NewAddressDuplicate) {}

TEST_F(AddressTrackerLinuxTest, DeleteAddress) {}

TEST_F(AddressTrackerLinuxTest, DeprecatedLifetime) {}

TEST_F(AddressTrackerLinuxTest, IgnoredMessage) {}

TEST_F(AddressTrackerLinuxTest, AddInterface) {}

TEST_F(AddressTrackerLinuxTest, RemoveInterface) {}

TEST_F(AddressTrackerLinuxTest, IgnoreInterface) {}

TEST_F(AddressTrackerLinuxTest, IgnoreInterface_NonIgnoredInterface) {}

TEST_F(AddressTrackerLinuxTest, TunnelInterface) {}

// Check AddressTrackerLinux::get_interface_name_ original implementation
// doesn't crash or return NULL.
TEST_F(AddressTrackerLinuxTest, GetInterfaceName) {}

TEST_F(AddressTrackerLinuxTest, NonTrackingMode) {}

TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) {}

class GetCurrentConnectionTypeRunner
    : public base::DelegateSimpleThread::Delegate {};

TEST_F(AddressTrackerLinuxTest, BroadcastInit) {}

TEST_F(AddressTrackerLinuxTest, TunnelInterfaceName) {}

}  // namespace
}  // namespace net::test

namespace net::internal {

// This is a regression test for https://crbug.com/1224428.
//
// This test initializes two instances of `AddressTrackerLinux` in the same
// process. The test will fail if the implementation reuses the value of
// `sockaddr_nl::nl_pid`.
//
// Note: consumers generally should not need to create two tracking instances of
// `AddressTrackerLinux` in the same process.
TEST(AddressTrackerLinuxNetlinkTest, TestInitializeTwoTrackers) {}

// These tests use `base::LaunchOptions::clone_flags` for fine-grained control
// over the clone syscall, but the field is only defined on Linux and ChromeOS.
// Unfortunately, this means these tests do not have coverage on Android.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// These tests require specific flag values defined in <sched.h>.
#if defined(CLONE_NEWUSER) && defined(CLONE_NEWPID)

namespace {
const char* const kSwitchParentWriteFd =;
const char* const kSwitchReadFd =;

enum IPCMessage {};

base::File GetSwitchValueFile(const base::CommandLine* command_line,
                              std::string_view name) {}
}  // namespace

// This is a regression test for https://crbug.com/1224428.
//
// This test creates multiple concurrent `AddressTrackerLinux` instances in
// separate processes, each in their own PID namespaces.
TEST(AddressTrackerLinuxNetlinkTest, TestInitializeTwoTrackersInPidNamespaces) {}

MULTIPROCESS_TEST_MAIN(ChildProcessInitializeTrackerForTesting) {}

#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#endif  // defined(CLONE_NEWUSER) && defined(CLONE_NEWPID)

}  // namespace net::internal