Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb84ac4d authored by Guang Zhu's avatar Guang Zhu Committed by Android Git Automerger
Browse files

am 5794f230: change the way test app waits for gc

* commit '5794f230':
  change the way test app waits for gc
parents d144b449 5794f230
Loading
Loading
Loading
Loading
+20 −10
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package com.android.dumprendertree;
package com.android.dumprendertree;


import dalvik.system.VMRuntime;

import android.app.Instrumentation;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -34,12 +32,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;


public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShellActivity> {
public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShellActivity> {


    private final static String LOGTAG = "LoadTest";
    private final static String LOGTAG = "LoadTest";
    private final static String LOAD_TEST_RESULT =
    private final static String LOAD_TEST_RESULT =
        Environment.getExternalStorageDirectory() + "/load_test_result.txt";
        Environment.getExternalStorageDirectory() + "/load_test_result.txt";
    private final static int MAX_GC_WAIT_SEC = 10;
    private boolean mFinished;
    private boolean mFinished;
    static final String LOAD_TEST_RUNNER_FILES[] = {
    static final String LOAD_TEST_RUNNER_FILES[] = {
        "run_page_cycler.py"
        "run_page_cycler.py"
@@ -90,14 +91,23 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel


    private void freeMem() {
    private void freeMem() {
        Log.v(LOGTAG, "freeMem: calling gc...");
        Log.v(LOGTAG, "freeMem: calling gc...");
        final VMRuntime runtime = VMRuntime.getRuntime();
        final CountDownLatch latch = new CountDownLatch(1);

        Object dummy = new Object() {
        runtime.gcSoftReferences();
            @Override
        runtime.gcSoftReferences();
            protected void finalize() throws Throwable {
        runtime.gcSoftReferences();
                latch.countDown();
        Runtime.getRuntime().gc();
                super.finalize();
        Runtime.getRuntime().gc();
            }

        };
        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) {
    private void printRow(PrintStream ps, String format, Object...objs) {