diff options
author | mukesh agrawal <quiche@google.com> | 2018-03-05 17:09:44 -0800 |
---|---|---|
committer | mukesh agrawal <quiche@google.com> | 2018-03-06 17:55:07 -0800 |
commit | f0adc273f23fe6cb06fdc92f3c2b9b7961b62b5b (patch) | |
tree | 270820e9199dd24db6fdae2ba7cc2cc400098328 /tests | |
parent | 34226fdc35f33a5c3a95e0b86138c933c5682370 (diff) |
WificondScannerTest: fix some spurious timer actions
There are some scenarios where we might attempt to
cancel a timer that has already been cancelled. This
CL addresses two of those scenarios:
1. An external program (e.g. wpa_supplicant) triggers
a scan. When those scan results arrive, we would
attempt to cancel our scan timeout.
But that wouldn't make sense, since we didn't have
a scan running. And, since we didn't have a scan
running, there was no timer set.
2. It is theoretically possible for the scan timeout
to race against the scan results. If the results
arrive after the timeout, there is no running
timer. So a timer cancellation in this case
would be spurious.
By addressing these spurious cancellations, we
reduce log spam of the following form:
02-25 20:08:25.255 991 1832 W AlarmManager: Unrecognized alarm listener com.android.server.wifi.scanner.WificondScannerImpl$1@6f30de8
While there: eliminate some error-prone warnings
- MissingOverride for onAlarm()
- MissingOverride for run()
- ShortCircuitBoolean in isHwPnoScanRequired()
Bug: 74085128
Test: tests/wifitests/runtests.sh (on walleye)
Test: m javac-check-wifi-service RUN_ERROR_PRONE=true 2>&1 \
| (grep WificondScannerImpl && echo FAIL)
Change-Id: I459abe3847cd73a4e1f4180f05e7805b354134b5
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/HalWifiScannerTest.java | 2 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java | 73 |
2 files changed, 74 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/HalWifiScannerTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/HalWifiScannerTest.java index f9d6f4522..fc6e41778 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/HalWifiScannerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/HalWifiScannerTest.java @@ -37,4 +37,6 @@ public class HalWifiScannerTest extends BaseWifiScannerImplTest { mScanner = new HalWifiScannerImpl(mContext, BaseWifiScannerImplTest.IFACE_NAME, mWifiNative, mWifiMonitor, mLooper.getLooper(), mClock); } + + // Subtle: tests are inherited from base class. } diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java index 61e633fb2..d398a9a35 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java @@ -22,9 +22,13 @@ import static com.android.server.wifi.ScanTestUtil.setupMockChannels; import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import android.app.AlarmManager; +import android.app.PendingIntent; import android.net.wifi.WifiScanner; import android.support.test.filters.SmallTest; +import com.android.server.wifi.ScanResults; +import com.android.server.wifi.WifiMonitor; import com.android.server.wifi.WifiNative; import com.android.server.wifi.scanner.ChannelHelper.ChannelCollection; @@ -34,6 +38,7 @@ import org.junit.Test; import java.io.FileDescriptor; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -87,6 +92,73 @@ public class WificondScannerTest extends BaseWifiScannerImplTest { verify(eventHandler).onScanStatus(WifiNative.WIFI_SCAN_FAILED); } + @Test + public void externalScanResultsDoNotCauseSpuriousTimerCancellationOrCrash() { + mWifiMonitor.sendMessage(IFACE_NAME, WifiMonitor.SCAN_RESULTS_EVENT); + mLooper.dispatchAll(); + verify(mAlarmManager.getAlarmManager(), never()).cancel(any(PendingIntent.class)); + verify(mAlarmManager.getAlarmManager(), never()) + .cancel(any(AlarmManager.OnAlarmListener.class)); + verify(mAlarmManager.getAlarmManager(), never()).cancel(isNull(PendingIntent.class)); + verify(mAlarmManager.getAlarmManager(), never()) + .cancel(isNull(AlarmManager.OnAlarmListener.class)); + } + + @Test + public void externalScanResultsAfterOurScanDoNotCauseSpuriousTimerCancellationOrCrash() { + WifiNative.ScanSettings settings = new NativeScanSettingsBuilder() + .withBasePeriod(10000) // ms + .withMaxApPerScan(10) + .addBucketWithBand(10000 /* ms */, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN, + WifiScanner.WIFI_BAND_24_GHZ) + .build(); + + doSuccessfulSingleScanTest(settings, + expectedBandScanFreqs(WifiScanner.WIFI_BAND_24_GHZ), + new HashSet<String>(), + ScanResults.create(0, isAllChannelsScanned(WifiScanner.WIFI_BAND_24_GHZ), + 2400, 2450, 2450, 2400, 2450, 2450, 2400, 2450, 2450), false); + + mWifiMonitor.sendMessage(IFACE_NAME, WifiMonitor.SCAN_RESULTS_EVENT); + mLooper.dispatchAll(); + verify(mAlarmManager.getAlarmManager(), never()).cancel(any(PendingIntent.class)); + verify(mAlarmManager.getAlarmManager(), times(1)) + .cancel(any(AlarmManager.OnAlarmListener.class)); + verify(mAlarmManager.getAlarmManager(), never()).cancel(isNull(PendingIntent.class)); + verify(mAlarmManager.getAlarmManager(), never()) + .cancel(isNull(AlarmManager.OnAlarmListener.class)); + } + + @Test + public void lateScanResultsDoNotCauseSpuriousTimerCancellationOrCrash() { + WifiNative.ScanSettings settings = new NativeScanSettingsBuilder() + .withBasePeriod(10000) // ms + .withMaxApPerScan(10) + .addBucketWithBand(10000 /* ms */, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN, + WifiScanner.WIFI_BAND_24_GHZ) + .build(); + + // Kick off a scan + when(mWifiNative.scan(eq(IFACE_NAME), anyInt(), any(), any(Set.class))).thenReturn(true); + WifiNative.ScanEventHandler eventHandler = mock(WifiNative.ScanEventHandler.class); + assertTrue(mScanner.startSingleScan(settings, eventHandler)); + mLooper.dispatchAll(); + + // Report a timeout + mAlarmManager.dispatch(WificondScannerImpl.TIMEOUT_ALARM_TAG); + mLooper.dispatchAll(); + + // Now report scan results (results lost the race with timeout) + mWifiMonitor.sendMessage(IFACE_NAME, WifiMonitor.SCAN_RESULTS_EVENT); + mLooper.dispatchAll(); + + verify(mAlarmManager.getAlarmManager(), never()).cancel(any(PendingIntent.class)); + verify(mAlarmManager.getAlarmManager(), never()) + .cancel(any(AlarmManager.OnAlarmListener.class)); + verify(mAlarmManager.getAlarmManager(), never()).cancel(isNull(PendingIntent.class)); + verify(mAlarmManager.getAlarmManager(), never()) + .cancel(isNull(AlarmManager.OnAlarmListener.class)); + } /** * Test that dump() of WificondScannerImpl dumps native scan results. @@ -109,5 +181,4 @@ public class WificondScannerTest extends BaseWifiScannerImplTest { new String[0]); return stringWriter.toString(); } - } |