Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1313)

Unified Diff: testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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/ChromeNativeTestInstrumentationTestRunner.java b/testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
similarity index 56%
rename from testing/android/native_test/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java
rename to testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
index 4e1a067907597e46d225b78f7256eba118bdd7f2..c5a4443e1a4c1c6122638dc793aab6691397f92d 100644
--- a/testing/android/native_test/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java
+++ b/testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java
@@ -10,7 +10,10 @@ import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
-import android.util.Log;
+
+import org.chromium.base.Log;
+import org.chromium.test.support.ResultsBundleGenerator;
+import org.chromium.test.support.RobotiumBundleGenerator;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
@@ -25,23 +28,19 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * An Instrumentation that runs tests based on ChromeNativeTestActivity.
+ * An Instrumentation that runs tests based on NativeTestActivity.
*/
-public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation {
+public class NativeTestInstrumentationTestRunner extends Instrumentation {
// TODO(jbudorick): Remove this extra when b/18981674 is fixed.
public static final String EXTRA_ONLY_OUTPUT_FAILURES =
- "org.chromium.native_test.ChromeNativeTestInstrumentationTestRunner."
+ "org.chromium.native_test.NativeTestInstrumentationTestRunner."
+ "OnlyOutputFailures";
- private static final String TAG = "ChromeNativeTestInstrumentationTestRunner";
+ private static final String TAG = Log.makeTag("native_test");
private static final int ACCEPT_TIMEOUT_MS = 5000;
private static final Pattern RE_TEST_OUTPUT = Pattern.compile("\\[ *([^ ]*) *\\] ?([^ ]+) .*");
- private static interface ResultsBundleGenerator {
- public Bundle generate(Map<String, TestResult> rawResults);
- }
-
private String mCommandLineFile;
private String mCommandLineFlags;
private File mStdoutFile;
@@ -51,14 +50,14 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation {
@Override
public void onCreate(Bundle arguments) {
- mCommandLineFile = arguments.getString(ChromeNativeTestActivity.EXTRA_COMMAND_LINE_FILE);
- mCommandLineFlags = arguments.getString(ChromeNativeTestActivity.EXTRA_COMMAND_LINE_FLAGS);
+ mCommandLineFile = arguments.getString(NativeTestActivity.EXTRA_COMMAND_LINE_FILE);
+ mCommandLineFlags = arguments.getString(NativeTestActivity.EXTRA_COMMAND_LINE_FLAGS);
try {
mStdoutFile = File.createTempFile(
".temp_stdout_", ".txt", Environment.getExternalStorageDirectory());
- Log.i(TAG, "stdout file created: " + mStdoutFile.getAbsolutePath());
+ Log.i(TAG, "stdout file created: %s", mStdoutFile.getAbsolutePath());
} catch (IOException e) {
- Log.e(TAG, "Unable to create temporary stdout file." + e.toString());
+ Log.e(TAG, "Unable to create temporary stdout file.", e);
finish(Activity.RESULT_CANCELED, new Bundle());
return;
}
@@ -75,7 +74,7 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation {
finish(Activity.RESULT_OK, results);
}
- /** Runs the tests in the ChromeNativeTestActivity and returns a Bundle containing the results.
+ /** Runs the tests in the NativeTestActivity and returns a Bundle containing the results.
*/
private Bundle runTests() {
Log.i(TAG, "Creating activity.");
@@ -87,46 +86,44 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation {
Thread.sleep(100);
}
} catch (InterruptedException e) {
- Log.e(TAG, "Interrupted while waiting for activity to be destroyed: " + e.toString());
+ Log.e(TAG, "Interrupted while waiting for activity to be destroyed: ", e);
}
Log.i(TAG, "Getting results.");
- Map<String, TestResult> results = parseResults(activityUnderTest);
+ Map<String, ResultsBundleGenerator.TestResult> results = parseResults(activityUnderTest);
Log.i(TAG, "Parsing results and generating output.");
return mBundleGenerator.generate(results);
}
- /** Starts the ChromeNativeTestActivty.
+ /** Starts the NativeTestActivty.
*/
private Activity startNativeTestActivity() {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName(
"org.chromium.native_test",
- "org.chromium.native_test.ChromeNativeTestActivity"));
+ "org.chromium.native_test.NativeTestActivity"));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (mCommandLineFile != null) {
- Log.i(TAG, "Passing command line file extra: " + mCommandLineFile);
- i.putExtra(ChromeNativeTestActivity.EXTRA_COMMAND_LINE_FILE, mCommandLineFile);
+ Log.i(TAG, "Passing command line file extra: %s", mCommandLineFile);
+ i.putExtra(NativeTestActivity.EXTRA_COMMAND_LINE_FILE, mCommandLineFile);
}
if (mCommandLineFlags != null) {
- Log.i(TAG, "Passing command line flag extra: " + mCommandLineFlags);
- i.putExtra(ChromeNativeTestActivity.EXTRA_COMMAND_LINE_FLAGS, mCommandLineFlags);
+ Log.i(TAG, "Passing command line flag extra: %s", mCommandLineFlags);
+ i.putExtra(NativeTestActivity.EXTRA_COMMAND_LINE_FLAGS, mCommandLineFlags);
}
- i.putExtra(ChromeNativeTestActivity.EXTRA_STDOUT_FILE, mStdoutFile.getAbsolutePath());
+ i.putExtra(NativeTestActivity.EXTRA_STDOUT_FILE, mStdoutFile.getAbsolutePath());
return startActivitySync(i);
}
- private static enum TestResult {
- PASSED, FAILED, ERROR, UNKNOWN
- }
-
/**
* Generates a map between test names and test results from the instrumented Activity's
* output.
*/
- private Map<String, TestResult> parseResults(Activity activityUnderTest) {
- Map<String, TestResult> results = new HashMap<String, TestResult>();
+ private Map<String, ResultsBundleGenerator.TestResult> parseResults(
+ Activity activityUnderTest) {
+ Map<String, ResultsBundleGenerator.TestResult> results =
+ new HashMap<String, ResultsBundleGenerator.TestResult>();
BufferedReader r = null;
@@ -145,14 +142,14 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation {
boolean isFailure = false;
if (m.matches()) {
if (m.group(1).equals("RUN")) {
- results.put(m.group(2), TestResult.UNKNOWN);
+ results.put(m.group(2), ResultsBundleGenerator.TestResult.UNKNOWN);
} else if (m.group(1).equals("FAILED")) {
- results.put(m.group(2), TestResult.FAILED);
+ results.put(m.group(2), ResultsBundleGenerator.TestResult.FAILED);
isFailure = true;
mLogBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, l + "\n");
sendStatus(0, mLogBundle);
} else if (m.group(1).equals("OK")) {
- results.put(m.group(2), TestResult.PASSED);
+ results.put(m.group(2), ResultsBundleGenerator.TestResult.PASSED);
}
}
@@ -165,66 +162,24 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation {
Log.i(TAG, l);
}
} catch (FileNotFoundException e) {
- Log.e(TAG, "Couldn't find stdout file file: " + e.toString());
+ Log.e(TAG, "Couldn't find stdout file file: ", e);
} catch (IOException e) {
- Log.e(TAG, "Error handling stdout file: " + e.toString());
+ 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.");
+ Log.e(TAG, "Error while closing stdout reader.", e);
}
}
if (mStdoutFile != null) {
if (!mStdoutFile.delete()) {
- Log.e(TAG, "Unable to delete " + mStdoutFile.getAbsolutePath());
+ Log.e(TAG, "Unable to delete %s", mStdoutFile.getAbsolutePath());
}
}
}
return results;
}
- /**
- * Creates a results bundle that emulates the one created by Robotium.
- */
- private static class RobotiumBundleGenerator implements ResultsBundleGenerator {
- public Bundle generate(Map<String, TestResult> rawResults) {
- Bundle resultsBundle = new Bundle();
-
- int testsPassed = 0;
- int testsFailed = 0;
-
- for (Map.Entry<String, TestResult> entry : rawResults.entrySet()) {
- switch (entry.getValue()) {
- case PASSED:
- ++testsPassed;
- break;
- case FAILED:
- // TODO(jbudorick): Remove this log message once AMP execution and
- // results handling has been stabilized.
- Log.d(TAG, "FAILED: " + entry.getKey());
- ++testsFailed;
- break;
- default:
- Log.w(TAG, "Unhandled: " + entry.getKey() + ", "
- + entry.getValue().toString());
- break;
- }
- }
-
- StringBuilder resultBuilder = new StringBuilder();
- if (testsFailed > 0) {
- resultBuilder.append(
- "\nFAILURES!!! Tests run: " + Integer.toString(rawResults.size())
- + ", Failures: " + Integer.toString(testsFailed) + ", Errors: 0");
- } else {
- resultBuilder.append("\nOK (" + Integer.toString(testsPassed) + " tests)");
- }
- resultsBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
- resultBuilder.toString());
- return resultsBundle;
- }
- }
-
}

Powered by Google App Engine
This is Rietveld 408576698