@@ -20,6 +20,7 @@ impl Simulation for VerilatorSim {}
2020pub mod tests {
2121 use crate :: yosys:: * ;
2222 use baa:: { BitVecOps , BitVecValue } ;
23+ use marlin_verilator:: dynamic:: DynamicVerilatedModel ;
2324 use marlin_verilator:: * ;
2425 use patronus:: sim:: Simulator ;
2526 use std:: path:: PathBuf ;
@@ -41,19 +42,48 @@ pub mod tests {
4142 . unwrap ( ) ;
4243
4344 let conf = VerilatedModelConfig :: default ( ) ;
44- let _dut = runtime
45+ let ( clk, rcon, inp, out_1, out_2) = ( "clk" , "rcon" , "in" , "out_1" , "out_2" ) ;
46+ let mut dut = runtime
4547 . create_dyn_model (
4648 "expand_key_128" ,
4749 "../examples/tinyaes128/aes_128.v" ,
4850 & [
4951 // you should be able to derive these from the struct
50- ( "in" , 127 , 0 , PortDirection :: Input ) ,
51- ( "out_1" , 127 , 0 , PortDirection :: Output ) ,
52- ( "out_2" , 127 , 0 , PortDirection :: Output ) ,
52+ ( clk, 0 , 0 , PortDirection :: Input ) ,
53+ ( rcon, 7 , 0 , PortDirection :: Input ) ,
54+ ( inp, 127 , 0 , PortDirection :: Input ) ,
55+ ( out_1, 127 , 0 , PortDirection :: Output ) ,
56+ ( out_2, 127 , 0 , PortDirection :: Output ) ,
5357 ] ,
5458 conf,
5559 )
5660 . unwrap ( ) ;
61+
62+ let step = |dut : & mut DynamicVerilatedModel | {
63+ dut. pin ( clk, 1u8 ) . unwrap ( ) ;
64+ dut. eval ( ) ;
65+ dut. pin ( clk, 0u8 ) . unwrap ( ) ;
66+ } ;
67+
68+ // execute an expand_key
69+ let inp_value = [ 0u32 ; 4 ] ;
70+ dut. pin ( inp, & inp_value) . unwrap ( ) ;
71+ dut. pin ( rcon, 1u8 ) . unwrap ( ) ; // rcon is a constant for the circuit
72+ dut. pin ( clk, 0u8 ) . unwrap ( ) ;
73+ dut. eval ( ) ;
74+ step ( & mut dut) ;
75+
76+ let inp_value_2 = [ 11u32 ; 4 ] ;
77+ dut. pin ( inp, & inp_value_2) . unwrap ( ) ; // X
78+ dut. eval ( ) ;
79+ let out_1_val = dut. read ( out_1) . unwrap ( ) ;
80+ println ! ( "out_1 = {out_1_val:?}" ) ;
81+ step ( & mut dut) ;
82+
83+ dut. pin ( inp, & inp_value_2) . unwrap ( ) ; // X
84+ dut. eval ( ) ;
85+ let out_2_val = dut. read ( out_2) . unwrap ( ) ;
86+ println ! ( "out_2 = {out_2_val:?}" ) ;
5787 }
5888
5989 #[ test]
0 commit comments