Skip to content

Commit

Permalink
test/unistd: add test_fexecve
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Aug 17, 2017
1 parent a7303ff commit 6e35a34
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod linux_android {
}

macro_rules! execve_test_factory(
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
($test_name:ident, $syscall:ident, $exe: expr) => (
#[test]
fn $test_name() {
#[allow(unused_variables)]
Expand All @@ -119,19 +119,13 @@ macro_rules! execve_test_factory(
// The tests make sure not to do that, though.
match fork().unwrap() {
Child => {
#[cfg(not(target_os = "android"))]
const SH_PATH: &'static [u8] = $unix_sh;

#[cfg(target_os = "android")]
const SH_PATH: &'static [u8] = $android_sh;

// Close stdout.
close(1).unwrap();
// Make `writer` be the stdout of the new process.
dup(writer).unwrap();
// exec!
$syscall(
&CString::new(SH_PATH).unwrap(),
$exe,
&[CString::new(b"".as_ref()).unwrap(),
CString::new(b"-c".as_ref()).unwrap(),
CString::new(b"echo nix!!! && echo foo=$foo && echo baz=$baz"
Expand All @@ -156,6 +150,15 @@ macro_rules! execve_test_factory(
)
);

#[cfg(not(target_os = "android"))]
const SH_PATH: &'static str = "/bin/sh";
#[cfg(target_os = "android")]
const SH_PATH: &'static str = "/system/bin/sh";

execve_test_factory!(test_execve, execve, &CString::new(SH_PATH).unwrap());
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
execve_test_factory!(test_fexecve, fexecve, File::open(SH_PATH).unwrap().into_raw_fd());

#[test]
fn test_fchdir() {
// fchdir changes the process's cwd
Expand Down Expand Up @@ -231,8 +234,6 @@ fn test_lseek64() {
close(tmpfd).unwrap();
}

execve_test_factory!(test_execve, execve, b"/bin/sh", b"/system/bin/sh");

#[test]
fn test_fpathconf_limited() {
let f = tempfile().unwrap();
Expand Down

0 comments on commit 6e35a34

Please sign in to comment.