Loading tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +0 −9 Original line number Diff line number Diff line Loading @@ -24,8 +24,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.util.Log; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; Loading @@ -38,7 +36,6 @@ import com.android.launcher3.tapl.AppIconMenu; import com.android.launcher3.tapl.AppIconMenuItem; import com.android.launcher3.tapl.Widgets; import com.android.launcher3.tapl.Workspace; import com.android.launcher3.util.rule.TestStabilityRule.Stability; import com.android.launcher3.views.OptionsPopupView; import com.android.launcher3.widget.WidgetsFullSheet; import com.android.launcher3.widget.WidgetsRecyclerView; Loading Loading @@ -362,10 +359,4 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { public static String getAppPackageName() { return getInstrumentation().getContext().getPackageName(); } @Test @Stability public void testTestStabilityAttribute() { Log.d("TestStabilityRule", "Hello world!"); } } tests/src/com/android/launcher3/util/rule/TestStabilityRule.java +44 −16 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.util.rule; import static androidx.test.InstrumentationRegistry.getInstrumentation; import android.content.pm.PackageManager; import android.os.Build; import android.util.Log; Loading Loading @@ -50,20 +51,33 @@ public class TestStabilityRule implements TestRule { + "(?<postsubmit>[0-9]+)" + ")$"); public static final int LOCAL = 0x1; public static final int UNBUNDLED_PRESUBMIT = 0x2; public static final int UNBUNDLED_POSTSUBMIT = 0x4; public static final int PLATFORM_PRESUBMIT = 0x8; public static final int PLATFORM_POSTSUBMIT = 0x10; private static final int RUN_FLAFOR = getRunFlavor(); @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Stability { int flavors(); } @Override public Statement apply(Statement base, Description description) { if (description.getAnnotation(Stability.class) != null) { final Stability stability = description.getAnnotation(Stability.class); if (stability != null) { return new Statement() { @Override public void evaluate() throws Throwable { getRunFlavor(); if ((stability.flavors() & RUN_FLAFOR) != 0) { Log.d(TAG, "Running " + description.getDisplayName()); base.evaluate(); } else { Log.d(TAG, "Skipping " + description.getDisplayName()); } } }; } else { Loading @@ -71,8 +85,10 @@ public class TestStabilityRule implements TestRule { } } private static void getRunFlavor() throws Exception { final String launcherVersion = getInstrumentation(). private static int getRunFlavor() { final String launcherVersion; try { launcherVersion = getInstrumentation(). getContext(). getPackageManager(). getPackageInfo( Loading @@ -80,40 +96,52 @@ public class TestStabilityRule implements TestRule { getLauncherPackageName(), 0). versionName; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } final Matcher launcherBuildMatcher = LAUNCHER_BUILD.matcher(launcherVersion); if (!launcherBuildMatcher.find()) { Log.e(TAG, "Match not found"); throw new AssertionError("Launcher build match not found"); } final String platformVersion = Build.VERSION.INCREMENTAL; final Matcher platformBuildMatcher = PLATFORM_BUILD.matcher(platformVersion); if (!platformBuildMatcher.find()) { Log.e(TAG, "Match not found"); throw new AssertionError("Platform build match not found"); } Log.d(TAG, "Launcher: " + launcherVersion + ", platform: " + platformVersion); final int runFlavor; if (launcherBuildMatcher.group("local") != null && ( platformBuildMatcher.group("commandLine") != null || platformBuildMatcher.group("postsubmit") != null)) { Log.d(TAG, "LOCAL RUN"); runFlavor = LOCAL; } else if (launcherBuildMatcher.group("presubmit") != null && platformBuildMatcher.group("postsubmit") != null) { Log.d(TAG, "UNBUNDLED PRESUBMIT"); runFlavor = UNBUNDLED_PRESUBMIT; } else if (launcherBuildMatcher.group("postsubmit") != null && platformBuildMatcher.group("postsubmit") != null) { Log.d(TAG, "UNBUNDLED POSTSUBMIT"); runFlavor = UNBUNDLED_POSTSUBMIT; } else if (launcherBuildMatcher.group("platform") != null && platformBuildMatcher.group("presubmit") != null) { Log.d(TAG, "PLATFORM PRESUBMIT"); runFlavor = PLATFORM_PRESUBMIT; } else if (launcherBuildMatcher.group("platform") != null && platformBuildMatcher.group("postsubmit") != null) { Log.d(TAG, "PLATFORM POSTSUBMIT"); runFlavor = PLATFORM_POSTSUBMIT; } else { Log.e(TAG, "ERROR3"); throw new AssertionError("Unrecognized run flavor"); } return runFlavor; } } Loading
tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +0 −9 Original line number Diff line number Diff line Loading @@ -24,8 +24,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.util.Log; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; Loading @@ -38,7 +36,6 @@ import com.android.launcher3.tapl.AppIconMenu; import com.android.launcher3.tapl.AppIconMenuItem; import com.android.launcher3.tapl.Widgets; import com.android.launcher3.tapl.Workspace; import com.android.launcher3.util.rule.TestStabilityRule.Stability; import com.android.launcher3.views.OptionsPopupView; import com.android.launcher3.widget.WidgetsFullSheet; import com.android.launcher3.widget.WidgetsRecyclerView; Loading Loading @@ -362,10 +359,4 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { public static String getAppPackageName() { return getInstrumentation().getContext().getPackageName(); } @Test @Stability public void testTestStabilityAttribute() { Log.d("TestStabilityRule", "Hello world!"); } }
tests/src/com/android/launcher3/util/rule/TestStabilityRule.java +44 −16 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.util.rule; import static androidx.test.InstrumentationRegistry.getInstrumentation; import android.content.pm.PackageManager; import android.os.Build; import android.util.Log; Loading Loading @@ -50,20 +51,33 @@ public class TestStabilityRule implements TestRule { + "(?<postsubmit>[0-9]+)" + ")$"); public static final int LOCAL = 0x1; public static final int UNBUNDLED_PRESUBMIT = 0x2; public static final int UNBUNDLED_POSTSUBMIT = 0x4; public static final int PLATFORM_PRESUBMIT = 0x8; public static final int PLATFORM_POSTSUBMIT = 0x10; private static final int RUN_FLAFOR = getRunFlavor(); @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Stability { int flavors(); } @Override public Statement apply(Statement base, Description description) { if (description.getAnnotation(Stability.class) != null) { final Stability stability = description.getAnnotation(Stability.class); if (stability != null) { return new Statement() { @Override public void evaluate() throws Throwable { getRunFlavor(); if ((stability.flavors() & RUN_FLAFOR) != 0) { Log.d(TAG, "Running " + description.getDisplayName()); base.evaluate(); } else { Log.d(TAG, "Skipping " + description.getDisplayName()); } } }; } else { Loading @@ -71,8 +85,10 @@ public class TestStabilityRule implements TestRule { } } private static void getRunFlavor() throws Exception { final String launcherVersion = getInstrumentation(). private static int getRunFlavor() { final String launcherVersion; try { launcherVersion = getInstrumentation(). getContext(). getPackageManager(). getPackageInfo( Loading @@ -80,40 +96,52 @@ public class TestStabilityRule implements TestRule { getLauncherPackageName(), 0). versionName; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } final Matcher launcherBuildMatcher = LAUNCHER_BUILD.matcher(launcherVersion); if (!launcherBuildMatcher.find()) { Log.e(TAG, "Match not found"); throw new AssertionError("Launcher build match not found"); } final String platformVersion = Build.VERSION.INCREMENTAL; final Matcher platformBuildMatcher = PLATFORM_BUILD.matcher(platformVersion); if (!platformBuildMatcher.find()) { Log.e(TAG, "Match not found"); throw new AssertionError("Platform build match not found"); } Log.d(TAG, "Launcher: " + launcherVersion + ", platform: " + platformVersion); final int runFlavor; if (launcherBuildMatcher.group("local") != null && ( platformBuildMatcher.group("commandLine") != null || platformBuildMatcher.group("postsubmit") != null)) { Log.d(TAG, "LOCAL RUN"); runFlavor = LOCAL; } else if (launcherBuildMatcher.group("presubmit") != null && platformBuildMatcher.group("postsubmit") != null) { Log.d(TAG, "UNBUNDLED PRESUBMIT"); runFlavor = UNBUNDLED_PRESUBMIT; } else if (launcherBuildMatcher.group("postsubmit") != null && platformBuildMatcher.group("postsubmit") != null) { Log.d(TAG, "UNBUNDLED POSTSUBMIT"); runFlavor = UNBUNDLED_POSTSUBMIT; } else if (launcherBuildMatcher.group("platform") != null && platformBuildMatcher.group("presubmit") != null) { Log.d(TAG, "PLATFORM PRESUBMIT"); runFlavor = PLATFORM_PRESUBMIT; } else if (launcherBuildMatcher.group("platform") != null && platformBuildMatcher.group("postsubmit") != null) { Log.d(TAG, "PLATFORM POSTSUBMIT"); runFlavor = PLATFORM_POSTSUBMIT; } else { Log.e(TAG, "ERROR3"); throw new AssertionError("Unrecognized run flavor"); } return runFlavor; } }