Loading tests/DumpRenderTree/assets/run_page_cycler.py +22 −6 Original line number Diff line number Diff line Loading @@ -56,7 +56,15 @@ def main(options, args): run_load_test_cmd_postfix = " -w com.android.dumprendertree/.LayoutTestsAutoRunner" # 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_postfix run_load_test_cmd = run_load_test_cmd_prefix + " -e class com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest -e path \"" + path + "\" -e timeout " + timeout_ms if options.drawtime: run_load_test_cmd += " -e drawtime true " if options.save_image: run_load_test_cmd += " -e saveimage \"%s\"" % options.save_image run_load_test_cmd += run_load_test_cmd_postfix (adb_output, adb_error) = subprocess.Popen(run_load_test_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() fail_flag = False Loading Loading @@ -101,18 +109,26 @@ def main(options, args): if '__main__' == __name__: option_parser = optparse.OptionParser() option_parser.add_option("", "--time-out-ms", option_parser.add_option("-t", "--time-out-ms", default=None, help="set the timeout for each test") option_parser.add_option("", "--verbose", action="store_true", option_parser.add_option("-v", "--verbose", action="store_true", default=False, help="include debug-level logging") option_parser.add_option("", "--adb-options", option_parser.add_option("-a", "--adb-options", default=None, help="pass options to adb, such as -d -e, etc"); option_parser.add_option("", "--results-directory", option_parser.add_option("-r", "--results-directory", default="layout-test-results", help="directory which results are stored.") option_parser.add_option("-d", "--drawtime", action="store_true", default=False, help="log draw time for each page rendered.") option_parser.add_option("-s", "--save-image", default=None, help="stores rendered page to a location on device.") options, args = option_parser.parse_args(); main(options, args) tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java +40 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.regex.Pattern; Loading Loading @@ -156,4 +157,43 @@ public class FsUtils { return same; } public static boolean isTestPageUrl(String url) { int qmPostion = url.indexOf('?'); int slashPostion = url.lastIndexOf('/'); if (slashPostion < qmPostion) { String fileName = url.substring(slashPostion + 1, qmPostion); if ("index.html".equals(fileName)) { return true; } } return false; } public static String getLastSegmentInPath(String path) { int endPos = path.lastIndexOf('/'); path = path.substring(0, endPos); endPos = path.lastIndexOf('/'); return path.substring(endPos + 1); } public static void writeDrawTime(String fileName, String url, long[] times) { StringBuffer lineBuffer = new StringBuffer(); // grab the last segment of path in url lineBuffer.append(getLastSegmentInPath(url)); for (long time : times) { lineBuffer.append('\t'); lineBuffer.append(time); } lineBuffer.append('\n'); String line = lineBuffer.toString(); Log.v(LOGTAG, "logging draw times: " + line); try { FileWriter fw = new FileWriter(fileName, true); fw.write(line); fw.close(); } catch (IOException ioe) { Log.e(LOGTAG, "Failed to log draw times", ioe); } } } tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java +8 −1 Original line number Diff line number Diff line Loading @@ -73,13 +73,20 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner { this.mLogtime = (logtime != null && logtime.toLowerCase().equals("true")); String drawTime = (String) icicle.get("drawtime"); this.mGetDrawTime = (drawTime != null && drawTime.toLowerCase().equals("true")); mSaveImagePath = (String) icicle.get("saveimage"); super.onCreate(icicle); } public String mTestPath = null; public String mSaveImagePath = null; public int mTimeoutInMillis = 0; public int mDelay = 0; public boolean mRebaseline = false; public boolean mLogtime = false; public boolean mGetDrawTime = false; } tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java +7 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,8 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel freeMem(); // Run tests runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis); runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis, runner.mGetDrawTime, runner.mSaveImagePath); activity.clearCache(); try { Loading Loading @@ -161,7 +162,8 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel } // A convenient method to be called by another activity. private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout) { private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout, boolean getDrawTime, String saveImagePath) { activity.setCallback(new TestShellCallback() { public void finished() { synchronized (LoadTestsAutoTest.this) { Loading @@ -181,6 +183,9 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel intent.putExtra(TestShellActivity.TEST_URL, url); intent.putExtra(TestShellActivity.TIMEOUT_IN_MILLIS, timeout); intent.putExtra(TestShellActivity.RESULT_FILE, LOAD_TEST_RESULT); intent.putExtra(TestShellActivity.GET_DRAW_TIME, getDrawTime); if (saveImagePath != null) intent.putExtra(TestShellActivity.SAVE_IMAGE, saveImagePath); activity.startActivity(intent); // Wait until done. Loading tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +59 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,9 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.DialogInterface.OnClickListener; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.Config; import android.net.http.SslError; import android.os.Bundle; import android.os.Handler; Loading Loading @@ -163,6 +166,8 @@ public class TestShellActivity extends Activity implements LayoutTestController mResultFile = intent.getStringExtra(RESULT_FILE); mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0); mGetDrawtime = intent.getBooleanExtra(GET_DRAW_TIME, false); mSaveImagePath = intent.getStringExtra(SAVE_IMAGE); Log.v(LOGTAG, " Loading " + mTestUrl); mWebView.loadUrl(mTestUrl); Loading Loading @@ -459,6 +464,18 @@ public class TestShellActivity extends Activity implements LayoutTestController public void onPageFinished(WebView view, String url) { Log.v(LOGTAG, "onPageFinished, url=" + url); mPageFinished = true; // get page draw time if (FsUtils.isTestPageUrl(url)) { if (mGetDrawtime) { long[] times = new long[DRAW_RUNS]; times = getDrawWebViewTime(mWebView, DRAW_RUNS); FsUtils.writeDrawTime(DRAW_TIME_LOG, url, times); } if (mSaveImagePath != null) { String name = FsUtils.getLastSegmentInPath(url); drawPageToFile(mSaveImagePath + "/" + name + ".png", mWebView); } } // Calling finished() will check if we've met all the conditions for completing // this test and move to the next one if we are ready. if (finished()) { Loading Loading @@ -691,6 +708,41 @@ public class TestShellActivity extends Activity implements LayoutTestController mPageFinished = false; mOneHundredPercentComplete = false; mDumpWebKitData = false; mGetDrawtime = false; mSaveImagePath = null; } private long[] getDrawWebViewTime(WebView view, int count) { if (count == 0) return null; long[] ret = new long[count]; long start; Canvas canvas = new Canvas(); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888); canvas.setBitmap(bitmap); for (int i = 0; i < count; i++) { start = System.currentTimeMillis(); view.draw(canvas); ret[i] = System.currentTimeMillis() - start; } return ret; } private void drawPageToFile(String fileName, WebView view) { Canvas canvas = new Canvas(); Bitmap bitmap = Bitmap.createBitmap(view.getContentWidth(), view.getContentHeight(), Config.ARGB_8888); canvas.setBitmap(bitmap); view.drawPage(canvas); try { FileOutputStream fos = new FileOutputStream(fileName); if(!bitmap.compress(CompressFormat.PNG, 90, fos)) { Log.w(LOGTAG, "Failed to compress and save image."); } } catch (IOException ioe) { Log.e(LOGTAG, "", ioe); } bitmap.recycle(); } private boolean canMoveToNextTest() { Loading Loading @@ -730,7 +782,9 @@ public class TestShellActivity extends Activity implements LayoutTestController private String mResultFile; private int mTimeoutInMillis; private String mUiAutoTestPath; private String mSaveImagePath; private BufferedReader mTestListReader; private boolean mGetDrawtime; // States private boolean mTimedOut; Loading Loading @@ -766,6 +820,11 @@ public class TestShellActivity extends Activity implements LayoutTestController static final String RESULT_FILE = "ResultFile"; static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis"; static final String UI_AUTO_TEST = "UiAutoTest"; static final String GET_DRAW_TIME = "GetDrawTime"; static final String SAVE_IMAGE = "SaveImage"; static final int DRAW_RUNS = 5; static final String DRAW_TIME_LOG = "/sdcard/android/page_draw_time.txt"; private boolean mGeolocationPermissionSet; private boolean mGeolocationPermission; Loading Loading
tests/DumpRenderTree/assets/run_page_cycler.py +22 −6 Original line number Diff line number Diff line Loading @@ -56,7 +56,15 @@ def main(options, args): run_load_test_cmd_postfix = " -w com.android.dumprendertree/.LayoutTestsAutoRunner" # 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_postfix run_load_test_cmd = run_load_test_cmd_prefix + " -e class com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest -e path \"" + path + "\" -e timeout " + timeout_ms if options.drawtime: run_load_test_cmd += " -e drawtime true " if options.save_image: run_load_test_cmd += " -e saveimage \"%s\"" % options.save_image run_load_test_cmd += run_load_test_cmd_postfix (adb_output, adb_error) = subprocess.Popen(run_load_test_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() fail_flag = False Loading Loading @@ -101,18 +109,26 @@ def main(options, args): if '__main__' == __name__: option_parser = optparse.OptionParser() option_parser.add_option("", "--time-out-ms", option_parser.add_option("-t", "--time-out-ms", default=None, help="set the timeout for each test") option_parser.add_option("", "--verbose", action="store_true", option_parser.add_option("-v", "--verbose", action="store_true", default=False, help="include debug-level logging") option_parser.add_option("", "--adb-options", option_parser.add_option("-a", "--adb-options", default=None, help="pass options to adb, such as -d -e, etc"); option_parser.add_option("", "--results-directory", option_parser.add_option("-r", "--results-directory", default="layout-test-results", help="directory which results are stored.") option_parser.add_option("-d", "--drawtime", action="store_true", default=False, help="log draw time for each page rendered.") option_parser.add_option("-s", "--save-image", default=None, help="stores rendered page to a location on device.") options, args = option_parser.parse_args(); main(options, args)
tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java +40 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.regex.Pattern; Loading Loading @@ -156,4 +157,43 @@ public class FsUtils { return same; } public static boolean isTestPageUrl(String url) { int qmPostion = url.indexOf('?'); int slashPostion = url.lastIndexOf('/'); if (slashPostion < qmPostion) { String fileName = url.substring(slashPostion + 1, qmPostion); if ("index.html".equals(fileName)) { return true; } } return false; } public static String getLastSegmentInPath(String path) { int endPos = path.lastIndexOf('/'); path = path.substring(0, endPos); endPos = path.lastIndexOf('/'); return path.substring(endPos + 1); } public static void writeDrawTime(String fileName, String url, long[] times) { StringBuffer lineBuffer = new StringBuffer(); // grab the last segment of path in url lineBuffer.append(getLastSegmentInPath(url)); for (long time : times) { lineBuffer.append('\t'); lineBuffer.append(time); } lineBuffer.append('\n'); String line = lineBuffer.toString(); Log.v(LOGTAG, "logging draw times: " + line); try { FileWriter fw = new FileWriter(fileName, true); fw.write(line); fw.close(); } catch (IOException ioe) { Log.e(LOGTAG, "Failed to log draw times", ioe); } } }
tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java +8 −1 Original line number Diff line number Diff line Loading @@ -73,13 +73,20 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner { this.mLogtime = (logtime != null && logtime.toLowerCase().equals("true")); String drawTime = (String) icicle.get("drawtime"); this.mGetDrawTime = (drawTime != null && drawTime.toLowerCase().equals("true")); mSaveImagePath = (String) icicle.get("saveimage"); super.onCreate(icicle); } public String mTestPath = null; public String mSaveImagePath = null; public int mTimeoutInMillis = 0; public int mDelay = 0; public boolean mRebaseline = false; public boolean mLogtime = false; public boolean mGetDrawTime = false; }
tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java +7 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,8 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel freeMem(); // Run tests runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis); runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis, runner.mGetDrawTime, runner.mSaveImagePath); activity.clearCache(); try { Loading Loading @@ -161,7 +162,8 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel } // A convenient method to be called by another activity. private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout) { private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout, boolean getDrawTime, String saveImagePath) { activity.setCallback(new TestShellCallback() { public void finished() { synchronized (LoadTestsAutoTest.this) { Loading @@ -181,6 +183,9 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel intent.putExtra(TestShellActivity.TEST_URL, url); intent.putExtra(TestShellActivity.TIMEOUT_IN_MILLIS, timeout); intent.putExtra(TestShellActivity.RESULT_FILE, LOAD_TEST_RESULT); intent.putExtra(TestShellActivity.GET_DRAW_TIME, getDrawTime); if (saveImagePath != null) intent.putExtra(TestShellActivity.SAVE_IMAGE, saveImagePath); activity.startActivity(intent); // Wait until done. Loading
tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +59 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,9 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.DialogInterface.OnClickListener; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.Config; import android.net.http.SslError; import android.os.Bundle; import android.os.Handler; Loading Loading @@ -163,6 +166,8 @@ public class TestShellActivity extends Activity implements LayoutTestController mResultFile = intent.getStringExtra(RESULT_FILE); mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0); mGetDrawtime = intent.getBooleanExtra(GET_DRAW_TIME, false); mSaveImagePath = intent.getStringExtra(SAVE_IMAGE); Log.v(LOGTAG, " Loading " + mTestUrl); mWebView.loadUrl(mTestUrl); Loading Loading @@ -459,6 +464,18 @@ public class TestShellActivity extends Activity implements LayoutTestController public void onPageFinished(WebView view, String url) { Log.v(LOGTAG, "onPageFinished, url=" + url); mPageFinished = true; // get page draw time if (FsUtils.isTestPageUrl(url)) { if (mGetDrawtime) { long[] times = new long[DRAW_RUNS]; times = getDrawWebViewTime(mWebView, DRAW_RUNS); FsUtils.writeDrawTime(DRAW_TIME_LOG, url, times); } if (mSaveImagePath != null) { String name = FsUtils.getLastSegmentInPath(url); drawPageToFile(mSaveImagePath + "/" + name + ".png", mWebView); } } // Calling finished() will check if we've met all the conditions for completing // this test and move to the next one if we are ready. if (finished()) { Loading Loading @@ -691,6 +708,41 @@ public class TestShellActivity extends Activity implements LayoutTestController mPageFinished = false; mOneHundredPercentComplete = false; mDumpWebKitData = false; mGetDrawtime = false; mSaveImagePath = null; } private long[] getDrawWebViewTime(WebView view, int count) { if (count == 0) return null; long[] ret = new long[count]; long start; Canvas canvas = new Canvas(); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888); canvas.setBitmap(bitmap); for (int i = 0; i < count; i++) { start = System.currentTimeMillis(); view.draw(canvas); ret[i] = System.currentTimeMillis() - start; } return ret; } private void drawPageToFile(String fileName, WebView view) { Canvas canvas = new Canvas(); Bitmap bitmap = Bitmap.createBitmap(view.getContentWidth(), view.getContentHeight(), Config.ARGB_8888); canvas.setBitmap(bitmap); view.drawPage(canvas); try { FileOutputStream fos = new FileOutputStream(fileName); if(!bitmap.compress(CompressFormat.PNG, 90, fos)) { Log.w(LOGTAG, "Failed to compress and save image."); } } catch (IOException ioe) { Log.e(LOGTAG, "", ioe); } bitmap.recycle(); } private boolean canMoveToNextTest() { Loading Loading @@ -730,7 +782,9 @@ public class TestShellActivity extends Activity implements LayoutTestController private String mResultFile; private int mTimeoutInMillis; private String mUiAutoTestPath; private String mSaveImagePath; private BufferedReader mTestListReader; private boolean mGetDrawtime; // States private boolean mTimedOut; Loading Loading @@ -766,6 +820,11 @@ public class TestShellActivity extends Activity implements LayoutTestController static final String RESULT_FILE = "ResultFile"; static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis"; static final String UI_AUTO_TEST = "UiAutoTest"; static final String GET_DRAW_TIME = "GetDrawTime"; static final String SAVE_IMAGE = "SaveImage"; static final int DRAW_RUNS = 5; static final String DRAW_TIME_LOG = "/sdcard/android/page_draw_time.txt"; private boolean mGeolocationPermissionSet; private boolean mGeolocationPermission; Loading