summaryrefslogtreecommitdiff
path: root/tools/runner/lib/TestActivity.java
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-03-31 23:51:56 -0700
committerJesse Wilson <jessewilson@google.com>2010-04-01 14:42:05 -0700
commit575e89934e81c1bebaecee13d3048268648f5adc (patch)
tree245873cb76eb1f5d49aacf40fab1046eca2f25f1 /tools/runner/lib/TestActivity.java
parentba6fad59410d74c4dbb19715dea6f5ea09a4b14c (diff)
New method-level granularity and output streaming for vogar.
Diffstat (limited to 'tools/runner/lib/TestActivity.java')
-rw-r--r--tools/runner/lib/TestActivity.java68
1 files changed, 12 insertions, 56 deletions
diff --git a/tools/runner/lib/TestActivity.java b/tools/runner/lib/TestActivity.java
index c4d9070e9b..6e6d09f198 100644
--- a/tools/runner/lib/TestActivity.java
+++ b/tools/runner/lib/TestActivity.java
@@ -20,11 +20,10 @@ import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
-import vogar.TestProperties;
+import vogar.Threads;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
/**
* Runs a user-supplied {@code main(String[] args)} method
@@ -44,62 +43,19 @@ public class TestActivity extends Activity {
this.view = new TextView(this);
log("TestActivity starting...");
setContentView(view);
- ActivityRunner activityRunner = new ActivityRunner();
- activityRunner.run();
- }
- private void log(String message, Throwable ex) {
- log(message + "\n" + Log.getStackTraceString(ex));
+ ExecutorService executor = Executors.newFixedThreadPool(
+ 1, Threads.daemonThreadFactory());
+ executor.submit(new Runnable() {
+ public void run() {
+ new TestRunner().run();
+ }
+ });
+ executor.shutdown();
}
+
private void log(String message) {
Log.i(TAG, message);
view.append(message + "\n");
}
-
- class ActivityRunner extends TestRunner {
-
- private final File runnerDir;
- private final Thread shutdownHook = new Thread(new ShutdownHook());
-
- ActivityRunner() {
- runnerDir = new File(properties.getProperty(TestProperties.DEVICE_RUNNER_DIR));
- }
-
- @Override public boolean run() {
- log("Using " + runnerClass + " to run " + qualifiedName);
- Runtime.getRuntime().addShutdownHook(shutdownHook);
- boolean success = super.run();
- Runtime.getRuntime().removeShutdownHook(shutdownHook);
- writeResultFile(success);
- return success;
- }
-
- private void writeResultFile (boolean success) {
- String result = TestProperties.result(success);
- File resultDir = new File(runnerDir, qualifiedName);
- File resultTemp = new File(resultDir, TestProperties.RESULT_FILE + ".temp");
- File resultFile = new File(resultDir, TestProperties.RESULT_FILE);
- log("TestActivity " + result + " " + resultFile);
- try {
- FileOutputStream resultOut = new FileOutputStream(resultTemp);
- resultOut.write(result.getBytes("UTF-8"));
- resultOut.close();
- // atomically rename since Vogar will be polling for this
- resultTemp.renameTo(resultFile);
- } catch (IOException e) {
- log("TestActivity could not create result file", e);
- }
- }
-
- /**
- * Used to trap tests that try to exit on the their own. We
- * treat this as a failure since they usually are calling
- * System.exit with a non-zero value.
- */
- class ShutdownHook implements Runnable {
- public void run() {
- writeResultFile(false);
- }
- }
- }
}