diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2016-04-21 01:35:28 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-04-21 01:35:28 +0000 |
commit | 0b775f08887d4d52e57a06c6a8680aa10a1c7bb8 (patch) | |
tree | 6ad42c75b93c4097e59a10af1d4fbd072b0f329c /tests | |
parent | de68b305e798943904671f1dd56413b51fc479cb (diff) | |
parent | 956fd40b6145c4aba9160e10bfc1ea609873ce8d (diff) |
Merge "WifiLogger: fix bug in HAL callback registration" into nyc-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java index 64bb880fe..357818e9a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -83,6 +84,48 @@ public class WifiLoggerTest { mWifiNative.enableVerboseLogging(0); } + /** Verifies that startLogging() registers a logging event handler. */ + @Test + public void startLoggingRegistersLogEventHandler() throws Exception { + final boolean verbosityToggle = false; // even default mode wants log events from HAL + mWifiLogger.startLogging(verbosityToggle); + verify(mWifiNative).setLoggingEventHandler(anyObject()); + } + + /** + * Verifies that a failure to set the logging event handler does not prevent a future + * startLogging() from setting the logging event handler. + */ + @Test + public void startLoggingRegistersLogEventHandlerIfPriorAttemptFailed() + throws Exception { + final boolean verbosityToggle = false; // even default mode wants log events from HAL + + when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(false); + mWifiLogger.startLogging(verbosityToggle); + verify(mWifiNative).setLoggingEventHandler(anyObject()); + reset(mWifiNative); + + when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true); + mWifiLogger.startLogging(verbosityToggle); + verify(mWifiNative).setLoggingEventHandler(anyObject()); + } + + /** Verifies that startLogging() does not make redundant calls to setLoggingEventHandler(). */ + @Test + public void startLoggingDoesNotRegisterLogEventHandlerIfPriorAttemptSucceeded() + throws Exception { + final boolean verbosityToggle = false; // even default mode wants log events from HAL + + when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true); + mWifiLogger.startLogging(verbosityToggle); + verify(mWifiNative).setLoggingEventHandler(anyObject()); + reset(mWifiNative); + + mWifiLogger.startLogging(verbosityToggle); + verify(mWifiNative, never()).setLoggingEventHandler(anyObject()); + } + /** * Verifies that startLogging() restarts HAL ringbuffers. * @@ -102,6 +145,45 @@ public class WifiLoggerTest { eq(FAKE_RING_BUFFER_NAME)); } + /** Verifies that, if a log handler was registered, then stopLogging() resets it. */ + @Test + public void stopLoggingResetsLogHandlerIfHandlerWasRegistered() throws Exception { + final boolean verbosityToggle = false; // even default mode wants log events from HAL + + when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true); + mWifiLogger.startLogging(verbosityToggle); + reset(mWifiNative); + + mWifiLogger.stopLogging(); + verify(mWifiNative).resetLogHandler(); + } + + /** Verifies that, if a log handler is not registered, stopLogging() skips resetLogHandler(). */ + @Test + public void stopLoggingOnlyResetsLogHandlerIfHandlerWasRegistered() throws Exception { + final boolean verbosityToggle = false; // even default mode wants log events from HAL + mWifiLogger.stopLogging(); + verify(mWifiNative, never()).resetLogHandler(); + } + + /** Verifies that stopLogging() remembers that we've reset the log handler. */ + @Test + public void multipleStopLoggingCallsOnlyResetLogHandlerOnce() throws Exception { + final boolean verbosityToggle = false; // even default mode wants log events from HAL + + when(mWifiNative.setLoggingEventHandler(anyObject())).thenReturn(true); + mWifiLogger.startLogging(verbosityToggle); + reset(mWifiNative); + + when(mWifiNative.resetLogHandler()).thenReturn(true); + mWifiLogger.stopLogging(); + verify(mWifiNative).resetLogHandler(); + reset(mWifiNative); + + mWifiLogger.stopLogging(); + verify(mWifiNative, never()).resetLogHandler(); + } + /** * Verifies that we capture ring-buffer data. */ |