diff options
| author | Yuexi Ma <yuexima@google.com> | 2021-06-23 11:10:22 -0700 |
|---|---|---|
| committer | Yuexi Ma <yuexima@google.com> | 2021-06-23 11:10:22 -0700 |
| commit | 4683f71db21776c06789a378fe2795d328acd356 (patch) | |
| tree | 329700caaa9bb800db946cb67b789cc8eb9a202c | |
| parent | 2e7b54eaafd5144d10f4dd27a2886283d9711f93 (diff) | |
| download | platform_test_app_compat_csuite-4683f71db21776c06789a378fe2795d328acd356.tar.gz platform_test_app_compat_csuite-4683f71db21776c06789a378fe2795d328acd356.tar.bz2 platform_test_app_compat_csuite-4683f71db21776c06789a378fe2795d328acd356.zip | |
Collect GMS core version information in launch tests
Add an option to collect the GMS core version name and version code in launch tests.
Test: atest csuite-harness-tests
Change-Id: I8226e4c9cb64ff869101203f6fa5607c62ba8925
| -rw-r--r-- | harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java | 27 | ||||
| -rw-r--r-- | harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java | 19 |
2 files changed, 46 insertions, 0 deletions
diff --git a/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java b/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java index 46e2844..6b5d183 100644 --- a/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java +++ b/harness/src/main/java/com/android/compatibility/testtype/AppLaunchTest.java @@ -61,6 +61,8 @@ public class AppLaunchTest implements IDeviceTest, IRemoteTest, IConfigurationReceiver, ITestFilterReceiver { @VisibleForTesting static final String SCREENSHOT_AFTER_LAUNCH = "screenshot-after-launch"; @VisibleForTesting static final String COLLECT_APP_VERSION = "collect-app-version"; + @VisibleForTesting static final String COLLECT_GMS_VERSION = "collect-gms-version"; + @VisibleForTesting static final String GMS_PACKAGE_NAME = "com.google.android.gms"; @Option( name = SCREENSHOT_AFTER_LAUNCH, @@ -74,6 +76,13 @@ public class AppLaunchTest + " test log files.") private boolean mCollectAppVersion; + @Option( + name = COLLECT_GMS_VERSION, + description = + "Whether to collect GMS core version information and store the information in" + + " test log files.") + private boolean mCollectGmsVersion; + @Option(name = "package-name", description = "Package name of testing app.") private String mPackageName; @@ -248,6 +257,24 @@ public class AppLaunchTest throw e; } } + + if (mCollectGmsVersion) { + String gmsVersionCode = + DeviceUtils.getPackageVersionCode(mDevice, GMS_PACKAGE_NAME); + String gmsVersionName = + DeviceUtils.getPackageVersionName(mDevice, GMS_PACKAGE_NAME); + CLog.i( + "GMS core versionCode=%s, versionName=%s", + mPackageName, gmsVersionCode, gmsVersionName); + listener.testLog( + String.format("%s_[GMS_versionCode=%s]", mPackageName, gmsVersionCode), + LogDataType.TEXT, + new ByteArrayInputStreamSource(gmsVersionCode.getBytes())); + listener.testLog( + String.format("%s_[GMS_versionName=%s]", mPackageName, gmsVersionName), + LogDataType.TEXT, + new ByteArrayInputStreamSource(gmsVersionName.getBytes())); + } } finally { reportResult(listener, testDescription, result); stopPackage(); diff --git a/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java b/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java index de60a7b..26facb0 100644 --- a/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java +++ b/harness/src/test/java/com/android/compatibility/testtype/AppLaunchTestTest.java @@ -121,6 +121,25 @@ public final class AppLaunchTestTest { } @Test + public void run_collectGmsVersion_savesToTestLog() throws Exception { + InstrumentationTest instrumentationTest = createPassingInstrumentationTest(); + AppLaunchTest appLaunchTest = createLaunchTestWithInstrumentation(instrumentationTest); + new OptionSetter(appLaunchTest).setOptionValue(AppLaunchTest.COLLECT_GMS_VERSION, "true"); + ITestDevice mockDevice = mock(ITestDevice.class); + appLaunchTest.setDevice(mockDevice); + when(mockDevice.executeShellV2Command( + Mockito.startsWith("dumpsys package " + AppLaunchTest.GMS_PACKAGE_NAME))) + .thenReturn(createSuccessfulCommandResult()); + + appLaunchTest.run(NULL_TEST_INFORMATION, mMockListener); + + Mockito.verify(mMockListener, times(1)) + .testLog(Mockito.contains("GMS_versionCode"), Mockito.any(), Mockito.any()); + Mockito.verify(mMockListener, times(1)) + .testLog(Mockito.contains("GMS_versionName"), Mockito.any(), Mockito.any()); + } + + @Test public void run_packageResetSuccess() throws DeviceNotAvailableException { ITestDevice mMockDevice = mock(ITestDevice.class); when(mMockDevice.executeShellV2Command(String.format("pm clear %s", TEST_PACKAGE_NAME))) |
