MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / p2_api_time

Function p2_api_time

crates/wasi/tests/all/p2/api.rs:44–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43#[test_log::test(tokio::test(flavor = "multi_thread"))]
44async fn p2_api_time() -> Result<()> {
45 struct FakeWallClock;
46
47 impl HostWallClock for FakeWallClock {
48 fn resolution(&self) -> Duration {
49 Duration::from_secs(1)
50 }
51
52 fn now(&self) -> Duration {
53 Duration::new(1431648000, 100)
54 }
55 }
56
57 struct FakeMonotonicClock {
58 now: Mutex<u64>,
59 }
60
61 impl HostMonotonicClock for FakeMonotonicClock {
62 fn resolution(&self) -> u64 {
63 1_000_000_000
64 }
65
66 fn now(&self) -> u64 {
67 let mut now = self.now.lock().unwrap();
68 let then = *now;
69 *now += 42 * 1_000_000_000;
70 then
71 }
72 }
73
74 let table = ResourceTable::new();
75 let wasi = WasiCtxBuilder::new()
76 .monotonic_clock(FakeMonotonicClock { now: Mutex::new(0) })
77 .wall_clock(FakeWallClock)
78 .build();
79
80 let (mut store, command) =
81 instantiate(P2_API_TIME_COMPONENT, CommandCtx { table, wasi }).await?;
82
83 command
84 .wasi_cli_run()
85 .call_run(&mut store)
86 .await?
87 .map_err(|()| wasmtime::format_err!("command returned with failing exit status"))
88}
89
90#[test_log::test(tokio::test(flavor = "multi_thread"))]
91async fn p2_api_read_only() -> Result<()> {

Callers

nothing calls this directly

Calls 6

wall_clockMethod · 0.80
monotonic_clockMethod · 0.80
call_runMethod · 0.80
instantiateFunction · 0.70
newFunction · 0.50
buildMethod · 0.45

Tested by

no test coverage detected