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

Commit b2193ac0 authored by Dan Shi's avatar Dan Shi Committed by Gerrit Code Review
Browse files

Merge "Convert VtsHalWifiSupplicantV1_0TargetTest to be parameterized test"

parents 0cd9dd38 59c74959
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ cc_test {
        "libwifi-system",
        "libwifi-system-iface",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}

cc_test {
@@ -71,4 +71,5 @@ cc_test {
        "libwifi-system",
        "libwifi-system-iface",
    ],
    test_suites: ["general-tests", "vts-core"],
}
+3 −35
Original line number Diff line number Diff line
@@ -14,40 +14,8 @@
 * limitations under the License.
 */

#include <android-base/logging.h>

#include "supplicant_hidl_test_utils.h"
#include "wifi_hidl_test_utils.h"

class WifiSupplicantHidlEnvironment_1_0 : public WifiSupplicantHidlEnvironment {
   public:
    // get the test environment singleton
    static WifiSupplicantHidlEnvironment_1_0* Instance() {
        static WifiSupplicantHidlEnvironment_1_0* instance =
            new WifiSupplicantHidlEnvironment_1_0;
        return instance;
    }
    virtual void registerTestServices() override {
        registerTestService<::android::hardware::wifi::V1_0::IWifi>();
        registerTestService<
            ::android::hardware::wifi::supplicant::V1_0::ISupplicant>();
    }

   private:
    WifiSupplicantHidlEnvironment_1_0() {}
};

WifiSupplicantHidlEnvironment* gEnv =
    WifiSupplicantHidlEnvironment_1_0::Instance();

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(gEnv);
    ::testing::InitGoogleTest(&argc, argv);
    gEnv->init(&argc, argv);
    int status = gEnv->initFromOptions(argc, argv);
    if (status == 0) {
        int status = RUN_ALL_TESTS();
        LOG(INFO) << "Test result = " << status;
    }
    return status;
}
// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is
// updated.
WifiSupplicantHidlEnvironment* gEnv = nullptr;
+0 −2
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@
#include <type_traits>
#include <utility>

#include <VtsHalHidlTargetTestBase.h>

namespace {
namespace detail {
template <typename>
+46 −22
Original line number Diff line number Diff line
@@ -16,35 +16,47 @@

#include <android-base/logging.h>

#include <VtsHalHidlTargetTestBase.h>

#include <VtsCoreUtil.h>
#include <android/hardware/wifi/1.0/IWifi.h>
#include <android/hardware/wifi/supplicant/1.0/ISupplicant.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include "supplicant_hidl_test_utils.h"

using ::android::sp;
using ::android::hardware::hidl_vec;
using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
using ::android::hardware::wifi::supplicant::V1_0::ISupplicant;
using ::android::hardware::wifi::supplicant::V1_0::ISupplicantIface;
using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
using ::android::hardware::wifi::V1_0::IWifi;

extern WifiSupplicantHidlEnvironment* gEnv;

class SupplicantHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class SupplicantHidlTest
    : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
   public:
    virtual void SetUp() override {
        startSupplicantAndWaitForHidlService();
        supplicant_ = getSupplicant();
        wifi_instance_name_ = std::get<0>(GetParam());
        supplicant_instance_name_ = std::get<1>(GetParam());
        stopSupplicant(wifi_instance_name_);
        startSupplicantAndWaitForHidlService(wifi_instance_name_,
                                             supplicant_instance_name_);
        isP2pOn_ =
            testing::deviceSupportsFeature("android.hardware.wifi.direct");
        supplicant_ = getSupplicant(supplicant_instance_name_, isP2pOn_);
        ASSERT_NE(supplicant_.get(), nullptr);
    }

    virtual void TearDown() override { stopSupplicant(); }
    virtual void TearDown() override { stopSupplicant(wifi_instance_name_); }

