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

Commit 4a60b887 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 3761 into donut

* changes:
  Added support to record page load time for each url.
parents b11e670e 2ab6f1fe
Loading
Loading
Loading
Loading
+50 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import time
TEST_LIST_FILE = "/sdcard/android/reliability_tests_list.txt"
TEST_STATUS_FILE = "/sdcard/android/reliability_running_test.txt"
TEST_TIMEOUT_FILE = "/sdcard/android/reliability_timeout_test.txt"
TEST_LOAD_TIME_FILE = "/sdcard/android/reliability_load_time.txt"
HTTP_URL_FILE = "urllist_http"
HTTPS_URL_FILE = "urllist_https"
NUM_URLS = 25
@@ -62,6 +63,36 @@ def Bugreport(url, bugreport_dir, adb_cmd):
  os.system(cmd)


def ProcessPageLoadTime(raw_log):
  """Processes the raw page load time logged by test app."""
  log_handle = open(raw_log, "r")
  load_times = {}

  for line in log_handle:
    line = line.strip()
    pair = line.split("|")
    if len(pair) != 2:
      logging.info("Line has more than one '|': " + line)
      continue
    if pair[0] not in load_times:
      load_times[pair[0]] = [0, 0]
    try:
      pair[1] = int(pair[1])
    except ValueError:
      logging.info("Lins has non-numeric load time: " + line)
      continue
    load_times[pair[0]][0] += pair[1]
    load_times[pair[0]][1] += 1

  log_handle.close()

  # rewrite the average time to file
  log_handle = open(raw_log, "w")
  for url, times in load_times.iteritems():
    log_handle.write("%s|%f\n" % (url, float(times[0]) / times[1]))
  log_handle.close()


def main(options, args):
  """Send the url list to device and start testing, restart if crashed."""

@@ -141,8 +172,13 @@ def main(options, args):
  # Call ReliabilityTestsAutoTest#startReliabilityTests
  test_cmd = (test_cmd_prefix + " -e class "
              "com.android.dumprendertree.ReliabilityTest#"
              "runReliabilityTest -e timeout %s -e delay %s %s" %
              (str(timeout_ms), str(manual_delay), test_cmd_postfix))
              "runReliabilityTest -e timeout %s -e delay %s" %
              (str(timeout_ms), str(manual_delay)))

  if options.logtime:
    test_cmd += " -e logtime true"

  test_cmd += test_cmd_postfix

  adb_output = subprocess.Popen(test_cmd, shell=True,
                                stdout=subprocess.PIPE,
@@ -176,11 +212,19 @@ def main(options, args):
  else:
    logging.info("No crash found.")

  # get timeout file from sdcard
  test_cmd = (adb_cmd + "pull \"" + TEST_TIMEOUT_FILE + "\" \""
              + timedout_file +  "\"")
  subprocess.Popen(test_cmd, shell=True, stdout=subprocess.PIPE,
                   stderr=subprocess.PIPE).communicate()

  if options.logtime:
    # get logged page load times from sdcard
    test_cmd = (adb_cmd + "pull \"" + TEST_LOAD_TIME_FILE + "\" \""
                + options.logtime +  "\"")
    subprocess.Popen(test_cmd, shell=True, stdout=subprocess.PIPE,
                     stderr=subprocess.PIPE).communicate()
    ProcessPageLoadTime(options.logtime)


if "__main__" == __name__:
@@ -206,5 +250,8 @@ if "__main__" == __name__:
  option_parser.add_option("-b", "--bugreport",
                           default=".",
                           help="the directory to store bugreport for crashes")
  option_parser.add_option("-l", "--logtime",
                           default=None,
                           help="Logs page load time for each url to the file")
  opts, arguments = option_parser.parse_args()
  main(opts, arguments)
+5 −0
Original line number Diff line number Diff line
@@ -69,11 +69,16 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner {
        String r = (String)icicle.get("rebaseline");
        this.mRebaseline = (r != null && r.toLowerCase().equals("true"));
        super.onCreate(icicle);
        
        String logtime = (String) icicle.get("logtime");
        this.mLogtime = (logtime != null
                && logtime.toLowerCase().equals("true"));
    }
    
    public String mTestPath = null;
    public int mTimeoutInMillis = 0;
    public int mDelay = 0;
    public boolean mRebaseline = false;
    public boolean mLogtime = false;
}
+38 −17
Original line number Diff line number Diff line
package com.android.dumprendertree;

import android.os.Handler;
import android.os.Message;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;

