Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eefb6da4 authored by Gabriel Biren's avatar Gabriel Biren Committed by Android (Google) Code Review
Browse files

Merge changes I4df7c4ec,I32aa97eb into main

* changes:
  Add VTS tests for the untested legacy P2P iface methods.
  Add VTS tests for Supplicant P2P networks.
parents fbc10798 c39728b4
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -137,3 +137,41 @@ cc_test {
        "vts",
    ],
}

cc_test {
    name: "VtsHalWifiSupplicantP2pNetworkTargetTest",
    defaults: [
        "VtsHalTargetTestDefaults",
        "use_libaidlvintf_gtest_helper_static",
    ],
    srcs: ["supplicant_p2p_network_aidl_test.cpp"],
    shared_libs: [
        "libbinder",
        "libbinder_ndk",
        "libvndksupport",
    ],
    static_libs: [
        "android.hardware.wifi@1.0",
        "android.hardware.wifi@1.1",
        "android.hardware.wifi@1.2",
        "android.hardware.wifi@1.3",
        "android.hardware.wifi@1.4",
        "android.hardware.wifi@1.5",
        "android.hardware.wifi.common-V2-ndk",
        "android.hardware.wifi.supplicant@1.0",
        "android.hardware.wifi.supplicant@1.1",
        "android.hardware.wifi.supplicant-V4-ndk",
        "libwifi-system",
        "libwifi-system-iface",
        "VtsHalWifiV1_0TargetTestUtil",
        "VtsHalWifiV1_5TargetTestUtil",
        "VtsHalWifiSupplicantV1_0TargetTestUtil",
        "android.hardware.wifi.common-V2-ndk",
        "android.hardware.wifi-V3-ndk",
        "VtsHalWifiTargetTestUtil",
    ],
    test_suites: [
        "general-tests",
        "vts",
    ],
}
+75 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ using aidl::android::hardware::wifi::supplicant::FreqRange;
using aidl::android::hardware::wifi::supplicant::IfaceType;
using aidl::android::hardware::wifi::supplicant::ISupplicant;
using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface;
using aidl::android::hardware::wifi::supplicant::ISupplicantP2pNetwork;
using aidl::android::hardware::wifi::supplicant::MiracastMode;
using aidl::android::hardware::wifi::supplicant::P2pAddGroupConfigurationParams;
using aidl::android::hardware::wifi::supplicant::P2pConnectInfo;
@@ -398,8 +399,8 @@ TEST_P(SupplicantP2pIfaceAidlTest, SetWpsModelName) {
 * SetWpsModelNumber
 */
TEST_P(SupplicantP2pIfaceAidlTest, SetWpsModelNumber) {
    const std::string modelNumber = "TestModelNumber";
    EXPECT_TRUE(p2p_iface_->setWpsModelName(modelNumber).isOk());
    const std::string modelNumber = "Model1234";
    EXPECT_TRUE(p2p_iface_->setWpsModelNumber(modelNumber).isOk());
}

/*
@@ -981,6 +982,78 @@ TEST_P(SupplicantP2pIfaceAidlTest, ReinvokePersistentGroup) {
    EXPECT_TRUE(p2p_iface_->reinvokePersistentGroup(params).isOk());
}

/*
 * Test the P2P network management functions.
 */
TEST_P(SupplicantP2pIfaceAidlTest, ManageNetworks) {
    std::shared_ptr<ISupplicantP2pNetwork> network;
    EXPECT_TRUE(p2p_iface_->addNetwork(&network).isOk());
    ASSERT_NE(network, nullptr);

    std::vector<int32_t> networkList;
    EXPECT_TRUE(p2p_iface_->listNetworks(&networkList).isOk());
    ASSERT_FALSE(networkList.empty());

    int networkId = networkList[0];
    EXPECT_TRUE(p2p_iface_->getNetwork(networkId, &network).isOk());
    ASSERT_NE(network, nullptr);
    EXPECT_TRUE(p2p_iface_->removeNetwork(networkId).isOk());
}

/*
 * Request and cancel service discovery
 */
TEST_P(SupplicantP2pIfaceAidlTest, RequestAndCancelServiceDiscovery) {
    int64_t discoveryId;
    std::vector<uint8_t> query = {0x11, 0x22, 0x33};
    EXPECT_TRUE(p2p_iface_->requestServiceDiscovery(kTestMacAddr, query, &discoveryId).isOk());
    EXPECT_TRUE(p2p_iface_->cancelServiceDiscovery(discoveryId).isOk());
}

/*
 * Start and stop WPS
 */
TEST_P(SupplicantP2pIfaceAidlTest, StartAndStopWps) {
    // Expected to fail with test values
    std::string generatedPin;
    EXPECT_FALSE(p2p_iface_->startWpsPbc(kTestGroupIfName, kTestMacAddr).isOk());
    EXPECT_FALSE(
            p2p_iface_->startWpsPinDisplay(kTestGroupIfName, kTestMacAddr, &generatedPin).isOk());
    EXPECT_FALSE(p2p_iface_->startWpsPinKeypad(kTestGroupIfName, kTestConnectPin).isOk());
    EXPECT_FALSE(p2p_iface_->cancelWps(kTestGroupIfName).isOk());
}

/*
 * Create message and report handover for NFC Request
 */
TEST_P(SupplicantP2pIfaceAidlTest, CreateAndReportNfcRequest) {
    std::vector<uint8_t> requestMsg;
    EXPECT_TRUE(p2p_iface_->createNfcHandoverRequestMessage(&requestMsg).isOk());
    EXPECT_FALSE(requestMsg.empty());
    EXPECT_TRUE(p2p_iface_->reportNfcHandoverResponse(requestMsg).isOk());
}

/*
 * Create message and report handover for NFC Select
 */
TEST_P(SupplicantP2pIfaceAidlTest, CreateAndReportNfcSelect) {
    std::vector<uint8_t> selectMsg;
    EXPECT_TRUE(p2p_iface_->createNfcHandoverSelectMessage(&selectMsg).isOk());
    EXPECT_FALSE(selectMsg.empty());
    EXPECT_TRUE(p2p_iface_->reportNfcHandoverInitiation(selectMsg).isOk());
}

/*
 * RemoveClient
 */
TEST_P(SupplicantP2pIfaceAidlTest, RemoveClient) {
    // Method returns success for any valid MAC address
    EXPECT_TRUE(p2p_iface_->removeClient(kTestMacAddr, false).isOk());
    // Returns failure for any invalid MAC address
    std::vector<uint8_t> invalidMacAddr = {0x11, 0x22};
    EXPECT_FALSE(p2p_iface_->removeClient(invalidMacAddr, false).isOk());
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pIfaceAidlTest);
INSTANTIATE_TEST_SUITE_P(Supplicant, SupplicantP2pIfaceAidlTest,
                         testing::ValuesIn(android::getAidlHalInstanceNames(
+165 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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 <VtsCoreUtil.h>
#include <aidl/Gtest.h>
#include <aidl/Vintf.h>
#include <aidl/android/hardware/wifi/supplicant/BnSupplicant.h>
#include <android/binder_manager.h>
#include <android/binder_status.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <cutils/properties.h>

#include "supplicant_test_utils.h"
#include "wifi_aidl_test_utils.h"

using aidl::android::hardware::wifi::supplicant::DebugLevel;
using aidl::android::hardware::wifi::supplicant::IfaceType;
using aidl::android::hardware::wifi::supplicant::ISupplicantP2pNetwork;
using aidl::android::hardware::wifi::supplicant::MacAddress;
using android::ProcessState;

class SupplicantP2pNetworkAidlTest : public testing::TestWithParam<std::string> {
  public:
    void SetUp() override {
        initializeService();
        supplicant_ = getSupplicant(GetParam().c_str());
        ASSERT_NE(supplicant_, nullptr);
        ASSERT_TRUE(supplicant_->setDebugParams(DebugLevel::EXCESSIVE, true, true).isOk());

        bool p2pEnabled = testing::deviceSupportsFeature("android.hardware.wifi.direct");
        if (!p2pEnabled) {
            GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test.";
        }

        EXPECT_TRUE(supplicant_->getP2pInterface(getP2pIfaceName(), &p2p_iface_).isOk());
        ASSERT_NE(p2p_iface_, nullptr);
        EXPECT_TRUE(p2p_iface_->addNetwork(&p2p_network_).isOk());
        ASSERT_NE(p2p_network_, nullptr);
    }

    void TearDown() override {
        stopSupplicantService();
        startWifiFramework();
    }

  protected:
    std::shared_ptr<ISupplicant> supplicant_;
    std::shared_ptr<ISupplicantP2pIface> p2p_iface_;
    std::shared_ptr<ISupplicantP2pNetwork> p2p_network_;
};

/*
 * GetBssid
 */
TEST_P(SupplicantP2pNetworkAidlTest, GetBssid) {
    std::vector<uint8_t> bssid;
    EXPECT_TRUE(p2p_network_->getBssid(&bssid).isOk());
}

/*
 * GetClientList
 */
TEST_P(SupplicantP2pNetworkAidlTest, GetClientList) {
    // Expect failure if there are no clients
    std::vector<MacAddress> clientList;
    EXPECT_FALSE(p2p_network_->getClientList(&clientList).isOk());
}

/*
 * GetId
 */
TEST_P(SupplicantP2pNetworkAidlTest, GetId) {
    int networkId;
    EXPECT_TRUE(p2p_network_->getId(&networkId).isOk());
}

/*
 * GetInterfaceName
 */
TEST_P(SupplicantP2pNetworkAidlTest, GetInterfaceName) {
    std::string expectedName = getP2pIfaceName();
    std::string retrievedName;
    EXPECT_TRUE(p2p_network_->getInterfaceName(&retrievedName).isOk());
    EXPECT_EQ(retrievedName, expectedName);
}

/*
 * GetSsid
 */
TEST_P(SupplicantP2pNetworkAidlTest, GetSsid) {
    std::vector<uint8_t> ssid;
    EXPECT_TRUE(p2p_network_->getSsid(&ssid).isOk());
}

/*
 * GetType
 */
TEST_P(SupplicantP2pNetworkAidlTest, GetType) {
    IfaceType ifaceType;
    EXPECT_TRUE(p2p_network_->getType(&ifaceType).isOk());
    EXPECT_EQ(ifaceType, IfaceType::P2P);
}

/*
 * IsCurrent
 */
TEST_P(SupplicantP2pNetworkAidlTest, IsCurrent) {
    bool isCurrent;
    EXPECT_TRUE(p2p_network_->isCurrent(&isCurrent).isOk());
    EXPECT_FALSE(isCurrent);
}

/*
 * IsGroupOwner
 */
TEST_P(SupplicantP2pNetworkAidlTest, IsGroupOwner) {
    bool isGroupOwner;
    EXPECT_TRUE(p2p_network_->isGroupOwner(&isGroupOwner).isOk());
    EXPECT_FALSE(isGroupOwner);
}

/*
 * IsPersistent
 */
TEST_P(SupplicantP2pNetworkAidlTest, IsPersistent) {
    bool isPersistent;
    EXPECT_TRUE(p2p_network_->isPersistent(&isPersistent).isOk());
    EXPECT_FALSE(isPersistent);
}

/*
 * SetClientList
 */
TEST_P(SupplicantP2pNetworkAidlTest, SetClientList) {
    MacAddress client = {{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc}};
    std::vector clientList = {client};
    EXPECT_TRUE(p2p_network_->setClientList(clientList).isOk());
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantP2pNetworkAidlTest);
INSTANTIATE_TEST_SUITE_P(
        Supplicant, SupplicantP2pNetworkAidlTest,
        testing::ValuesIn(android::getAidlHalInstanceNames(ISupplicant::descriptor)),
        android::PrintInstanceNameToString);

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ProcessState::self()->setThreadPoolMaxThreadCount(1);
    ProcessState::self()->startThreadPool();
    return RUN_ALL_TESTS();
}