Capture stderr when we run composd_cmd
Errors are written to stderr, but on failure we only log stdout, so we
can't tell what the problem is.
This is only one instance of this - there are others in ComposTestCase
and AVFHostTestCase - but this is the one causing me problems right
now. I'll do the others in a following CL.
Bug: 275469579
Test: atest ComposBenchmarkApp (having modified composd_cmd to fail)
Change-Id: Ib6cd6312a6dac6e33760f3a82863648985cdb3c2
diff --git a/tests/helper/Android.bp b/tests/helper/Android.bp
index c9eafad..f36a15d 100644
--- a/tests/helper/Android.bp
+++ b/tests/helper/Android.bp
@@ -19,5 +19,5 @@
"MicrodroidTestHelper",
"truth-prebuilt",
],
- sdk_version: "system_current",
+ sdk_version: "test_current",
}
diff --git a/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java b/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
index 744f94c..cf17e5b 100644
--- a/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
+++ b/tests/helper/src/java/com/android/microdroid/test/device/MicrodroidDeviceTestBase.java
@@ -444,7 +444,25 @@
return stdout;
} catch (IOException e) {
Log.e(tag, "Error executing: " + command, e);
- throw new RuntimeException("Failed to run the command.");
+ throw new RuntimeException("Failed to run the command.", e);
+ }
+ }
+
+ /** Execute a command. Returns the concatenation of stdout and stderr. */
+ protected String runInShellWithStderr(String tag, UiAutomation uiAutomation, String command) {
+ ParcelFileDescriptor[] files = uiAutomation.executeShellCommandRwe(command);
+ try (InputStream stdout = new ParcelFileDescriptor.AutoCloseInputStream(files[0]);
+ InputStream stderr = new ParcelFileDescriptor.AutoCloseInputStream(files[2]);
+ ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ files[1].close(); // The command's stdin
+ stdout.transferTo(out);
+ stderr.transferTo(out);
+ String output = out.toString("UTF-8");
+ Log.i(tag, "Got output : " + stdout);
+ return output;
+ } catch (IOException e) {
+ Log.e(tag, "Error executing: " + command, e);
+ throw new RuntimeException("Failed to run the command.", e);
}
}