@@ -56,3 +56,45 @@ impl Mvendorid {
56
56
} )
57
57
}
58
58
}
59
+
60
+ #[ cfg( test) ]
61
+ mod tests {
62
+ use super :: * ;
63
+
64
+ #[ test]
65
+ fn test_mvendorid ( ) {
66
+ ( 0 ..u32:: BITS )
67
+ . map ( |r| ( ( 1u64 << r) - 1 ) as usize )
68
+ . for_each ( |raw| {
69
+ let exp_bank = raw >> 7 ;
70
+ let exp_offset = raw & ( Mvendorid :: CONTINUATION as usize ) ;
71
+ let exp_parity = ( ( 1 - ( exp_offset. count_ones ( ) % 2 ) ) << 7 ) as u8 ;
72
+ let exp_mvendorid = Mvendorid :: from_bits ( raw) ;
73
+
74
+ assert_eq ! ( exp_mvendorid. bank( ) , exp_bank) ;
75
+ assert_eq ! ( exp_mvendorid. offset( ) , exp_offset) ;
76
+
77
+ let mut jedec_iter = exp_mvendorid. jedec_manufacturer ( ) ;
78
+ ( 0 ..exp_bank)
79
+ . for_each ( |_| assert_eq ! ( jedec_iter. next( ) , Some ( Mvendorid :: CONTINUATION ) ) ) ;
80
+ assert_eq ! ( jedec_iter. next( ) , Some ( exp_parity | ( exp_offset as u8 ) ) ) ;
81
+ assert_eq ! ( jedec_iter. next( ) , None ) ;
82
+ } ) ;
83
+
84
+ // ISA example used as a concrete test vector.
85
+
86
+ let exp_bank = 0xc ;
87
+ let exp_offset = 0x0a ;
88
+ let exp_decoded_offset = 0x8a ;
89
+ let raw_mvendorid = 0x60a ;
90
+ let exp_mvendorid = Mvendorid :: from_bits ( raw_mvendorid) ;
91
+
92
+ assert_eq ! ( exp_mvendorid. bank( ) , exp_bank) ;
93
+ assert_eq ! ( exp_mvendorid. offset( ) , exp_offset) ;
94
+
95
+ let mut jedec_iter = exp_mvendorid. jedec_manufacturer ( ) ;
96
+ ( 0 ..exp_bank) . for_each ( |_| assert_eq ! ( jedec_iter. next( ) , Some ( Mvendorid :: CONTINUATION ) ) ) ;
97
+ assert_eq ! ( jedec_iter. next( ) , Some ( exp_decoded_offset) ) ;
98
+ assert_eq ! ( jedec_iter. next( ) , None ) ;
99
+ }
100
+ }
0 commit comments