Merge "wifi(tests): Unit tests for iface event cb's" into qt-dev
This commit is contained in:
commit
4ae7dd19ba
18 changed files with 317 additions and 30 deletions
|
@ -142,12 +142,14 @@ LOCAL_CPPFLAGS := -Wall -Werror -Wextra
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
tests/hidl_struct_util_unit_tests.cpp \
|
tests/hidl_struct_util_unit_tests.cpp \
|
||||||
tests/main.cpp \
|
tests/main.cpp \
|
||||||
|
tests/mock_interface_tool.cpp \
|
||||||
tests/mock_wifi_feature_flags.cpp \
|
tests/mock_wifi_feature_flags.cpp \
|
||||||
tests/mock_wifi_iface_util.cpp \
|
tests/mock_wifi_iface_util.cpp \
|
||||||
tests/mock_wifi_legacy_hal.cpp \
|
tests/mock_wifi_legacy_hal.cpp \
|
||||||
tests/mock_wifi_mode_controller.cpp \
|
tests/mock_wifi_mode_controller.cpp \
|
||||||
tests/ringbuffer_unit_tests.cpp \
|
tests/ringbuffer_unit_tests.cpp \
|
||||||
tests/wifi_ap_iface_unit_tests.cpp \
|
tests/wifi_ap_iface_unit_tests.cpp \
|
||||||
|
tests/wifi_nan_iface_unit_tests.cpp \
|
||||||
tests/wifi_chip_unit_tests.cpp \
|
tests/wifi_chip_unit_tests.cpp \
|
||||||
tests/wifi_iface_util_unit_tests.cpp
|
tests/wifi_iface_util_unit_tests.cpp
|
||||||
LOCAL_STATIC_LIBRARIES := \
|
LOCAL_STATIC_LIBRARIES := \
|
||||||
|
|
|
@ -48,12 +48,14 @@ int main(int /*argc*/, char** argv) {
|
||||||
|
|
||||||
configureRpcThreadpool(1, true /* callerWillJoin */);
|
configureRpcThreadpool(1, true /* callerWillJoin */);
|
||||||
|
|
||||||
|
const auto iface_tool =
|
||||||
|
std::make_shared<android::wifi_system::InterfaceTool>();
|
||||||
// Setup hwbinder service
|
// Setup hwbinder service
|
||||||
android::sp<android::hardware::wifi::V1_3::IWifi> service =
|
android::sp<android::hardware::wifi::V1_3::IWifi> service =
|
||||||
new android::hardware::wifi::V1_3::implementation::Wifi(
|
new android::hardware::wifi::V1_3::implementation::Wifi(
|
||||||
std::make_shared<WifiLegacyHal>(),
|
iface_tool, std::make_shared<WifiLegacyHal>(iface_tool),
|
||||||
std::make_shared<WifiModeController>(),
|
std::make_shared<WifiModeController>(),
|
||||||
std::make_shared<WifiIfaceUtil>(),
|
std::make_shared<WifiIfaceUtil>(iface_tool),
|
||||||
std::make_shared<WifiFeatureFlags>());
|
std::make_shared<WifiFeatureFlags>());
|
||||||
if (kLazyService) {
|
if (kLazyService) {
|
||||||
LazyServiceRegistrar registrar;
|
LazyServiceRegistrar registrar;
|
||||||
|
|
29
wifi/1.3/default/tests/mock_interface_tool.cpp
Normal file
29
wifi/1.3/default/tests/mock_interface_tool.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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 <android-base/logging.h>
|
||||||
|
#include <android-base/macros.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
|
||||||
|
#include "mock_interface_tool.h"
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace wifi_system {
|
||||||
|
|
||||||
|
MockInterfaceTool::MockInterfaceTool() {}
|
||||||
|
|
||||||
|
} // namespace wifi_system
|
||||||
|
} // namespace android
|
44
wifi/1.3/default/tests/mock_interface_tool.h
Normal file
44
wifi/1.3/default/tests/mock_interface_tool.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MOCK_INTERFACE_TOOL_H
|
||||||
|
#define MOCK_INTERFACE_TOOL_H
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <wifi_system/interface_tool.h>
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace wifi_system {
|
||||||
|
|
||||||
|
class MockInterfaceTool : public InterfaceTool {
|
||||||
|
public:
|
||||||
|
MockInterfaceTool();
|
||||||
|
|
||||||
|
MOCK_METHOD1(GetUpState, bool(const char* if_name));
|
||||||
|
MOCK_METHOD2(SetUpState, bool(const char* if_name, bool request_up));
|
||||||
|
MOCK_METHOD1(SetWifiUpState, bool(bool request_up));
|
||||||
|
MOCK_METHOD2(SetMacAddress,
|
||||||
|
bool(const char* if_name,
|
||||||
|
const std::array<uint8_t, ETH_ALEN>& address));
|
||||||
|
MOCK_METHOD1(GetFactoryMacAddress,
|
||||||
|
std::array<uint8_t, ETH_ALEN>(const char* if_name));
|
||||||
|
|
||||||
|
}; // class MockInterfaceTool
|
||||||
|
|
||||||
|
} // namespace wifi_system
|
||||||
|
} // namespace android
|
||||||
|
|
||||||
|
#endif // MOCK_INTERFACE_TOOL_H
|
|
@ -28,7 +28,9 @@ namespace V1_3 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
namespace iface_util {
|
namespace iface_util {
|
||||||
|
|
||||||
MockWifiIfaceUtil::MockWifiIfaceUtil() : WifiIfaceUtil() {}
|
MockWifiIfaceUtil::MockWifiIfaceUtil(
|
||||||
|
const std::weak_ptr<wifi_system::InterfaceTool> iface_tool)
|
||||||
|
: WifiIfaceUtil(iface_tool) {}
|
||||||
} // namespace iface_util
|
} // namespace iface_util
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V1_3
|
} // namespace V1_3
|
||||||
|
|
|
@ -30,12 +30,16 @@ namespace iface_util {
|
||||||
|
|
||||||
class MockWifiIfaceUtil : public WifiIfaceUtil {
|
class MockWifiIfaceUtil : public WifiIfaceUtil {
|
||||||
public:
|
public:
|
||||||
MockWifiIfaceUtil();
|
MockWifiIfaceUtil(
|
||||||
|
const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
|
||||||
MOCK_METHOD1(getFactoryMacAddress,
|
MOCK_METHOD1(getFactoryMacAddress,
|
||||||
std::array<uint8_t, 6>(const std::string&));
|
std::array<uint8_t, 6>(const std::string&));
|
||||||
MOCK_METHOD2(setMacAddress,
|
MOCK_METHOD2(setMacAddress,
|
||||||
bool(const std::string&, const std::array<uint8_t, 6>&));
|
bool(const std::string&, const std::array<uint8_t, 6>&));
|
||||||
MOCK_METHOD0(getOrCreateRandomMacAddress, std::array<uint8_t, 6>());
|
MOCK_METHOD0(getOrCreateRandomMacAddress, std::array<uint8_t, 6>());
|
||||||
|
MOCK_METHOD2(registerIfaceEventHandlers,
|
||||||
|
void(const std::string&, IfaceEventHandlers));
|
||||||
|
MOCK_METHOD1(unregisterIfaceEventHandlers, void(const std::string&));
|
||||||
};
|
};
|
||||||
} // namespace iface_util
|
} // namespace iface_util
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
|
|
|
@ -28,7 +28,9 @@ namespace V1_3 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
namespace legacy_hal {
|
namespace legacy_hal {
|
||||||
|
|
||||||
MockWifiLegacyHal::MockWifiLegacyHal() : WifiLegacyHal() {}
|
MockWifiLegacyHal::MockWifiLegacyHal(
|
||||||
|
const std::weak_ptr<wifi_system::InterfaceTool> iface_tool)
|
||||||
|
: WifiLegacyHal(iface_tool) {}
|
||||||
} // namespace legacy_hal
|
} // namespace legacy_hal
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V1_3
|
} // namespace V1_3
|
||||||
|
|
|
@ -30,7 +30,8 @@ namespace legacy_hal {
|
||||||
|
|
||||||
class MockWifiLegacyHal : public WifiLegacyHal {
|
class MockWifiLegacyHal : public WifiLegacyHal {
|
||||||
public:
|
public:
|
||||||
MockWifiLegacyHal();
|
MockWifiLegacyHal(
|
||||||
|
const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
|
||||||
MOCK_METHOD0(initialize, wifi_error());
|
MOCK_METHOD0(initialize, wifi_error());
|
||||||
MOCK_METHOD0(start, wifi_error());
|
MOCK_METHOD0(start, wifi_error());
|
||||||
MOCK_METHOD2(stop, wifi_error(std::unique_lock<std::recursive_mutex>*,
|
MOCK_METHOD2(stop, wifi_error(std::unique_lock<std::recursive_mutex>*,
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
|
#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
|
||||||
#include "wifi_ap_iface.h"
|
#include "wifi_ap_iface.h"
|
||||||
|
|
||||||
|
#include "mock_interface_tool.h"
|
||||||
#include "mock_wifi_feature_flags.h"
|
#include "mock_wifi_feature_flags.h"
|
||||||
#include "mock_wifi_iface_util.h"
|
#include "mock_wifi_iface_util.h"
|
||||||
#include "mock_wifi_legacy_hal.h"
|
#include "mock_wifi_legacy_hal.h"
|
||||||
|
@ -42,10 +43,12 @@ namespace implementation {
|
||||||
|
|
||||||
class WifiApIfaceTest : public Test {
|
class WifiApIfaceTest : public Test {
|
||||||
protected:
|
protected:
|
||||||
|
std::shared_ptr<NiceMock<wifi_system::MockInterfaceTool>> iface_tool_{
|
||||||
|
new NiceMock<wifi_system::MockInterfaceTool>};
|
||||||
std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
|
std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
|
||||||
new NiceMock<legacy_hal::MockWifiLegacyHal>};
|
new NiceMock<legacy_hal::MockWifiLegacyHal>(iface_tool_)};
|
||||||
std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
|
std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
|
||||||
new NiceMock<iface_util::MockWifiIfaceUtil>};
|
new NiceMock<iface_util::MockWifiIfaceUtil>(iface_tool_)};
|
||||||
std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
|
std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
|
||||||
feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};
|
feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
|
#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
|
||||||
#include "wifi_chip.h"
|
#include "wifi_chip.h"
|
||||||
|
|
||||||
|
#include "mock_interface_tool.h"
|
||||||
#include "mock_wifi_feature_flags.h"
|
#include "mock_wifi_feature_flags.h"
|
||||||
#include "mock_wifi_iface_util.h"
|
#include "mock_wifi_iface_util.h"
|
||||||
#include "mock_wifi_legacy_hal.h"
|
#include "mock_wifi_legacy_hal.h"
|
||||||
|
@ -263,12 +264,14 @@ class WifiChipTest : public Test {
|
||||||
|
|
||||||
sp<WifiChip> chip_;
|
sp<WifiChip> chip_;
|
||||||
ChipId chip_id_ = kFakeChipId;
|
ChipId chip_id_ = kFakeChipId;
|
||||||
|
std::shared_ptr<NiceMock<wifi_system::MockInterfaceTool>> iface_tool_{
|
||||||
|
new NiceMock<wifi_system::MockInterfaceTool>};
|
||||||
std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
|
std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
|
||||||
new NiceMock<legacy_hal::MockWifiLegacyHal>};
|
new NiceMock<legacy_hal::MockWifiLegacyHal>(iface_tool_)};
|
||||||
std::shared_ptr<NiceMock<mode_controller::MockWifiModeController>>
|
std::shared_ptr<NiceMock<mode_controller::MockWifiModeController>>
|
||||||
mode_controller_{new NiceMock<mode_controller::MockWifiModeController>};
|
mode_controller_{new NiceMock<mode_controller::MockWifiModeController>};
|
||||||
std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
|
std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
|
||||||
new NiceMock<iface_util::MockWifiIfaceUtil>};
|
new NiceMock<iface_util::MockWifiIfaceUtil>(iface_tool_)};
|
||||||
std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
|
std::shared_ptr<NiceMock<feature_flags::MockWifiFeatureFlags>>
|
||||||
feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};
|
feature_flags_{new NiceMock<feature_flags::MockWifiFeatureFlags>};
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,15 @@
|
||||||
#undef NAN
|
#undef NAN
|
||||||
#include "wifi_iface_util.h"
|
#include "wifi_iface_util.h"
|
||||||
|
|
||||||
|
#include "mock_interface_tool.h"
|
||||||
|
|
||||||
|
using testing::NiceMock;
|
||||||
using testing::Test;
|
using testing::Test;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t kValidUnicastLocallyAssignedMacAddressMask = 0x02;
|
constexpr uint8_t kValidUnicastLocallyAssignedMacAddressMask = 0x02;
|
||||||
|
constexpr uint8_t kMacAddress[] = {0x02, 0x12, 0x45, 0x56, 0xab, 0xcc};
|
||||||
|
constexpr char kIfaceName[] = "test-wlan0";
|
||||||
|
|
||||||
bool isValidUnicastLocallyAssignedMacAddress(
|
bool isValidUnicastLocallyAssignedMacAddress(
|
||||||
const std::array<uint8_t, 6>& mac_address) {
|
const std::array<uint8_t, 6>& mac_address) {
|
||||||
|
@ -38,19 +43,52 @@ namespace hardware {
|
||||||
namespace wifi {
|
namespace wifi {
|
||||||
namespace V1_3 {
|
namespace V1_3 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
namespace iface_util {
|
||||||
class WifiIfaceUtilTest : public Test {
|
class WifiIfaceUtilTest : public Test {
|
||||||
protected:
|
protected:
|
||||||
iface_util::WifiIfaceUtil iface_util_;
|
std::shared_ptr<NiceMock<wifi_system::MockInterfaceTool>> iface_tool_{
|
||||||
|
new NiceMock<wifi_system::MockInterfaceTool>};
|
||||||
|
WifiIfaceUtil* iface_util_ = new WifiIfaceUtil(iface_tool_);
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(WifiIfaceUtilTest, GetOrCreateRandomMacAddress) {
|
TEST_F(WifiIfaceUtilTest, GetOrCreateRandomMacAddress) {
|
||||||
auto mac_address = iface_util_.getOrCreateRandomMacAddress();
|
auto mac_address = iface_util_->getOrCreateRandomMacAddress();
|
||||||
ASSERT_TRUE(isValidUnicastLocallyAssignedMacAddress(mac_address));
|
ASSERT_TRUE(isValidUnicastLocallyAssignedMacAddress(mac_address));
|
||||||
|
|
||||||
// All further calls should return the same MAC address.
|
// All further calls should return the same MAC address.
|
||||||
ASSERT_EQ(mac_address, iface_util_.getOrCreateRandomMacAddress());
|
ASSERT_EQ(mac_address, iface_util_->getOrCreateRandomMacAddress());
|
||||||
ASSERT_EQ(mac_address, iface_util_.getOrCreateRandomMacAddress());
|
ASSERT_EQ(mac_address, iface_util_->getOrCreateRandomMacAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(WifiIfaceUtilTest, IfaceEventHandlers_SetMacAddress) {
|
||||||
|
std::array<uint8_t, 6> mac_address = {};
|
||||||
|
std::copy(std::begin(kMacAddress), std::end(kMacAddress),
|
||||||
|
std::begin(mac_address));
|
||||||
|
EXPECT_CALL(*iface_tool_, SetMacAddress(testing::_, testing::_))
|
||||||
|
.WillRepeatedly(testing::Return(true));
|
||||||
|
EXPECT_CALL(*iface_tool_, SetUpState(testing::_, testing::_))
|
||||||
|
.WillRepeatedly(testing::Return(true));
|
||||||
|
|
||||||
|
// Register for iface state toggle events.
|
||||||
|
bool callback_invoked = false;
|
||||||
|
iface_util::IfaceEventHandlers event_handlers = {};
|
||||||
|
event_handlers.on_state_toggle_off_on =
|
||||||
|
[&callback_invoked](const std::string& /* iface_name */) {
|
||||||
|
callback_invoked = true;
|
||||||
|
};
|
||||||
|
iface_util_->registerIfaceEventHandlers(kIfaceName, event_handlers);
|
||||||
|
// Invoke setMacAddress and ensure that the cb is invoked.
|
||||||
|
ASSERT_TRUE(iface_util_->setMacAddress(kIfaceName, mac_address));
|
||||||
|
ASSERT_TRUE(callback_invoked);
|
||||||
|
|
||||||
|
// Unregister for iface state toggle events.
|
||||||
|
callback_invoked = false;
|
||||||
|
iface_util_->unregisterIfaceEventHandlers(kIfaceName);
|
||||||
|
// Invoke setMacAddress and ensure that the cb is not invoked.
|
||||||
|
ASSERT_TRUE(iface_util_->setMacAddress(kIfaceName, mac_address));
|
||||||
|
ASSERT_FALSE(callback_invoked);
|
||||||
|
}
|
||||||
|
} // namespace iface_util
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V1_3
|
} // namespace V1_3
|
||||||
} // namespace wifi
|
} // namespace wifi
|
||||||
|
|
148
wifi/1.3/default/tests/wifi_nan_iface_unit_tests.cpp
Normal file
148
wifi/1.3/default/tests/wifi_nan_iface_unit_tests.cpp
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019, 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 <android-base/logging.h>
|
||||||
|
#include <android-base/macros.h>
|
||||||
|
#include <cutils/properties.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#undef NAN // This is weird, NAN is defined in bionic/libc/include/math.h:38
|
||||||
|
#include "wifi_nan_iface.h"
|
||||||
|
|
||||||
|
#include "mock_interface_tool.h"
|
||||||
|
#include "mock_wifi_feature_flags.h"
|
||||||
|
#include "mock_wifi_iface_util.h"
|
||||||
|
#include "mock_wifi_legacy_hal.h"
|
||||||
|
|
||||||
|
using testing::NiceMock;
|
||||||
|
using testing::Return;
|
||||||
|
using testing::Test;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr char kIfaceName[] = "mockWlan0";
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace wifi {
|
||||||
|
namespace V1_3 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
bool CaptureIfaceEventHandlers(
|
||||||
|
const std::string& /* iface_name*/,
|
||||||
|
iface_util::IfaceEventHandlers in_iface_event_handlers,
|
||||||
|
iface_util::IfaceEventHandlers* out_iface_event_handlers) {
|
||||||
|
*out_iface_event_handlers = in_iface_event_handlers;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MockNanIfaceEventCallback : public IWifiNanIfaceEventCallback {
|
||||||
|
public:
|
||||||
|
MockNanIfaceEventCallback() = default;
|
||||||
|
|
||||||
|
MOCK_METHOD3(notifyCapabilitiesResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&,
|
||||||
|
const NanCapabilities&));
|
||||||
|
MOCK_METHOD2(notifyEnableResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(notifyConfigResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(notifyDisableResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD3(notifyStartPublishResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&, uint8_t));
|
||||||
|
MOCK_METHOD2(notifyStopPublishResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD3(notifyStartSubscribeResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&, uint8_t));
|
||||||
|
MOCK_METHOD2(notifyStopSubscribeResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(notifyTransmitFollowupResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(notifyCreateDataInterfaceResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(notifyDeleteDataInterfaceResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD3(notifyInitiateDataPathResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&, uint32_t));
|
||||||
|
MOCK_METHOD2(notifyRespondToDataPathIndicationResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(notifyTerminateDataPathResponse,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD1(eventClusterEvent, Return<void>(const NanClusterEventInd&));
|
||||||
|
MOCK_METHOD1(eventDisabled, Return<void>(const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(eventPublishTerminated,
|
||||||
|
Return<void>(uint8_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD2(eventSubscribeTerminated,
|
||||||
|
Return<void>(uint8_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD1(eventMatch, Return<void>(const NanMatchInd&));
|
||||||
|
MOCK_METHOD2(eventMatchExpired, Return<void>(uint8_t, uint32_t));
|
||||||
|
MOCK_METHOD1(eventFollowupReceived,
|
||||||
|
Return<void>(const NanFollowupReceivedInd&));
|
||||||
|
MOCK_METHOD2(eventTransmitFollowup,
|
||||||
|
Return<void>(uint16_t, const WifiNanStatus&));
|
||||||
|
MOCK_METHOD1(eventDataPathRequest,
|
||||||
|
Return<void>(const NanDataPathRequestInd&));
|
||||||
|
MOCK_METHOD1(eventDataPathConfirm,
|
||||||
|
Return<void>(const NanDataPathConfirmInd&));
|
||||||
|
MOCK_METHOD1(eventDataPathTerminated, Return<void>(uint32_t));
|
||||||
|
};
|
||||||
|
|
||||||
|
class WifiNanIfaceTest : public Test {
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<NiceMock<wifi_system::MockInterfaceTool>> iface_tool_{
|
||||||
|
new NiceMock<wifi_system::MockInterfaceTool>};
|
||||||
|
std::shared_ptr<NiceMock<legacy_hal::MockWifiLegacyHal>> legacy_hal_{
|
||||||
|
new NiceMock<legacy_hal::MockWifiLegacyHal>(iface_tool_)};
|
||||||
|
std::shared_ptr<NiceMock<iface_util::MockWifiIfaceUtil>> iface_util_{
|
||||||
|
new NiceMock<iface_util::MockWifiIfaceUtil>(iface_tool_)};
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(WifiNanIfaceTest, IfacEventHandlers_OnStateToggleOffOn) {
|
||||||
|
iface_util::IfaceEventHandlers captured_iface_event_handlers = {};
|
||||||
|
EXPECT_CALL(*legacy_hal_,
|
||||||
|
nanRegisterCallbackHandlers(testing::_, testing::_))
|
||||||
|
.WillOnce(testing::Return(legacy_hal::WIFI_SUCCESS));
|
||||||
|
EXPECT_CALL(*iface_util_,
|
||||||
|
registerIfaceEventHandlers(testing::_, testing::_))
|
||||||
|
.WillOnce(testing::Invoke(
|
||||||
|
bind(CaptureIfaceEventHandlers, std::placeholders::_1,
|
||||||
|
std::placeholders::_2, &captured_iface_event_handlers)));
|
||||||
|
sp<WifiNanIface> nan_iface =
|
||||||
|
new WifiNanIface(kIfaceName, legacy_hal_, iface_util_);
|
||||||
|
|
||||||
|
// Register a mock nan event callback.
|
||||||
|
sp<NiceMock<MockNanIfaceEventCallback>> mock_event_callback{
|
||||||
|
new NiceMock<MockNanIfaceEventCallback>};
|
||||||
|
nan_iface->registerEventCallback(
|
||||||
|
mock_event_callback, [](const WifiStatus& status) {
|
||||||
|
ASSERT_EQ(WifiStatusCode::SUCCESS, status.code);
|
||||||
|
});
|
||||||
|
// Ensure that the eventDisabled() function in mock callback will be
|
||||||
|
// invoked.
|
||||||
|
WifiNanStatus expected_nan_status = {
|
||||||
|
NanStatusType::UNSUPPORTED_CONCURRENCY_NAN_DISABLED, ""};
|
||||||
|
EXPECT_CALL(*mock_event_callback, eventDisabled(expected_nan_status))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
// Trigger the iface state toggle callback.
|
||||||
|
captured_iface_event_handlers.on_state_toggle_off_on(kIfaceName);
|
||||||
|
}
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V1_3
|
||||||
|
} // namespace wifi
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
|
@ -34,11 +34,13 @@ using hidl_return_util::validateAndCall;
|
||||||
using hidl_return_util::validateAndCallWithLock;
|
using hidl_return_util::validateAndCallWithLock;
|
||||||
|
|
||||||
Wifi::Wifi(
|
Wifi::Wifi(
|
||||||
|
const std::shared_ptr<wifi_system::InterfaceTool> iface_tool,
|
||||||
const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
|
const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
|
||||||
const std::shared_ptr<mode_controller::WifiModeController> mode_controller,
|
const std::shared_ptr<mode_controller::WifiModeController> mode_controller,
|
||||||
const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
|
const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
|
||||||
const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags)
|
const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags)
|
||||||
: legacy_hal_(legacy_hal),
|
: iface_tool_(iface_tool),
|
||||||
|
legacy_hal_(legacy_hal),
|
||||||
mode_controller_(mode_controller),
|
mode_controller_(mode_controller),
|
||||||
iface_util_(iface_util),
|
iface_util_(iface_util),
|
||||||
feature_flags_(feature_flags),
|
feature_flags_(feature_flags),
|
||||||
|
|
|
@ -40,7 +40,8 @@ namespace implementation {
|
||||||
*/
|
*/
|
||||||
class Wifi : public V1_3::IWifi {
|
class Wifi : public V1_3::IWifi {
|
||||||
public:
|
public:
|
||||||
Wifi(const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
|
Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool,
|
||||||
|
const std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
|
||||||
const std::shared_ptr<mode_controller::WifiModeController>
|
const std::shared_ptr<mode_controller::WifiModeController>
|
||||||
mode_controller,
|
mode_controller,
|
||||||
const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
|
const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
|
||||||
|
@ -77,6 +78,7 @@ class Wifi : public V1_3::IWifi {
|
||||||
|
|
||||||
// Instance is created in this root level |IWifi| HIDL interface object
|
// Instance is created in this root level |IWifi| HIDL interface object
|
||||||
// and shared with all the child HIDL interface objects.
|
// and shared with all the child HIDL interface objects.
|
||||||
|
std::shared_ptr<wifi_system::InterfaceTool> iface_tool_;
|
||||||
std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
|
std::shared_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
|
||||||
std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
|
std::shared_ptr<mode_controller::WifiModeController> mode_controller_;
|
||||||
std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
|
std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
|
||||||
|
|
|
@ -39,25 +39,28 @@ namespace V1_3 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
namespace iface_util {
|
namespace iface_util {
|
||||||
|
|
||||||
WifiIfaceUtil::WifiIfaceUtil()
|
WifiIfaceUtil::WifiIfaceUtil(
|
||||||
: random_mac_address_(nullptr), event_handlers_map_() {}
|
const std::weak_ptr<wifi_system::InterfaceTool> iface_tool)
|
||||||
|
: iface_tool_(iface_tool),
|
||||||
|
random_mac_address_(nullptr),
|
||||||
|
event_handlers_map_() {}
|
||||||
|
|
||||||
std::array<uint8_t, 6> WifiIfaceUtil::getFactoryMacAddress(
|
std::array<uint8_t, 6> WifiIfaceUtil::getFactoryMacAddress(
|
||||||
const std::string& iface_name) {
|
const std::string& iface_name) {
|
||||||
return iface_tool_.GetFactoryMacAddress(iface_name.c_str());
|
return iface_tool_.lock()->GetFactoryMacAddress(iface_name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WifiIfaceUtil::setMacAddress(const std::string& iface_name,
|
bool WifiIfaceUtil::setMacAddress(const std::string& iface_name,
|
||||||
const std::array<uint8_t, 6>& mac) {
|
const std::array<uint8_t, 6>& mac) {
|
||||||
if (!iface_tool_.SetUpState(iface_name.c_str(), false)) {
|
if (!iface_tool_.lock()->SetUpState(iface_name.c_str(), false)) {
|
||||||
LOG(ERROR) << "SetUpState(false) failed.";
|
LOG(ERROR) << "SetUpState(false) failed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!iface_tool_.SetMacAddress(iface_name.c_str(), mac)) {
|
if (!iface_tool_.lock()->SetMacAddress(iface_name.c_str(), mac)) {
|
||||||
LOG(ERROR) << "SetMacAddress failed.";
|
LOG(ERROR) << "SetMacAddress failed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!iface_tool_.SetUpState(iface_name.c_str(), true)) {
|
if (!iface_tool_.lock()->SetUpState(iface_name.c_str(), true)) {
|
||||||
LOG(ERROR) << "SetUpState(true) failed.";
|
LOG(ERROR) << "SetUpState(true) failed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct IfaceEventHandlers {
|
||||||
*/
|
*/
|
||||||
class WifiIfaceUtil {
|
class WifiIfaceUtil {
|
||||||
public:
|
public:
|
||||||
WifiIfaceUtil();
|
WifiIfaceUtil(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
|
||||||
virtual ~WifiIfaceUtil() = default;
|
virtual ~WifiIfaceUtil() = default;
|
||||||
|
|
||||||
virtual std::array<uint8_t, 6> getFactoryMacAddress(
|
virtual std::array<uint8_t, 6> getFactoryMacAddress(
|
||||||
|
@ -60,7 +60,7 @@ class WifiIfaceUtil {
|
||||||
private:
|
private:
|
||||||
std::array<uint8_t, 6> createRandomMacAddress();
|
std::array<uint8_t, 6> createRandomMacAddress();
|
||||||
|
|
||||||
wifi_system::InterfaceTool iface_tool_;
|
std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
|
||||||
std::unique_ptr<std::array<uint8_t, 6>> random_mac_address_;
|
std::unique_ptr<std::array<uint8_t, 6>> random_mac_address_;
|
||||||
std::map<std::string, IfaceEventHandlers> event_handlers_map_;
|
std::map<std::string, IfaceEventHandlers> event_handlers_map_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -333,10 +333,12 @@ void onAsyncNanEventScheduleUpdate(NanDataPathScheduleUpdateInd* event) {
|
||||||
}
|
}
|
||||||
// End of the free-standing "C" style callbacks.
|
// End of the free-standing "C" style callbacks.
|
||||||
|
|
||||||
WifiLegacyHal::WifiLegacyHal()
|
WifiLegacyHal::WifiLegacyHal(
|
||||||
|
const std::weak_ptr<wifi_system::InterfaceTool> iface_tool)
|
||||||
: global_handle_(nullptr),
|
: global_handle_(nullptr),
|
||||||
awaiting_event_loop_termination_(false),
|
awaiting_event_loop_termination_(false),
|
||||||
is_started_(false) {}
|
is_started_(false),
|
||||||
|
iface_tool_(iface_tool) {}
|
||||||
|
|
||||||
wifi_error WifiLegacyHal::initialize() {
|
wifi_error WifiLegacyHal::initialize() {
|
||||||
LOG(DEBUG) << "Initialize legacy HAL";
|
LOG(DEBUG) << "Initialize legacy HAL";
|
||||||
|
@ -371,7 +373,7 @@ wifi_error WifiLegacyHal::start() {
|
||||||
property_set(kDriverPropName, "ok");
|
property_set(kDriverPropName, "ok");
|
||||||
|
|
||||||
LOG(DEBUG) << "Starting legacy HAL";
|
LOG(DEBUG) << "Starting legacy HAL";
|
||||||
if (!iface_tool_.SetWifiUpState(true)) {
|
if (!iface_tool_.lock()->SetWifiUpState(true)) {
|
||||||
LOG(ERROR) << "Failed to set WiFi interface up";
|
LOG(ERROR) << "Failed to set WiFi interface up";
|
||||||
return WIFI_ERROR_UNKNOWN;
|
return WIFI_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -407,7 +409,7 @@ wifi_error WifiLegacyHal::stop(
|
||||||
// Invalidate all the internal pointers now that the HAL is
|
// Invalidate all the internal pointers now that the HAL is
|
||||||
// stopped.
|
// stopped.
|
||||||
invalidate();
|
invalidate();
|
||||||
iface_tool_.SetWifiUpState(false);
|
iface_tool_.lock()->SetWifiUpState(false);
|
||||||
on_stop_complete_user_callback();
|
on_stop_complete_user_callback();
|
||||||
is_started_ = false;
|
is_started_ = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -170,7 +170,7 @@ using on_radio_mode_change_callback =
|
||||||
*/
|
*/
|
||||||
class WifiLegacyHal {
|
class WifiLegacyHal {
|
||||||
public:
|
public:
|
||||||
WifiLegacyHal();
|
WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
|
||||||
virtual ~WifiLegacyHal() = default;
|
virtual ~WifiLegacyHal() = default;
|
||||||
|
|
||||||
// Initialize the legacy HAL function table.
|
// Initialize the legacy HAL function table.
|
||||||
|
@ -391,7 +391,7 @@ class WifiLegacyHal {
|
||||||
std::condition_variable_any stop_wait_cv_;
|
std::condition_variable_any stop_wait_cv_;
|
||||||
// Flag to indicate if the legacy HAL has been started.
|
// Flag to indicate if the legacy HAL has been started.
|
||||||
bool is_started_;
|
bool is_started_;
|
||||||
wifi_system::InterfaceTool iface_tool_;
|
std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace legacy_hal
|
} // namespace legacy_hal
|
||||||
|
|
Loading…
Reference in a new issue