@@ -111,9 +111,11 @@ impl<'a> FuzzTestRegistrationCtx<'a> {
111111
112112 let fuzz_test_struct_instance_tokens = quote ! (
113113 #fuzz_test_struct_name {
114- domain: #domain_struct_name {
114+ domain: std:: sync:: Arc :: new( std:: sync:: Mutex :: new(
115+ #domain_struct_name {
115116 #( #fuzz_test_domain_field_names: #domain_ctors) , *
116- } ,
117+ }
118+ ) ) ,
117119 test_fn: #prop_fn_ident
118120 }
119121 ) ;
@@ -214,7 +216,7 @@ impl<'a> FuzzTestRegistrationCtx<'a> {
214216 {
215217 where_clauses. predicates . push (
216218 parse_quote ! {
217- for <#user_value_lifetime_generic> #domain_gen: #crate_name:: domains:: Domain <UserValue <#user_value_lifetime_generic> = #ty >
219+ for <#user_value_lifetime_generic> #domain_gen: #crate_name:: domains:: Domain <UserValue <#user_value_lifetime_generic> = #ty > + ' static
218220 } ) ;
219221 where_clauses. predicates . push ( parse_quote ! { #corpus_gen: ' static } ) ;
220222 }
@@ -229,7 +231,7 @@ impl<'a> FuzzTestRegistrationCtx<'a> {
229231 #fuzz_test_domain_definition
230232
231233 struct #fuzz_test_struct_name #generics {
232- domain: #domain_struct_name #generics,
234+ domain: std :: sync :: Arc <std :: sync :: Mutex < #domain_struct_name #generics>> ,
233235 test_fn: #test_fn_type
234236 }
235237
@@ -250,7 +252,10 @@ impl<'a> FuzzTestRegistrationCtx<'a> {
250252 . downcast_ref:: <#domain_struct_name<#( #corpus_generics) , * >>( )
251253 . expect( "Attempt to recover user value before testing failed." ) ;
252254
253- let user_value = self . domain. corpus_to_user_value( wrapper) . expect( "Failed to get user value from corpus value" ) ;
255+ let user_value = self . domain. lock( )
256+ . expect( "Failed to acquire domain lock" )
257+ . corpus_to_user_value( wrapper)
258+ . expect( "Failed to get user value from corpus value" ) ;
254259
255260 let result = std:: panic:: catch_unwind( std:: panic:: AssertUnwindSafe ( || ( self . test_fn) ( #( user_value. #fuzz_test_domain_field_names) , * ) ) ) ;
256261
@@ -259,8 +264,8 @@ impl<'a> FuzzTestRegistrationCtx<'a> {
259264 fn print_finding_report( & self ) {
260265 todo!( "Not implemented!" )
261266 }
262- fn domains( & self ) -> & dyn #crate_name:: domains:: GenericDomain {
263- & self . domain
267+ fn domains( & self ) -> std :: sync :: Arc <std :: sync :: Mutex < dyn #crate_name:: domains:: GenericDomain >> {
268+ std :: sync :: Arc :: clone ( & self . domain) as std :: sync :: Arc <std :: sync :: Mutex <dyn #crate_name :: domains :: GenericDomain >>
264269 }
265270 }
266271
@@ -301,14 +306,14 @@ mod tests {
301306 expect_that ! (
302307 fuzztest_object_tokenstream. to_string( ) , ends_with( quote! {
303308 struct __FuzzTestTestFuzz<T0 , T1 > {
304- domain: __FuzzTestTestFuzzStateWrapper<T0 , T1 >,
309+ domain: std :: sync :: Arc <std :: sync :: Mutex < __FuzzTestTestFuzzStateWrapper<T0 , T1 > > >,
305310 test_fn: fn ( i32 , std:: string:: String )
306311 }
307312
308313 impl <T0 , T1 > :: fuzztest:: internal:: FuzzTest for __FuzzTestTestFuzz<T0 , T1 >
309- where for <' user> T0 : :: fuzztest:: domains:: Domain <UserValue <' user> = i32 >,
314+ where for <' user> T0 : :: fuzztest:: domains:: Domain <UserValue <' user> = i32 > + ' static ,
310315 T0 :: CorpusValue : ' static ,
311- for <' user> T1 : :: fuzztest:: domains:: Domain <UserValue <' user> = std:: string:: String >,
316+ for <' user> T1 : :: fuzztest:: domains:: Domain <UserValue <' user> = std:: string:: String > + ' static ,
312317 T1 :: CorpusValue : ' static {
313318 fn name( & self ) -> & ' static str {
314319 "test_fuzz"
@@ -326,7 +331,10 @@ mod tests {
326331 . downcast_ref:: <__FuzzTestTestFuzzStateWrapper<T0 :: CorpusValue , T1 :: CorpusValue >>( )
327332 . expect( "Attempt to recover user value before testing failed." ) ;
328333
329- let user_value = self . domain. corpus_to_user_value( wrapper) . expect( "Failed to get user value from corpus value" ) ;
334+ let user_value = self . domain. lock( )
335+ . expect( "Failed to acquire domain lock" )
336+ . corpus_to_user_value( wrapper)
337+ . expect( "Failed to get user value from corpus value" ) ;
330338 // Safety: Data is not reused after the test.
331339 let result = std:: panic:: catch_unwind( std:: panic:: AssertUnwindSafe ( || ( self . test_fn) ( user_value. a, user_value. b) ) ) ;
332340
@@ -335,17 +343,19 @@ mod tests {
335343 fn print_finding_report( & self ) {
336344 todo!( "Not implemented!" )
337345 }
338- fn domains( & self ) -> & dyn :: fuzztest:: domains:: GenericDomain {
339- & self . domain
346+ fn domains( & self ) -> std :: sync :: Arc <std :: sync :: Mutex < dyn :: fuzztest:: domains:: GenericDomain >> {
347+ std :: sync :: Arc :: clone ( & self . domain) as std :: sync :: Arc <std :: sync :: Mutex <dyn :: fuzztest :: domains :: GenericDomain >>
340348 }
341349 }
342350
343351 fn __FuzzTestTestFuzz_factory( ) -> :: fuzztest:: internal:: BoxedFuzzTest {
344352 :: std:: boxed:: Box :: new( __FuzzTestTestFuzz {
345- domain: __FuzzTestTestFuzzStateWrapper {
346- a: :: fuzztest:: domains:: arbitrary:: Arbitrary :: <i32 >:: default ( ) ,
347- b: :: fuzztest:: domains:: arbitrary:: Arbitrary :: <String >:: default ( )
348- } ,
353+ domain: std:: sync:: Arc :: new( std:: sync:: Mutex :: new(
354+ __FuzzTestTestFuzzStateWrapper {
355+ a: :: fuzztest:: domains:: arbitrary:: Arbitrary :: <i32 >:: default ( ) ,
356+ b: :: fuzztest:: domains:: arbitrary:: Arbitrary :: <String >:: default ( )
357+ }
358+ ) ) ,
349359 test_fn: __property_fn__test_fuzz
350360 } )
351361 }
0 commit comments