Skip to content

Commit

Permalink
Make std tests pass on newer Android
Browse files Browse the repository at this point in the history
Newer versions of Android forbid the creation of hardlinks as well as
Unix domain sockets in the /data filesystem via SELinux rules, which
causes several tests depending on this behavior to fail. So let's
skip these tests on Android with an #[ignore] directive.
  • Loading branch information
pcc committed Mar 3, 2023
1 parent 13471d3 commit fed6fce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ fn readlink_not_symlink() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
fn links_work() {
let tmpdir = tmpdir();
let input = tmpdir.join("in.txt");
Expand Down Expand Up @@ -1431,6 +1432,7 @@ fn metadata_access_times() {

/// Test creating hard links to symlinks.
#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
fn symlink_hard_link() {
let tmpdir = tmpdir();
if !got_symlink_permission(&tmpdir) {
Expand Down
18 changes: 18 additions & 0 deletions library/std/src/os/unix/net/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ macro_rules! or_panic {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn basic() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand Down Expand Up @@ -93,6 +94,7 @@ fn pair() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn try_clone() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand All @@ -119,6 +121,7 @@ fn try_clone() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn iter() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand Down Expand Up @@ -168,6 +171,7 @@ fn long_path() {

#[test]
#[cfg(not(target_os = "nto"))]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn timeouts() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand Down Expand Up @@ -195,6 +199,7 @@ fn timeouts() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_read_timeout() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand All @@ -214,6 +219,7 @@ fn test_read_timeout() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_read_with_timeout() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand Down Expand Up @@ -241,6 +247,7 @@ fn test_read_with_timeout() {
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations
#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_stream_timeout_zero_duration() {
let dir = tmpdir();
let socket_path = dir.path().join("sock");
Expand All @@ -260,6 +267,7 @@ fn test_unix_stream_timeout_zero_duration() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
Expand All @@ -276,6 +284,7 @@ fn test_unix_datagram() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unnamed_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
Expand All @@ -293,6 +302,7 @@ fn test_unnamed_unix_datagram() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_connect_to_recv_addr() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
Expand All @@ -317,6 +327,7 @@ fn test_unix_datagram_connect_to_recv_addr() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_connect_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
Expand All @@ -343,6 +354,7 @@ fn test_connect_unix_datagram() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_recv() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
Expand Down Expand Up @@ -385,6 +397,7 @@ fn datagram_pair() {
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations
#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_timeout_zero_duration() {
let dir = tmpdir();
let path = dir.path().join("sock");
Expand Down Expand Up @@ -529,6 +542,7 @@ fn test_abstract_no_pathname_and_not_unnamed() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_stream_peek() {
let (txdone, rxdone) = crate::sync::mpsc::channel();

Expand Down Expand Up @@ -561,6 +575,7 @@ fn test_unix_stream_peek() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_peek() {
let dir = tmpdir();
let path1 = dir.path().join("sock");
Expand All @@ -585,6 +600,7 @@ fn test_unix_datagram_peek() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_peek_from() {
let dir = tmpdir();
let path1 = dir.path().join("sock");
Expand Down Expand Up @@ -648,6 +664,7 @@ fn test_send_vectored_fds_unix_stream() {

#[cfg(any(target_os = "android", target_os = "linux",))]
#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_send_vectored_with_ancillary_to_unix_datagram() {
fn getpid() -> libc::pid_t {
unsafe { libc::getpid() }
Expand Down Expand Up @@ -715,6 +732,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() {

#[cfg(any(target_os = "android", target_os = "linux"))]
#[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_send_vectored_with_ancillary_unix_datagram() {
let dir = tmpdir();
let path1 = dir.path().join("sock1");
Expand Down

0 comments on commit fed6fce

Please sign in to comment.