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

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

Merge "Convert VtsHalWifiHostapdV1_*TargetTest to be parameterized test"

parents 9d11eca8 3d4d4960
Loading
Loading
Loading
Loading
+27 −18
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include <android/log.h>

#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestBase.h>


#include "wifi_hidl_call_util.h"
#include "wifi_hidl_call_util.h"
@@ -87,14 +89,21 @@ bool configureChipToSupportIfaceTypeInternal(const sp<IWifiChip>& wifi_chip,
}
}
}  // namespace
}  // namespace


sp<IWifi> getWifi() {
sp<IWifi> getWifi(const std::string& instance_name) {
    sp<IWifi> wifi = ::testing::VtsHalHidlTargetTestBase::getService<IWifi>(
    if ((!gEnv && instance_name.empty()) || (gEnv && !instance_name.empty())) {
        ALOGE("instance_name and gEnv must have one and only one set.");
        return nullptr;
    }
    if (gEnv) {
        return ::testing::VtsHalHidlTargetTestBase::getService<IWifi>(
            gEnv->getServiceName<IWifi>());
            gEnv->getServiceName<IWifi>());
    return wifi;
    } else {
        return IWifi::getService(instance_name);
    }
}
}


sp<IWifiChip> getWifiChip() {
sp<IWifiChip> getWifiChip(const std::string& instance_name) {
    sp<IWifi> wifi = getWifi();
    sp<IWifi> wifi = getWifi(instance_name);
    if (!wifi.get()) {
    if (!wifi.get()) {
        return nullptr;
        return nullptr;
    }
    }
@@ -122,8 +131,8 @@ sp<IWifiChip> getWifiChip() {
    return status_and_chip.second;
    return status_and_chip.second;
}
}


sp<IWifiApIface> getWifiApIface() {
sp<IWifiApIface> getWifiApIface(const std::string& instance_name) {
    sp<IWifiChip> wifi_chip = getWifiChip();
    sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
    if (!wifi_chip.get()) {
    if (!wifi_chip.get()) {
        return nullptr;
        return nullptr;
    }
    }
@@ -137,8 +146,8 @@ sp<IWifiApIface> getWifiApIface() {
    return status_and_iface.second;
    return status_and_iface.second;
}
}


sp<IWifiNanIface> getWifiNanIface() {
sp<IWifiNanIface> getWifiNanIface(const std::string& instance_name) {
    sp<IWifiChip> wifi_chip = getWifiChip();
    sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
    if (!wifi_chip.get()) {
    if (!wifi_chip.get()) {
        return nullptr;
        return nullptr;
    }
    }
@@ -152,8 +161,8 @@ sp<IWifiNanIface> getWifiNanIface() {
    return status_and_iface.second;
    return status_and_iface.second;
}
}


sp<IWifiP2pIface> getWifiP2pIface() {
sp<IWifiP2pIface> getWifiP2pIface(const std::string& instance_name) {
    sp<IWifiChip> wifi_chip = getWifiChip();
    sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
    if (!wifi_chip.get()) {
    if (!wifi_chip.get()) {
        return nullptr;
        return nullptr;
    }
    }
@@ -167,8 +176,8 @@ sp<IWifiP2pIface> getWifiP2pIface() {
    return status_and_iface.second;
    return status_and_iface.second;
}
}


sp<IWifiStaIface> getWifiStaIface() {
sp<IWifiStaIface> getWifiStaIface(const std::string& instance_name) {
    sp<IWifiChip> wifi_chip = getWifiChip();
    sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
    if (!wifi_chip.get()) {
    if (!wifi_chip.get()) {
        return nullptr;
        return nullptr;
    }
    }
@@ -182,8 +191,8 @@ sp<IWifiStaIface> getWifiStaIface() {
    return status_and_iface.second;
    return status_and_iface.second;
}
}


sp<IWifiRttController> getWifiRttController() {
sp<IWifiRttController> getWifiRttController(const std::string& instance_name) {
    sp<IWifiChip> wifi_chip = getWifiChip();
    sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
    if (!wifi_chip.get()) {
    if (!wifi_chip.get()) {
        return nullptr;
        return nullptr;
    }
    }
@@ -206,8 +215,8 @@ bool configureChipToSupportIfaceType(const sp<IWifiChip>& wifi_chip,
                                                   configured_mode_id);
                                                   configured_mode_id);
}
}


void stopWifi() {
void stopWifi(const std::string& instance_name) {
    sp<IWifi> wifi = getWifi();
    sp<IWifi> wifi = getWifi(instance_name);
    ASSERT_NE(wifi, nullptr);
    ASSERT_NE(wifi, nullptr);
    HIDL_INVOKE(wifi, stop);
    HIDL_INVOKE(wifi, stop);
}
}
+15 −8
Original line number Original line Diff line number Diff line
@@ -31,14 +31,21 @@
// Note: We only have a single instance of each of these objects currently.
// Note: We only have a single instance of each of these objects currently.
// These helper functions should be modified to return vectors if we support
// These helper functions should be modified to return vectors if we support
// multiple instances.
// multiple instances.
android::sp<android::hardware::wifi::V1_0::IWifi> getWifi();
// TODO(b/143892896): Remove the default value as part of the cleanup.
android::sp<android::hardware::wifi::V1_0::IWifiChip> getWifiChip();
android::sp<android::hardware::wifi::V1_0::IWifi> getWifi(
android::sp<android::hardware::wifi::V1_0::IWifiApIface> getWifiApIface();
    const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiNanIface> getWifiNanIface();
android::sp<android::hardware::wifi::V1_0::IWifiChip> getWifiChip(
android::sp<android::hardware::wifi::V1_0::IWifiP2pIface> getWifiP2pIface();
    const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiStaIface> getWifiStaIface();
android::sp<android::hardware::wifi::V1_0::IWifiApIface> getWifiApIface(
    const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiNanIface> getWifiNanIface(
    const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiP2pIface> getWifiP2pIface(
    const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiStaIface> getWifiStaIface(
    const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiRttController>
android::sp<android::hardware::wifi::V1_0::IWifiRttController>
getWifiRttController();
getWifiRttController(const std::string& instance_name = "");
// Configure the chip in a mode to support the creation of the provided
// Configure the chip in a mode to support the creation of the provided
// iface type.
// iface type.
bool configureChipToSupportIfaceType(
bool configureChipToSupportIfaceType(
@@ -46,7 +53,7 @@ bool configureChipToSupportIfaceType(
    android::hardware::wifi::V1_0::IfaceType type,
    android::hardware::wifi::V1_0::IfaceType type,
    android::hardware::wifi::V1_0::ChipModeId* configured_mode_id);
    android::hardware::wifi::V1_0::ChipModeId* configured_mode_id);
// Used to trigger IWifi.stop() at the end of every test.
// Used to trigger IWifi.stop() at the end of every test.
void stopWifi();
void stopWifi(const std::string& instance_name = "");


class WifiHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
class WifiHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
   protected:
   protected:
+1 −1
Original line number Original line Diff line number Diff line
@@ -49,5 +49,5 @@ cc_test {
        "libwifi-system",
        "libwifi-system",
        "libwifi-system-iface",
        "libwifi-system-iface",
    ],
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}
}
+4 −32
Original line number Original line Diff line number Diff line
@@ -14,36 +14,8 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include <android-base/logging.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <android/hardware/wifi/1.0/IWifi.h>


#include "hostapd_hidl_test_utils.h"
// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is

// updated.
class WifiHostapdHidlEnvironment_1_0 : public WifiHostapdHidlEnvironment {
::testing::VtsHalHidlTargetTestEnvBase* gEnv = nullptr;
   public:
    // get the test environment singleton
    static WifiHostapdHidlEnvironment_1_0* Instance() {
        static WifiHostapdHidlEnvironment_1_0* instance =
            new WifiHostapdHidlEnvironment_1_0;
        return instance;
    }

    virtual void registerTestServices() override {
        registerTestService<::android::hardware::wifi::V1_0::IWifi>();
        registerTestService<android::hardware::wifi::hostapd::V1_0::IHostapd>();
    }

   private:
    WifiHostapdHidlEnvironment_1_0() {}
};

WifiHostapdHidlEnvironment* gEnv = WifiHostapdHidlEnvironment_1_0::Instance();

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(gEnv);
    ::testing::InitGoogleTest(&argc, argv);
    gEnv->init(&argc, argv);
    int status = RUN_ALL_TESTS();
    LOG(INFO) << "Test result = " << status;
    return status;
}
+42 −23
Original line number Original line Diff line number Diff line
@@ -17,18 +17,22 @@
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <cutils/properties.h>
#include <cutils/properties.h>


#include <VtsHalHidlTargetTestBase.h>
#include <android/hardware/wifi/1.0/IWifi.h>

#include <android/hardware/wifi/hostapd/1.0/IHostapd.h>
#include <android/hardware/wifi/hostapd/1.0/IHostapd.h>


#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include "hostapd_hidl_call_util.h"
#include "hostapd_hidl_call_util.h"
#include "hostapd_hidl_test_utils.h"
#include "hostapd_hidl_test_utils.h"


using ::android::sp;
using ::android::sp;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_vec;
using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatus;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatus;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatusCode;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatusCode;
using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
using ::android::hardware::wifi::V1_0::IWifi;


namespace {
namespace {
constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1',
constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1',
@@ -38,16 +42,20 @@ constexpr int kIfaceChannel = 6;
constexpr int kIfaceInvalidChannel = 567;
constexpr int kIfaceInvalidChannel = 567;
}  // namespace
}  // namespace


class HostapdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class HostapdHidlTest
    : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
   public:
   public:
    virtual void SetUp() override {
    virtual void SetUp() override {
        stopSupplicantIfNeeded();
        wifi_instance_name_ = std::get<0>(GetParam());
        startHostapdAndWaitForHidlService();
        hostapd_instance_name_ = std::get<1>(GetParam());
        hostapd_ = getHostapd();
        stopSupplicantIfNeeded(wifi_instance_name_);
        startHostapdAndWaitForHidlService(wifi_instance_name_,
                                          hostapd_instance_name_);
        hostapd_ = IHostapd::getService(hostapd_instance_name_);
        ASSERT_NE(hostapd_.get(), nullptr);
        ASSERT_NE(hostapd_.get(), nullptr);
    }
    }


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


   protected:
   protected:
    std::string getPrimaryWlanIfaceName() {
    std::string getPrimaryWlanIfaceName() {
@@ -121,6 +129,8 @@ class HostapdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    }
    }
    // IHostapd object used for all tests in this fixture.
    // IHostapd object used for all tests in this fixture.
    sp<IHostapd> hostapd_;
    sp<IHostapd> hostapd_;
    std::string wifi_instance_name_;
    std::string hostapd_instance_name_;
};
};


/*
/*
@@ -128,17 +138,19 @@ class HostapdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 * Ensures that an instance of the IHostapd proxy object is
 * Ensures that an instance of the IHostapd proxy object is
 * successfully created.
 * successfully created.
 */
 */
TEST(HostapdHidlTestNoFixture, Create) {
TEST_P(HostapdHidlTest, Create) {
    startHostapdAndWaitForHidlService();
    stopHostapd(wifi_instance_name_);
    EXPECT_NE(nullptr, getHostapd().get());
    startHostapdAndWaitForHidlService(wifi_instance_name_,
    stopHostapd();
                                      hostapd_instance_name_);
    sp<IHostapd> hostapd = IHostapd::getService(hostapd_instance_name_);
    EXPECT_NE(nullptr, hostapd.get());
}
}


/**
/**
 * Adds an access point with PSK network config & ACS enabled.
 * Adds an access point with PSK network config & ACS enabled.
 * Access point creation should pass.
 * Access point creation should pass.
 */
 */
TEST_F(HostapdHidlTest, AddPskAccessPointWithAcs) {
TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
                                  getIfaceParamsWithAcs(), getPskNwParams());
                                  getIfaceParamsWithAcs(), getPskNwParams());
@@ -151,7 +163,7 @@ TEST_F(HostapdHidlTest, AddPskAccessPointWithAcs) {
 * Adds an access point with Open network config & ACS enabled.
 * Adds an access point with Open network config & ACS enabled.
 * Access point creation should pass.
 * Access point creation should pass.
 */
 */
TEST_F(HostapdHidlTest, AddOpenAccessPointWithAcs) {
TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
                                  getIfaceParamsWithAcs(), getOpenNwParams());
                                  getIfaceParamsWithAcs(), getOpenNwParams());
@@ -164,7 +176,7 @@ TEST_F(HostapdHidlTest, AddOpenAccessPointWithAcs) {
 * Adds an access point with PSK network config & ACS disabled.
 * Adds an access point with PSK network config & ACS disabled.
 * Access point creation should pass.
 * Access point creation should pass.
 */
 */
TEST_F(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
                                  getIfaceParamsWithoutAcs(), getPskNwParams());
                                  getIfaceParamsWithoutAcs(), getPskNwParams());
@@ -176,7 +188,7 @@ TEST_F(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
 * Adds an access point with Open network config & ACS disabled.
 * Adds an access point with Open network config & ACS disabled.
 * Access point creation should pass.
 * Access point creation should pass.
 */
 */
TEST_F(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status =
        auto status =
            HIDL_INVOKE(hostapd_, addAccessPoint, getIfaceParamsWithoutAcs(),
            HIDL_INVOKE(hostapd_, addAccessPoint, getIfaceParamsWithoutAcs(),
@@ -189,7 +201,7 @@ TEST_F(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
 * Adds & then removes an access point with PSK network config & ACS enabled.
 * Adds & then removes an access point with PSK network config & ACS enabled.
 * Access point creation & removal should pass.
 * Access point creation & removal should pass.
 */
 */
TEST_F(HostapdHidlTest, RemoveAccessPointWithAcs) {
TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
                                  getIfaceParamsWithAcs(), getPskNwParams());
                                  getIfaceParamsWithAcs(), getPskNwParams());
@@ -207,7 +219,7 @@ TEST_F(HostapdHidlTest, RemoveAccessPointWithAcs) {
 * Adds & then removes an access point with PSK network config & ACS disabled.
 * Adds & then removes an access point with PSK network config & ACS disabled.
 * Access point creation & removal should pass.
 * Access point creation & removal should pass.
 */
 */
TEST_F(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
        auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
                                  getIfaceParamsWithoutAcs(), getPskNwParams());
                                  getIfaceParamsWithoutAcs(), getPskNwParams());
@@ -222,7 +234,7 @@ TEST_F(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
 * Adds an access point with invalid channel.
 * Adds an access point with invalid channel.
 * Access point creation should fail.
 * Access point creation should fail.
 */
 */
TEST_F(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status =
        auto status =
            HIDL_INVOKE(hostapd_, addAccessPoint,
            HIDL_INVOKE(hostapd_, addAccessPoint,
@@ -235,7 +247,7 @@ TEST_F(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
 * Adds an access point with invalid PSK network config.
 * Adds an access point with invalid PSK network config.
 * Access point creation should fail.
 * Access point creation should fail.
 */
 */
TEST_F(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
    if (!is_1_1(hostapd_)) {
    if (!is_1_1(hostapd_)) {
        auto status =
        auto status =
            HIDL_INVOKE(hostapd_, addAccessPoint, getIfaceParamsWithoutAcs(),
            HIDL_INVOKE(hostapd_, addAccessPoint, getIfaceParamsWithoutAcs(),
@@ -248,6 +260,13 @@ TEST_F(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
 * Terminate
 * Terminate
 * This terminates the service.
 * This terminates the service.
 */
 */
TEST_F(HostapdHidlTest, Terminate) {
TEST_P(HostapdHidlTest, Terminate) { hostapd_->terminate(); }
    hostapd_->terminate();

}
INSTANTIATE_TEST_SUITE_P(
    PerInstance, HostapdHidlTest,
    testing::Combine(
        testing::ValuesIn(
            android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
        testing::ValuesIn(
            android::hardware::getAllHalInstanceNames(IHostapd::descriptor))),
    android::hardware::PrintInstanceTupleNameToString<>);
Loading