diff options
author | jbudorick <jbudorick@chromium.org> | 2015-01-28 09:10:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-28 17:11:41 +0000 |
commit | e1799e662af4e87b1e6d501e3511628f8579174d (patch) | |
tree | 5846896f5c966ef35fbf12b18a4f187a985ba61b /testing/android | |
parent | 61288e6cf8a84fb0f11556231deb29b25e24e180 (diff) | |
download | chromium_src-e1799e662af4e87b1e6d501e3511628f8579174d.zip chromium_src-e1799e662af4e87b1e6d501e3511628f8579174d.tar.gz chromium_src-e1799e662af4e87b1e6d501e3511628f8579174d.tar.bz2 |
[Android] Add a java version of the test server spawner.
BUG=448626
Review URL: https://codereview.chromium.org/867073002
Cr-Commit-Position: refs/heads/master@{#313532}
Diffstat (limited to 'testing/android')
-rw-r--r-- | testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java index 5043932..cc89268 100644 --- a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java +++ b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java @@ -12,13 +12,17 @@ import android.os.Bundle; import android.os.Environment; import android.util.Log; +import org.chromium.net.test.TestServerSpawner; + import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -32,9 +36,15 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation { public static final String EXTRA_ONLY_OUTPUT_FAILURES = "org.chromium.native_test.ChromeNativeTestInstrumentationTestRunner." + "OnlyOutputFailures"; + public static final String EXTRA_ENABLE_TEST_SERVER_SPAWNER = + "org.chromium.native_test.ChromeNativeTestInstrumentationTestRunner." + + "EnableTestServerSpawner"; private static final String TAG = "ChromeNativeTestInstrumentationTestRunner"; + + private static final int ACCEPT_TIMEOUT_MS = 5000; private static final Pattern RE_TEST_OUTPUT = Pattern.compile("\\[ *([^ ]*) *\\] ?([^ ]+) .*"); + private static final int SERVER_SPAWNER_PORT = 0; private static interface ResultsBundleGenerator { public Bundle generate(Map<String, TestResult> rawResults); @@ -47,6 +57,10 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation { private ResultsBundleGenerator mBundleGenerator; private boolean mOnlyOutputFailures; + private boolean mEnableTestServerSpawner; + private TestServerSpawner mTestServerSpawner; + private Thread mTestServerSpawnerThread; + @Override public void onCreate(Bundle arguments) { mCommandLineFile = arguments.getString(ChromeNativeTestActivity.EXTRA_COMMAND_LINE_FILE); @@ -63,16 +77,55 @@ public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation { mLogBundle = new Bundle(); mBundleGenerator = new RobotiumBundleGenerator(); mOnlyOutputFailures = arguments.containsKey(EXTRA_ONLY_OUTPUT_FAILURES); + mEnableTestServerSpawner = arguments.containsKey(EXTRA_ENABLE_TEST_SERVER_SPAWNER); + mTestServerSpawner = null; + mTestServerSpawnerThread = null; start(); } @Override public void onStart() { super.onStart(); + + setUp(); Bundle results = runTests(); + tearDown(); + finish(Activity.RESULT_OK, results); } + private void setUp() { + if (mEnableTestServerSpawner) { + Log.i(TAG, "Test server spawner enabled."); + try { + mTestServerSpawner = new TestServerSpawner(SERVER_SPAWNER_PORT, ACCEPT_TIMEOUT_MS); + + File portFile = new File( + Environment.getExternalStorageDirectory(), "net-test-server-ports"); + OutputStreamWriter writer = + new OutputStreamWriter(new FileOutputStream(portFile)); + writer.write(Integer.toString(mTestServerSpawner.getServerPort()) + ":0"); + writer.close(); + + mTestServerSpawnerThread = new Thread(mTestServerSpawner); + mTestServerSpawnerThread.start(); + } catch (IOException e) { + Log.e(TAG, "Error creating TestServerSpawner: " + e.toString()); + } + } + } + + private void tearDown() { + if (mTestServerSpawnerThread != null) { + try { + mTestServerSpawner.stop(); + mTestServerSpawnerThread.join(); + } catch (InterruptedException e) { + Log.e(TAG, "Interrupted while shutting down test server spawner: " + e.toString()); + } + } + } + /** Runs the tests in the ChromeNativeTestActivity and returns a Bundle containing the results. */ private Bundle runTests() { |