From 4f2837788da0279a37a8b083be9bd7ddc268f9cd Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Fri, 28 Oct 2022 07:06:43 +0000 Subject: [PATCH 1/4] fix internal structure change of nightly std::time::{SystemTime, Interval} Signed-off-by: Runji Wang --- madsim/src/sim/time/system_time.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/madsim/src/sim/time/system_time.rs b/madsim/src/sim/time/system_time.rs index ea62427..d02bf24 100644 --- a/madsim/src/sim/time/system_time.rs +++ b/madsim/src/sim/time/system_time.rs @@ -47,7 +47,12 @@ unsafe extern "C" fn clock_gettime( // inside a madsim context, use the simulated time. match clockid { // used by SystemTime - libc::CLOCK_REALTIME | libc::CLOCK_REALTIME_COARSE => { + libc::CLOCK_REALTIME + | libc::CLOCK_REALTIME_COARSE + // used by Instant + | libc::CLOCK_MONOTONIC + | libc::CLOCK_MONOTONIC_RAW + | libc::CLOCK_MONOTONIC_COARSE => { let dur = time .now_time() .duration_since(std::time::SystemTime::UNIX_EPOCH) @@ -57,10 +62,6 @@ unsafe extern "C" fn clock_gettime( tv_nsec: dur.subsec_nanos() as _, }); } - // used by Instant - libc::CLOCK_MONOTONIC | libc::CLOCK_MONOTONIC_RAW | libc::CLOCK_MONOTONIC_COARSE => { - tp.write(std::mem::transmute(time.now_instant())); - } _ => panic!("unsupported clockid: {}", clockid), } 0 From 64a4c511688bb1659fa4b6f45a7e88b1ce158dad Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Fri, 28 Oct 2022 07:10:07 +0000 Subject: [PATCH 2/4] release: v0.2.9 Signed-off-by: Runji Wang --- CHANGELOG.md | 6 ++++++ madsim/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f79f3b..fb0c8e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.9] - 2022-10-28 + +### Fixed + +- madsim: Fix internal structure change of nightly `std::time::{SystemTime, Interval}`. + ## [0.2.8] - 2022-09-26 ### Added diff --git a/madsim/Cargo.toml b/madsim/Cargo.toml index 08e491b..c12479e 100644 --- a/madsim/Cargo.toml +++ b/madsim/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "madsim" -version = "0.2.8" +version = "0.2.9" edition = "2021" authors = ["Runji Wang "] description = "Deterministic Simulator for distributed systems." From 1696cdfda0a2ffc0c52dac2a376b842f6ccacfe4 Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Fri, 28 Oct 2022 07:25:30 +0000 Subject: [PATCH 3/4] ci: add test on the latest nightly toolchain Signed-off-by: Runji Wang --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce6932b..daf9223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + toolchain: [stable, nightly] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -76,7 +77,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.toolchain }} - name: Test std uses: actions-rs/cargo@v1 with: @@ -87,6 +88,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + toolchain: [stable, nightly] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -97,7 +99,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.toolchain }} - name: Test sim uses: actions-rs/cargo@v1 env: From efe976e39fad1d4addced09ba549a0992d838872 Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Fri, 28 Oct 2022 08:18:19 +0000 Subject: [PATCH 4/4] fix Instant Signed-off-by: Runji Wang --- madsim/src/sim/time/system_time.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/madsim/src/sim/time/system_time.rs b/madsim/src/sim/time/system_time.rs index d02bf24..4dd4e4e 100644 --- a/madsim/src/sim/time/system_time.rs +++ b/madsim/src/sim/time/system_time.rs @@ -1,3 +1,5 @@ +use std::time::SystemTime; + /// Override the libc `gettimeofday` function. For `SystemTime` on macOS. #[no_mangle] #[inline(never)] @@ -12,7 +14,7 @@ unsafe extern "C" fn gettimeofday(tp: *mut libc::timeval, tz: *mut libc::c_void) // inside a madsim context, use the simulated time. let dur = time .now_time() - .duration_since(std::time::SystemTime::UNIX_EPOCH) + .duration_since(SystemTime::UNIX_EPOCH) .unwrap(); tp.write(libc::timeval { tv_sec: dur.as_secs() as _, @@ -47,15 +49,20 @@ unsafe extern "C" fn clock_gettime( // inside a madsim context, use the simulated time. match clockid { // used by SystemTime - libc::CLOCK_REALTIME - | libc::CLOCK_REALTIME_COARSE - // used by Instant - | libc::CLOCK_MONOTONIC - | libc::CLOCK_MONOTONIC_RAW - | libc::CLOCK_MONOTONIC_COARSE => { + libc::CLOCK_REALTIME | libc::CLOCK_REALTIME_COARSE => { let dur = time .now_time() - .duration_since(std::time::SystemTime::UNIX_EPOCH) + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap(); + tp.write(libc::timespec { + tv_sec: dur.as_secs() as _, + tv_nsec: dur.subsec_nanos() as _, + }); + } + // used by Instant + libc::CLOCK_MONOTONIC | libc::CLOCK_MONOTONIC_RAW | libc::CLOCK_MONOTONIC_COARSE => { + let dur = std::mem::transmute::<_, SystemTime>(time.now_instant()) + .duration_since(SystemTime::UNIX_EPOCH) .unwrap(); tp.write(libc::timespec { tv_sec: dur.as_secs() as _,