wifi: fix NULL pointer in unit tests
getSupportedIfaceName() should be mocked to avoid
NULL pointer exception.
Bug: 217267980
Test: atest android.hardware.wifi@1.0-service-tests
Change-Id: I97a9cb8430ea77a6fe068f20586ab27df9291400
diff --git a/wifi/1.6/default/tests/mock_wifi_legacy_hal.h b/wifi/1.6/default/tests/mock_wifi_legacy_hal.h
index b1f5327..85dbf0f 100644
--- a/wifi/1.6/default/tests/mock_wifi_legacy_hal.h
+++ b/wifi/1.6/default/tests/mock_wifi_legacy_hal.h
@@ -56,6 +56,10 @@
wifi_error(const std::string& ifname, wifi_interface_type iftype));
MOCK_METHOD1(deleteVirtualInterface, wifi_error(const std::string& ifname));
MOCK_METHOD0(waitForDriverReady, wifi_error());
+ MOCK_METHOD2(getSupportedIfaceName, wifi_error(uint32_t, std::string&));
+ MOCK_METHOD1(registerSubsystemRestartCallbackHandler,
+ wifi_error(const on_subsystem_restart_callback&));
+ MOCK_METHOD1(getSupportedFeatureSet, std::pair<wifi_error, uint64_t>(const std::string&));
};
} // namespace legacy_hal
} // namespace implementation
diff --git a/wifi/1.6/default/tests/wifi_chip_unit_tests.cpp b/wifi/1.6/default/tests/wifi_chip_unit_tests.cpp
index 48c0065..eaab211 100644
--- a/wifi/1.6/default/tests/wifi_chip_unit_tests.cpp
+++ b/wifi/1.6/default/tests/wifi_chip_unit_tests.cpp
@@ -278,6 +278,9 @@
.WillRepeatedly(testing::Return(true));
EXPECT_CALL(*legacy_hal_, start())
.WillRepeatedly(testing::Return(legacy_hal::WIFI_SUCCESS));
+ // Vendor HAL does not override the name by default.
+ EXPECT_CALL(*legacy_hal_, getSupportedIfaceName(testing::_, testing::_))
+ .WillRepeatedly(testing::Return(legacy_hal::WIFI_ERROR_UNKNOWN));
}
void TearDown() override {
diff --git a/wifi/1.6/default/wifi_legacy_hal.h b/wifi/1.6/default/wifi_legacy_hal.h
index ab21e8e..6f42f70 100644
--- a/wifi/1.6/default/wifi_legacy_hal.h
+++ b/wifi/1.6/default/wifi_legacy_hal.h
@@ -496,7 +496,7 @@
const std::string& iface_name);
std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
const std::string& iface_name);
- std::pair<wifi_error, uint64_t> getSupportedFeatureSet(const std::string& iface_name);
+ virtual std::pair<wifi_error, uint64_t> getSupportedFeatureSet(const std::string& iface_name);
// APF functions.
std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
const std::string& iface_name);
@@ -564,7 +564,7 @@
wifi_error registerRingBufferCallbackHandler(
const std::string& iface_name, const on_ring_buffer_data_callback& on_data_callback);
wifi_error deregisterRingBufferCallbackHandler(const std::string& iface_name);
- wifi_error registerSubsystemRestartCallbackHandler(
+ virtual wifi_error registerSubsystemRestartCallbackHandler(
const on_subsystem_restart_callback& on_restart_callback);
std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> getRingBuffersStatus(
const std::string& iface_name);
@@ -637,7 +637,7 @@
virtual wifi_error createVirtualInterface(const std::string& ifname,
wifi_interface_type iftype);
virtual wifi_error deleteVirtualInterface(const std::string& ifname);
- wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
+ virtual wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
// STA + STA functions
virtual wifi_error multiStaSetPrimaryConnection(const std::string& ifname);