Files
wasmtime/crates/test-programs/wasi-tests/src/bin/clock_time_get.rs
Alex Crichton e13fabb276 Start to update the wasi crate in wasi tests (#675)
* Move `wasi` to `wasi_old` in wasi-tests

Leave space for the new `wasi` crate but allow us to incrementally
update tests.

* Update the big_random_buf test

* Update clock_time_get test

* Update close_preopen test

* Review comments

* Update to latest Wasmtime API
2019-12-09 13:08:47 +01:00

20 lines
745 B
Rust

use more_asserts::assert_le;
unsafe fn test_clock_time_get() {
// Test that clock_time_get succeeds. Even in environments where it's not
// desirable to expose high-precision timers, it should still succeed.
// clock_res_get is where information about precision can be provided.
wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 1).expect("precision 1 should work");
let first_time =
wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 0).expect("precision 0 should work");
let time = wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 0).expect("re-fetch time should work");
assert_le!(first_time, time, "CLOCK_MONOTONIC should be monotonic");
}
fn main() {
// Run the tests.
unsafe { test_clock_time_get() }
}