@@ -30,10 +30,8 @@ pub fn config() -> Config {
3030 config. memory_reservation ( 1 << 20 ) ;
3131 config. memory_guard_size ( 0 ) ;
3232 config. signals_based_traps ( false ) ;
33- config. debug_info ( false ) ;
3433 } else {
3534 config. cranelift_debug_verifier ( true ) ;
36- config. debug_info ( true ) ;
3735 }
3836 config. wasm_component_model ( true ) ;
3937 config. wasm_component_model_async ( true ) ;
@@ -44,6 +42,54 @@ pub fn config() -> Config {
4442 config
4543}
4644
45+ pub async fn sleep ( duration : std:: time:: Duration ) {
46+ if cfg ! ( miri) {
47+ // TODO: We should be able to use `tokio::time::sleep` here, but as of
48+ // this writing the miri-compatible version of `wasmtime-fiber` uses
49+ // threads behind the scenes, which means thread-local storage is not
50+ // preserved when we switch fibers, and that confuses Tokio. If we ever
51+ // fix that we can stop using our own, special version of `sleep` and
52+ // switch back to the Tokio version.
53+
54+ use std:: {
55+ future,
56+ sync:: {
57+ Arc , Mutex ,
58+ atomic:: { AtomicU32 , Ordering :: SeqCst } ,
59+ } ,
60+ task:: Poll ,
61+ thread,
62+ } ;
63+
64+ let state = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
65+ let waker = Arc :: new ( Mutex :: new ( None ) ) ;
66+ future:: poll_fn ( move |cx| match state. load ( SeqCst ) {
67+ 0 => {
68+ state. store ( 1 , SeqCst ) ;
69+ let state = state. clone ( ) ;
70+ * waker. lock ( ) . unwrap ( ) = Some ( cx. waker ( ) . clone ( ) ) ;
71+ let waker = waker. clone ( ) ;
72+ thread:: spawn ( move || {
73+ thread:: sleep ( duration) ;
74+ state. store ( 2 , SeqCst ) ;
75+ let waker = waker. lock ( ) . unwrap ( ) . clone ( ) . unwrap ( ) ;
76+ waker. wake ( ) ;
77+ } ) ;
78+ Poll :: Pending
79+ }
80+ 1 => {
81+ * waker. lock ( ) . unwrap ( ) = Some ( cx. waker ( ) . clone ( ) ) ;
82+ Poll :: Pending
83+ }
84+ 2 => Poll :: Ready ( ( ) ) ,
85+ _ => unreachable ! ( ) ,
86+ } )
87+ . await ;
88+ } else {
89+ tokio:: time:: sleep ( duration) . await ;
90+ }
91+ }
92+
4793/// Compose two components
4894///
4995/// a is the "root" component, and b is composed into it
@@ -168,7 +214,11 @@ pub async fn test_run(components: &[&str]) -> Result<()> {
168214
169215pub async fn test_run_with_count ( components : & [ & str ] , count : usize ) -> Result < ( ) > {
170216 let mut config = config ( ) ;
171- config. epoch_interruption ( true ) ;
217+ // As of this writing, miri/pulley/epochs is a problematic combination, so
218+ // we don't test it.
219+ if env:: var_os ( "MIRI_TEST_CWASM_DIR" ) . is_none ( ) {
220+ config. epoch_interruption ( true ) ;
221+ }
172222
173223 let engine = Engine :: new ( & config) ?;
174224
@@ -200,12 +250,15 @@ pub async fn test_run_with_count(components: &[&str], count: usize) -> Result<()
200250 wakers : Arc :: new ( std:: sync:: Mutex :: new ( None ) ) ,
201251 } ,
202252 ) ;
203- store. set_epoch_deadline ( 1 ) ;
204253
205- std:: thread:: spawn ( move || {
206- std:: thread:: sleep ( Duration :: from_secs ( 10 ) ) ;
207- engine. increment_epoch ( ) ;
208- } ) ;
254+ if env:: var_os ( "MIRI_TEST_CWASM_DIR" ) . is_none ( ) {
255+ store. set_epoch_deadline ( 1 ) ;
256+
257+ std:: thread:: spawn ( move || {
258+ std:: thread:: sleep ( Duration :: from_secs ( 10 ) ) ;
259+ engine. increment_epoch ( ) ;
260+ } ) ;
261+ }
209262
210263 let instance = linker. instantiate_async ( & mut store, & component) . await ?;
211264 let yield_host = super :: yield_host:: bindings:: YieldHost :: new ( & mut store, & instance) ?;
0 commit comments