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

Commit f6d1b3f1 authored by Guang Zhu's avatar Guang Zhu
Browse files

Make DRT pull data over network

command format:

adb shell am instrument -w -e class \
    com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest \
    -e suite moz \
    -e iteration 1 \
    -e forward android-browser-test:80/page_cycler/ \
    com.android.dumprendertree/.LayoutTestsAutoRunner

Change-Id: Ib4e9db28953f6be155517bb4b139e4477305c2c2
parent 46baa14f
Loading
Loading
Loading
Loading
+30 −1
Original line number Original line Diff line number Diff line
@@ -33,10 +33,16 @@ def main(options, args):
  # Include all tests if none are specified.
  # Include all tests if none are specified.
  if not args:
  if not args:
    print "need a URL, e.g. file:///sdcard/webkit/page_cycler/moz/start.html\?auto=1\&iterations=10"
    print "need a URL, e.g. file:///sdcard/webkit/page_cycler/moz/start.html\?auto=1\&iterations=10"
    print "  or remote:android-browser-test:80/page_cycler/"
    sys.exit(1)
    sys.exit(1)
  else:
  else:
    path = ' '.join(args);
    path = ' '.join(args);


  if path[:7] == "remote:":
    remote_path = path[7:]
  else:
    remote_path = None

  adb_cmd = "adb ";
  adb_cmd = "adb ";
  if options.adb_options:
  if options.adb_options:
    adb_cmd += options.adb_options
    adb_cmd += options.adb_options
@@ -56,7 +62,20 @@ def main(options, args):
  run_load_test_cmd_postfix = " -w com.android.dumprendertree/.LayoutTestsAutoRunner"
  run_load_test_cmd_postfix = " -w com.android.dumprendertree/.LayoutTestsAutoRunner"


  # Call LoadTestsAutoTest::runTest.
  # Call LoadTestsAutoTest::runTest.
  run_load_test_cmd = run_load_test_cmd_prefix + " -e class com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest -e path \"" + path + "\" -e timeout " + timeout_ms
  run_load_test_cmd = run_load_test_cmd_prefix + " -e class com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest -e timeout " + timeout_ms

  if remote_path:
    if options.suite:
      run_load_test_cmd += " -e suite %s -e forward %s " % (options.suite,
                                                            remote_path)
    else:
      print "for network mode, need to specify --suite as well."
      sys.exit(1)
    if options.iteration:
      run_load_test_cmd += " -e iteration %s" % options.iteration
  else:
    run_load_test_cmd += " -e path \"%s\" " % path



  if options.drawtime:
  if options.drawtime:
    run_load_test_cmd += " -e drawtime true "
    run_load_test_cmd += " -e drawtime true "
@@ -130,5 +149,15 @@ if '__main__' == __name__:
                           default=None,
                           default=None,
                           help="stores rendered page to a location on device.")
                           help="stores rendered page to a location on device.")


  option_parser.add_option("-u", "--suite",
                           default=None,
                           help="(for network mode) specify the suite to"
                           " run by name")

  option_parser.add_option("-i", "--iteration",
                           default="5",
                           help="(for network mode) specify how many iterations"
                           " to run")

  options, args = option_parser.parse_args();
  options, args = option_parser.parse_args();
  main(options, args)
  main(options, args)
+23 −16
Original line number Original line Diff line number Diff line
@@ -66,30 +66,37 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner {
            }
            }
        }
        }


        String r = (String)icicle.get("rebaseline");
        String r = icicle.getString("rebaseline");
        this.mRebaseline = (r != null && r.toLowerCase().equals("true"));
        this.mRebaseline = (r != null && r.toLowerCase().equals("true"));


        String logtime = (String) icicle.get("logtime");
        String logtime = icicle.getString("logtime");
        this.mLogtime = (logtime != null
        this.mLogtime = (logtime != null
                && logtime.toLowerCase().equals("true"));
                && logtime.toLowerCase().equals("true"));


        String drawTime = (String) icicle.get("drawtime");
        String drawTime = icicle.getString("drawtime");
        this.mGetDrawTime = (drawTime != null
        this.mGetDrawTime = (drawTime != null
                && drawTime.toLowerCase().equals("true"));
                && drawTime.toLowerCase().equals("true"));


        mSaveImagePath = (String) icicle.get("saveimage");
        mSaveImagePath = icicle.getString("saveimage");


        mJsEngine = (String) icicle.get("jsengine");
        mJsEngine = icicle.getString("jsengine");

        mPageCyclerSuite = icicle.getString("suite");
        mPageCyclerForwardHost = icicle.getString("forward");
        mPageCyclerIteration = icicle.getString("iteration", "5");


        super.onCreate(icicle);
        super.onCreate(icicle);
    }
    }


    public String mTestPath;
    String mPageCyclerSuite;
    public String mSaveImagePath;
    String mPageCyclerForwardHost;
    public int mTimeoutInMillis;
    String mPageCyclerIteration;
    public int mDelay;
    String mTestPath;
    public boolean mRebaseline;
    String mSaveImagePath;
    public boolean mLogtime;
    int mTimeoutInMillis;
    public boolean mGetDrawTime;
    int mDelay;
    public String mJsEngine;
    boolean mRebaseline;
    boolean mLogtime;
    boolean mGetDrawTime;
    String mJsEngine;
}
}
+0 −9
Original line number Original line Diff line number Diff line
@@ -401,15 +401,6 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
        activity.setDefaultDumpDataType(DumpDataType.EXT_REPR);
        activity.setDefaultDumpDataType(DumpDataType.EXT_REPR);


        // Run tests.
        // Run tests.
        int addr = -1;
        try{
            addr = AdbUtils.resolve("android-browser-test.mtv.corp.google.com");
        } catch (IOException ioe) {
            Log.w(LOGTAG, "error while resolving test host name", ioe);
        }
        if(addr == -1) {
            Log.w(LOGTAG, "failed to resolve test host. http tests will fail.");
        }
        for (int i = 0; i < mTestList.size(); i++) {
        for (int i = 0; i < mTestList.size(); i++) {
            String s = mTestList.elementAt(i);
            String s = mTestList.elementAt(i);
            boolean ignoreResult = mTestListIgnoreResult.elementAt(i);
            boolean ignoreResult = mTestListIgnoreResult.elementAt(i);
+41 −4
Original line number Original line Diff line number Diff line
@@ -16,6 +16,9 @@


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


import com.android.dumprendertree.forwarder.AdbUtils;
import com.android.dumprendertree.forwarder.ForwardServer;

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,6 +37,8 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


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


@@ -41,13 +46,15 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
    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 final static int MAX_GC_WAIT_SEC = 10;
    private final static int LOCAL_PORT = 17171;
    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"
    };
    };
    private ForwardServer mForwardServer;


    public LoadTestsAutoTest() {
    public LoadTestsAutoTest() {
        super("com.android.dumprendertree", TestShellActivity.class);
        super(TestShellActivity.class);
    }
    }


    // This function writes the result of the layout test to
    // This function writes the result of the layout test to
