summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2011-01-25 15:43:57 -0800
committerGuang Zhu <guangzhu@google.com>2011-01-25 17:25:59 -0800
commit5794f2302209981c64425ea2b661b17f00b8f808 (patch)
tree57358456261d67323208a62799ff6716b21d86eb /tests/DumpRenderTree
parentd63219f62248d067462403bed9e0539df53dd2dd (diff)
downloadframeworks_base-5794f2302209981c64425ea2b661b17f00b8f808.zip
frameworks_base-5794f2302209981c64425ea2b661b17f00b8f808.tar.gz
frameworks_base-5794f2302209981c64425ea2b661b17f00b8f808.tar.bz2
change the way test app waits for gc
gcSoftReferences methods are being obsoleted, so we need a different approach to wait for gc: create a CountDownLatch and release it in a dummy object's finalizer, call gc and await on the CDL. Change-Id: I54d9e6bc05540b16ee1f3959ace9008041ac4903
Diffstat (limited to 'tests/DumpRenderTree')
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java30
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
index 5bcf727..622fb0e 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
@@ -16,8 +16,6 @@
package com.android.dumprendertree;
-import dalvik.system.VMRuntime;
-
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
@@ -34,12 +32,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShellActivity> {
private final static String LOGTAG = "LoadTest";
private final static String LOAD_TEST_RESULT =
Environment.getExternalStorageDirectory() + "/load_test_result.txt";
+ private final static int MAX_GC_WAIT_SEC = 10;
private boolean mFinished;
static final String LOAD_TEST_RUNNER_FILES[] = {
"run_page_cycler.py"
@@ -90,14 +91,23 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
private void freeMem() {
Log.v(LOGTAG, "freeMem: calling gc...");
- final VMRuntime runtime = VMRuntime.getRuntime();
-
- runtime.gcSoftReferences();
- runtime.gcSoftReferences();
- runtime.gcSoftReferences();
- Runtime.getRuntime().gc();
- Runtime.getRuntime().gc();
-
+ final CountDownLatch latch = new CountDownLatch(1);
+ Object dummy = new Object() {
+ @Override
+ protected void finalize() throws Throwable {
+ latch.countDown();
+ super.finalize();
+ }
+ };
+ dummy = null;
+ System.gc();
+ try {
+ if (!latch.await(MAX_GC_WAIT_SEC, TimeUnit.SECONDS)) {
+ Log.w(LOGTAG, "gc did not happen in 10s");
+ }
+ } catch (InterruptedException e) {
+ //ignore
+ }
}
private void printRow(PrintStream ps, String format, Object...objs) {