Loading tests/BinaryTransparencyHostTest/src/android/transparency/test/BinaryTransparencyHostTest.java +52 −29 Original line number Diff line number Diff line Loading @@ -16,17 +16,20 @@ package android.transparency.test; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; import com.android.tradefed.testtype.junit4.DeviceTestRunOptions; import com.android.tradefed.util.CommandResult; import com.android.tradefed.util.CommandStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -40,12 +43,11 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { private static final String JOB_ID = "1740526926"; /** Waiting time for the job to be scheduled */ private static final int JOB_CREATION_MAX_SECONDS = 5; private static final int JOB_CREATION_MAX_SECONDS = 30; @After public void tearDown() throws Exception { uninstallPackage("com.android.egg"); uninstallRebootlessApex(); @Before public void setUp() throws Exception { cancelPendingJob(); } @Test Loading @@ -68,35 +70,41 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { @Test public void testCollectAllUpdatedPreloadInfo() throws Exception { installPackage("EasterEgg.apk"); try { updatePreloadApp(); runDeviceTest("testCollectAllUpdatedPreloadInfo"); } finally { // No need to wait until job complete, since we can't verifying very meaningfully. cancelPendingJob(); uninstallPackage("com.android.egg"); } } @Test public void testRebootlessApexUpdateTriggersJobScheduling() throws Exception { cancelPendingJob(); try { installRebootlessApex(); // Verify expectJobToBeScheduled(); // Just cancel since we can't verifying very meaningfully. cancelPendingJob(); } finally { // No need to wait until job complete, since we can't verifying very meaningfully. uninstallRebootlessApexThenReboot(); } } @Test public void testPreloadUpdateTriggersJobScheduling() throws Exception { cancelPendingJob(); installPackage("EasterEgg.apk"); try { updatePreloadApp(); // Verify expectJobToBeScheduled(); // Just cancel since we can't verifying very meaningfully. } finally { // No need to wait until job complete, since we can't verifying very meaningfully. cancelPendingJob(); uninstallPackage("com.android.egg"); } @Test public void testMeasureMbas() throws Exception { // TODO(265244016): figure out a way to install an MBA } private void runDeviceTest(String method) throws DeviceNotAvailableException { Loading @@ -109,7 +117,11 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { private void cancelPendingJob() throws DeviceNotAvailableException { CommandResult result = getDevice().executeShellV2Command( "cmd jobscheduler cancel android " + JOB_ID); assertTrue(result.getStatus() == CommandStatus.SUCCESS); if (result.getStatus() == CommandStatus.SUCCESS) { CLog.d("Canceling, output: " + result.getStdout()); } else { CLog.d("Something went wrong, error: " + result.getStderr()); } } private void expectJobToBeScheduled() throws Exception { Loading @@ -117,6 +129,7 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { CommandResult result = getDevice().executeShellV2Command( "cmd jobscheduler get-job-state android " + JOB_ID); String state = result.getStdout().toString(); CLog.i("Job status: " + state); if (state.startsWith("unknown")) { // The job hasn't been scheduled yet. So try again. TimeUnit.SECONDS.sleep(1); Loading @@ -134,7 +147,7 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { installPackage("com.android.apex.cts.shim.v2_rebootless.apex", "--force-non-staged"); } private void uninstallRebootlessApex() throws DeviceNotAvailableException { private void uninstallRebootlessApexThenReboot() throws DeviceNotAvailableException { // Reboot only if the APEX is not the pre-install one. CommandResult result = getDevice().executeShellV2Command( "pm list packages -f --apex-only |grep com.android.apex.cts.shim"); Loading @@ -148,4 +161,14 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { assertTrue(runResult.getStatus() == CommandStatus.SUCCESS); } } private void updatePreloadApp() throws DeviceNotAvailableException { CommandResult result = getDevice().executeShellV2Command("pm path com.android.egg"); assertTrue(result.getStatus() == CommandStatus.SUCCESS); assertThat(result.getStdout()).startsWith("package:/system/app/"); String path = result.getStdout().replaceFirst("^package:", ""); result = getDevice().executeShellV2Command("pm install " + path); assertTrue(result.getStatus() == CommandStatus.SUCCESS); } } tests/BinaryTransparencyHostTest/test-app/src/android/transparency/test/app/BinaryTransparencyTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.HashSet; import java.util.HexFormat; import java.util.stream.Collectors; Loading @@ -56,11 +57,12 @@ public class BinaryTransparencyTest { assertThat(args).isNotNull(); int number = Integer.valueOf(args.getString("apex-number")); assertThat(number).isGreaterThan(0); var expectedApexNames = new HashSet<String>(); var expectedApexNames = new ArrayList<String>(); for (var i = 0; i < number; i++) { String moduleName = args.getString("apex-" + Integer.toString(i)); expectedApexNames.add(moduleName); } assertThat(expectedApexNames).containsNoDuplicates(); // Action var apexInfoList = mBt.collectAllApexInfo(/* includeTestOnly */ true); Loading Loading
tests/BinaryTransparencyHostTest/src/android/transparency/test/BinaryTransparencyHostTest.java +52 −29 Original line number Diff line number Diff line Loading @@ -16,17 +16,20 @@ package android.transparency.test; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; import com.android.tradefed.testtype.junit4.DeviceTestRunOptions; import com.android.tradefed.util.CommandResult; import com.android.tradefed.util.CommandStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -40,12 +43,11 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { private static final String JOB_ID = "1740526926"; /** Waiting time for the job to be scheduled */ private static final int JOB_CREATION_MAX_SECONDS = 5; private static final int JOB_CREATION_MAX_SECONDS = 30; @After public void tearDown() throws Exception { uninstallPackage("com.android.egg"); uninstallRebootlessApex(); @Before public void setUp() throws Exception { cancelPendingJob(); } @Test Loading @@ -68,35 +70,41 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { @Test public void testCollectAllUpdatedPreloadInfo() throws Exception { installPackage("EasterEgg.apk"); try { updatePreloadApp(); runDeviceTest("testCollectAllUpdatedPreloadInfo"); } finally { // No need to wait until job complete, since we can't verifying very meaningfully. cancelPendingJob(); uninstallPackage("com.android.egg"); } } @Test public void testRebootlessApexUpdateTriggersJobScheduling() throws Exception { cancelPendingJob(); try { installRebootlessApex(); // Verify expectJobToBeScheduled(); // Just cancel since we can't verifying very meaningfully. cancelPendingJob(); } finally { // No need to wait until job complete, since we can't verifying very meaningfully. uninstallRebootlessApexThenReboot(); } } @Test public void testPreloadUpdateTriggersJobScheduling() throws Exception { cancelPendingJob(); installPackage("EasterEgg.apk"); try { updatePreloadApp(); // Verify expectJobToBeScheduled(); // Just cancel since we can't verifying very meaningfully. } finally { // No need to wait until job complete, since we can't verifying very meaningfully. cancelPendingJob(); uninstallPackage("com.android.egg"); } @Test public void testMeasureMbas() throws Exception { // TODO(265244016): figure out a way to install an MBA } private void runDeviceTest(String method) throws DeviceNotAvailableException { Loading @@ -109,7 +117,11 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { private void cancelPendingJob() throws DeviceNotAvailableException { CommandResult result = getDevice().executeShellV2Command( "cmd jobscheduler cancel android " + JOB_ID); assertTrue(result.getStatus() == CommandStatus.SUCCESS); if (result.getStatus() == CommandStatus.SUCCESS) { CLog.d("Canceling, output: " + result.getStdout()); } else { CLog.d("Something went wrong, error: " + result.getStderr()); } } private void expectJobToBeScheduled() throws Exception { Loading @@ -117,6 +129,7 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { CommandResult result = getDevice().executeShellV2Command( "cmd jobscheduler get-job-state android " + JOB_ID); String state = result.getStdout().toString(); CLog.i("Job status: " + state); if (state.startsWith("unknown")) { // The job hasn't been scheduled yet. So try again. TimeUnit.SECONDS.sleep(1); Loading @@ -134,7 +147,7 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { installPackage("com.android.apex.cts.shim.v2_rebootless.apex", "--force-non-staged"); } private void uninstallRebootlessApex() throws DeviceNotAvailableException { private void uninstallRebootlessApexThenReboot() throws DeviceNotAvailableException { // Reboot only if the APEX is not the pre-install one. CommandResult result = getDevice().executeShellV2Command( "pm list packages -f --apex-only |grep com.android.apex.cts.shim"); Loading @@ -148,4 +161,14 @@ public final class BinaryTransparencyHostTest extends BaseHostJUnit4Test { assertTrue(runResult.getStatus() == CommandStatus.SUCCESS); } } private void updatePreloadApp() throws DeviceNotAvailableException { CommandResult result = getDevice().executeShellV2Command("pm path com.android.egg"); assertTrue(result.getStatus() == CommandStatus.SUCCESS); assertThat(result.getStdout()).startsWith("package:/system/app/"); String path = result.getStdout().replaceFirst("^package:", ""); result = getDevice().executeShellV2Command("pm install " + path); assertTrue(result.getStatus() == CommandStatus.SUCCESS); } }
tests/BinaryTransparencyHostTest/test-app/src/android/transparency/test/app/BinaryTransparencyTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.HashSet; import java.util.HexFormat; import java.util.stream.Collectors; Loading @@ -56,11 +57,12 @@ public class BinaryTransparencyTest { assertThat(args).isNotNull(); int number = Integer.valueOf(args.getString("apex-number")); assertThat(number).isGreaterThan(0); var expectedApexNames = new HashSet<String>(); var expectedApexNames = new ArrayList<String>(); for (var i = 0; i < number; i++) { String moduleName = args.getString("apex-" + Integer.toString(i)); expectedApexNames.add(moduleName); } assertThat(expectedApexNames).containsNoDuplicates(); // Action var apexInfoList = mBt.collectAllApexInfo(/* includeTestOnly */ true); Loading