From 54be79ec8a00adb955a994382e01fe19045a6202 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sun, 2 Mar 2014 15:15:16 -0500 Subject: [PATCH] Tests for execvp Write data to and from the child process. Requires having busybox installed. Update the typespecs. --- bin/alcove.escript | 12 ++++++------ test/alcove_tests.erl | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/bin/alcove.escript b/bin/alcove.escript index 2233d11..ab4e97a 100755 --- a/bin/alcove.escript +++ b/bin/alcove.escript @@ -153,7 +153,7 @@ static() -> static({stdin,2}) -> " stdin(Port, Data) -> - alcove_drv:cast(Port, <>). + alcove_drv:cast(Port, [<>, Data]). "; static({stdout,1}) -> @@ -265,10 +265,10 @@ specs() -> -spec setrlimit(port(),non_neg_integer(),non_neg_integer(),non_neg_integer()) -> 'ok' | {'error', file:posix()}. -spec setrlimit(port(),non_neg_integer(),#rlimit{}) -> 'ok' | {'error', file:posix()}. -spec setuid(port(),non_neg_integer()) -> 'ok' | {'error', file:posix()}. --spec stderr(port()) -> any(). --spec stderr(port(),'infinity' | non_neg_integer()) -> any(). --spec stdin(port(),binary()) -> 'true'. --spec stdout(port()) -> any(). --spec stdout(port(),'infinity' | non_neg_integer()) -> any(). +-spec stderr(port()) -> 'false' | binary(). +-spec stderr(port(),'infinity' | non_neg_integer()) -> 'false' | binary(). +-spec stdin(port(),iodata()) -> 'true'. +-spec stdout(port()) -> 'false' | binary(). +-spec stdout(port(),'infinity' | non_neg_integer()) -> 'false' | binary(). -spec version(port()) -> binary(). ". diff --git a/test/alcove_tests.erl b/test/alcove_tests.erl index 9a86d81..8ac92ab 100644 --- a/test/alcove_tests.erl +++ b/test/alcove_tests.erl @@ -27,13 +27,16 @@ erlxc_test_() -> }. run(Port) -> + % Test order must be maintained [ version(Port), chroot(Port), chdir(Port), setrlimit(Port), setgid(Port), - setuid(Port) + setuid(Port), + execvp(Port), + stdin(Port) ]. start() -> @@ -81,3 +84,20 @@ setuid(Port) -> ?_assertEqual(ok, Reply), ?_assertEqual(65534, UID) ]. + +execvp(Port) -> + % cwd = /, chroot'ed in /bin + Reply = alcove:execvp(Port, "/busybox", ["/busybox", "sh", "-i"]), + Stderr = alcove:stderr(Port, 5000), + [ + ?_assertEqual(ok, Reply), + ?_assertNotEqual(false, Stderr) + ]. + +stdin(Port) -> + Reply = alcove:stdin(Port, "help\n"), + Stdout = alcove:stdout(Port, 5000), + [ + ?_assertEqual(true, Reply), + ?_assertNotEqual(false, Stdout) + ].