| Index: testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
|
| diff --git a/testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java b/testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
|
| index 3d9c44242bac222edbb0f92320024193194dd9e6..b881bcc817607ed32623ab70c06d35691a0917df 100644
|
| --- a/testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
|
| +++ b/testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
|
| @@ -19,25 +19,15 @@ import android.util.SparseArray;
|
|
|
| import org.chromium.base.Log;
|
| import org.chromium.test.reporter.TestStatusReceiver;
|
| -import org.chromium.test.support.ResultsBundleGenerator;
|
| -import org.chromium.test.support.RobotiumBundleGenerator;
|
|
|
| -import java.io.BufferedInputStream;
|
| import java.io.BufferedReader;
|
| import java.io.File;
|
| -import java.io.FileInputStream;
|
| -import java.io.FileNotFoundException;
|
| import java.io.FileReader;
|
| import java.io.IOException;
|
| -import java.io.InputStreamReader;
|
| import java.util.ArrayDeque;
|
| import java.util.ArrayList;
|
| -import java.util.HashMap;
|
| -import java.util.Map;
|
| import java.util.Queue;
|
| import java.util.concurrent.atomic.AtomicBoolean;
|
| -import java.util.regex.Matcher;
|
| -import java.util.regex.Pattern;
|
|
|
| /**
|
| * An Instrumentation that runs tests based on NativeTest.
|
| @@ -50,6 +40,8 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
|
| "org.chromium.native_test.NativeTestInstrumentationTestRunner.ShardNanoTimeout";
|
| public static final String EXTRA_SHARD_SIZE_LIMIT =
|
| "org.chromium.native_test.NativeTestInstrumentationTestRunner.ShardSizeLimit";
|
| + public static final String EXTRA_STDOUT_FILE =
|
| + "org.chromium.native_test.NativeTestInstrumentationTestRunner.StdoutFile";
|
| public static final String EXTRA_TEST_LIST_FILE =
|
| "org.chromium.native_test.NativeTestInstrumentationTestRunner.TestList";
|
| public static final String EXTRA_TEST =
|
| @@ -62,16 +54,12 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
|
| private static final int DEFAULT_SHARD_SIZE_LIMIT = 0;
|
| private static final String DEFAULT_NATIVE_TEST_ACTIVITY =
|
| "org.chromium.native_test.NativeUnitTestActivity";
|
| - private static final Pattern RE_TEST_OUTPUT =
|
| - Pattern.compile("\\[ *([^ ]*) *\\] ?([^ \\.]+)\\.([^ \\.]+)( .*)?$");
|
|
|
| - private ResultsBundleGenerator mBundleGenerator = new RobotiumBundleGenerator();
|
| private Handler mHandler = new Handler();
|
| private Bundle mLogBundle = new Bundle();
|
| private SparseArray<ShardMonitor> mMonitors = new SparseArray<ShardMonitor>();
|
| private String mNativeTestActivity;
|
| private TestStatusReceiver mReceiver;
|
| - private TestResults mResults = new TestResults();
|
| private Queue<ArrayList<String>> mShards = new ArrayDeque<ArrayList<String>>();
|
| private long mShardNanoTimeout = DEFAULT_SHARD_NANO_TIMEOUT;
|
| private int mShardSizeLimit = DEFAULT_SHARD_SIZE_LIMIT;
|
| @@ -94,6 +82,23 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
|
| if (shardSizeLimit != null) mShardSizeLimit = Integer.parseInt(shardSizeLimit);
|
| mTransparentArguments.remove(EXTRA_SHARD_SIZE_LIMIT);
|
|
|
| + String stdoutFile = arguments.getString(EXTRA_STDOUT_FILE);
|
| + if (stdoutFile != null) {
|
| + mStdoutFile = new File(stdoutFile);
|
| + } else {
|
| + try {
|
| + mStdoutFile = File.createTempFile(
|
| + ".temp_stdout_", ".txt", Environment.getExternalStorageDirectory());
|
| + Log.i(TAG, "stdout file created: %s", mStdoutFile.getAbsolutePath());
|
| + } catch (IOException e) {
|
| + Log.e(TAG, "Unable to create temporary stdout file.", e);
|
| + finish(Activity.RESULT_CANCELED, new Bundle());
|
| + return;
|
| + }
|
| + }
|
| +
|
| + mTransparentArguments.remove(EXTRA_STDOUT_FILE);
|
| +
|
| String singleTest = arguments.getString(EXTRA_TEST);
|
| if (singleTest != null) {
|
| ArrayList<String> shard = new ArrayList<>(1);
|
| @@ -129,16 +134,6 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
|
| }
|
| mTransparentArguments.remove(EXTRA_TEST_LIST_FILE);
|
|
|
| - try {
|
| - mStdoutFile = File.createTempFile(
|
| - ".temp_stdout_", ".txt", Environment.getExternalStorageDirectory());
|
| - Log.i(TAG, "stdout file created: %s", mStdoutFile.getAbsolutePath());
|
| - } catch (IOException e) {
|
| - Log.e(TAG, "Unable to create temporary stdout file.", e);
|
| - finish(Activity.RESULT_CANCELED, new Bundle());
|
| - return;
|
| - }
|
| -
|
| start();
|
| }
|
|
|
| @@ -182,26 +177,6 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
|
| mHandler.post(new ShardStarter());
|
| }
|
|
|
| - /** Holds the results of a test run. */
|
| - private static class TestResults {
|
| - Map<String, ResultsBundleGenerator.TestResult> mResults =
|
| - new HashMap<String, ResultsBundleGenerator.TestResult>();
|
| - int mTestsPassed = 0;
|
| - int mTestsFailed = 0;
|
| - int mTestsErrored = 0;
|
| -
|
| - public void merge(TestResults other) {
|
| - mResults.putAll(other.mResults);
|
| - mTestsPassed += other.mTestsPassed;
|
| - mTestsFailed += other.mTestsFailed;
|
| - mTestsErrored += other.mTestsErrored;
|
| - }
|
| -
|
| - public int total() {
|
| - return mTestsPassed + mTestsFailed + mTestsErrored;
|
| - }
|
| - }
|
| -
|
| /** Monitors a test shard's execution. */
|
| private class ShardMonitor implements Runnable {
|
| private static final int MONITOR_FREQUENCY_MS = 1000;
|
| @@ -292,155 +267,11 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
|
| Log.e(TAG, "%d may still be alive.", mPid, e);
|
| }
|
| }
|
| - mResults.merge(parseResults());
|
| -
|
| if (mShards != null && !mShards.isEmpty()) {
|
| mHandler.post(new ShardStarter());
|
| } else {
|
| - sendResultsAndFinish(mResults);
|
| + finish(Activity.RESULT_OK, new Bundle());
|
| }
|
| }
|
| }
|
| -
|
| - private void sendResultsAndFinish(TestResults results) {
|
| - for (ResultsBundleGenerator.TestCaseResult result :
|
| - mBundleGenerator.generateIntermediateTestResults(results.mResults)) {
|
| - sendStatus(result.mStatusCode, result.mBundle);
|
| - }
|
| - Bundle bundle = mBundleGenerator.generate(
|
| - results.mTestsPassed, results.mTestsFailed, results.mTestsErrored, results.total());
|
| - finish(Activity.RESULT_OK, bundle);
|
| - }
|
| -
|
| - private static class NativeTestResult implements ResultsBundleGenerator.TestResult {
|
| - private String mTestClass;
|
| - private String mTestName;
|
| - private int mTestIndex;
|
| - private StringBuilder mLogBuilder = new StringBuilder();
|
| - private ResultsBundleGenerator.TestStatus mStatus =
|
| - ResultsBundleGenerator.TestStatus.UNKNOWN;
|
| -
|
| - private NativeTestResult(String testClass, String testName, int index) {
|
| - mTestClass = testClass;
|
| - mTestName = testName;
|
| - mTestIndex = index;
|
| - }
|
| -
|
| - @Override
|
| - public String getTestClass() {
|
| - return mTestClass;
|
| - }
|
| -
|
| - @Override
|
| - public String getTestName() {
|
| - return mTestName;
|
| - }
|
| -
|
| - @Override
|
| - public int getTestIndex() {
|
| - return mTestIndex;
|
| - }
|
| -
|
| - @Override
|
| - public String getMessage() {
|
| - return mStatus.toString();
|
| - }
|
| -
|
| - @Override
|
| - public String getLog() {
|
| - return mLogBuilder.toString();
|
| - }
|
| -
|
| - public void appendToLog(String logLine) {
|
| - mLogBuilder.append(logLine);
|
| - mLogBuilder.append("\n");
|
| - }
|
| -
|
| - @Override
|
| - public ResultsBundleGenerator.TestStatus getStatus() {
|
| - return mStatus;
|
| - }
|
| -
|
| - public void setStatus(ResultsBundleGenerator.TestStatus status) {
|
| - mStatus = status;
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Generates a map between test names and test results from the instrumented Activity's
|
| - * output.
|
| - */
|
| - private TestResults parseResults() {
|
| - TestResults results = new TestResults();
|
| -
|
| - BufferedReader r = null;
|
| -
|
| - try {
|
| - if (mStdoutFile == null || !mStdoutFile.exists()) {
|
| - Log.e(TAG, "Unable to find stdout file.");
|
| - return results;
|
| - }
|
| -
|
| - r = new BufferedReader(new InputStreamReader(
|
| - new BufferedInputStream(new FileInputStream(mStdoutFile))));
|
| -
|
| - NativeTestResult testResult = null;
|
| - int testNum = 0;
|
| - for (String l = r.readLine(); l != null && !l.equals("<<ScopedMainEntryLogger");
|
| - l = r.readLine()) {
|
| - Matcher m = RE_TEST_OUTPUT.matcher(l);
|
| - if (m.matches()) {
|
| - String testClass = m.group(2);
|
| - String testName = m.group(3);
|
| - if (m.group(1).equals("RUN")) {
|
| - testResult = new NativeTestResult(testClass, testName, ++testNum);
|
| - results.mResults.put(
|
| - String.format("%s.%s", testClass, testName), testResult);
|
| - } else if (m.group(1).equals("FAILED")) {
|
| - if (testResult == null) {
|
| - Log.e(TAG, "Test %s.%s failed without running.", testClass, testName);
|
| - continue;
|
| - }
|
| - results.mTestsFailed++;
|
| - testResult.setStatus(ResultsBundleGenerator.TestStatus.FAILED);
|
| - testResult = null;
|
| - } else if (m.group(1).equals("OK")) {
|
| - if (testResult == null) {
|
| - Log.e(TAG, "Test %s.%s succeeded without running.", testClass,
|
| - testName);
|
| - continue;
|
| - }
|
| - results.mTestsPassed++;
|
| - testResult.setStatus(ResultsBundleGenerator.TestStatus.PASSED);
|
| - testResult = null;
|
| - }
|
| - } else if (testResult != null) {
|
| - // We are inside a test. Let's collect log data in case there is a failure.
|
| - testResult.appendToLog(l);
|
| - }
|
| - mLogBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, l + "\n");
|
| - sendStatus(0, mLogBundle);
|
| - Log.i(TAG, l);
|
| - }
|
| - } catch (FileNotFoundException e) {
|
| - Log.e(TAG, "Couldn't find stdout file: ", e);
|
| - } catch (IOException e) {
|
| - Log.e(TAG, "Error handling stdout file: ", e);
|
| - } finally {
|
| - if (r != null) {
|
| - try {
|
| - r.close();
|
| - } catch (IOException e) {
|
| - Log.e(TAG, "Error while closing stdout reader.", e);
|
| - }
|
| - }
|
| - if (mStdoutFile != null) {
|
| - if (!mStdoutFile.delete()) {
|
| - Log.e(TAG, "Unable to delete %s", mStdoutFile.getAbsolutePath());
|
| - }
|
| - }
|
| - }
|
| - return results;
|
| - }
|
| -
|
| }
|
|
|