diff options
author | Guang Zhu <guangzhu@google.com> | 2012-03-05 15:31:04 -0800 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2012-03-05 15:33:17 -0800 |
commit | 3ae8c42152d890ab771053fa6b16b038ee44326d (patch) | |
tree | 5a4dab5c9ccc09a7763726299b7b2a60d0c6405a /tests/DumpRenderTree | |
parent | d55191d0866550f245907dba9152753744c2935c (diff) | |
download | frameworks_base-3ae8c42152d890ab771053fa6b16b038ee44326d.zip frameworks_base-3ae8c42152d890ab771053fa6b16b038ee44326d.tar.gz frameworks_base-3ae8c42152d890ab771053fa6b16b038ee44326d.tar.bz2 |
Update to DumpRenderTree test harness
* removed some unused parameters
* removed obsolete live website test harness
* updated test class so that mean suite time for page cycler
is emmitted via instrumentation status
Change-Id: Iccb40f70a62a4ac9b8d5bceab9a6a715c611c573
Diffstat (limited to 'tests/DumpRenderTree')
6 files changed, 35 insertions, 280 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java index 3ba3488..fb2a1f4 100755 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java @@ -58,27 +58,9 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner { } } - String delay_str = (String) icicle.get("delay"); - if(delay_str != null) { - try { - this.mDelay = Integer.parseInt(delay_str); - } catch (Exception e) { - } - } - String r = icicle.getString("rebaseline"); this.mRebaseline = (r != null && r.toLowerCase().equals("true")); - String logtime = icicle.getString("logtime"); - this.mLogtime = (logtime != null - && logtime.toLowerCase().equals("true")); - - String drawTime = icicle.getString("drawtime"); - this.mGetDrawTime = (drawTime != null - && drawTime.toLowerCase().equals("true")); - - mSaveImagePath = icicle.getString("saveimage"); - mJsEngine = icicle.getString("jsengine"); mPageCyclerSuite = icicle.getString("suite"); @@ -92,11 +74,7 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner { String mPageCyclerForwardHost; String mPageCyclerIteration; String mTestPath; - String mSaveImagePath; - int mTimeoutInMillis; - int mDelay; + int mTimeoutInMillis = 0; boolean mRebaseline; - boolean mLogtime; - boolean mGetDrawTime; String mJsEngine; } diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java index 7ac0665..3fe4e70 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java @@ -314,6 +314,10 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh public void timedOut(String url) { Log.v(LOGTAG, "layout timeout: " + url); } + + @Override + public void dumpResult(String webViewDump) { + } }); String resultFile = getResultFile(test); diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java index d883a32..4b86a0b 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java @@ -19,6 +19,7 @@ package com.android.dumprendertree; import com.android.dumprendertree.forwarder.AdbUtils; import com.android.dumprendertree.forwarder.ForwardServer; +import android.app.Activity; import android.app.Instrumentation; import android.content.Context; import android.content.Intent; @@ -106,8 +107,7 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel freeMem(); // Run tests - runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis, - runner.mGetDrawTime, runner.mSaveImagePath); + runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis); getInstrumentation().runOnMainSync(new Runnable() { @@ -215,9 +215,9 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel } // A convenient method to be called by another activity. - private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout, - boolean getDrawTime, String saveImagePath) { + private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout) { activity.setCallback(new TestShellCallback() { + @Override public void finished() { synchronized (LoadTestsAutoTest.this) { mFinished = true; @@ -225,8 +225,29 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel } } + @Override public void timedOut(String url) { } + + @Override + public void dumpResult(String webViewDump) { + String lines[] = webViewDump.split("\\r?\\n"); + for (String line : lines) { + line = line.trim(); + // parse for a line like this: + // totals: 9620.00 11947.00 10099.75 380.38 + // and return the 3rd number, which is mean + if (line.startsWith("totals:")) { + line = line.substring(7).trim(); // strip "totals:" + String[] numbers = line.split("\\s+"); + if (numbers.length == 4) { + Bundle b = new Bundle(); + b.putString("mean", numbers[2]); + getInstrumentation().sendStatus(Activity.RESULT_FIRST_USER, b); + } + } + } + } }); mFinished = false; @@ -236,9 +257,6 @@ 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. diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java deleted file mode 100644 index d146fc7..0000000 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dumprendertree; - -import android.app.Activity; -import android.content.Intent; -import android.os.Environment; -import android.os.Handler; -import android.os.Message; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -public class ReliabilityTest extends ActivityInstrumentationTestCase2<ReliabilityTestActivity> { - - private static final String LOGTAG = "ReliabilityTest"; - private static final String PKG_NAME = "com.android.dumprendertree"; - private static final String EXTERNAL_DIR = - Environment.getExternalStorageDirectory().toString(); - private static final String TEST_LIST_FILE = EXTERNAL_DIR + - "/android/reliability_tests_list.txt"; - private static final String TEST_STATUS_FILE = EXTERNAL_DIR + - "/android/reliability_running_test.txt"; - private static final String TEST_TIMEOUT_FILE = EXTERNAL_DIR + - "/android/reliability_timeout_test.txt"; - private static final String TEST_LOAD_TIME_FILE = EXTERNAL_DIR + - "/android/reliability_load_time.txt"; - private static final String TEST_DONE = "#DONE"; - static final String RELIABILITY_TEST_RUNNER_FILES[] = { - "run_reliability_tests.py" - }; - - public ReliabilityTest() { - super(PKG_NAME, ReliabilityTestActivity.class); - } - - public void runReliabilityTest() throws Throwable { -// ReliabilityTestActivity activity = getActivity(); - LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner)getInstrumentation(); - - File testListFile = new File(TEST_LIST_FILE); - if(!testListFile.exists()) - throw new FileNotFoundException("test list file not found."); - - BufferedReader listReader = new BufferedReader( - new FileReader(testListFile)); - - //always try to resume first, hence cleaning up status will be the - //responsibility of driver scripts - String lastUrl = FsUtils.readTestStatus(TEST_STATUS_FILE); - if(lastUrl != null && !TEST_DONE.equals(lastUrl)) - fastForward(listReader, lastUrl); - - String url = null; - Handler handler = null; - boolean timeoutFlag = false; - long start, elapsed; - - Intent intent = new Intent(runner.getContext(), ReliabilityTestActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - ReliabilityTestActivity activity = (ReliabilityTestActivity)runner.startActivitySync( - intent); - //read from BufferedReader instead of populating a list in advance, - //this will avoid excessive memory usage in case of a large list - while((url = listReader.readLine()) != null) { - url = url.trim(); - if(url.length() == 0) - continue; - start = System.currentTimeMillis(); - Log.v(LOGTAG, "Testing URL: " + url); - FsUtils.updateTestStatus(TEST_STATUS_FILE, url); - activity.reset(); - //use message to send new URL to avoid interacting with - //WebView in non-UI thread - handler = activity.getHandler(); - Message msg = handler.obtainMessage( - ReliabilityTestActivity.MSG_NAVIGATE, - 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) { - Log.w(LOGTAG, "Page load finished in " + elapsed - + "ms, too soon?"); - } else { - Log.v(LOGTAG, "Page load finished in " + elapsed + "ms"); - } - if(timeoutFlag) { - writeTimeoutFile(url); - } - if(runner.mLogtime) { - writeLoadTime(url, activity.getPageLoadTime()); - } - System.runFinalization(); - System.gc(); - System.gc(); - } - activity.finish(); - FsUtils.updateTestStatus(TEST_STATUS_FILE, TEST_DONE); -// activity.finish(); - listReader.close(); - } - - public void copyRunnerAssetsToCache() { - try { - String out_dir = getActivity().getApplicationContext() - .getCacheDir().getPath() + "/"; - - for( int i=0; i< RELIABILITY_TEST_RUNNER_FILES.length; i++) { - InputStream in = getActivity().getAssets().open( - RELIABILITY_TEST_RUNNER_FILES[i]); - OutputStream out = new FileOutputStream( - out_dir + RELIABILITY_TEST_RUNNER_FILES[i]); - - byte[] buf = new byte[2048]; - int len; - - while ((len = in.read(buf)) >= 0 ) { - out.write(buf, 0, len); - } - out.close(); - in.close(); - } - }catch (IOException e) { - Log.e(LOGTAG, "Cannot extract scripts for testing.", e); - } - } - - private void fastForward(BufferedReader testListReader, String lastUrl) { - //fastforward the BufferedReader to the position right after last url - if(lastUrl == null) - return; - - String line = null; - try { - while((line = testListReader.readLine()) != null) { - if(lastUrl.equals(line)) - return; - } - } catch (IOException ioe) { - Log.e(LOGTAG, "Error while reading test list.", ioe); - return; - } - } - - private void writeTimeoutFile(String s) { - //append to the file containing the list of timeout urls - try { - BufferedOutputStream bos = new BufferedOutputStream( - new FileOutputStream(TEST_TIMEOUT_FILE, true)); - bos.write(s.getBytes()); - bos.write('\n'); - bos.close(); - } catch (Exception e) { - 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); - } - } -} diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java index 856ebcc..d151d9e 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java @@ -25,9 +25,6 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; -import android.graphics.Bitmap.Config; -import android.graphics.Canvas; import android.net.http.SslError; import android.os.Bundle; import android.os.Environment; @@ -200,8 +197,6 @@ 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); mStopOnRefError = intent.getBooleanExtra(STOP_ON_REF_ERROR, false); setTitle("Test " + mCurrentTestNumber + " of " + mTotalTestCount); float ratio = (float)mCurrentTestNumber / mTotalTestCount; @@ -311,6 +306,10 @@ public class TestShellActivity extends Activity implements LayoutTestController return; } + if (mCallback != null) { + mCallback.dumpResult(webkitData); + } + try { File parentDir = new File(mResultFile).getParentFile(); if (!parentDir.exists()) { @@ -564,18 +563,6 @@ 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. Otherwise we ask WebCore to @@ -830,47 +817,12 @@ public class TestShellActivity extends Activity implements LayoutTestController mEventSender.clearTouchMetaState(); mPageFinished = false; mDumpWebKitData = false; - mGetDrawtime = false; - mSaveImagePath = null; setDefaultWebSettings(mWebView); mIsGeolocationPermissionSet = false; mPendingGeolocationPermissionCallbacks = null; CookieManager.getInstance().removeAllCookie(); } - 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); - WebViewClassic.fromWebView(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() { return (mDumpWebKitData && mPageFinished && !mWaitUntilDone) || mTimedOut; } @@ -922,9 +874,7 @@ 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; private int mTotalTestCount; private int mCurrentTestNumber; private boolean mStopOnRefError; diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java index 55bf947..5220d57 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java @@ -18,5 +18,6 @@ package com.android.dumprendertree; public interface TestShellCallback { public void finished(); + public void dumpResult(String webViewDump); public void timedOut(String url); } |