@@ -21,6 +22,7 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
    private static final String TEST_LIST_FILE = "/sdcard/android/reliability_tests_list.txt";
    private static final String TEST_STATUS_FILE = "/sdcard/android/reliability_running_test.txt";
    private static final String TEST_TIMEOUT_FILE = "/sdcard/android/reliability_timeout_test.txt";
    private static final String TEST_LOAD_TIME_FILE = "/sdcard/android/reliability_load_time.txt";
    private static final String TEST_DONE = "#DONE";
    static final String RELIABILITY_TEST_RUNNER_FILES[] = {
        "run_reliability_tests.py"
@@ -65,9 +67,13 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
            //use message to send new URL to avoid interacting with
            //WebView in non-UI thread
            handler = activity.getHandler();
            handler.sendMessage(handler.obtainMessage(
            Message msg = handler.obtainMessage(
                    ReliabilityTestActivity.MSG_NAVIGATE,
                    runner.mTimeoutInMillis, runner.mDelay, url));
                    runner.mTimeoutInMillis, runner.mDelay);
            msg.getData().putString(ReliabilityTestActivity.MSG_NAV_URL, url);
            msg.getData().putBoolean(ReliabilityTestActivity.MSG_NAV_LOGTIME,
                    runner.mLogtime);
            handler.sendMessage(msg);
            timeoutFlag = activity.waitUntilDone();
            elapsed = System.currentTimeMillis() - start;
            if(elapsed < 1000) {
@@ -79,6 +85,9 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
            if(timeoutFlag) {
                writeTimeoutFile(url);
            }
            if(runner.mLogtime) {
                writeLoadTime(url, activity.getPageLoadTime());
            }
            System.runFinalization();
            System.gc();
            System.gc();
@@ -171,4 +180,16 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
            Log.e(LOGTAG, "Cannot update file " + TEST_TIMEOUT_FILE, e);
        }
    }

    private void writeLoadTime(String s, long time) {
        //append to the file containing the list of timeout urls
        try {
            BufferedOutputStream bos = new BufferedOutputStream(
                    new FileOutputStream(TEST_LOAD_TIME_FILE, true));
            bos.write((s + '|' + time + '\n').getBytes());
            bos.close();
        } catch (Exception e) {
            Log.e(LOGTAG, "Cannot update file " + TEST_LOAD_TIME_FILE, e);
        }
    }
}
+55 −40
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ public class ReliabilityTestActivity extends Activity {
    public static final int RESULT_TIMEOUT = 0xDEAD;
    public static final int MSG_TIMEOUT = 0xC001;
    public static final int MSG_NAVIGATE = 0xC002;
    public static final String MSG_NAV_URL = "url";
    public static final String MSG_NAV_LOGTIME = "logtime";

    private static final String LOGTAG = "ReliabilityTestActivity";

@@ -36,10 +38,13 @@ public class ReliabilityTestActivity extends Activity {
    private SimpleChromeClient chromeClient;
    private Handler handler;
    private boolean timeoutFlag;
    private boolean logTime;
    private boolean pageDone;
    private Object pageDoneLock;
    private int pageStartCount;
    private int manualDelay;
    private long startTime;
    private long pageLoadTime;
    private PageDoneRunner pageDoneRunner = new PageDoneRunner();

    @Override
@@ -76,7 +81,8 @@ public class ReliabilityTestActivity extends Activity {
                        return;
                    case MSG_NAVIGATE:
                        manualDelay = msg.arg2;
                        navigate((String)msg.obj, msg.arg1);
                        navigate(msg.getData().getString(MSG_NAV_URL), msg.arg1);
                        logTime = msg.getData().getBoolean(MSG_NAV_LOGTIME);
                        return;
                }
            }
@@ -100,6 +106,10 @@ public class ReliabilityTestActivity extends Activity {
            finish();
        }
        webView.stopLoading();
        if(logTime) {
            webView.clearCache(true);
        }
        startTime = System.currentTimeMillis();
        Log.v(LOGTAG, "Navigating to URL: " + url);
        webView.loadUrl(url);

@@ -162,6 +172,10 @@ public class ReliabilityTestActivity extends Activity {
        }
    }

    public long getPageLoadTime() {
        return pageLoadTime;
    }

    class SimpleWebViewClient extends WebViewClient {

        @Override
@@ -269,6 +283,7 @@ public class ReliabilityTestActivity extends Activity {

        public void run() {
            Log.v(LOGTAG, "Finishing URL: " + webView.getUrl());
            pageLoadTime = System.currentTimeMillis() - startTime;
            setPageDone(true);
        }
    }