Added a basic version of python script and supporting code in DumpRenderTree.
Change-Id: Ic60ef9b89f74a3a36a4c31765f99c8de08dce911
This commit is contained in:
@@ -5,6 +5,8 @@ LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := diff_match_patch
|
||||
|
||||
LOCAL_PACKAGE_NAME := DumpRenderTree2
|
||||
|
||||
@@ -16,6 +16,8 @@ limitations under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.dumprendertree2">
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
|
||||
<activity android:name=".ui.DirListActivity"
|
||||
android:label="Dump Render Tree 2"
|
||||
android:configChanges="orientation">
|
||||
@@ -45,6 +47,10 @@ limitations under the License.
|
||||
</service>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
|
||||
android:targetPackage="com.android.dumprendertree2"
|
||||
android:label="Layout tests script runner" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_SDCARD" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
65
tests/DumpRenderTree2/assets/run_layout_tests.py
Normal file
65
tests/DumpRenderTree2/assets/run_layout_tests.py
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""Run layout tests on the device.
|
||||
|
||||
It runs the specified tests on the device, downloads the summaries to the temporary directory
|
||||
and opens html details in the default browser.
|
||||
|
||||
Usage:
|
||||
run_layout_tests.py PATH
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
import webbrowser
|
||||
import tempfile
|
||||
|
||||
#TODO: These should not be hardcoded
|
||||
RESULTS_ABSOLUTE_PATH = "/sdcard/android/LayoutTests-results/"
|
||||
DETAILS_HTML = "details.html"
|
||||
SUMMARY_TXT = "summary.txt"
|
||||
|
||||
def main():
|
||||
if len(sys.argv) > 1:
|
||||
path = sys.argv[1]
|
||||
else:
|
||||
path = ""
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
||||
|
||||
tmpdir = tempfile.gettempdir()
|
||||
|
||||
# Run the tests in path
|
||||
cmd = "adb shell am instrument "
|
||||
cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests "
|
||||
cmd += "-e path \"" + path + "\" "
|
||||
cmd +="-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
|
||||
|
||||
logging.info("Running the tests...")
|
||||
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
|
||||
logging.info("Downloading the summaries...")
|
||||
|
||||
# Download the txt summary to tmp folder
|
||||
summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT)
|
||||
cmd = "adb pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
|
||||
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
|
||||
# Download the html summary to tmp folder
|
||||
details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
|
||||
cmd = "adb pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
|
||||
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
|
||||
# Print summary to console
|
||||
logging.info("All done.\n")
|
||||
cmd = "cat " + summary_txt_tmp_path
|
||||
os.system(cmd)
|
||||
logging.info("")
|
||||
|
||||
# Open the browser with summary
|
||||
webbrowser.open(details_html_tmp_path)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main();
|
||||
@@ -166,7 +166,7 @@ public class Summarizer {
|
||||
"</script>";
|
||||
|
||||
/** TODO: Make it a setting */
|
||||
private static final String HTML_SUMMARY_RELATIVE_PATH = "summary.html";
|
||||
private static final String HTML_DETAILS_RELATIVE_PATH = "details.html";
|
||||
private static final String TXT_SUMMARY_RELATIVE_PATH = "summary.txt";
|
||||
|
||||
private int mCrashedTestsCount = 0;
|
||||
@@ -201,7 +201,7 @@ public class Summarizer {
|
||||
}
|
||||
|
||||
public void summarize() {
|
||||
createHtmlSummary();
|
||||
createHtmlDetails();
|
||||
createTxtSummary();
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ public class Summarizer {
|
||||
txt.toString().getBytes(), false);
|
||||
}
|
||||
|
||||
private void createHtmlSummary() {
|
||||
private void createHtmlDetails() {
|
||||
StringBuilder html = new StringBuilder();
|
||||
|
||||
html.append("<html><head>");
|
||||
@@ -247,7 +247,7 @@ public class Summarizer {
|
||||
|
||||
html.append("</body></html>");
|
||||
|
||||
FsUtils.writeDataToStorage(new File(mResultsRootDirPath, HTML_SUMMARY_RELATIVE_PATH),
|
||||
FsUtils.writeDataToStorage(new File(mResultsRootDirPath, HTML_DETAILS_RELATIVE_PATH),
|
||||
html.toString().getBytes(), false);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.Window;
|
||||
|
||||
import com.android.dumprendertree2.scriptsupport.OnEverythingFinishedCallback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -57,6 +59,9 @@ public class TestsListActivity extends Activity {
|
||||
private ArrayList<String> mTestsList;
|
||||
private int mTotalTestCount;
|
||||
|
||||
private OnEverythingFinishedCallback mOnEverythingFinishedCallback;
|
||||
private boolean mEverythingFinished;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -110,8 +115,19 @@ public class TestsListActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerOnEverythingFinishedCallback(OnEverythingFinishedCallback callback) {
|
||||
mOnEverythingFinishedCallback = callback;
|
||||
if (mEverythingFinished) {
|
||||
mOnEverythingFinishedCallback.onFinished();
|
||||
}
|
||||
}
|
||||
|
||||
private void onEverythingFinishedIntent(Intent intent) {
|
||||
/** TODO: Show some kind of summary to the user */
|
||||
mEverythingFinished = true;
|
||||
if (mOnEverythingFinishedCallback != null) {
|
||||
mOnEverythingFinishedCallback.onFinished();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.dumprendertree2.scriptsupport;
|
||||
|
||||
/**
|
||||
* Callback used to inform scriptsupport.Starter that everything is finished and
|
||||
* we can exit
|
||||
*/
|
||||
public interface OnEverythingFinishedCallback {
|
||||
public void onFinished();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.dumprendertree2.scriptsupport;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
|
||||
/**
|
||||
* Extends InstrumentationTestRunner to allow the script to pass arguments to the application
|
||||
*/
|
||||
public class ScriptTestRunner extends InstrumentationTestRunner {
|
||||
String mTestsRelativePath;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle arguments) {
|
||||
mTestsRelativePath = arguments.getString("path");
|
||||
super.onCreate(arguments);
|
||||
}
|
||||
|
||||
public String getTestsRelativePath() {
|
||||
return mTestsRelativePath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.dumprendertree2.scriptsupport;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.dumprendertree2.TestsListActivity;
|
||||
|
||||
/**
|
||||
* A class which provides methods that can be invoked by a script running on the host machine to
|
||||
* run the tests.
|
||||
*
|
||||
* It starts a TestsListActivity and does not return until all the tests finish executing.
|
||||
*/
|
||||
public class Starter extends ActivityInstrumentationTestCase2<TestsListActivity> {
|
||||
private static final String LOG_TAG = "Starter";
|
||||
private boolean mEverythingFinished;
|
||||
|
||||
public Starter() {
|
||||
super(TestsListActivity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from adb to start executing the tests. It doesn't return
|
||||
* until everything is finished so that the script can wait for the end if it needs
|
||||
* to.
|
||||
*/
|
||||
public void startLayoutTests() {
|
||||
ScriptTestRunner runner = (ScriptTestRunner)getInstrumentation();
|
||||
String relativePath = runner.getTestsRelativePath();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("com.android.dumprendertree2", "TestsListActivity");
|
||||
intent.setAction(Intent.ACTION_RUN);
|
||||
intent.putExtra(TestsListActivity.EXTRA_TEST_PATH, relativePath);
|
||||
setActivityIntent(intent);
|
||||
getActivity().registerOnEverythingFinishedCallback(new OnEverythingFinishedCallback() {
|
||||
/** This method is safe to call on any thread */
|
||||
@Override
|
||||
public void onFinished() {
|
||||
synchronized (Starter.this) {
|
||||
mEverythingFinished = true;
|
||||
Starter.this.notifyAll();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
synchronized (this) {
|
||||
while (!mEverythingFinished) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(LOG_TAG + "::startLayoutTests", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user