diff options
author | Tobias Thierer <tobiast@google.com> | 2016-11-15 14:33:32 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-11-15 14:33:32 +0000 |
commit | c9637cda5068e91330bf73bb81b8afc176e2b48c (patch) | |
tree | 452a5866be3c17298fee9882007be4661309e805 | |
parent | 1f9933397eb3374355bc3e4c6c041a949d40050a (diff) | |
parent | 3ad2773818481c00cbdc093c0a625a6cc61a97f9 (diff) |
Merge "Let ProcessBuilderTest.testRedirectInherit() run sleep rather than sh"
-rw-r--r-- | luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java b/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java index 9254b8ddd1..7b7da9d8b0 100644 --- a/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java +++ b/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java @@ -16,6 +16,7 @@ package libcore.java.lang; +import android.system.ErrnoException; import android.system.Os; import java.io.ByteArrayOutputStream; import java.io.File; @@ -46,10 +47,22 @@ import static java.lang.ProcessBuilder.Redirect.PIPE; public class ProcessBuilderTest extends TestCase { private static final String TAG = ProcessBuilderTest.class.getSimpleName(); + /** + * Returns the path to a command that is in /system/bin/ on Android but + * /bin/ elsewhere. + * + * @param desktopPath the command path outside Android; must start with /bin/. + */ + private static String commandPath(String desktopPath) { + if (!desktopPath.startsWith("/bin/")) { + throw new IllegalArgumentException(desktopPath); + } + String devicePath = System.getenv("ANDROID_ROOT") + desktopPath; + return new File(devicePath).exists() ? devicePath : desktopPath; + } + private static String shell() { - String deviceSh = System.getenv("ANDROID_ROOT") + "/bin/sh"; - String desktopSh = "/bin/sh"; - return new File(deviceSh).exists() ? deviceSh : desktopSh; + return commandPath("/bin/sh"); } private static void assertRedirectErrorStream(boolean doRedirect, @@ -87,8 +100,10 @@ public class ProcessBuilderTest extends TestCase { * stdin / stdout / stderr file descriptors. */ public void testRedirectInherit() throws Exception { + // We can't run shell() here because that exits when run with INHERITed + // file descriptors from this process; "sleep" is less picky. Process process = new ProcessBuilder() - .command(shell()) + .command(commandPath("/bin/sleep"), "5") // in seconds .redirectInput(Redirect.INHERIT) .redirectOutput(Redirect.INHERIT) .redirectError(Redirect.INHERIT) @@ -106,6 +121,9 @@ public class ProcessBuilderTest extends TestCase { Os.stat("/proc/" + childPid + "/fd/2").st_ino); assertEquals(parentInodes, childInodes); + } catch (ErrnoException e) { + // Either (a) Os.fstat on our PID, or (b) Os.stat on our child's PID, failed. + throw new AssertionError("stat failed; child process: " + process, e); } finally { process.destroy(); } |