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

Commit 336fe46a authored by Dan Shi's avatar Dan Shi
Browse files

Convert VtsHalWifiV1_*Target to be parameterized test

Bug: 142397658
Bug: 142304083
Test: atest \
  VtsHalWifiV1_0TargetTest \
  VtsHalWifiNanV1_0TargetTest \
  VtsHalWifiApV1_0TargetTest \
  VtsHalWifiV1_1TargetTest \
  VtsHalWifiV1_2TargetTest \
  VtsHalWifiNanV1_2TargetTest \
  VtsHalWifiV1_3TargetTest \
  VtsHalWifiApV1_4TargetTest

Change-Id: I05bf1c4cff378a99c015ac514eefb49debb8b1af
parent 93126ccb
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ cc_test {
        "android.hardware.wifi@1.2",
        "android.hardware.wifi@1.3",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}

// These tests are split out so that they can be conditioned on presence of the
@@ -67,7 +67,7 @@ cc_test {
        "VtsHalWifiV1_0TargetTestUtil",
        "android.hardware.wifi@1.0",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}

// These tests are split out so that they can be conditioned on presence of
@@ -84,5 +84,5 @@ cc_test {
        "VtsHalWifiV1_0TargetTestUtil",
        "android.hardware.wifi@1.0",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}
+4 −30
Original line number Diff line number Diff line
@@ -14,34 +14,8 @@
 * limitations under the License.
 */

#include <android-base/logging.h>
#include <VtsHalHidlTargetTestEnvBase.h>

#include "wifi_hidl_test_utils.h"

class WifiVtsHidlEnvironment_1_0 : public WifiHidlEnvironment {
   public:
    // get the test environment singleton
    static WifiVtsHidlEnvironment_1_0* Instance() {
        static WifiVtsHidlEnvironment_1_0* instance =
            new WifiVtsHidlEnvironment_1_0;
        return instance;
    }

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

   private:
    WifiVtsHidlEnvironment_1_0() {}
};

WifiHidlEnvironment* gEnv = WifiVtsHidlEnvironment_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;
}
// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is
// updated.
::testing::VtsHalHidlTargetTestEnvBase* gEnv = nullptr;
 No newline at end of file
+21 −14
Original line number Diff line number Diff line
@@ -16,35 +16,37 @@

#include <android-base/logging.h>

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

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

#include "wifi_hidl_call_util.h"
#include "wifi_hidl_test_utils.h"

using ::android::sp;
using ::android::hardware::wifi::V1_0::IfaceType;
using ::android::hardware::wifi::V1_0::IWifi;
using ::android::hardware::wifi::V1_0::IWifiApIface;
using ::android::hardware::wifi::V1_0::WifiBand;
using ::android::hardware::wifi::V1_0::WifiStatusCode;
using ::android::sp;

/**
 * Fixture to use for all AP Iface HIDL interface tests.
 */
class WifiApIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class WifiApIfaceHidlTest : public ::testing::TestWithParam<std::string> {
   public:
    virtual void SetUp() override {
        wifi_ap_iface_ = getWifiApIface();
        wifi_ap_iface_ = getWifiApIface(GetInstanceName());
        ASSERT_NE(nullptr, wifi_ap_iface_.get());
    }

    virtual void TearDown() override {
        stopWifi();
    }
    virtual void TearDown() override { stopWifi(GetInstanceName()); }

   protected:
    sp<IWifiApIface> wifi_ap_iface_;
    std::string GetInstanceName() { return GetParam(); }
};

/*
@@ -52,16 +54,15 @@ class WifiApIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 * Ensures that an instance of the IWifiApIface proxy object is
 * successfully created.
 */
