Skip to content

Commit

Permalink
fix tests on wasm targets that have 32bit time_t and don't have threads
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Aug 20, 2021
1 parent 6c92bae commit cd82b42
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions library/std/src/time/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Duration, Instant, SystemTime, UNIX_EPOCH};
use core::sync::atomic::AtomicU64;
#[cfg(not(target_arch = "wasm32"))]
use test::{black_box, Bencher};

macro_rules! assert_almost_eq {
Expand All @@ -25,6 +25,7 @@ fn instant_monotonic() {
}

#[test]
#[cfg(not(target_arch = "wasm32"))]
fn instant_monotonic_concurrent() -> crate::thread::Result<()> {
let threads: Vec<_> = (0..8)
.map(|_| {
Expand Down Expand Up @@ -195,10 +196,18 @@ fn since_epoch() {
#[test]
fn monotonizer_wrapping_backslide() {
use super::monotonic::inner::{monotonize_impl, ZERO};
use core::sync::atomic::AtomicU64;

let reference = AtomicU64::new(0);

let time = ZERO.checked_add_duration(&Duration::from_secs(0xffff_ffff)).unwrap();
let time = match ZERO.checked_add_duration(&Duration::from_secs(0xffff_ffff)) {
Some(time) => time,
None => {
// platform cannot represent u32::MAX seconds so it won't have to deal with this kind
// of overflow either
return;
}
};

let monotonized = monotonize_impl(&reference, time);
let expected = ZERO.checked_add_duration(&Duration::from_secs(1 << 32)).unwrap();
Expand All @@ -211,6 +220,7 @@ fn monotonizer_wrapping_backslide() {
macro_rules! bench_instant_threaded {
($bench_name:ident, $thread_count:expr) => {
#[bench]
#[cfg(not(target_arch = "wasm32"))]
fn $bench_name(b: &mut Bencher) -> crate::thread::Result<()> {
use crate::sync::atomic::{AtomicBool, Ordering};
use crate::sync::Arc;
Expand Down

0 comments on commit cd82b42

Please sign in to comment.