@@ -294,6 +294,12 @@ def test_function_tuple_param(self):
294294 packed_type = '' ,
295295 unpacked_type = '' ,
296296 specialized_type = None ,
297+ fuzztest_info = jit_wrapper_generator .FuzzTestInfo (
298+ domain_snippet = (
299+ 'fuzztest::TupleOf(fuzztest::Arbitrary<uint8_t>(),'
300+ ' fuzztest::Arbitrary<uint64_t>())'
301+ )
302+ ),
297303 ),
298304 ],
299305 result = jit_wrapper_generator .XlsNamedValue (
@@ -312,6 +318,14 @@ def test_function_tuple_param(self):
312318 self .assertLen (prop_func .params , 1 )
313319 self .assertEqual (prop_func .params [0 ].name , 't' )
314320 self .assertEqual (prop_func .params [0 ].index , 0 )
321+ self .assertEqual (
322+ prop_func .params [0 ].cpp_type , 'std::tuple<uint8_t, uint64_t>'
323+ )
324+ self .assertEqual (
325+ prop_func .params [0 ].domain_snippet ,
326+ 'fuzztest::TupleOf(fuzztest::TupleOf(fuzztest::Arbitrary<uint8_t>(),'
327+ ' fuzztest::Arbitrary<uint64_t>()))' ,
328+ )
315329
316330 def test_function_no_result (self ):
317331 u8 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 8 )
@@ -344,6 +358,72 @@ def test_function_no_result(self):
344358 self .assertEqual (prop_func .params [0 ].name , 'a' )
345359
346360
361+ class JitWrapperGeneratorToValueConversionTest (absltest .TestCase ):
362+
363+ def test_bits (self ):
364+ u32 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 32 )
365+ self .assertEqual (
366+ jit_wrapper_generator .to_value_conversion (u32 , 'x' ),
367+ 'xls::Value(xls::UBits(x, 32))' ,
368+ )
369+
370+ def test_tuple_of_tuples (self ):
371+ u8 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 8 )
372+ inner_tup = type_pb2 .TypeProto (
373+ type_enum = type_pb2 .TypeProto .TUPLE , tuple_elements = [u8 ]
374+ )
375+ outer_tup = type_pb2 .TypeProto (
376+ type_enum = type_pb2 .TypeProto .TUPLE , tuple_elements = [inner_tup ]
377+ )
378+ self .assertEqual (
379+ jit_wrapper_generator .to_value_conversion (outer_tup , 't' ),
380+ 'xls::Value::Tuple({xls::Value::Tuple({xls::Value(xls::UBits('
381+ 'std::get<0>(std::get<0>(t)), 8))})})' ,
382+ )
383+
384+ def test_tuple_of_arrays (self ):
385+ u8 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 8 )
386+ a8 = type_pb2 .TypeProto (
387+ type_enum = type_pb2 .TypeProto .ARRAY , array_size = 2 , array_element = u8
388+ )
389+ tup = type_pb2 .TypeProto (
390+ type_enum = type_pb2 .TypeProto .TUPLE , tuple_elements = [a8 ]
391+ )
392+ self .assertEqual (
393+ jit_wrapper_generator .to_value_conversion (tup , 't' ),
394+ 'xls::Value::Tuple({xls::Value::Array({xls::Value(xls::UBits('
395+ 'std::get<0>(t)[0], 8)), xls::Value(xls::UBits(std::get<0>(t)[1], 8))})'
396+ '})' ,
397+ )
398+
399+ def test_tuple_of_primitives (self ):
400+ u8 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 8 )
401+ u32 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 32 )
402+ tup = type_pb2 .TypeProto (
403+ type_enum = type_pb2 .TypeProto .TUPLE , tuple_elements = [u8 , u32 ]
404+ )
405+ self .assertEqual (
406+ jit_wrapper_generator .to_value_conversion (tup , 't' ),
407+ 'xls::Value::Tuple({xls::Value(xls::UBits(std::get<0>(t), 8)),'
408+ ' xls::Value(xls::UBits(std::get<1>(t), 32))})' ,
409+ )
410+
411+ def test_mixed_tuple (self ):
412+ u8 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 8 )
413+ u32 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 32 )
414+ a8 = type_pb2 .TypeProto (
415+ type_enum = type_pb2 .TypeProto .ARRAY , array_size = 1 , array_element = u8
416+ )
417+ tup = type_pb2 .TypeProto (
418+ type_enum = type_pb2 .TypeProto .TUPLE , tuple_elements = [u32 , a8 ]
419+ )
420+ self .assertEqual (
421+ jit_wrapper_generator .to_value_conversion (tup , 't' ),
422+ 'xls::Value::Tuple({xls::Value(xls::UBits(std::get<0>(t), 32)),'
423+ ' xls::Value::Array({xls::Value(xls::UBits(std::get<1>(t)[0], 8))})})' ,
424+ )
425+
426+
347427class JitWrapperGeneratorRenderFuzztestTest (absltest .TestCase ):
348428
349429 def setUp (self ):
@@ -396,7 +476,7 @@ def test_render_fuzztest_basic(self):
396476 'xls::test::MyFuncJit' ,
397477 'my_func_jit.h' ,
398478 )
399- self .assertIn ('void my_func(xls::Value a, xls::Value b)' , rendered_code )
479+ self .assertIn ('void my_func(uint8_t a, uint32_t b)' , rendered_code )
400480 self .assertIn (
401481 'XLS_ASSERT_OK_AND_ASSIGN(xls::Value result, f->Run(' , rendered_code
402482 )
@@ -441,7 +521,9 @@ def test_render_fuzztest_array_of_int(self):
441521 'xls::test::ArrayIntFuncJit' ,
442522 'array_int_func_jit.h' ,
443523 )
444- self .assertIn ('void array_int_func(xls::Value x)' , rendered_code )
524+ self .assertIn (
525+ 'void array_int_func(std::array<uint16_t, 4> x)' , rendered_code
526+ )
445527 self .assertIn (
446528 'FUZZ_TEST(array_int_func_fuzztest, array_int_func)' , rendered_code
447529 )
@@ -483,7 +565,10 @@ def test_render_fuzztest_array_of_tuple(self):
483565 'xls::test::ArrayTupleFuncJit' ,
484566 'array_tuple_func_jit.h' ,
485567 )
486- self .assertIn ('void array_tuple_func(xls::Value y)' , rendered_code )
568+ self .assertIn (
569+ 'void array_tuple_func(std::array<std::tuple<uint8_t, uint32_t>, 3> y)' ,
570+ rendered_code ,
571+ )
487572 self .assertIn (
488573 'FUZZ_TEST(array_tuple_func_fuzztest, array_tuple_func)' , rendered_code
489574 )
@@ -524,7 +609,9 @@ def test_render_fuzztest_tuple_of_int(self):
524609 'xls::test::TupleIntFuncJit' ,
525610 'tuple_int_func_jit.h' ,
526611 )
527- self .assertIn ('void tuple_int_func(xls::Value t)' , rendered_code )
612+ self .assertIn (
613+ 'void tuple_int_func(std::tuple<uint16_t, uint64_t> t)' , rendered_code
614+ )
528615 self .assertIn (
529616 'FUZZ_TEST(tuple_int_func_fuzztest, tuple_int_func)' , rendered_code
530617 )
@@ -569,7 +656,11 @@ def test_render_fuzztest_tuple_mixed(self):
569656 'xls::test::TupleMixedFuncJit' ,
570657 'tuple_mixed_func_jit.h' ,
571658 )
572- self .assertIn ('void tuple_mixed_func(xls::Value m)' , rendered_code )
659+ self .assertIn (
660+ 'void tuple_mixed_func(std::tuple<uint8_t, std::tuple<uint8_t,'
661+ ' uint16_t>> m)' ,
662+ rendered_code ,
663+ )
573664 self .assertIn (
574665 'FUZZ_TEST(tuple_mixed_func_fuzztest, tuple_mixed_func)' , rendered_code
575666 )
@@ -607,7 +698,7 @@ def test_render_fuzztest_uses_property_param_filter(self):
607698 'xls::test::MyFuncJit' ,
608699 'my_func_jit.h' ,
609700 )
610- self .assertEqual (rendered_code , 'const xls::Value& a' )
701+ self .assertEqual (rendered_code , 'uint8_t a' )
611702
612703 def test_render_fuzztest_default_domain (self ):
613704 u32 = type_pb2 .TypeProto (type_enum = type_pb2 .TypeProto .BITS , bit_count = 32 )
0 commit comments