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 16, 2017
1 parent a81fd5b commit f5d2083
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 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,14 @@ 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());
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 +233,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 f5d2083

Please sign in to comment.