OSDN Git Service

Wait for broadcast queue to become idle between test runs
authorFyodor Kupolov <fkupolov@google.com>
Thu, 5 Oct 2017 19:46:21 +0000 (12:46 -0700)
committerFyodor Kupolov <fkupolov@google.com>
Thu, 5 Oct 2017 21:26:00 +0000 (14:26 -0700)
Test: bit MultiUserPerfTests:android.multiuser.UserLifecycleTests
Bug: 64165549
Change-Id: I593885d737fab1ef717a166f6219129809ccfd99

apct-tests/perftests/multiuser/Android.mk
apct-tests/perftests/multiuser/src/android/multiuser/BenchmarkRunner.java

index e3f7775..2db0dd6 100644 (file)
@@ -20,7 +20,8 @@ LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
-    android-support-test
+    android-support-test \
+    ub-uiautomator
 
 LOCAL_PACKAGE_NAME := MultiUserPerfTests
 
index c7bebf3..629e6f4 100644 (file)
@@ -17,13 +17,16 @@ package android.multiuser;
 
 import android.os.Bundle;
 import android.os.SystemClock;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.uiautomator.UiDevice;
 
+import java.io.IOException;
 import java.util.ArrayList;
 
 // Based on //platform/frameworks/base/apct-tests/perftests/utils/BenchmarkState.java
 public class BenchmarkRunner {
 
-    private static long COOL_OFF_PERIOD_MS = 2000;
+    private static final long COOL_OFF_PERIOD_MS = 1000;
 
     private static final int NUM_ITERATIONS = 4;
 
@@ -70,9 +73,13 @@ public class BenchmarkRunner {
     }
 
     private void prepareForNextRun() {
-        // TODO: Once http://b/63115387 is fixed, look into using "am wait-for-broadcast-idle"
-        // command instead of waiting for a fixed amount of time.
         SystemClock.sleep(COOL_OFF_PERIOD_MS);
+        try {
+            UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+                    .executeShellCommand("am wait-for-broadcast-idle");
+        } catch (IOException e) {
+            throw new IllegalStateException("Cannot execute shell command", e);
+        }
         mStartTimeNs = System.nanoTime();
         mPausedDurationNs = 0;
     }