@@ -59,14 +66,38 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
        inst.sendStatus(0, bundle);
        inst.sendStatus(0, bundle);
    }
    }


    private String setUpForwarding(String forwardInfo, String suite, String iteration) throws IOException {
        // read forwarding information first
        Pattern forwardPattern = Pattern.compile("(.*):(\\d+)/(.*)/");
        Matcher matcher = forwardPattern.matcher(forwardInfo);
        if (!matcher.matches()) {
            throw new RuntimeException("Invalid forward information");
        }
        String host = matcher.group(1);
        int port = Integer.parseInt(matcher.group(2));
        mForwardServer = new ForwardServer(LOCAL_PORT, AdbUtils.resolve(host), port);
        mForwardServer.start();
        return String.format("http://127.0.0.1:%d/%s/%s/start.html?auto=1&iterations=%s",
                LOCAL_PORT, matcher.group(3), suite, iteration);
    }

    // Invokes running of layout tests
    // Invokes running of layout tests
    // and waits till it has finished running.
    // and waits till it has finished running.
    public void runPageCyclerTest() {
    public void runPageCyclerTest() throws IOException {
        LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner) getInstrumentation();
        LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner) getInstrumentation();


        if (runner.mPageCyclerSuite != null) {
            // start forwarder to use page cycler suites hosted on external web server
            if (runner.mPageCyclerForwardHost == null) {
                throw new RuntimeException("no forwarder information provided");
            }
            runner.mTestPath = setUpForwarding(runner.mPageCyclerForwardHost,
                    runner.mPageCyclerSuite, runner.mPageCyclerIteration);
            Log.d(LOGTAG, "using path: " + runner.mTestPath);
        }

        if (runner.mTestPath == null) {
        if (runner.mTestPath == null) {
            Log.e(LOGTAG, "No test specified");
            throw new RuntimeException("No test specified");
            return;
        }
        }


        TestShellActivity activity = (TestShellActivity) getActivity();
        TestShellActivity activity = (TestShellActivity) getActivity();
@@ -79,6 +110,10 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
                runner.mGetDrawTime, runner.mSaveImagePath);
                runner.mGetDrawTime, runner.mSaveImagePath);


        activity.clearCache();
        activity.clearCache();
        if (mForwardServer != null) {
            mForwardServer.stop();
            mForwardServer = null;
        }
        try {
        try {
            Thread.sleep(5000);
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        } catch (InterruptedException e) {
@@ -92,7 +127,9 @@ 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 CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch latch = new CountDownLatch(1);
        @SuppressWarnings("unused")
        Object dummy = new Object() {
        Object dummy = new Object() {
            // this object instance is used to track gc
            @Override
            @Override
            protected void finalize() throws Throwable {
            protected void finalize() throws Throwable {
                latch.countDown();
                latch.countDown();
+2 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ public class Forwarder {
    private Socket from, to;
    private Socket from, to;


    private static final String LOGTAG = "Forwarder";
    private static final String LOGTAG = "Forwarder";
    private static final int BUFFER_SIZE = 16384;


    public Forwarder (Socket from, Socket to, ForwardServer server) {
    public Forwarder (Socket from, Socket to, ForwardServer server) {
        this.server = server;
        this.server = server;
@@ -90,7 +91,7 @@ public class Forwarder {
                int length;
                int length;
                InputStream is = in.getInputStream();
                InputStream is = in.getInputStream();
                OutputStream os = out.getOutputStream();
                OutputStream os = out.getOutputStream();
                byte[] buffer = new byte[4096];
                byte[] buffer = new byte[BUFFER_SIZE];
                while ((length = is.read(buffer)) > 0) {
                while ((length = is.read(buffer)) > 0) {
                    os.write(buffer, 0, length);
                    os.write(buffer, 0, length);
                }
                }