cts(wifi): Disable scan throttling for tests with startScan
Scan throttling could lead to flaky tests. Bug: 152048238 Test: atest android.net.wifi.cts Change-Id: Id314da9238c592fcbfde448231bf86f3cf679e62
This commit is contained in:
@@ -34,6 +34,7 @@ import android.net.wifi.WifiManager.WifiLock;
|
||||
import android.platform.test.annotations.AppModeFull;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.compatibility.common.util.ShellIdentityUtils;
|
||||
import com.android.compatibility.common.util.SystemUtil;
|
||||
|
||||
@AppModeFull(reason = "Cannot get WifiManager in instant app mode")
|
||||
@@ -45,6 +46,8 @@ public class ScanResultTest extends AndroidTestCase {
|
||||
private WifiManager mWifiManager;
|
||||
private WifiLock mWifiLock;
|
||||
private static MySync mMySync;
|
||||
private boolean mWasVerboseLoggingEnabled;
|
||||
private boolean mWasScanThrottleEnabled;
|
||||
|
||||
private static final int STATE_NULL = 0;
|
||||
private static final int STATE_WIFI_CHANGING = 1;
|
||||
@@ -113,6 +116,18 @@ public class ScanResultTest extends AndroidTestCase {
|
||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||
mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
|
||||
assertThat(mWifiManager).isNotNull();
|
||||
|
||||
// turn on verbose logging for tests
|
||||
mWasVerboseLoggingEnabled = ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.isVerboseLoggingEnabled());
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setVerboseLoggingEnabled(true));
|
||||
// Disable scan throttling for tests.
|
||||
mWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.isScanThrottleEnabled());
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setScanThrottleEnabled(false));
|
||||
|
||||
mWifiLock = mWifiManager.createWifiLock(TAG);
|
||||
mWifiLock.acquire();
|
||||
if (!mWifiManager.isWifiEnabled())
|
||||
@@ -133,6 +148,10 @@ public class ScanResultTest extends AndroidTestCase {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
if (!mWifiManager.isWifiEnabled())
|
||||
setWifiEnabled(true);
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setScanThrottleEnabled(mWasScanThrottleEnabled));
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
|
||||
Thread.sleep(ENABLE_WAIT_MSEC);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ public class WifiManagerTest extends AndroidTestCase {
|
||||
private final Object mLock = new Object();
|
||||
private UiDevice mUiDevice;
|
||||
private boolean mWasVerboseLoggingEnabled;
|
||||
private boolean mWasScanThrottleEnabled;
|
||||
private SoftApConfiguration mOriginalSoftApConfig = null;
|
||||
|
||||
// Please refer to WifiManager
|
||||
@@ -278,6 +279,11 @@ public class WifiManagerTest extends AndroidTestCase {
|
||||
() -> mWifiManager.isVerboseLoggingEnabled());
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setVerboseLoggingEnabled(true));
|
||||
// Disable scan throttling for tests.
|
||||
mWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.isScanThrottleEnabled());
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setScanThrottleEnabled(false));
|
||||
|
||||
mWifiLock = mWifiManager.createWifiLock(TAG);
|
||||
mWifiLock.acquire();
|
||||
@@ -311,6 +317,8 @@ public class WifiManagerTest extends AndroidTestCase {
|
||||
setWifiEnabled(true);
|
||||
mWifiLock.release();
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setScanThrottleEnabled(mWasScanThrottleEnabled));
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
|
||||
// restore original softap config
|
||||
|
||||
@@ -71,6 +71,7 @@ public class WifiNetworkSpecifierTest extends AndroidTestCase {
|
||||
private final Object mUiLock = new Object();
|
||||
private WifiConfiguration mTestNetwork;
|
||||
private boolean mWasVerboseLoggingEnabled;
|
||||
private boolean mWasScanThrottleEnabled;
|
||||
|
||||
private static final int DURATION = 10_000;
|
||||
private static final int DURATION_UI_INTERACTION = 15_000;
|
||||
@@ -93,6 +94,11 @@ public class WifiNetworkSpecifierTest extends AndroidTestCase {
|
||||
() -> mWifiManager.isVerboseLoggingEnabled());
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setVerboseLoggingEnabled(true));
|
||||
// Disable scan throttling for tests.
|
||||
mWasScanThrottleEnabled = ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.isScanThrottleEnabled());
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setScanThrottleEnabled(false));
|
||||
|
||||
if (!mWifiManager.isWifiEnabled()) setWifiEnabled(true);
|
||||
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
@@ -126,6 +132,8 @@ public class WifiNetworkSpecifierTest extends AndroidTestCase {
|
||||
turnScreenOff();
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.enableNetwork(mTestNetwork.networkId, false));
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setScanThrottleEnabled(mWasScanThrottleEnabled));
|
||||
ShellIdentityUtils.invokeWithShellPermissions(
|
||||
() -> mWifiManager.setVerboseLoggingEnabled(mWasVerboseLoggingEnabled));
|
||||
super.tearDown();
|
||||
|
||||
Reference in New Issue
Block a user