Merge "[CTS] Skip the test appropriately" into stage-aosp-sc-ts-dev am: 70c384b122 am: b2b2a0126d am: 39ee1abaf9
Original change: https://googleplex-android-review.googlesource.com/c/platform/cts/+/15560888
Change-Id: I1eccf5da811eca0c626fcf4a2f9693112af34757
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyRestrictedWifiNetworkSuggestionTest.java b/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyRestrictedWifiNetworkSuggestionTest.java
index 55b7366..271035f 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyRestrictedWifiNetworkSuggestionTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/MultiStaConcurrencyRestrictedWifiNetworkSuggestionTest.java
@@ -76,6 +76,7 @@
private static boolean sWasVerboseLoggingEnabled;
private static boolean sWasScanThrottleEnabled;
private static boolean sWasWifiEnabled;
+ private static boolean sShouldRunTest = false;
private Context mContext;
private WifiManager mWifiManager;
@@ -96,6 +97,7 @@
// skip the test if WiFi is not supported or not automotive platform.
// Don't use assumeTrue in @BeforeClass
if (!WifiFeature.isWifiSupported(context)) return;
+ sShouldRunTest = true;
WifiManager wifiManager = context.getSystemService(WifiManager.class);
assertThat(wifiManager).isNotNull();
@@ -122,9 +124,9 @@
@AfterClass
public static void tearDownClass() throws Exception {
- Context context = InstrumentationRegistry.getInstrumentation().getContext();
- if (!WifiFeature.isWifiSupported(context)) return;
+ if (!sShouldRunTest) return;
+ Context context = InstrumentationRegistry.getInstrumentation().getContext();
WifiManager wifiManager = context.getSystemService(WifiManager.class);
assertThat(wifiManager).isNotNull();
@@ -138,6 +140,7 @@
@Before
public void setUp() throws Exception {
+ assumeTrue(sShouldRunTest);
mContext = InstrumentationRegistry.getInstrumentation().getContext();
mWifiManager = mContext.getSystemService(WifiManager.class);
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
@@ -199,6 +202,7 @@
@After
public void tearDown() throws Exception {
+ if (!sShouldRunTest) return;
// Re-enable networks.
ShellIdentityUtils.invokeWithShellPermissions(
() -> {
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
index 9eea9e5..600a545 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
@@ -184,6 +184,7 @@
private static boolean sWasVerboseLoggingEnabled;
private static boolean sWasScanThrottleEnabled;
private static WifiConfiguration sTestNetwork;
+ private static boolean sShouldRunTest = false;
private Context mContext;
private WifiManager mWifiManager;
@@ -199,6 +200,7 @@
Context context = InstrumentationRegistry.getInstrumentation().getContext();
// skip the test if WiFi is not supported
if (!WifiFeature.isWifiSupported(context)) return;
+ sShouldRunTest = true;
WifiManager wifiManager = context.getSystemService(WifiManager.class);
assertThat(wifiManager).isNotNull();
@@ -251,9 +253,9 @@
@AfterClass
public static void tearDownClass() throws Exception {
- Context context = InstrumentationRegistry.getInstrumentation().getContext();
- if (!WifiFeature.isWifiSupported(context)) return;
+ if (!sShouldRunTest) return;
+ Context context = InstrumentationRegistry.getInstrumentation().getContext();
WifiManager wifiManager = context.getSystemService(WifiManager.class);
assertThat(wifiManager).isNotNull();
@@ -272,6 +274,7 @@
@Before
public void setUp() throws Exception {
+ assumeTrue(sShouldRunTest);
mContext = InstrumentationRegistry.getInstrumentation().getContext();
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
@@ -302,6 +305,7 @@
@After
public void tearDown() throws Exception {
+ if (!sShouldRunTest) return;
// If there is failure, ensure we unregister the previous request.
if (mNrNetworkCallback != null) {
mConnectivityManager.unregisterNetworkCallback(mNrNetworkCallback);
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSuggestionTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSuggestionTest.java
index 5d80467..5e54e9b 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSuggestionTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSuggestionTest.java
@@ -97,6 +97,7 @@
private static boolean sWasVerboseLoggingEnabled;
private static boolean sWasScanThrottleEnabled;
private static boolean sWasWifiEnabled;
+ private static boolean sShouldRunTest = false;
private static Context sContext;
private static WifiManager sWifiManager;
@@ -120,6 +121,7 @@
if (!sContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION)) return;
// skip if the location is disabled
if (!sContext.getSystemService(LocationManager.class).isLocationEnabled()) return;
+ sShouldRunTest = true;
sWifiManager = sContext.getSystemService(WifiManager.class);
assertThat(sWifiManager).isNotNull();
@@ -172,7 +174,7 @@
@AfterClass
public static void tearDownClass() throws Exception {
- if (!WifiFeature.isWifiSupported(sContext)) return;
+ if (!sShouldRunTest) return;
ShellIdentityUtils.invokeWithShellPermissions(
() -> sWifiManager.setScanThrottleEnabled(sWasScanThrottleEnabled));
@@ -192,6 +194,7 @@
@Before
public void setUp() throws Exception {
+ assumeTrue(sShouldRunTest);
mExecutorService = Executors.newSingleThreadScheduledExecutor();
// turn screen on
sTestHelper.turnScreenOn();
@@ -215,6 +218,7 @@
@After
public void tearDown() throws Exception {
+ if (!sShouldRunTest) return;
// Release the requests after the test.
if (sNsNetworkCallback != null) {
sConnectivityManager.unregisterNetworkCallback(sNsNetworkCallback);