Auto merge of #102757 - pcc:android-std-tests, r=workingjubilee

Make std tests pass on newer Android

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 if we see an EACCES from one of these syscalls. To achieve this, introduce a macro with the horrible name of or_panic_or_skip_on_android_eacces (better suggestions welcome) which skips (returns from) the test if an EACCES return value is seen on Android.
This commit is contained in:
bors 2023-07-26 07:57:32 +00:00
commit a6236fa460
2 changed files with 20 additions and 0 deletions

View File

@ -957,6 +957,7 @@ fn readlink_not_symlink() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
fn links_work() { fn links_work() {
let tmpdir = tmpdir(); let tmpdir = tmpdir();
let input = tmpdir.join("in.txt"); let input = tmpdir.join("in.txt");
@ -1453,6 +1454,7 @@ fn metadata_access_times() {
/// Test creating hard links to symlinks. /// Test creating hard links to symlinks.
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
fn symlink_hard_link() { fn symlink_hard_link() {
let tmpdir = tmpdir(); let tmpdir = tmpdir();
if !got_symlink_permission(&tmpdir) { if !got_symlink_permission(&tmpdir) {

View File

@ -23,6 +23,7 @@ macro_rules! or_panic {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn basic() { fn basic() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -93,6 +94,7 @@ fn pair() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn try_clone() { fn try_clone() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -119,6 +121,7 @@ fn try_clone() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn iter() { fn iter() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -168,6 +171,7 @@ fn long_path() {
#[test] #[test]
#[cfg(not(target_os = "nto"))] #[cfg(not(target_os = "nto"))]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn timeouts() { fn timeouts() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -195,6 +199,7 @@ fn timeouts() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_read_timeout() { fn test_read_timeout() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -214,6 +219,7 @@ fn test_read_timeout() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_read_with_timeout() { fn test_read_with_timeout() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -241,6 +247,7 @@ fn test_read_with_timeout() {
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors // Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations // when passed zero Durations
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_stream_timeout_zero_duration() { fn test_unix_stream_timeout_zero_duration() {
let dir = tmpdir(); let dir = tmpdir();
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
@ -260,6 +267,7 @@ fn test_unix_stream_timeout_zero_duration() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram() { fn test_unix_datagram() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock1"); let path1 = dir.path().join("sock1");
@ -276,6 +284,7 @@ fn test_unix_datagram() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unnamed_unix_datagram() { fn test_unnamed_unix_datagram() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock1"); let path1 = dir.path().join("sock1");
@ -293,6 +302,7 @@ fn test_unnamed_unix_datagram() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_connect_to_recv_addr() { fn test_unix_datagram_connect_to_recv_addr() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock1"); let path1 = dir.path().join("sock1");
@ -317,6 +327,7 @@ fn test_unix_datagram_connect_to_recv_addr() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_connect_unix_datagram() { fn test_connect_unix_datagram() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock1"); let path1 = dir.path().join("sock1");
@ -343,6 +354,7 @@ fn test_connect_unix_datagram() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_recv() { fn test_unix_datagram_recv() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock1"); let path1 = dir.path().join("sock1");
@ -385,6 +397,7 @@ fn datagram_pair() {
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors // Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations // when passed zero Durations
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_timeout_zero_duration() { fn test_unix_datagram_timeout_zero_duration() {
let dir = tmpdir(); let dir = tmpdir();
let path = dir.path().join("sock"); let path = dir.path().join("sock");
@ -529,6 +542,7 @@ fn test_abstract_no_pathname_and_not_unnamed() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_stream_peek() { fn test_unix_stream_peek() {
let (txdone, rxdone) = crate::sync::mpsc::channel(); let (txdone, rxdone) = crate::sync::mpsc::channel();
@ -561,6 +575,7 @@ fn test_unix_stream_peek() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_peek() { fn test_unix_datagram_peek() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock"); let path1 = dir.path().join("sock");
@ -585,6 +600,7 @@ fn test_unix_datagram_peek() {
} }
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_unix_datagram_peek_from() { fn test_unix_datagram_peek_from() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock"); let path1 = dir.path().join("sock");
@ -648,6 +664,7 @@ fn test_send_vectored_fds_unix_stream() {
#[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))] #[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))]
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_send_vectored_with_ancillary_to_unix_datagram() { fn test_send_vectored_with_ancillary_to_unix_datagram() {
fn getpid() -> libc::pid_t { fn getpid() -> libc::pid_t {
unsafe { libc::getpid() } unsafe { libc::getpid() }
@ -715,6 +732,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() {
#[cfg(any(target_os = "android", target_os = "linux"))] #[cfg(any(target_os = "android", target_os = "linux"))]
#[test] #[test]
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
fn test_send_vectored_with_ancillary_unix_datagram() { fn test_send_vectored_with_ancillary_unix_datagram() {
let dir = tmpdir(); let dir = tmpdir();
let path1 = dir.path().join("sock1"); let path1 = dir.path().join("sock1");