TEST(WifiApIfaceHidlTestNoFixture, Create) {
    EXPECT_NE(nullptr, getWifiApIface().get());
    stopWifi();
TEST_P(WifiApIfaceHidlTest, Create) {
    // The creation of a proxy object is tested as part of SetUp method.
}

/*
 * GetType:
 * Ensures that the correct interface type is returned for AP interface.
 */
TEST_F(WifiApIfaceHidlTest, GetType) {
TEST_P(WifiApIfaceHidlTest, GetType) {
    const auto& status_and_type = HIDL_INVOKE(wifi_ap_iface_, getType);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_type.first.code);
    EXPECT_EQ(IfaceType::AP, status_and_type.second);
@@ -72,7 +73,7 @@ TEST_F(WifiApIfaceHidlTest, GetType) {
 * Ensures that a call to set the country code will return with a success
 * status code.
 */
TEST_F(WifiApIfaceHidlTest, SetCountryCode) {
TEST_P(WifiApIfaceHidlTest, SetCountryCode) {
    const android::hardware::hidl_array<int8_t, 2> kCountryCode{
        std::array<int8_t, 2>{{0x55, 0x53}}};
    EXPECT_EQ(WifiStatusCode::SUCCESS,
@@ -83,9 +84,15 @@ TEST_F(WifiApIfaceHidlTest, SetCountryCode) {
 * GetValidFrequenciesForBand:
 * Ensures that we can retrieve valid frequencies for 2.4 GHz band.
 */
TEST_F(WifiApIfaceHidlTest, GetValidFrequenciesForBand) {
TEST_P(WifiApIfaceHidlTest, GetValidFrequenciesForBand) {
    const auto& status_and_freqs = HIDL_INVOKE(
        wifi_ap_iface_, getValidFrequenciesForBand, WifiBand::BAND_24GHZ);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_freqs.first.code);
    EXPECT_GT(status_and_freqs.second.size(), 0u);
}

INSTANTIATE_TEST_SUITE_P(
    PerInstance, WifiApIfaceHidlTest,
    testing::ValuesIn(
        android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
    android::hardware::PrintInstanceNameToString);
 No newline at end of file
+21 −9
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

#include <android-base/logging.h>

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

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

#include "wifi_hidl_call_util.h"
#include "wifi_hidl_test_utils.h"
@@ -26,6 +28,7 @@
using ::android::sp;
using ::android::hardware::wifi::V1_0::ChipModeId;
using ::android::hardware::wifi::V1_0::IfaceType;
using ::android::hardware::wifi::V1_0::IWifi;
using ::android::hardware::wifi::V1_0::IWifiApIface;
using ::android::hardware::wifi::V1_0::IWifiChip;
using ::android::hardware::wifi::V1_0::IWifiIface;
@@ -35,14 +38,14 @@ using ::android::hardware::wifi::V1_0::WifiStatusCode;
/**
 * Fixture for IWifiChip tests that are conditioned on SoftAP support.
 */
class WifiChipHidlApTest : public ::testing::VtsHalHidlTargetTestBase {
class WifiChipHidlApTest : public ::testing::TestWithParam<std::string> {
   public:
    virtual void SetUp() override {
        wifi_chip_ = getWifiChip();
        wifi_chip_ = getWifiChip(GetInstanceName());
        ASSERT_NE(nullptr, wifi_chip_.get());
    }

    virtual void TearDown() override { stopWifi(); }
    virtual void TearDown() override { stopWifi(GetInstanceName()); }

   protected:
    // Helper function to configure the Chip in one of the supported modes.
@@ -72,6 +75,9 @@ class WifiChipHidlApTest : public ::testing::VtsHalHidlTargetTestBase {
    }

    sp<IWifiChip> wifi_chip_;

   private:
    std::string GetInstanceName() { return GetParam(); }
};

/*
@@ -79,7 +85,7 @@ class WifiChipHidlApTest : public ::testing::VtsHalHidlTargetTestBase {
 * Configures the chip in AP mode and ensures that at least 1 iface creation
 * succeeds.
 */
TEST_F(WifiChipHidlApTest, CreateApIface) {
TEST_P(WifiChipHidlApTest, CreateApIface) {
    configureChipForIfaceType(IfaceType::AP, true);

    sp<IWifiApIface> iface;
@@ -93,7 +99,7 @@ TEST_F(WifiChipHidlApTest, CreateApIface) {
 * before creating the iface. Then, create the iface and ensure that
 * iface name is returned via the list.
 */
TEST_F(WifiChipHidlApTest, GetApIfaceNames) {
TEST_P(WifiChipHidlApTest, GetApIfaceNames) {
    configureChipForIfaceType(IfaceType::AP, true);

    const auto& status_and_iface_names1 =
@@ -125,7 +131,7 @@ TEST_F(WifiChipHidlApTest, GetApIfaceNames) {
 * the iface object using the correct name and ensure any other name
 * doesn't retrieve an iface object.
 */
TEST_F(WifiChipHidlApTest, GetApIface) {
TEST_P(WifiChipHidlApTest, GetApIface) {
    configureChipForIfaceType(IfaceType::AP, true);

    sp<IWifiApIface> ap_iface;
@@ -151,7 +157,7 @@ TEST_F(WifiChipHidlApTest, GetApIface) {
 * the iface object using the correct name and ensure any other name
 * doesn't remove the iface.
 */
TEST_F(WifiChipHidlApTest, RemoveApIface) {
TEST_P(WifiChipHidlApTest, RemoveApIface) {
    configureChipForIfaceType(IfaceType::AP, true);

    sp<IWifiApIface> ap_iface;
@@ -166,3 +172,9 @@ TEST_F(WifiChipHidlApTest, RemoveApIface) {
    // No such iface exists now. So, this should return failure.
    EXPECT_EQ(WifiStatusCode::ERROR_INVALID_ARGS, removeApIface(iface_name));
}

INSTANTIATE_TEST_SUITE_P(
    PerInstance, WifiChipHidlApTest,
    testing::ValuesIn(
        android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
    android::hardware::PrintInstanceNameToString);
 No newline at end of file
+21 −9
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

#include <android-base/logging.h>

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

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

#include "wifi_hidl_call_util.h"
#include "wifi_hidl_test_utils.h"
@@ -26,6 +28,7 @@
using ::android::sp;
using ::android::hardware::wifi::V1_0::ChipModeId;
using ::android::hardware::wifi::V1_0::IfaceType;
using ::android::hardware::wifi::V1_0::IWifi;
using ::android::hardware::wifi::V1_0::IWifiChip;
using ::android::hardware::wifi::V1_0::IWifiIface;
using ::android::hardware::wifi::V1_0::IWifiNanIface;
@@ -35,14 +38,14 @@ using ::android::hardware::wifi::V1_0::WifiStatusCode;
/**
 * Fixture for IWifiChip tests that are conditioned on NAN support.
 */
class WifiChipHidlNanTest : public ::testing::VtsHalHidlTargetTestBase {
class WifiChipHidlNanTest : public ::testing::TestWithParam<std::string> {
   public:
    virtual void SetUp() override {
        wifi_chip_ = getWifiChip();
        wifi_chip_ = getWifiChip(GetInstanceName());
        ASSERT_NE(nullptr, wifi_chip_.get());
    }

    virtual void TearDown() override { stopWifi(); }
    virtual void TearDown() override { stopWifi(GetInstanceName()); }

   protected:
    // Helper function to configure the Chip in one of the supported modes.
@@ -72,6 +75,9 @@ class WifiChipHidlNanTest : public ::testing::VtsHalHidlTargetTestBase {
    }

    sp<IWifiChip> wifi_chip_;

   private:
    std::string GetInstanceName() { return GetParam(); }
};

/*
@@ -79,7 +85,7 @@ class WifiChipHidlNanTest : public ::testing::VtsHalHidlTargetTestBase {
 * Configures the chip in NAN mode and ensures that at least 1 iface creation
 * succeeds.
 */
TEST_F(WifiChipHidlNanTest, CreateNanIface) {
TEST_P(WifiChipHidlNanTest, CreateNanIface) {
    configureChipForIfaceType(IfaceType::NAN, true);

    sp<IWifiNanIface> iface;
@@ -93,7 +99,7 @@ TEST_F(WifiChipHidlNanTest, CreateNanIface) {
 * before creating the iface. Then, create the iface and ensure that
 * iface name is returned via the list.
 */
TEST_F(WifiChipHidlNanTest, GetNanIfaceNames) {
TEST_P(WifiChipHidlNanTest, GetNanIfaceNames) {
    configureChipForIfaceType(IfaceType::NAN, true);

    const auto& status_and_iface_names1 =
@@ -125,7 +131,7 @@ TEST_F(WifiChipHidlNanTest, GetNanIfaceNames) {
 * the iface object using the correct name and ensure any other name
 * doesn't retrieve an iface object.
 */
TEST_F(WifiChipHidlNanTest, GetNanIface) {
TEST_P(WifiChipHidlNanTest, GetNanIface) {
    configureChipForIfaceType(IfaceType::NAN, true);

    sp<IWifiNanIface> nan_iface;
@@ -151,7 +157,7 @@ TEST_F(WifiChipHidlNanTest, GetNanIface) {
 * the iface object using the correct name and ensure any other name
 * doesn't remove the iface.
 */
TEST_F(WifiChipHidlNanTest, RemoveNanIface) {
TEST_P(WifiChipHidlNanTest, RemoveNanIface) {
    configureChipForIfaceType(IfaceType::NAN, true);

    sp<IWifiNanIface> nan_iface;
@@ -167,3 +173,9 @@ TEST_F(WifiChipHidlNanTest, RemoveNanIface) {
    // No such iface exists now. So, this should return failure.
    EXPECT_EQ(WifiStatusCode::ERROR_INVALID_ARGS, removeNanIface(iface_name));
}

INSTANTIATE_TEST_SUITE_P(
    PerInstance, WifiChipHidlNanTest,
    testing::ValuesIn(
        android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
    android::hardware::PrintInstanceNameToString);
 No newline at end of file
Loading