summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSohani Rao2017-08-18 16:23:59 -0500
committerandroid-build-merger2017-08-18 16:23:59 -0500
commitc9bcea5f47da0f53d1550f3836b873a507497c2d (patch)
tree5b884129713f58fd80674edcd08c0b9085649b2d
parentc2ae6ac259e261bb41502526767544340d2817c1 (diff)
parent8f574ac480a39accc9fe5a5f065f4212e8175bd5 (diff)
downloadsystem-connectivity-wificond-c9bcea5f47da0f53d1550f3836b873a507497c2d.tar.gz
system-connectivity-wificond-c9bcea5f47da0f53d1550f3836b873a507497c2d.tar.xz
system-connectivity-wificond-c9bcea5f47da0f53d1550f3836b873a507497c2d.zip
Wificond ScannerImpl Unit testing Offload HAL
am: 8f574ac480 Change-Id: I6167b0f9d03b366caca1058bfcfaa91e38a0dc90
-rw-r--r--scanning/offload/offload_scan_manager.h31
-rw-r--r--scanning/scanner_impl.cpp5
-rw-r--r--tests/scanner_unittest.cpp232
3 files changed, 227 insertions, 41 deletions
diff --git a/scanning/offload/offload_scan_manager.h b/scanning/offload/offload_scan_manager.h
index 7b23d8e..6be3ec0 100644
--- a/scanning/offload/offload_scan_manager.h
+++ b/scanning/offload/offload_scan_manager.h
@@ -97,23 +97,24 @@ class OffloadScanManager {
97 * settings. Internally calls Offload HAL service with configureScans() 97 * settings. Internally calls Offload HAL service with configureScans()
98 * and subscribeScanResults() APIs. Reason code indicates failure reason. 98 * and subscribeScanResults() APIs. Reason code indicates failure reason.
99 */ 99 */
100 bool startScan(uint32_t /* interval_ms */, int32_t /* rssi_threshold */, 100 virtual bool startScan(
101 const std::vector<std::vector<uint8_t>>& /* scan_ssids */, 101 uint32_t /* interval_ms */, int32_t /* rssi_threshold */,
102 const std::vector<std::vector<uint8_t>>& /* match_ssids */, 102 const std::vector<std::vector<uint8_t>>& /* scan_ssids */,
103 const std::vector<uint8_t>& /* match_security */, 103 const std::vector<std::vector<uint8_t>>& /* match_ssids */,
104 const std::vector<uint32_t>& /* freqs */, 104 const std::vector<uint8_t>& /* match_security */,
105 ReasonCode* /* failure reason */); 105 const std::vector<uint32_t>& /* freqs */,
106 ReasonCode* /* failure reason */);
106 /* Request stop of offload scans, returns true if the operation succeeds 107 /* Request stop of offload scans, returns true if the operation succeeds
107 * Otherwise, returns false. Reason code is updated in case of failure. 108 * Otherwise, returns false. Reason code is updated in case of failure.
108 */ 109 */
109 bool stopScan(ReasonCode* /* failure reason */); 110 virtual bool stopScan(ReasonCode* /* failure reason */);
110 /* Get statistics for scans performed by Offload HAL */ 111 /* Get statistics for scans performed by Offload HAL */
111 bool getScanStats( 112 virtual bool getScanStats(
112 ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); 113 ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */);
113 /* Otain status of the Offload HAL service */ 114 /* Otain status of the Offload HAL service */
114 StatusCode getOffloadStatus() const; 115 virtual StatusCode getOffloadStatus() const;
115 /* Returns the most recent scan result available from Offload HAL */ 116 /* Returns the most recent scan result available from Offload HAL */
116 bool getScanResults( 117 virtual bool getScanResults(
117 std::vector<::com::android::server::wifi::wificond::NativeScanResult>* 118 std::vector<::com::android::server::wifi::wificond::NativeScanResult>*
118 out_scan_results); 119 out_scan_results);
119 120
@@ -129,10 +130,12 @@ class OffloadScanManager {
129 OffloadScanManager::ReasonCode* reason_code); 130 OffloadScanManager::ReasonCode* reason_code);
130 bool GetScanStats( 131 bool GetScanStats(
131 ::com::android::server::wifi::wificond::NativeScanStats* stats); 132 ::com::android::server::wifi::wificond::NativeScanStats* stats);
132 bool SubscribeScanResults(OffloadScanManager::ReasonCode* reason_code); 133 bool SubscribeScanResults(
133 bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam, 134 OffloadScanManager::ReasonCode* reason_code);
134 android::hardware::wifi::offload::V1_0::ScanFilter, 135 bool ConfigureScans(
135 OffloadScanManager::ReasonCode* reason_code); 136 android::hardware::wifi::offload::V1_0::ScanParam,
137 android::hardware::wifi::offload::V1_0::ScanFilter,
138 OffloadScanManager::ReasonCode* reason_code);
136 bool InitServiceIfNeeded(); 139 bool InitServiceIfNeeded();
137 bool InitService(); 140 bool InitService();
138 141
diff --git a/scanning/scanner_impl.cpp b/scanning/scanner_impl.cpp
index b14d788..0f6ab52 100644
--- a/scanning/scanner_impl.cpp
+++ b/scanning/scanner_impl.cpp
@@ -233,6 +233,7 @@ Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings,
233 bool* out_success) { 233 bool* out_success) {
234 pno_settings_ = pno_settings; 234 pno_settings_ = pno_settings;
235 pno_scan_results_from_offload_ = false; 235 pno_scan_results_from_offload_ = false;
236 LOG(VERBOSE) << "startPnoScan";
236 if (offload_scan_supported_ && StartPnoScanOffload(pno_settings)) { 237 if (offload_scan_supported_ && StartPnoScanOffload(pno_settings)) {
237 // scanning over offload succeeded 238 // scanning over offload succeeded
238 *out_success = true; 239 *out_success = true;
@@ -252,7 +253,6 @@ bool ScannerImpl::StartPnoScanOffload(const PnoSettings& pno_settings) {
252 253
253 ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs, 254 ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs,
254 &match_security); 255 &match_security);
255
256 pno_scan_running_over_offload_ = offload_scan_manager_->startScan( 256 pno_scan_running_over_offload_ = offload_scan_manager_->startScan(
257 pno_settings.interval_ms_, 257 pno_settings.interval_ms_,
258 // TODO: honor both rssi thresholds. 258 // TODO: honor both rssi thresholds.
@@ -464,6 +464,7 @@ void ScannerImpl::OnSchedScanResultsReady(uint32_t interface_index,
464 pno_scan_started_ = false; 464 pno_scan_started_ = false;
465 } else { 465 } else {
466 LOG(INFO) << "Pno scan result ready event"; 466 LOG(INFO) << "Pno scan result ready event";
467 pno_scan_results_from_offload_ = false;
467 pno_scan_event_handler_->OnPnoNetworkFound(); 468 pno_scan_event_handler_->OnPnoNetworkFound();
468 } 469 }
469 } 470 }
@@ -540,7 +541,7 @@ void ScannerImpl::OnOffloadError(
540 LOG(WARNING) << "Invalid Error code"; 541 LOG(WARNING) << "Invalid Error code";
541 break; 542 break;
542 } 543 }
543 bool success; 544 bool success = false;
544 // Stop scans over Offload HAL and request them over netlink 545 // Stop scans over Offload HAL and request them over netlink
545 stopPnoScan(&success); 546 stopPnoScan(&success);
546 if (success) { 547 if (success) {
diff --git a/tests/scanner_unittest.cpp b/tests/scanner_unittest.cpp
index 1a93e31..d69e8b1 100644
--- a/tests/scanner_unittest.cpp
+++ b/tests/scanner_unittest.cpp
@@ -21,6 +21,7 @@
21#include <wifi_system_test/mock_interface_tool.h> 21#include <wifi_system_test/mock_interface_tool.h>
22#include <wifi_system_test/mock_supplicant_manager.h> 22#include <wifi_system_test/mock_supplicant_manager.h>
23 23
24#include "wificond/scanning/offload/offload_scan_utils.h"
24#include "wificond/scanning/scanner_impl.h" 25#include "wificond/scanning/scanner_impl.h"
25#include "wificond/tests/mock_client_interface_impl.h" 26#include "wificond/tests/mock_client_interface_impl.h"
26#include "wificond/tests/mock_netlink_manager.h" 27#include "wificond/tests/mock_netlink_manager.h"
@@ -29,6 +30,7 @@
29#include "wificond/tests/mock_offload_scan_manager.h" 30#include "wificond/tests/mock_offload_scan_manager.h"
30#include "wificond/tests/mock_offload_service_utils.h" 31#include "wificond/tests/mock_offload_service_utils.h"
31#include "wificond/tests/mock_scan_utils.h" 32#include "wificond/tests/mock_scan_utils.h"
33#include "wificond/tests/offload_test_utils.h"
32 34
33using ::android::binder::Status; 35using ::android::binder::Status;
34using ::android::wifi_system::MockInterfaceTool; 36using ::android::wifi_system::MockInterfaceTool;
@@ -36,6 +38,7 @@ using ::android::wifi_system::MockSupplicantManager;
36using ::com::android::server::wifi::wificond::SingleScanSettings; 38using ::com::android::server::wifi::wificond::SingleScanSettings;
37using ::com::android::server::wifi::wificond::PnoSettings; 39using ::com::android::server::wifi::wificond::PnoSettings;
38using ::com::android::server::wifi::wificond::NativeScanResult; 40using ::com::android::server::wifi::wificond::NativeScanResult;
41using android::hardware::wifi::offload::V1_0::ScanResult;
39using ::testing::Invoke; 42using ::testing::Invoke;
40using ::testing::NiceMock; 43using ::testing::NiceMock;
41using ::testing::Return; 44using ::testing::Return;
@@ -86,25 +89,36 @@ bool CaptureSchedScanIntervalSetting(
86 return true; 89 return true;
87} 90}
88 91
92bool ReturnOffloadScanResults(
93 std::vector<NativeScanResult>* native_scan_results_,
94 const std::vector<ScanResult>& offload_scan_results) {
95 return OffloadScanUtils::convertToNativeScanResults(offload_scan_results,
96 native_scan_results_);
97}
98
99bool ReturnNetlinkScanResults(
100 uint32_t interface_index,
101 std::vector<NativeScanResult>* native_scan_results_,
102 const std::vector<ScanResult>& offload_scan_results) {
103 return OffloadScanUtils::convertToNativeScanResults(offload_scan_results,
104 native_scan_results_);
105}
106
89} // namespace 107} // namespace
90 108
91class ScannerTest : public ::testing::Test { 109class ScannerTest : public ::testing::Test {
92 protected: 110 protected:
93 void SetUp() override { 111 void SetUp() override {
94 ON_CALL(*offload_service_utils_, IsOffloadScanSupported()).WillByDefault( 112 ON_CALL(*offload_service_utils_, GetOffloadScanManager(_, _))
95 Return(false)); 113 .WillByDefault(Return(offload_scan_manager_));
96 ON_CALL(*offload_service_utils_, GetOffloadScanManager(_, _)) 114 ON_CALL(*offload_service_utils_, GetOffloadScanCallbackInterface(_))
97 .WillByDefault(Return(offload_scan_manager_)); 115 .WillByDefault(Return(offload_scan_callback_interface_));
98 ON_CALL(*offload_service_utils_, GetOffloadScanCallbackInterface(_)) 116 dummy_scan_results_ = OffloadTestUtils::createOffloadScanResults();
99 .WillByDefault(Return(offload_scan_callback_interface_));
100 netlink_scanner_.reset(new ScannerImpl(
101 kFakeWiphyIndex, kFakeInterfaceIndex,
102 scan_capabilities_, wiphy_features_,
103 &client_interface_impl_,
104 &netlink_utils_, &scan_utils_, offload_service_utils_));
105 } 117 }
106 118
107 unique_ptr<ScannerImpl> netlink_scanner_; 119 void TearDown() override { dummy_scan_results_.clear(); }
120
121 unique_ptr<ScannerImpl> scanner_impl_;
108 NiceMock<MockNetlinkManager> netlink_manager_; 122 NiceMock<MockNetlinkManager> netlink_manager_;
109 NiceMock<MockNetlinkUtils> netlink_utils_{&netlink_manager_}; 123 NiceMock<MockNetlinkUtils> netlink_utils_{&netlink_manager_};
110 NiceMock<MockScanUtils> scan_utils_{&netlink_manager_}; 124 NiceMock<MockScanUtils> scan_utils_{&netlink_manager_};
@@ -117,22 +131,31 @@ class ScannerTest : public ::testing::Test {
117 shared_ptr<NiceMock<MockOffloadScanCallbackInterfaceImpl>> 131 shared_ptr<NiceMock<MockOffloadScanCallbackInterfaceImpl>>
118 offload_scan_callback_interface_{ 132 offload_scan_callback_interface_{
119 new NiceMock<MockOffloadScanCallbackInterfaceImpl>( 133 new NiceMock<MockOffloadScanCallbackInterfaceImpl>(
120 netlink_scanner_.get())}; 134 scanner_impl_.get())};
121 std::shared_ptr<NiceMock<MockOffloadScanManager>> offload_scan_manager_{ 135 std::shared_ptr<NiceMock<MockOffloadScanManager>> offload_scan_manager_{
122 new NiceMock<MockOffloadScanManager>(offload_service_utils_, 136 new NiceMock<MockOffloadScanManager>(offload_service_utils_,
123 offload_scan_callback_interface_)}; 137 offload_scan_callback_interface_)};
124 ScanCapabilities scan_capabilities_; 138 ScanCapabilities scan_capabilities_;
125 WiphyFeatures wiphy_features_; 139 WiphyFeatures wiphy_features_;
140 std::vector<ScanResult> dummy_scan_results_;
126}; 141};
127 142
128TEST_F(ScannerTest, TestSingleScan) { 143TEST_F(ScannerTest, TestSingleScan) {
129 EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); 144 EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true));
130 bool success = false; 145 bool success = false;
131 EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk()); 146 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
147 scan_capabilities_, wiphy_features_,
148 &client_interface_impl_, &netlink_utils_,
149 &scan_utils_, offload_service_utils_));
150 EXPECT_TRUE(scanner_impl_->scan(SingleScanSettings(), &success).isOk());
132 EXPECT_TRUE(success); 151 EXPECT_TRUE(success);
133} 152}
134 153
135TEST_F(ScannerTest, TestSingleScanFailure) { 154TEST_F(ScannerTest, TestSingleScanFailure) {
155 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
156 scan_capabilities_, wiphy_features_,
157 &client_interface_impl_, &netlink_utils_,
158 &scan_utils_, offload_service_utils_));
136 EXPECT_CALL( 159 EXPECT_CALL(
137 scan_utils_, 160 scan_utils_,
138 Scan(_, _, _, _, _)). 161 Scan(_, _, _, _, _)).
@@ -140,11 +163,15 @@ TEST_F(ScannerTest, TestSingleScanFailure) {
140 ReturnErrorCodeForScanRequest, EBUSY, _1, _2, _3, _4, _5))); 163 ReturnErrorCodeForScanRequest, EBUSY, _1, _2, _3, _4, _5)));
141 164
142 bool success = false; 165 bool success = false;
143 EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk()); 166 EXPECT_TRUE(scanner_impl_->scan(SingleScanSettings(), &success).isOk());
144 EXPECT_FALSE(success); 167 EXPECT_FALSE(success);
145} 168}
146 169
147TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) { 170TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) {
171 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
172 scan_capabilities_, wiphy_features_,
173 &client_interface_impl_, &netlink_utils_,
174 &scan_utils_, offload_service_utils_));
148 ON_CALL( 175 ON_CALL(
149 scan_utils_, 176 scan_utils_,
150 Scan(_, _, _, _, _)). 177 Scan(_, _, _, _, _)).
@@ -152,47 +179,202 @@ TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) {
152 ReturnErrorCodeForScanRequest, ENODEV, _1, _2, _3, _4, _5))); 179 ReturnErrorCodeForScanRequest, ENODEV, _1, _2, _3, _4, _5)));
153 180
154 bool success_ignored; 181 bool success_ignored;
155 EXPECT_DEATH( 182 EXPECT_DEATH(scanner_impl_->scan(SingleScanSettings(), &success_ignored),
156 netlink_scanner_->scan(SingleScanSettings(), &success_ignored), 183 "Driver is in a bad state*");
157 "Driver is in a bad state*");
158} 184}
159 185
160TEST_F(ScannerTest, TestAbortScan) { 186TEST_F(ScannerTest, TestAbortScan) {
161 bool single_scan_success = false; 187 bool single_scan_success = false;
188 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
189 scan_capabilities_, wiphy_features_,
190 &client_interface_impl_, &netlink_utils_,
191 &scan_utils_, offload_service_utils_));
162 EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true)); 192 EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true));
163 EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), 193 EXPECT_TRUE(
164 &single_scan_success).isOk()); 194 scanner_impl_->scan(SingleScanSettings(), &single_scan_success).isOk());
165 EXPECT_TRUE(single_scan_success); 195 EXPECT_TRUE(single_scan_success);
166 196
167 EXPECT_CALL(scan_utils_, AbortScan(_)); 197 EXPECT_CALL(scan_utils_, AbortScan(_));
168 EXPECT_TRUE(netlink_scanner_->abortScan().isOk()); 198 EXPECT_TRUE(scanner_impl_->abortScan().isOk());
169} 199}
170 200
171TEST_F(ScannerTest, TestAbortScanNotIssuedIfNoOngoingScan) { 201TEST_F(ScannerTest, TestAbortScanNotIssuedIfNoOngoingScan) {
202 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
203 scan_capabilities_, wiphy_features_,
204 &client_interface_impl_, &netlink_utils_,
205 &scan_utils_, offload_service_utils_));
172 EXPECT_CALL(scan_utils_, AbortScan(_)).Times(0); 206 EXPECT_CALL(scan_utils_, AbortScan(_)).Times(0);
173 EXPECT_TRUE(netlink_scanner_->abortScan().isOk()); 207 EXPECT_TRUE(scanner_impl_->abortScan().isOk());
174} 208}
175 209
176TEST_F(ScannerTest, TestGetScanResults) { 210TEST_F(ScannerTest, TestGetScanResults) {
177 vector<NativeScanResult> scan_results; 211 vector<NativeScanResult> scan_results;
212 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
213 scan_capabilities_, wiphy_features_,
214 &client_interface_impl_, &netlink_utils_,
215 &scan_utils_, offload_service_utils_));
178 EXPECT_CALL(scan_utils_, GetScanResult(_, _)).WillOnce(Return(true)); 216 EXPECT_CALL(scan_utils_, GetScanResult(_, _)).WillOnce(Return(true));
179 EXPECT_TRUE(netlink_scanner_->getScanResults(&scan_results).isOk()); 217 EXPECT_TRUE(scanner_impl_->getScanResults(&scan_results).isOk());
180} 218}
181 219
182TEST_F(ScannerTest, TestStartPnoScanViaNetlink) { 220TEST_F(ScannerTest, TestStartPnoScanViaNetlink) {
183 bool success = false; 221 bool success = false;
222 EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported())
223 .Times(1)
224 .WillRepeatedly(Return(false));
225 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
226 scan_capabilities_, wiphy_features_,
227 &client_interface_impl_, &netlink_utils_,
228 &scan_utils_, offload_service_utils_));
184 EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)). 229 EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)).
185 WillOnce(Return(true)); 230 WillOnce(Return(true));
186 EXPECT_TRUE(netlink_scanner_->startPnoScan(PnoSettings(), &success).isOk()); 231 EXPECT_TRUE(scanner_impl_->startPnoScan(PnoSettings(), &success).isOk());
187 EXPECT_TRUE(success); 232 EXPECT_TRUE(success);
188} 233}
189 234
190TEST_F(ScannerTest, TestStopPnoScanViaNetlink) { 235TEST_F(ScannerTest, TestStopPnoScanViaNetlink) {
191 bool success = false; 236 bool success = false;
237 EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported())
238 .Times(1)
239 .WillRepeatedly(Return(false));
240 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
241 scan_capabilities_, wiphy_features_,
242 &client_interface_impl_, &netlink_utils_,
243 &scan_utils_, offload_service_utils_));
192 // StopScheduledScan() will be called no matter if there is an ongoing 244 // StopScheduledScan() will be called no matter if there is an ongoing
193 // scheduled scan or not. This is for making the system more robust. 245 // scheduled scan or not. This is for making the system more robust.
194 EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true)); 246 EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true));
195 EXPECT_TRUE(netlink_scanner_->stopPnoScan(&success).isOk()); 247 EXPECT_TRUE(scanner_impl_->stopPnoScan(&success).isOk());
248 EXPECT_TRUE(success);
249}
250
251TEST_F(ScannerTest, TestStartScanOverOffload) {
252 bool success = false;
253 EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported())
254 .Times(1)
255 .WillRepeatedly(Return(true));
256 EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _))
257 .Times(1)
258 .WillRepeatedly(Return(true));
259 EXPECT_CALL(*offload_scan_manager_, stopScan(_))
260 .Times(1)
261 .WillRepeatedly(Return(true));
262 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
263 scan_capabilities_, wiphy_features_,
264 &client_interface_impl_, &netlink_utils_,
265 &scan_utils_, offload_service_utils_));
266 scanner_impl_->startPnoScan(PnoSettings(), &success);
267 EXPECT_TRUE(success);
268 scanner_impl_->stopPnoScan(&success);
269 EXPECT_TRUE(success);
270}
271
272TEST_F(ScannerTest, TestStartScanOverNetlinkFallback) {
273 bool success = false;
274 ON_CALL(*offload_service_utils_, IsOffloadScanSupported())
275 .WillByDefault(Return(true));
276 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
277 scan_capabilities_, wiphy_features_,
278 &client_interface_impl_, &netlink_utils_,
279 &scan_utils_, offload_service_utils_));
280 EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _))
281 .WillOnce(Return(false));
282 EXPECT_CALL(*offload_scan_manager_, stopScan(_)).Times(0);
283 EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _))
284 .WillOnce(Return(true));
285 EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true));
286 EXPECT_TRUE(scanner_impl_->startPnoScan(PnoSettings(), &success).isOk());
287 EXPECT_TRUE(success == true);
288 scanner_impl_->stopPnoScan(&success);
289 EXPECT_TRUE(success);
290}
291
292TEST_F(ScannerTest, TestAsyncErrorOverOffload) {
293 bool success = false;
294 EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported())
295 .Times(1)
296 .WillRepeatedly(Return(true));
297 EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _))
298 .Times(1)
299 .WillRepeatedly(Return(true));
300 EXPECT_CALL(*offload_scan_manager_, stopScan(_))
301 .Times(1)
302 .WillRepeatedly(Return(true));
303 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
304 scan_capabilities_, wiphy_features_,
305 &client_interface_impl_, &netlink_utils_,
306 &scan_utils_, offload_service_utils_));
307 EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _))
308 .WillOnce(Return(true));
309 EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true));
310 scanner_impl_->startPnoScan(PnoSettings(), &success);
311 EXPECT_TRUE(success);
312 scanner_impl_->OnOffloadError(
313 OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE);
314 scanner_impl_->stopPnoScan(&success);
315 EXPECT_TRUE(success);
316}
317
318TEST_F(ScannerTest, TestGetScanResultsFromOffload) {
319 bool success = false;
320 EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported())
321 .Times(1)
322 .WillRepeatedly(Return(true));
323 EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _))
324 .Times(1)
325 .WillRepeatedly(Return(true));
326 EXPECT_CALL(*offload_scan_manager_, getScanResults(_))
327 .Times(1)
328 .WillOnce(
329 Invoke(bind(ReturnOffloadScanResults, _1, dummy_scan_results_)));
330 EXPECT_CALL(*offload_scan_manager_, stopScan(_))
331 .Times(1)
332 .WillRepeatedly(Return(true));
333 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
334 scan_capabilities_, wiphy_features_,
335 &client_interface_impl_, &netlink_utils_,
336 &scan_utils_, offload_service_utils_));
337 scanner_impl_->startPnoScan(PnoSettings(), &success);
338 EXPECT_TRUE(success);
339 scanner_impl_->OnOffloadScanResult();
340 std::vector<NativeScanResult> scan_results;
341 EXPECT_TRUE(scanner_impl_->getPnoScanResults(&scan_results).isOk());
342 EXPECT_FALSE(scan_results.empty());
343 scanner_impl_->stopPnoScan(&success);
344 EXPECT_TRUE(success);
345}
346
347TEST_F(ScannerTest, TestGetScanResultsWhenOffloadFails) {
348 bool success = false;
349 EXPECT_CALL(*offload_service_utils_, IsOffloadScanSupported())
350 .Times(1)
351 .WillRepeatedly(Return(true));
352 EXPECT_CALL(*offload_scan_manager_, startScan(_, _, _, _, _, _, _))
353 .Times(1)
354 .WillRepeatedly(Return(true));
355 EXPECT_CALL(*offload_scan_manager_, stopScan(_))
356 .Times(1)
357 .WillRepeatedly(Return(true));
358 EXPECT_CALL(*offload_scan_manager_, getScanResults(_)).Times(0);
359 EXPECT_CALL(scan_utils_, GetScanResult(_, _))
360 .Times(1)
361 .WillOnce(
362 Invoke(bind(ReturnNetlinkScanResults, _1, _2, dummy_scan_results_)));
363 scanner_impl_.reset(new ScannerImpl(kFakeWiphyIndex, kFakeInterfaceIndex,
364 scan_capabilities_, wiphy_features_,
365 &client_interface_impl_, &netlink_utils_,
366 &scan_utils_, offload_service_utils_));
367 EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _))
368 .WillOnce(Return(true));
369 EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true));
370 EXPECT_TRUE(scanner_impl_->startPnoScan(PnoSettings(), &success).isOk());
371 EXPECT_TRUE(success);
372 scanner_impl_->OnOffloadError(
373 OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE);
374 std::vector<NativeScanResult> scan_results;
375 EXPECT_TRUE(scanner_impl_->getPnoScanResults(&scan_results).isOk());
376 EXPECT_FALSE(scan_results.empty());
377 scanner_impl_->stopPnoScan(&success);
196 EXPECT_TRUE(success); 378 EXPECT_TRUE(success);
197} 379}
198 380