Skip to content

Commit

Permalink
Android: Fixed tests for libc time API
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Sep 24, 2024
1 parent 894c264 commit ae3ff3b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ case $HOST_TARGET in
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname pthread time fs
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX thread sync available-parallelism time tls
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX thread sync available-parallelism time tls
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX pthread --skip threadname --skip pthread_cond_timedwait
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX pthread time --skip threadname --skip pthread_cond_timedwait
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
Expand Down
2 changes: 1 addition & 1 deletion src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let mut relative_clocks;

match this.tcx.sess.target.os.as_ref() {
"linux" | "freebsd" => {
"linux" | "freebsd" | "android" => {
// Linux and FreeBSD have two main kinds of clocks. REALTIME clocks return the actual time since the
// Unix epoch, including effects which may cause time to move backwards such as NTP.
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
Expand Down
30 changes: 25 additions & 5 deletions tests/pass-dep/libc/libc-time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_clocks() {
assert_eq!(is_error, 0);
let is_error = unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC, tp.as_mut_ptr()) };
assert_eq!(is_error, 0);
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "android"))]
{
let is_error = unsafe { libc::clock_gettime(libc::CLOCK_REALTIME_COARSE, tp.as_mut_ptr()) };
assert_eq!(is_error, 0);
Expand Down Expand Up @@ -63,9 +63,19 @@ fn test_localtime_r() {
tm_wday: 0,
tm_yday: 0,
tm_isdst: 0,
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "android"
))]
tm_gmtoff: 0,
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "android"
))]
tm_zone: std::ptr::null_mut::<libc::c_char>(),
};
let res = unsafe { libc::localtime_r(custom_time_ptr, &mut tm) };
Expand All @@ -79,9 +89,19 @@ fn test_localtime_r() {
assert_eq!(tm.tm_wday, 0);
assert_eq!(tm.tm_yday, 97);
assert_eq!(tm.tm_isdst, -1);
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "android"
))]
assert_eq!(tm.tm_gmtoff, 0);
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "android"
))]
unsafe {
assert_eq!(std::ffi::CStr::from_ptr(tm.tm_zone).to_str().unwrap(), "+00")
};
Expand Down

0 comments on commit ae3ff3b

Please sign in to comment.