Skip to content

Commit fed6fce

Browse files
committed
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 with an #[ignore] directive.
1 parent 13471d3 commit fed6fce

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

library/std/src/fs/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ fn readlink_not_symlink() {
935935
}
936936

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

14321433
/// Test creating hard links to symlinks.
14331434
#[test]
1435+
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating hardlinks
14341436
fn symlink_hard_link() {
14351437
let tmpdir = tmpdir();
14361438
if !got_symlink_permission(&tmpdir) {

library/std/src/os/unix/net/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ macro_rules! or_panic {
2323
}
2424

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

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

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

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

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

216221
#[test]
222+
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
217223
fn test_read_with_timeout() {
218224
let dir = tmpdir();
219225
let socket_path = dir.path().join("sock");
@@ -241,6 +247,7 @@ fn test_read_with_timeout() {
241247
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
242248
// when passed zero Durations
243249
#[test]
250+
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
244251
fn test_unix_stream_timeout_zero_duration() {
245252
let dir = tmpdir();
246253
let socket_path = dir.path().join("sock");
@@ -260,6 +267,7 @@ fn test_unix_stream_timeout_zero_duration() {
260267
}
261268

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

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

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

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

345356
#[test]
357+
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
346358
fn test_unix_datagram_recv() {
347359
let dir = tmpdir();
348360
let path1 = dir.path().join("sock1");
@@ -385,6 +397,7 @@ fn datagram_pair() {
385397
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
386398
// when passed zero Durations
387399
#[test]
400+
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
388401
fn test_unix_datagram_timeout_zero_duration() {
389402
let dir = tmpdir();
390403
let path = dir.path().join("sock");
@@ -529,6 +542,7 @@ fn test_abstract_no_pathname_and_not_unnamed() {
529542
}
530543

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

@@ -561,6 +575,7 @@ fn test_unix_stream_peek() {
561575
}
562576

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

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

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

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

0 commit comments

Comments
 (0)