From e1ebbceea0832f2b6e4e30e84ec4ea1ff84762e4 Mon Sep 17 00:00:00 2001 From: Isaac Chiou Date: Fri, 12 Apr 2019 12:03:45 +0800 Subject: WifiDiagnostics: Collect logs when detecting fatal firmware alert When detecting fatal firmware alert, flushing HAL ring buffer to files Bug: 114766171 Test: Manual test Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I687efca90c25d8d9de224b6b2e426294cae1f0f1 --- .../src/com/android/server/wifi/MockResources.java | 15 +++++++++++++ .../android/server/wifi/WifiDiagnosticsTest.java | 26 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/MockResources.java b/tests/wifitests/src/com/android/server/wifi/MockResources.java index 1a061e22a..dd4413228 100644 --- a/tests/wifitests/src/com/android/server/wifi/MockResources.java +++ b/tests/wifitests/src/com/android/server/wifi/MockResources.java @@ -24,12 +24,14 @@ public class MockResources extends android.test.mock.MockResources { private HashMap mIntegerValues; private HashMap mStringValues; private HashMap mTextValues; + private HashMap mIntArrayValues; public MockResources() { mBooleanValues = new HashMap(); mIntegerValues = new HashMap(); mStringValues = new HashMap(); mTextValues = new HashMap(); + mIntArrayValues = new HashMap(); } @Override @@ -68,6 +70,15 @@ public class MockResources extends android.test.mock.MockResources { } } + @Override + public int[] getIntArray(int id) { + if (mIntArrayValues.containsKey(id)) { + return mIntArrayValues.get(id); + } else { + return null; + } + } + public void setBoolean(int id, boolean value) { mBooleanValues.put(id, value); } @@ -83,4 +94,8 @@ public class MockResources extends android.test.mock.MockResources { public void setText(int id, CharSequence value) { mTextValues.put(id, value); } + + public void setIntArray(int id, int[] value) { + mIntArrayValues.put(id, value); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java index 1c33d3920..6b63137a2 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java @@ -79,6 +79,10 @@ public class WifiDiagnosticsTest { private static final int BYTES_PER_KBYTE = 1024; private static final int ALERT_REASON_CODE = 1; private static final byte[] ALERT_DATA = {0 , 4, 5}; + /** Mock resource for fatal firmware alert list */ + private static final int[] FATAL_FW_ALART_LIST = {256, 257, 258}; + /** Mock a non fatal firmware alert */ + private static final int NON_FATAL_FW_ALART = 0; private WifiNative.RingBufferStatus mFakeRbs; /** @@ -117,6 +121,8 @@ public class WifiDiagnosticsTest { SMALL_RING_BUFFER_SIZE_KB); resources.setInteger(R.integer.config_wifi_logger_ring_buffer_verbose_size_limit_kb, LARGE_RING_BUFFER_SIZE_KB); + resources.setIntArray(R.array.config_wifi_fatal_firmware_alert_error_code_list, + FATAL_FW_ALART_LIST); when(mContext.getResources()).thenReturn(resources); when(mWifiInjector.makeLog(anyString())).thenReturn(mLog); when(mWifiInjector.getJavaRuntime()).thenReturn(mJavaRuntime); @@ -864,4 +870,24 @@ public class WifiDiagnosticsTest { mWifiDiagnostics.captureBugReportData(WifiDiagnostics.REPORT_REASON_NONE); verify(mWifiNative).flushRingBufferData(); } + + /** Verifies that we flush HAL ringbuffer when detecting fatal firmware alert. */ + @Test + public void captureAlertFlushRingBufferData() { + when(mBuildProperties.isUserBuild()).thenReturn(false); + when(mWifiNative.flushRingBufferData()).thenReturn(true); + /** captureAlertData with mock fatal firmware alert*/ + mWifiDiagnostics.captureAlertData(FATAL_FW_ALART_LIST[0], ALERT_DATA); + verify(mWifiNative).flushRingBufferData(); + } + + /** Verifies that we don't flush HAL ringbuffer when detecting non fatal firmware alert. */ + @Test + public void captureNonAlertFlushRingBufferData() { + when(mBuildProperties.isUserBuild()).thenReturn(false); + when(mWifiNative.flushRingBufferData()).thenReturn(true); + /** captureAlertData with mock non fatal firmware alert*/ + mWifiDiagnostics.captureAlertData(NON_FATAL_FW_ALART, ALERT_DATA); + verify(mWifiNative, never()).flushRingBufferData(); + } } -- cgit v1.2.3