Skip to content

Commit 4ef8f60

Browse files
committed
Auto merge of rust-lang#3910 - YohDeadfall:android-libc-time, r=RalfJung
Android: Fixed tests for libc time API Closes rust-lang#3888. There's nothing to do, really. All of the API is already supported by `miri`, but I just tweaked tests a bit to match the data structures and functions from `bionic`.
2 parents b862076 + c69b457 commit 4ef8f60

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/tools/miri/ci/ci.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ case $HOST_TARGET in
154154
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname pthread time fs
155155
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX thread sync available-parallelism time tls
156156
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX thread sync available-parallelism time tls
157-
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX hashmap pthread --skip threadname --skip pthread_cond_timedwait
157+
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX hashmap pthread time --skip threadname
158158
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
159159
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
160160
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std

src/tools/miri/src/shims/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3636
let mut relative_clocks;
3737

3838
match this.tcx.sess.target.os.as_ref() {
39-
"linux" | "freebsd" => {
40-
// Linux and FreeBSD have two main kinds of clocks. REALTIME clocks return the actual time since the
39+
"linux" | "freebsd" | "android" => {
40+
// Linux, Android, and FreeBSD have two main kinds of clocks. REALTIME clocks return the actual time since the
4141
// Unix epoch, including effects which may cause time to move backwards such as NTP.
4242
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
4343
// is just specified to be "faster and less precise", so we implement both the same way.

src/tools/miri/tests/pass-dep/libc/libc-time.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn test_clocks() {
1515
assert_eq!(is_error, 0);
1616
let is_error = unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC, tp.as_mut_ptr()) };
1717
assert_eq!(is_error, 0);
18-
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
18+
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "android"))]
1919
{
2020
let is_error = unsafe { libc::clock_gettime(libc::CLOCK_REALTIME_COARSE, tp.as_mut_ptr()) };
2121
assert_eq!(is_error, 0);
@@ -63,9 +63,19 @@ fn test_localtime_r() {
6363
tm_wday: 0,
6464
tm_yday: 0,
6565
tm_isdst: 0,
66-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
66+
#[cfg(any(
67+
target_os = "linux",
68+
target_os = "macos",
69+
target_os = "freebsd",
70+
target_os = "android"
71+
))]
6772
tm_gmtoff: 0,
68-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
73+
#[cfg(any(
74+
target_os = "linux",
75+
target_os = "macos",
76+
target_os = "freebsd",
77+
target_os = "android"
78+
))]
6979
tm_zone: std::ptr::null_mut::<libc::c_char>(),
7080
};
7181
let res = unsafe { libc::localtime_r(custom_time_ptr, &mut tm) };
@@ -79,9 +89,19 @@ fn test_localtime_r() {
7989
assert_eq!(tm.tm_wday, 0);
8090
assert_eq!(tm.tm_yday, 97);
8191
assert_eq!(tm.tm_isdst, -1);
82-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
92+
#[cfg(any(
93+
target_os = "linux",
94+
target_os = "macos",
95+
target_os = "freebsd",
96+
target_os = "android"
97+
))]
8398
assert_eq!(tm.tm_gmtoff, 0);
84-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
99+
#[cfg(any(
100+
target_os = "linux",
101+
target_os = "macos",
102+
target_os = "freebsd",
103+
target_os = "android"
104+
))]
85105
unsafe {
86106
assert_eq!(std::ffi::CStr::from_ptr(tm.tm_zone).to_str().unwrap(), "+00")
87107
};

0 commit comments

Comments
 (0)