   protected:
    // ISupplicant object used for all tests in this fixture.
    sp<ISupplicant> supplicant_;
    bool isP2pOn_ = false;
    std::string wifi_instance_name_;
    std::string supplicant_instance_name_;
};

/*
@@ -52,16 +64,19 @@ class SupplicantHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 * Ensures that an instance of the ISupplicant proxy object is
 * successfully created.
 */
TEST(SupplicantHidlTestNoFixture, Create) {
    startSupplicantAndWaitForHidlService();
    EXPECT_NE(nullptr, getSupplicant().get());
    stopSupplicant();
TEST_P(SupplicantHidlTest, Create) {
    // Stop the proxy object created in setup.
    stopSupplicant(wifi_instance_name_);
    startSupplicantAndWaitForHidlService(wifi_instance_name_,
                                         supplicant_instance_name_);
    EXPECT_NE(nullptr,
              getSupplicant(supplicant_instance_name_, isP2pOn_).get());
}

/*
 * ListInterfaces
 */
TEST_F(SupplicantHidlTest, ListInterfaces) {
TEST_P(SupplicantHidlTest, ListInterfaces) {
    std::vector<ISupplicant::IfaceInfo> ifaces;
    supplicant_->listInterfaces(
        [&](const SupplicantStatus& status,
@@ -74,7 +89,7 @@ TEST_F(SupplicantHidlTest, ListInterfaces) {
              std::find_if(ifaces.begin(), ifaces.end(), [](const auto& iface) {
                  return iface.type == IfaceType::STA;
              }));
    if (gEnv->isP2pOn) {
    if (isP2pOn_) {
        EXPECT_NE(
            ifaces.end(),
            std::find_if(ifaces.begin(), ifaces.end(), [](const auto& iface) {
@@ -86,7 +101,7 @@ TEST_F(SupplicantHidlTest, ListInterfaces) {
/*
 * GetInterface
 */
TEST_F(SupplicantHidlTest, GetInterface) {
TEST_P(SupplicantHidlTest, GetInterface) {
    std::vector<ISupplicant::IfaceInfo> ifaces;
    supplicant_->listInterfaces(
        [&](const SupplicantStatus& status,
@@ -107,7 +122,7 @@ TEST_F(SupplicantHidlTest, GetInterface) {
/*
 * SetDebugParams
 */
TEST_F(SupplicantHidlTest, SetDebugParams) {
TEST_P(SupplicantHidlTest, SetDebugParams) {
    bool show_timestamp = true;
    bool show_keys = true;
    ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
@@ -124,7 +139,7 @@ TEST_F(SupplicantHidlTest, SetDebugParams) {
/*
 * GetDebugLevel
 */
TEST_F(SupplicantHidlTest, GetDebugLevel) {
TEST_P(SupplicantHidlTest, GetDebugLevel) {
    bool show_timestamp = true;
    bool show_keys = true;
    ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
@@ -142,7 +157,7 @@ TEST_F(SupplicantHidlTest, GetDebugLevel) {
/*
 * IsDebugShowTimestampEnabled
 */
TEST_F(SupplicantHidlTest, IsDebugShowTimestampEnabled) {
TEST_P(SupplicantHidlTest, IsDebugShowTimestampEnabled) {
    bool show_timestamp = true;
    bool show_keys = true;
    ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
@@ -160,7 +175,7 @@ TEST_F(SupplicantHidlTest, IsDebugShowTimestampEnabled) {
/*
 * IsDebugShowKeysEnabled
 */
TEST_F(SupplicantHidlTest, IsDebugShowKeysEnabled) {
TEST_P(SupplicantHidlTest, IsDebugShowKeysEnabled) {
    bool show_timestamp = true;
    bool show_keys = true;
    ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
@@ -178,15 +193,24 @@ TEST_F(SupplicantHidlTest, IsDebugShowKeysEnabled) {
/*
 * SetConcurrenyPriority
 */
TEST_F(SupplicantHidlTest, SetConcurrencyPriority) {
TEST_P(SupplicantHidlTest, SetConcurrencyPriority) {
    supplicant_->setConcurrencyPriority(
        IfaceType::STA, [](const SupplicantStatus& status) {
            EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
        });
    if (gEnv->isP2pOn) {
    if (isP2pOn_) {
        supplicant_->setConcurrencyPriority(
            IfaceType::P2P, [](const SupplicantStatus& status) {
                EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
            });
    }
}

INSTANTIATE_TEST_CASE_P(
    PerInstance, SupplicantHidlTest,
    testing::Combine(
        testing::ValuesIn(
            android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(
            ISupplicant::descriptor))),
    android::hardware::PrintInstanceTupleNameToString<>);
 No newline at end of file
+60 −12
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@ namespace {

// Helper function to initialize the driver and firmware to STA mode
// using the vendor HAL HIDL interface.
void initilializeDriverAndFirmware() {
    sp<IWifiChip> wifi_chip = getWifiChip();
void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {
    sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
    ChipModeId mode_id;
    EXPECT_TRUE(configureChipToSupportIfaceType(
        wifi_chip, ::android::hardware::wifi::V1_0::IfaceType::STA, &mode_id));
@@ -65,7 +65,9 @@ void initilializeDriverAndFirmware() {

// Helper function to deinitialize the driver and firmware
// using the vendor HAL HIDL interface.
void deInitilializeDriverAndFirmware() { stopWifi(); }
void deInitilializeDriverAndFirmware(const std::string& wifi_instance_name) {
    stopWifi(wifi_instance_name);
}

// Helper function to find any iface of the desired type exposed.
bool findIfaceOfType(sp<ISupplicant> supplicant, IfaceType desired_type,
@@ -154,28 +156,38 @@ class ServiceNotificationListener : public IServiceNotification {
    std::condition_variable condition_;
};

void stopSupplicant() {
void stopSupplicant() { stopSupplicant(""); }

void stopSupplicant(const std::string& wifi_instance_name) {
    SupplicantManager supplicant_manager;

    ASSERT_TRUE(supplicant_manager.StopSupplicant());
    deInitilializeDriverAndFirmware();
    deInitilializeDriverAndFirmware(wifi_instance_name);
    ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
}

// TODO(b/143892896): Remove old APIs after all supplicant tests are updated.
void startSupplicantAndWaitForHidlService() {
    initilializeDriverAndFirmware();
    startSupplicantAndWaitForHidlService("",
                                         gEnv->getServiceName<ISupplicant>());
}

void startSupplicantAndWaitForHidlService(
    const std::string& wifi_instance_name,
    const std::string& supplicant_instance_name) {
    initilializeDriverAndFirmware(wifi_instance_name);

    android::sp<ServiceNotificationListener> notification_listener =
        new ServiceNotificationListener();
    string service_name = gEnv->getServiceName<ISupplicant>();
    ASSERT_TRUE(notification_listener->registerForHidlServiceNotifications(
        service_name));
        supplicant_instance_name));

    SupplicantManager supplicant_manager;
    ASSERT_TRUE(supplicant_manager.StartSupplicant());
    ASSERT_TRUE(supplicant_manager.IsSupplicantRunning());

    ASSERT_TRUE(notification_listener->waitForHidlService(500, service_name));
    ASSERT_TRUE(notification_listener->waitForHidlService(
        500, supplicant_instance_name));
}

bool is_1_1(const sp<ISupplicant>& supplicant) {
@@ -218,6 +230,7 @@ void addSupplicantP2pIface_1_1(const sp<ISupplicant>& supplicant) {
        });
}

// TODO(b/143892896): Remove old APIs after all supplicant tests are updated.
sp<ISupplicant> getSupplicant() {
    sp<ISupplicant> supplicant =
        ::testing::VtsHalHidlTargetTestBase::getService<ISupplicant>(
@@ -232,8 +245,28 @@ sp<ISupplicant> getSupplicant() {
    return supplicant;
}

sp<ISupplicant> getSupplicant(const std::string& supplicant_instance_name,
                              bool isP2pOn) {
    sp<ISupplicant> supplicant =
        ISupplicant::getService(supplicant_instance_name);
    // For 1.1 supplicant, we need to add interfaces at initialization.
    if (is_1_1(supplicant)) {
        addSupplicantStaIface_1_1(supplicant);
        if (isP2pOn) {
            addSupplicantP2pIface_1_1(supplicant);
        }
    }
    return supplicant;
}

// TODO(b/143892896): Remove old APIs after all supplicant tests are updated.
sp<ISupplicantStaIface> getSupplicantStaIface() {
    sp<ISupplicant> supplicant = getSupplicant();
    return getSupplicantStaIface(supplicant);
}

sp<ISupplicantStaIface> getSupplicantStaIface(
    const sp<ISupplicant>& supplicant) {
    if (!supplicant.get()) {
        return nullptr;
    }
@@ -257,8 +290,14 @@ sp<ISupplicantStaIface> getSupplicantStaIface() {
    return sta_iface;
}

// TODO(b/143892896): Remove old APIs after all supplicant tests are updated.
sp<ISupplicantStaNetwork> createSupplicantStaNetwork() {
    sp<ISupplicantStaIface> sta_iface = getSupplicantStaIface();
    return createSupplicantStaNetwork(getSupplicant());
}

sp<ISupplicantStaNetwork> createSupplicantStaNetwork(
    const sp<ISupplicant>& supplicant) {
    sp<ISupplicantStaIface> sta_iface = getSupplicantStaIface(supplicant);
    if (!sta_iface.get()) {
        return nullptr;
    }
@@ -278,8 +317,13 @@ sp<ISupplicantStaNetwork> createSupplicantStaNetwork() {
    return sta_network;
}

// TODO(b/143892896): Remove old APIs after all supplicant tests are updated.
sp<ISupplicantP2pIface> getSupplicantP2pIface() {
    sp<ISupplicant> supplicant = getSupplicant();
    return getSupplicantP2pIface(getSupplicant());
}

sp<ISupplicantP2pIface> getSupplicantP2pIface(
    const sp<ISupplicant>& supplicant) {
    if (!supplicant.get()) {
        return nullptr;
    }
@@ -303,8 +347,12 @@ sp<ISupplicantP2pIface> getSupplicantP2pIface() {
    return p2p_iface;
}

// TODO(b/143892896): Remove old APIs after all supplicant tests are updated.
bool turnOnExcessiveLogging() {
    sp<ISupplicant> supplicant = getSupplicant();
    return turnOnExcessiveLogging(getSupplicant());
}

bool turnOnExcessiveLogging(const sp<ISupplicant>& supplicant) {
    if (!supplicant.get()) {
        return false;
    }
Loading