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

Commit 5fb9ff42 authored by Maksymilian Osowski's avatar Maksymilian Osowski
Browse files

Added a basic version of python script and supporting code in DumpRenderTree.

Change-Id: Ic60ef9b89f74a3a36a4c31765f99c8de08dce911
parent cbfe6ec1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
#!/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();
+4 −4
Original line number Diff line number Diff line
@@ -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);
    }

+16 −0
Original line number Diff line number Diff line
@@ -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
Loading