system/connectivity/wificond
Révision | 7a3d8ddff0ea3bca99fb3e554651e1541a93121e (tree) |
---|---|
l'heure | 2017-07-13 03:11:07 |
Auteur | Ningyuan Wang <nywang@goog...> |
Commiter | Ningyuan Wang |
ScannerImpl: Add unit tests for scheduled scans
This patch adds unit tests for scheduled scans.
In order to do that, this also moves the isOffloadScanSupprted()
out of OffloadScanManager to OffloadServiceUtils. By injecting
MockOffloadServiceUtils to ScannerImpl, we can test either offload
supported or not supported cases.
Bug: 33452931
Test: compile, unit tests
Test: manual test that offload scan is not enabled by mistake.
This is done by checking manually inserted logs.
Change-Id: I6c78df78605321013676e5f4578026f21d953e3b
@@ -24,6 +24,7 @@ | ||
24 | 24 | #include "wificond/client_interface_binder.h" |
25 | 25 | #include "wificond/net/mlme_event.h" |
26 | 26 | #include "wificond/net/netlink_utils.h" |
27 | +#include "wificond/scanning/offload/offload_service_utils.h" | |
27 | 28 | #include "wificond/scanning/scan_result.h" |
28 | 29 | #include "wificond/scanning/scan_utils.h" |
29 | 30 | #include "wificond/scanning/scanner_impl.h" |
@@ -116,6 +117,7 @@ ClientInterfaceImpl::ClientInterfaceImpl( | ||
116 | 117 | supplicant_manager_(supplicant_manager), |
117 | 118 | netlink_utils_(netlink_utils), |
118 | 119 | scan_utils_(scan_utils), |
120 | + offload_service_utils_(new OffloadServiceUtils()), | |
119 | 121 | mlme_event_handler_(new MlmeEventHandlerImpl(this)), |
120 | 122 | binder_(new ClientInterfaceBinder(this)), |
121 | 123 | is_associated_(false) { |
@@ -136,7 +138,8 @@ ClientInterfaceImpl::ClientInterfaceImpl( | ||
136 | 138 | wiphy_features_, |
137 | 139 | this, |
138 | 140 | netlink_utils_, |
139 | - scan_utils_); | |
141 | + scan_utils_, | |
142 | + offload_service_utils_); | |
140 | 143 | } |
141 | 144 | |
142 | 145 | ClientInterfaceImpl::~ClientInterfaceImpl() { |
@@ -27,6 +27,7 @@ | ||
27 | 27 | #include "android/net/wifi/IClientInterface.h" |
28 | 28 | #include "wificond/net/mlme_event_handler.h" |
29 | 29 | #include "wificond/net/netlink_utils.h" |
30 | +#include "wificond/scanning/offload/offload_service_utils.h" | |
30 | 31 | #include "wificond/scanning/scanner_impl.h" |
31 | 32 | |
32 | 33 | namespace android { |
@@ -96,6 +97,7 @@ class ClientInterfaceImpl { | ||
96 | 97 | android::wifi_system::SupplicantManager* const supplicant_manager_; |
97 | 98 | NetlinkUtils* const netlink_utils_; |
98 | 99 | ScanUtils* const scan_utils_; |
100 | + const std::shared_ptr<OffloadServiceUtils> offload_service_utils_; | |
99 | 101 | const std::unique_ptr<MlmeEventHandlerImpl> mlme_event_handler_; |
100 | 102 | const android::sp<ClientInterfaceBinder> binder_; |
101 | 103 | android::sp<ScannerImpl> scanner_; |
@@ -38,8 +38,10 @@ using android::wificond::OffloadCallback; | ||
38 | 38 | using android::wificond::OnNativeScanResultsReadyHandler; |
39 | 39 | using ::com::android::server::wifi::wificond::NativeScanResult; |
40 | 40 | using ::com::android::server::wifi::wificond::NativeScanStats; |
41 | -using namespace std::placeholders; | |
42 | 41 | using std::vector; |
42 | +using std::weak_ptr; | |
43 | + | |
44 | +using namespace std::placeholders; | |
43 | 45 | |
44 | 46 | namespace { |
45 | 47 | const uint32_t kSubscriptionDelayMs = 5000; |
@@ -67,7 +69,7 @@ void OffloadCallbackHandlersImpl::OnErrorHandler(const OffloadStatus& status) { | ||
67 | 69 | } |
68 | 70 | } |
69 | 71 | |
70 | -OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils, | |
72 | +OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils, | |
71 | 73 | OnNativeScanResultsReadyHandler handler) |
72 | 74 | : wifi_offload_hal_(nullptr), |
73 | 75 | wifi_offload_callback_(nullptr), |
@@ -75,21 +77,18 @@ OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils, | ||
75 | 77 | subscription_enabled_(false), |
76 | 78 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), |
77 | 79 | scan_result_handler_(handler) { |
78 | - if (utils == nullptr) { | |
79 | - LOG(ERROR) << "Invalid arguments for Offload ScanManager"; | |
80 | - return; | |
81 | - } | |
80 | + auto offload_scan_utils = utils.lock(); | |
82 | 81 | if (scan_result_handler_ == nullptr) { |
83 | 82 | LOG(ERROR) << "Invalid Offload scan result handler"; |
84 | 83 | return; |
85 | 84 | } |
86 | - wifi_offload_hal_ = utils->GetOffloadService(); | |
85 | + wifi_offload_hal_ = offload_scan_utils->GetOffloadService(); | |
87 | 86 | if (wifi_offload_hal_ == nullptr) { |
88 | 87 | LOG(ERROR) << "No Offload Service available"; |
89 | 88 | return; |
90 | 89 | } |
91 | 90 | |
92 | - death_recipient_ = utils->GetOffloadDeathRecipient( | |
91 | + death_recipient_ = offload_scan_utils->GetOffloadDeathRecipient( | |
93 | 92 | std::bind(&OffloadScanManager::OnObjectDeath, this, _1)); |
94 | 93 | uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get()); |
95 | 94 | auto link_to_death_status = |
@@ -101,7 +100,7 @@ OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils, | ||
101 | 100 | } |
102 | 101 | |
103 | 102 | wifi_offload_callback_ = |
104 | - utils->GetOffloadCallback(offload_callback_handlers_.get()); | |
103 | + offload_scan_utils->GetOffloadCallback(offload_callback_handlers_.get()); | |
105 | 104 | if (wifi_offload_callback_ == nullptr) { |
106 | 105 | LOG(ERROR) << "Invalid Offload callback object"; |
107 | 106 | return; |
@@ -215,15 +214,6 @@ OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { | ||
215 | 214 | return offload_status_; |
216 | 215 | } |
217 | 216 | |
218 | -bool OffloadScanManager::isOffloadScanSupported() const { | |
219 | - bool result = false; | |
220 | -#ifdef WIFI_OFFLOAD_SCANS | |
221 | - LOG(VERBOSE) << "Offload HAL supported"; | |
222 | - result = true; | |
223 | -#endif | |
224 | - return result; | |
225 | -} | |
226 | - | |
227 | 217 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { |
228 | 218 | if (getOffloadStatus() != OffloadScanManager::kNoError) { |
229 | 219 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; |
@@ -94,7 +94,7 @@ class OffloadScanManager { | ||
94 | 94 | kTransactionFailed, |
95 | 95 | }; |
96 | 96 | |
97 | - explicit OffloadScanManager(OffloadServiceUtils* utils, | |
97 | + explicit OffloadScanManager(std::weak_ptr<OffloadServiceUtils> utils, | |
98 | 98 | OnNativeScanResultsReadyHandler handler); |
99 | 99 | virtual ~OffloadScanManager(); |
100 | 100 | /* Request start of offload scans with scan parameters and scan filter |
@@ -118,8 +118,6 @@ class OffloadScanManager { | ||
118 | 118 | ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); |
119 | 119 | /* Otain status of the Offload HAL service */ |
120 | 120 | StatusCode getOffloadStatus() const; |
121 | - /* Check if Offload service is supported on this device */ | |
122 | - bool isOffloadScanSupported() const; | |
123 | 121 | |
124 | 122 | private: |
125 | 123 | void ReportScanResults( |
@@ -35,6 +35,15 @@ OffloadDeathRecipient* OffloadServiceUtils::GetOffloadDeathRecipient( | ||
35 | 35 | return new OffloadDeathRecipient(handler); |
36 | 36 | } |
37 | 37 | |
38 | +bool OffloadServiceUtils::IsOffloadScanSupported() const { | |
39 | + bool result = false; | |
40 | +#ifdef WIFI_OFFLOAD_SCANS | |
41 | + LOG(VERBOSE) << "Offload HAL supported"; | |
42 | + result = true; | |
43 | +#endif | |
44 | + return result; | |
45 | +} | |
46 | + | |
38 | 47 | OffloadDeathRecipient::OffloadDeathRecipient( |
39 | 48 | OffloadDeathRecipientHandler handler) |
40 | 49 | : handler_(handler) {} |
@@ -46,6 +46,8 @@ class OffloadServiceUtils { | ||
46 | 46 | virtual ~OffloadServiceUtils() = default; |
47 | 47 | virtual android::sp<android::hardware::wifi::offload::V1_0::IOffload> |
48 | 48 | GetOffloadService(); |
49 | + // Check if Offload scan is supported on this device. | |
50 | + virtual bool IsOffloadScanSupported() const; | |
49 | 51 | virtual android::sp<OffloadCallback> GetOffloadCallback( |
50 | 52 | OffloadCallbackHandlers* handlers); |
51 | 53 | virtual OffloadDeathRecipient* GetOffloadDeathRecipient( |
@@ -37,6 +37,7 @@ using com::android::server::wifi::wificond::SingleScanSettings; | ||
37 | 37 | |
38 | 38 | using std::string; |
39 | 39 | using std::vector; |
40 | +using std::weak_ptr; | |
40 | 41 | |
41 | 42 | using namespace std::placeholders; |
42 | 43 |
@@ -49,7 +50,8 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index, | ||
49 | 50 | const WiphyFeatures& wiphy_features, |
50 | 51 | ClientInterfaceImpl* client_interface, |
51 | 52 | NetlinkUtils* netlink_utils, |
52 | - ScanUtils* scan_utils) | |
53 | + ScanUtils* scan_utils, | |
54 | + weak_ptr<OffloadServiceUtils> offload_service_utils) | |
53 | 55 | : valid_(true), |
54 | 56 | scan_started_(false), |
55 | 57 | pno_scan_started_(false), |
@@ -77,10 +79,11 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index, | ||
77 | 79 | this, |
78 | 80 | _1, _2)); |
79 | 81 | offload_scan_manager_.reset( |
80 | - new OffloadScanManager(new OffloadServiceUtils(), | |
82 | + new OffloadScanManager( | |
83 | + offload_service_utils, | |
81 | 84 | std::bind(&ScannerImpl::OnOffloadScanResult, |
82 | 85 | this, _1))); |
83 | - offload_scan_supported_ = offload_scan_manager_->isOffloadScanSupported(); | |
86 | + offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported(); | |
84 | 87 | } |
85 | 88 | |
86 | 89 | ScannerImpl::~ScannerImpl() { |
@@ -30,6 +30,7 @@ namespace android { | ||
30 | 30 | namespace wificond { |
31 | 31 | |
32 | 32 | class ClientInterfaceImpl; |
33 | +class OffloadServiceUtils; | |
33 | 34 | class ScanUtils; |
34 | 35 | |
35 | 36 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { |
@@ -40,7 +41,8 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | ||
40 | 41 | const WiphyFeatures& wiphy_features, |
41 | 42 | ClientInterfaceImpl* client_interface, |
42 | 43 | NetlinkUtils* netlink_utils, |
43 | - ScanUtils* scan_utils); | |
44 | + ScanUtils* scan_utils, | |
45 | + std::weak_ptr<OffloadServiceUtils> offload_service_utils); | |
44 | 46 | ~ScannerImpl(); |
45 | 47 | // Returns a vector of available frequencies for 2.4GHz channels. |
46 | 48 | ::android::binder::Status getAvailable2gChannels( |
@@ -32,7 +32,7 @@ class MockOffloadServiceUtils : public OffloadServiceUtils { | ||
32 | 32 | public: |
33 | 33 | MockOffloadServiceUtils(); |
34 | 34 | ~MockOffloadServiceUtils() override = default; |
35 | - | |
35 | + MOCK_CONST_METHOD0(IsOffloadScanSupported, bool()); | |
36 | 36 | MOCK_METHOD0(GetOffloadService, |
37 | 37 | sp<android::hardware::wifi::offload::V1_0::IOffload>()); |
38 | 38 | MOCK_METHOD1(GetOffloadCallback, |
@@ -29,8 +29,14 @@ class MockScanUtils : public ScanUtils { | ||
29 | 29 | MockScanUtils(NetlinkManager* netlink_manager); |
30 | 30 | ~MockScanUtils() override = default; |
31 | 31 | |
32 | + MOCK_METHOD1(UnsubscribeScanResultNotification, | |
33 | + void(uint32_t interface_index)); | |
32 | 34 | MOCK_METHOD1(AbortScan, bool(uint32_t interface_index)); |
35 | + MOCK_METHOD1(StopScheduledScan, bool(uint32_t interface_index)); | |
33 | 36 | |
37 | + MOCK_METHOD2(SubscribeScanResultNotification,void( | |
38 | + uint32_t interface_index, | |
39 | + OnScanResultsReadyHandler handler)); | |
34 | 40 | MOCK_METHOD2(GetScanResult, bool( |
35 | 41 | uint32_t interface_index, |
36 | 42 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>* out_scan_results)); |
@@ -42,12 +48,15 @@ class MockScanUtils : public ScanUtils { | ||
42 | 48 | const std::vector<uint32_t>& freqs, |
43 | 49 | int* error_code)); |
44 | 50 | |
45 | - MOCK_METHOD2(SubscribeScanResultNotification,void( | |
51 | + MOCK_METHOD8(StartScheduledScan, bool( | |
46 | 52 | uint32_t interface_index, |
47 | - OnScanResultsReadyHandler handler)); | |
48 | - | |
49 | - MOCK_METHOD1(UnsubscribeScanResultNotification, | |
50 | - void(uint32_t interface_index)); | |
53 | + uint32_t interval_ms, | |
54 | + int32_t rssi_threshold, | |
55 | + bool request_random_mac, | |
56 | + const std::vector<std::vector<uint8_t>>& scan_ssids, | |
57 | + const std::vector<std::vector<uint8_t>>& match_ssids, | |
58 | + const std::vector<uint32_t>& freqs, | |
59 | + int* error_code)); | |
51 | 60 | |
52 | 61 | }; // class MockScanUtils |
53 | 62 |
@@ -47,6 +47,7 @@ using com::android::server::wifi::wificond::NativeScanStats; | ||
47 | 47 | using testing::NiceMock; |
48 | 48 | using testing::_; |
49 | 49 | using testing::Invoke; |
50 | +using std::shared_ptr; | |
50 | 51 | using std::unique_ptr; |
51 | 52 | using std::vector; |
52 | 53 | using std::bind; |
@@ -109,7 +110,7 @@ class OffloadScanManagerTest : public ::testing::Test { | ||
109 | 110 | sp<NiceMock<MockOffload>> mock_offload_{new NiceMock<MockOffload>()}; |
110 | 111 | sp<OffloadCallback> offload_callback_; |
111 | 112 | sp<OffloadDeathRecipient> death_recipient_; |
112 | - unique_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ | |
113 | + shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ | |
113 | 114 | new NiceMock<MockOffloadServiceUtils>()}; |
114 | 115 | unique_ptr<OffloadScanManager> offload_scan_manager_; |
115 | 116 | OffloadStatus status; |
@@ -130,7 +131,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathRegisteredCookieAndService) { | ||
130 | 131 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
131 | 132 | .WillByDefault(testing::Return(mock_offload_)); |
132 | 133 | offload_scan_manager_.reset(new OffloadScanManager( |
133 | - mock_offload_service_utils_.get(), | |
134 | + mock_offload_service_utils_, | |
134 | 135 | [](vector<NativeScanResult> scanResult) -> void {})); |
135 | 136 | death_recipient_->serviceDied(cookie_, mock_offload_); |
136 | 137 | EXPECT_EQ(OffloadScanManager::kNoService, |
@@ -146,7 +147,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) { | ||
146 | 147 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
147 | 148 | .WillByDefault(testing::Return(mock_offload_)); |
148 | 149 | offload_scan_manager_.reset(new OffloadScanManager( |
149 | - mock_offload_service_utils_.get(), | |
150 | + mock_offload_service_utils_, | |
150 | 151 | [](vector<NativeScanResult> scanResult) -> void {})); |
151 | 152 | death_recipient_->serviceDied(kDeathCode, mock_offload_); |
152 | 153 | EXPECT_FALSE(OffloadScanManager::kNoService == |
@@ -154,15 +155,6 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) { | ||
154 | 155 | } |
155 | 156 | |
156 | 157 | /** |
157 | - * Testing OffloadScanManager with OffloadServiceUtils null argument | |
158 | - */ | |
159 | -TEST_F(OffloadScanManagerTest, ServiceUtilsNotAvailableTest) { | |
160 | - offload_scan_manager_.reset(new OffloadScanManager(nullptr, nullptr)); | |
161 | - EXPECT_EQ(OffloadScanManager::kNoService, | |
162 | - offload_scan_manager_->getOffloadStatus()); | |
163 | -} | |
164 | - | |
165 | -/** | |
166 | 158 | * Testing OffloadScanManager with no handle on Offloal HAL service |
167 | 159 | * and no registered handler for Offload Scan results |
168 | 160 | */ |
@@ -171,7 +163,7 @@ TEST_F(OffloadScanManagerTest, ServiceNotAvailableTest) { | ||
171 | 163 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
172 | 164 | .WillByDefault(testing::Return(nullptr)); |
173 | 165 | offload_scan_manager_.reset(new OffloadScanManager( |
174 | - mock_offload_service_utils_.get(), | |
166 | + mock_offload_service_utils_, | |
175 | 167 | [](vector<NativeScanResult> scanResult) -> void {})); |
176 | 168 | EXPECT_EQ(OffloadScanManager::kNoService, |
177 | 169 | offload_scan_manager_->getOffloadStatus()); |
@@ -188,7 +180,7 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) { | ||
188 | 180 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
189 | 181 | .WillByDefault(testing::Return(mock_offload_)); |
190 | 182 | offload_scan_manager_.reset(new OffloadScanManager( |
191 | - mock_offload_service_utils_.get(), | |
183 | + mock_offload_service_utils_, | |
192 | 184 | [](vector<NativeScanResult> scanResult) -> void {})); |
193 | 185 | EXPECT_EQ(OffloadScanManager::kNoError, |
194 | 186 | offload_scan_manager_->getOffloadStatus()); |
@@ -207,7 +199,7 @@ TEST_F(OffloadScanManagerTest, CallbackInvokedTest) { | ||
207 | 199 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
208 | 200 | .WillByDefault(testing::Return(mock_offload_)); |
209 | 201 | offload_scan_manager_.reset(new OffloadScanManager( |
210 | - mock_offload_service_utils_.get(), | |
202 | + mock_offload_service_utils_, | |
211 | 203 | [&callback_invoked](vector<NativeScanResult> scanResult) -> void { |
212 | 204 | callback_invoked = true; |
213 | 205 | })); |
@@ -228,7 +220,7 @@ TEST_F(OffloadScanManagerTest, ErrorCallbackInvokedTest) { | ||
228 | 220 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
229 | 221 | .WillByDefault(testing::Return(mock_offload_)); |
230 | 222 | offload_scan_manager_.reset(new OffloadScanManager( |
231 | - mock_offload_service_utils_.get(), | |
223 | + mock_offload_service_utils_, | |
232 | 224 | [](vector<NativeScanResult> scanResult) -> void {})); |
233 | 225 | OffloadStatus status = |
234 | 226 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); |
@@ -248,7 +240,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) { | ||
248 | 240 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
249 | 241 | .WillByDefault(testing::Return(mock_offload_)); |
250 | 242 | offload_scan_manager_.reset(new OffloadScanManager( |
251 | - mock_offload_service_utils_.get(), | |
243 | + mock_offload_service_utils_, | |
252 | 244 | [](vector<NativeScanResult> scanResult) -> void {})); |
253 | 245 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
254 | 246 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
@@ -268,7 +260,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { | ||
268 | 260 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
269 | 261 | .WillByDefault(testing::Return(nullptr)); |
270 | 262 | offload_scan_manager_.reset(new OffloadScanManager( |
271 | - mock_offload_service_utils_.get(), | |
263 | + mock_offload_service_utils_, | |
272 | 264 | [](vector<NativeScanResult> scanResult) -> void {})); |
273 | 265 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
274 | 266 | bool result = offload_scan_manager_->startScan( |
@@ -289,7 +281,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotConnected) { | ||
289 | 281 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
290 | 282 | .WillByDefault(testing::Return(mock_offload_)); |
291 | 283 | offload_scan_manager_.reset(new OffloadScanManager( |
292 | - mock_offload_service_utils_.get(), | |
284 | + mock_offload_service_utils_, | |
293 | 285 | [](vector<NativeScanResult> scanResult) -> void {})); |
294 | 286 | OffloadStatus status = |
295 | 287 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
@@ -313,7 +305,7 @@ TEST_F(OffloadScanManagerTest, StartScanTwiceTestWhenServiceIsOk) { | ||
313 | 305 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
314 | 306 | .WillByDefault(testing::Return(mock_offload_)); |
315 | 307 | offload_scan_manager_.reset(new OffloadScanManager( |
316 | - mock_offload_service_utils_.get(), | |
308 | + mock_offload_service_utils_, | |
317 | 309 | [](vector<NativeScanResult> scanResult) -> void {})); |
318 | 310 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(1); |
319 | 311 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2); |
@@ -339,7 +331,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) { | ||
339 | 331 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
340 | 332 | .WillByDefault(testing::Return(mock_offload_)); |
341 | 333 | offload_scan_manager_.reset(new OffloadScanManager( |
342 | - mock_offload_service_utils_.get(), | |
334 | + mock_offload_service_utils_, | |
343 | 335 | [](vector<NativeScanResult> scanResult) -> void {})); |
344 | 336 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
345 | 337 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
@@ -364,7 +356,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWithoutStartWhenServiceIsOk) { | ||
364 | 356 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
365 | 357 | .WillByDefault(testing::Return(mock_offload_)); |
366 | 358 | offload_scan_manager_.reset(new OffloadScanManager( |
367 | - mock_offload_service_utils_.get(), | |
359 | + mock_offload_service_utils_, | |
368 | 360 | [](vector<NativeScanResult> scanResult) -> void {})); |
369 | 361 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
370 | 362 | bool result = offload_scan_manager_->stopScan(&reason_code); |
@@ -382,7 +374,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | ||
382 | 374 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
383 | 375 | .WillByDefault(testing::Return(mock_offload_)); |
384 | 376 | offload_scan_manager_.reset(new OffloadScanManager( |
385 | - mock_offload_service_utils_.get(), | |
377 | + mock_offload_service_utils_, | |
386 | 378 | [](vector<NativeScanResult> scanResult) -> void {})); |
387 | 379 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
388 | 380 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
@@ -410,7 +402,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsOk) { | ||
410 | 402 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
411 | 403 | .WillByDefault(testing::Return(mock_offload_)); |
412 | 404 | offload_scan_manager_.reset(new OffloadScanManager( |
413 | - mock_offload_service_utils_.get(), | |
405 | + mock_offload_service_utils_, | |
414 | 406 | [](vector<NativeScanResult> scanResult) -> void {})); |
415 | 407 | EXPECT_CALL(*mock_offload_, getScanStats(_)); |
416 | 408 | NativeScanStats stats; |
@@ -429,7 +421,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsNotOk) { | ||
429 | 421 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
430 | 422 | .WillByDefault(testing::Return(mock_offload_)); |
431 | 423 | offload_scan_manager_.reset(new OffloadScanManager( |
432 | - mock_offload_service_utils_.get(), | |
424 | + mock_offload_service_utils_, | |
433 | 425 | [](vector<NativeScanResult> scanResult) -> void {})); |
434 | 426 | OffloadStatus status = |
435 | 427 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
@@ -451,7 +443,7 @@ TEST_F(OffloadScanManagerTest, StartScanFailedTest) { | ||
451 | 443 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
452 | 444 | .WillByDefault(testing::Return(mock_offload_)); |
453 | 445 | offload_scan_manager_.reset(new OffloadScanManager( |
454 | - mock_offload_service_utils_.get(), | |
446 | + mock_offload_service_utils_, | |
455 | 447 | [](vector<NativeScanResult> scanResult) -> void {})); |
456 | 448 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0); |
457 | 449 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1); |
@@ -475,7 +467,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsFailedTest) { | ||
475 | 467 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
476 | 468 | .WillByDefault(testing::Return(mock_offload_)); |
477 | 469 | offload_scan_manager_.reset(new OffloadScanManager( |
478 | - mock_offload_service_utils_.get(), | |
470 | + mock_offload_service_utils_, | |
479 | 471 | [](vector<NativeScanResult> scanResult) -> void {})); |
480 | 472 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT); |
481 | 473 | EXPECT_CALL(*mock_offload_, getScanStats(_)); |
@@ -25,17 +25,21 @@ | ||
25 | 25 | #include "wificond/tests/mock_client_interface_impl.h" |
26 | 26 | #include "wificond/tests/mock_netlink_manager.h" |
27 | 27 | #include "wificond/tests/mock_netlink_utils.h" |
28 | +#include "wificond/tests/mock_offload_service_utils.h" | |
28 | 29 | #include "wificond/tests/mock_scan_utils.h" |
29 | 30 | |
30 | 31 | using ::android::binder::Status; |
31 | 32 | using ::android::wifi_system::MockInterfaceTool; |
32 | 33 | using ::android::wifi_system::MockSupplicantManager; |
33 | 34 | using ::com::android::server::wifi::wificond::SingleScanSettings; |
35 | +using ::com::android::server::wifi::wificond::PnoSettings; | |
34 | 36 | using ::com::android::server::wifi::wificond::NativeScanResult; |
35 | 37 | using ::testing::Invoke; |
36 | 38 | using ::testing::NiceMock; |
37 | 39 | using ::testing::Return; |
38 | 40 | using ::testing::_; |
41 | +using std::shared_ptr; | |
42 | +using std::unique_ptr; | |
39 | 43 | using std::vector; |
40 | 44 | |
41 | 45 | using namespace std::placeholders; |
@@ -69,6 +73,17 @@ bool ReturnErrorCodeForScanRequest( | ||
69 | 73 | |
70 | 74 | class ScannerTest : public ::testing::Test { |
71 | 75 | protected: |
76 | + void SetUp() override { | |
77 | + ON_CALL(*offload_service_utils_, IsOffloadScanSupported()).WillByDefault( | |
78 | + Return(false)); | |
79 | + netlink_scanner_.reset(new ScannerImpl( | |
80 | + kFakeWiphyIndex, kFakeInterfaceIndex, | |
81 | + scan_capabilities_, wiphy_features_, | |
82 | + &client_interface_impl_, | |
83 | + &netlink_utils_, &scan_utils_, offload_service_utils_)); | |
84 | + } | |
85 | + | |
86 | + unique_ptr<ScannerImpl> netlink_scanner_; | |
72 | 87 | NiceMock<MockNetlinkManager> netlink_manager_; |
73 | 88 | NiceMock<MockNetlinkUtils> netlink_utils_{&netlink_manager_}; |
74 | 89 | NiceMock<MockScanUtils> scan_utils_{&netlink_manager_}; |
@@ -76,19 +91,16 @@ class ScannerTest : public ::testing::Test { | ||
76 | 91 | NiceMock<MockSupplicantManager> supplicant_manager_; |
77 | 92 | NiceMock<MockClientInterfaceImpl> client_interface_impl_{ |
78 | 93 | &if_tool_, &supplicant_manager_, &netlink_utils_, &scan_utils_}; |
94 | + shared_ptr<NiceMock<MockOffloadServiceUtils>> offload_service_utils_{ | |
95 | + new NiceMock<MockOffloadServiceUtils>()}; | |
79 | 96 | ScanCapabilities scan_capabilities_; |
80 | 97 | WiphyFeatures wiphy_features_; |
81 | - ScannerImpl scanner_{ | |
82 | - kFakeWiphyIndex, kFakeInterfaceIndex, | |
83 | - scan_capabilities_, wiphy_features_, | |
84 | - &client_interface_impl_, | |
85 | - &netlink_utils_, &scan_utils_}; | |
86 | 98 | }; |
87 | 99 | |
88 | 100 | TEST_F(ScannerTest, TestSingleScan) { |
89 | 101 | EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); |
90 | 102 | bool success = false; |
91 | - EXPECT_TRUE(scanner_.scan(SingleScanSettings(), &success).isOk()); | |
103 | + EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk()); | |
92 | 104 | EXPECT_TRUE(success); |
93 | 105 | } |
94 | 106 |
@@ -100,7 +112,7 @@ TEST_F(ScannerTest, TestSingleScanFailure) { | ||
100 | 112 | ReturnErrorCodeForScanRequest, EBUSY, _1, _2, _3, _4, _5))); |
101 | 113 | |
102 | 114 | bool success = false; |
103 | - EXPECT_TRUE(scanner_.scan(SingleScanSettings(), &success).isOk()); | |
115 | + EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk()); | |
104 | 116 | EXPECT_FALSE(success); |
105 | 117 | } |
106 | 118 |
@@ -113,33 +125,48 @@ TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) { | ||
113 | 125 | |
114 | 126 | bool success_ignored; |
115 | 127 | EXPECT_DEATH( |
116 | - scanner_.scan(SingleScanSettings(), &success_ignored), | |
128 | + netlink_scanner_->scan(SingleScanSettings(), &success_ignored), | |
117 | 129 | "Driver is in a bad state*"); |
118 | 130 | } |
119 | 131 | |
120 | 132 | TEST_F(ScannerTest, TestAbortScan) { |
121 | 133 | bool single_scan_success = false; |
122 | 134 | EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); |
123 | - EXPECT_TRUE(scanner_.scan(SingleScanSettings(), | |
135 | + EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), | |
124 | 136 | &single_scan_success).isOk()); |
125 | 137 | EXPECT_TRUE(single_scan_success); |
126 | 138 | |
127 | 139 | EXPECT_CALL(scan_utils_, AbortScan(_)); |
128 | - EXPECT_TRUE(scanner_.abortScan().isOk()); | |
140 | + EXPECT_TRUE(netlink_scanner_->abortScan().isOk()); | |
129 | 141 | } |
130 | 142 | |
131 | 143 | TEST_F(ScannerTest, TestAbortScanNotIssuedIfNoOngoingScan) { |
132 | 144 | EXPECT_CALL(scan_utils_, AbortScan(_)).Times(0); |
133 | - EXPECT_TRUE(scanner_.abortScan().isOk()); | |
145 | + EXPECT_TRUE(netlink_scanner_->abortScan().isOk()); | |
134 | 146 | } |
135 | 147 | |
136 | 148 | TEST_F(ScannerTest, TestGetScanResults) { |
137 | 149 | vector<NativeScanResult> scan_results; |
138 | 150 | EXPECT_CALL(scan_utils_, GetScanResult(_, _)).WillOnce(Return(true)); |
139 | - EXPECT_TRUE(scanner_.getScanResults(&scan_results).isOk()); | |
151 | + EXPECT_TRUE(netlink_scanner_->getScanResults(&scan_results).isOk()); | |
140 | 152 | } |
141 | 153 | |
142 | -//TODO(b/33452931): Add more test cases for ScannerImpl. | |
154 | +TEST_F(ScannerTest, TestStartPnoScanViaNetlink) { | |
155 | + bool success = false; | |
156 | + EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)). | |
157 | + WillOnce(Return(true)); | |
158 | + EXPECT_TRUE(netlink_scanner_->startPnoScan(PnoSettings(), &success).isOk()); | |
159 | + EXPECT_TRUE(success); | |
160 | +} | |
161 | + | |
162 | +TEST_F(ScannerTest, TestStopPnoScanViaNetlink) { | |
163 | + bool success = false; | |
164 | + // StopScheduledScan() will be called no matter if there is an ongoing | |
165 | + // scheduled scan or not. This is for making the system more robust. | |
166 | + EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); | |
167 | + EXPECT_TRUE(netlink_scanner_->stopPnoScan(&success).isOk()); | |
168 | + EXPECT_TRUE(success); | |
169 | +} | |
143 | 170 | |
144 | 171 | } // namespace wificond |
145 | 172 | } // namespace android |