Skip to content

Commit ced3e43

Browse files
committed
Merge #693
693: fix some tests for Android r=asomers I tested the crate on an Android emulator and quite all the tests passed. Only 6 were failing. > failures: > > ---- sys::test_pthread::test_pthread_self stdout ---- > thread 'sys::test_pthread::test_pthread_self' panicked at 'assertion failed: tid > 0', test/sys/test_pthread.rs:6 > note: Run with `RUST_BACKTRACE=1` for a backtrace. > > ---- sys::test_socket::test_getsockname stdout ---- > thread 'sys::test_socket::test_getsockname' panicked at 'bind failed: Sys(EACCES)', /checkout/src/libcore/result.rs:859 > > ---- sys::test_socket::test_unixdomain stdout ---- > thread 'sys::test_socket::test_unixdomain' panicked at 'bind failed: Sys(EACCES)', /checkout/src/libcore/result.rs:859 > > ---- sys::test_termios::test_local_flags stdout ---- > thread 'sys::test_termios::test_local_flags' panicked at 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:329 > > ---- test_net::test_if_nametoindex stdout ---- > thread 'test_net::test_if_nametoindex' panicked at 'assertion failed: if_nametoindex(&LOOPBACK[..]).is_ok()', test/test_net.rs:11 > > ---- test_unistd::test_mkstemp stdout ---- > thread 'test_unistd::test_mkstemp' panicked at 'mkstemp failed: ENOENT: No such file or directory', test/test_unistd.rs:73 This PR fixes 3 of those: - `test_pthread_self`: pthread_t is unsigned, so it can be negative (and it is often the case) - `test_if_nametoindex`: constant `LOOPBACK` is the same than on Linux - `test_mkstemp`: directory `/tmp` does not exist in Android Two are still failing (`test_unixdomain` and `test_getsockname`) because we need some special permissions on Android for playing with sockets. On a rooted physical device, they passed. So, if tests for Android are integrated in CI, we should try to embed the tests to run in an APK with requested permissions or find a way to give the permission to a native program. `test_local_flags` is still failing also because `O_LARGEFILE` is hardcoded and is not the right value in Android. Then `fcntl::OFlag::from_bits(flags).unwrap()` fails because this flag is then not recognised. I made a PR in `libc` so that we can rely on libc definitions for all `O_*` flags. (rust-lang/libc#683) Do you prefer to wait for this one to be fixed for this PR to merged as well ?
2 parents ce3b129 + a546ef9 commit ced3e43

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

test/sys/test_pthread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ use nix::sys::pthread::*;
33
#[test]
44
fn test_pthread_self() {
55
let tid = pthread_self();
6-
assert!(tid > 0);
6+
assert!(tid != 0);
77
}

test/test_net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use nix::net::if_::*;
22

3-
#[cfg(target_os = "linux")]
3+
#[cfg(any(target_os = "android", target_os = "linux"))]
44
const LOOPBACK: &'static [u8] = b"lo";
55

6-
#[cfg(not(target_os = "linux"))]
6+
#[cfg(not(any(target_os = "android", target_os = "linux")))]
77
const LOOPBACK: &'static [u8] = b"lo0";
88

99
#[test]

test/test_unistd.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use nix::unistd::*;
44
use nix::unistd::ForkResult::*;
55
use nix::sys::wait::*;
66
use nix::sys::stat;
7-
use std::iter;
7+
use std::{env, iter};
88
use std::ffi::CString;
99
use std::fs::File;
1010
use std::io::Write;
@@ -66,22 +66,23 @@ fn test_wait() {
6666

6767
#[test]
6868
fn test_mkstemp() {
69-
let result = mkstemp("/tmp/nix_tempfile.XXXXXX");
69+
let mut path = env::temp_dir();
70+
path.push("nix_tempfile.XXXXXX");
71+
72+
let result = mkstemp(&path);
7073
match result {
7174
Ok((fd, path)) => {
7275
close(fd).unwrap();
7376
unlink(path.as_path()).unwrap();
7477
},
7578
Err(e) => panic!("mkstemp failed: {}", e)
7679
}
80+
}
7781

78-
let result = mkstemp("/tmp/");
79-
match result {
80-
Ok(_) => {
81-
panic!("mkstemp succeeded even though it should fail (provided a directory)");
82-
},
83-
Err(_) => {}
84-
}
82+
#[test]
83+
fn test_mkstemp_directory() {
84+
// mkstemp should fail if a directory is given
85+
assert!(mkstemp(&env::temp_dir()).is_err());
8586
}
8687

8788
#[test]

0 commit comments

Comments
 (0)