@@ -28,8 +28,14 @@ fn test_encode_with_properties() {
2828 // 添加一些属性到根节点
2929 let root_id = fdt. root_id ( ) ;
3030 let node = fdt. node_mut ( root_id) . unwrap ( ) ;
31- node. set_property ( crate :: Property :: new ( "#address-cells" , vec ! [ 0x00 , 0x00 , 0x00 , 0x02 ] ) ) ;
32- node. set_property ( crate :: Property :: new ( "#size-cells" , vec ! [ 0x00 , 0x00 , 0x00 , 0x01 ] ) ) ;
31+ node. set_property ( crate :: Property :: new (
32+ "#address-cells" ,
33+ vec ! [ 0x00 , 0x00 , 0x00 , 0x02 ] ,
34+ ) ) ;
35+ node. set_property ( crate :: Property :: new (
36+ "#size-cells" ,
37+ vec ! [ 0x00 , 0x00 , 0x00 , 0x01 ] ,
38+ ) ) ;
3339 node. set_property ( crate :: Property :: new ( "model" , {
3440 let mut v = b"Test Device" . to_vec ( ) ;
3541 v. push ( 0 ) ;
@@ -46,7 +52,10 @@ fn test_encode_with_properties() {
4652 // 验证属性
4753 assert_eq ! ( node_ref. address_cells( ) , Some ( 2 ) ) ;
4854 assert_eq ! ( node_ref. size_cells( ) , Some ( 1 ) ) ;
49- assert_eq ! ( node_ref. get_property( "model" ) . unwrap( ) . as_str( ) , Some ( "Test Device" ) ) ;
55+ assert_eq ! (
56+ node_ref. get_property( "model" ) . unwrap( ) . as_str( ) ,
57+ Some ( "Test Device" )
58+ ) ;
5059}
5160
5261/// 测试带有子节点的 FDT 编码
@@ -57,8 +66,14 @@ fn test_encode_with_children() {
5766 // 添加子节点
5867 let root_id = fdt. root_id ( ) ;
5968 let mut soc = crate :: Node :: new ( "soc" ) ;
60- soc. set_property ( crate :: Property :: new ( "#address-cells" , vec ! [ 0x00 , 0x00 , 0x00 , 0x02 ] ) ) ;
61- soc. set_property ( crate :: Property :: new ( "#size-cells" , vec ! [ 0x00 , 0x00 , 0x00 , 0x02 ] ) ) ;
69+ soc. set_property ( crate :: Property :: new (
70+ "#address-cells" ,
71+ vec ! [ 0x00 , 0x00 , 0x00 , 0x02 ] ,
72+ ) ) ;
73+ soc. set_property ( crate :: Property :: new (
74+ "#size-cells" ,
75+ vec ! [ 0x00 , 0x00 , 0x00 , 0x02 ] ,
76+ ) ) ;
6277 let soc_id = fdt. add_node ( root_id, soc) ;
6378
6479 let mut uart = crate :: Node :: new ( "uart@1000" ) ;
@@ -104,8 +119,15 @@ fn test_parse_and_encode() {
104119 assert_eq ! ( original. node_count( ) , reparsed. node_count( ) ) ;
105120
106121 // 验证内存保留区一致
107- assert_eq ! ( original. memory_reservations. len( ) , reparsed. memory_reservations. len( ) ) ;
108- for ( orig, rep) in original. memory_reservations . iter ( ) . zip ( reparsed. memory_reservations . iter ( ) ) {
122+ assert_eq ! (
123+ original. memory_reservations. len( ) ,
124+ reparsed. memory_reservations. len( )
125+ ) ;
126+ for ( orig, rep) in original
127+ . memory_reservations
128+ . iter ( )
129+ . zip ( reparsed. memory_reservations . iter ( ) )
130+ {
109131 assert_eq ! ( orig. address, rep. address) ;
110132 assert_eq ! ( orig. size, rep. size) ;
111133 }
@@ -114,7 +136,11 @@ fn test_parse_and_encode() {
114136 for id in original. iter_node_ids ( ) {
115137 let path = original. path_of ( id) ;
116138 let reparsed_id = reparsed. get_by_path_id ( & path) ;
117- assert ! ( reparsed_id. is_some( ) , "path {} not found in reparsed FDT" , path) ;
139+ assert ! (
140+ reparsed_id. is_some( ) ,
141+ "path {} not found in reparsed FDT" ,
142+ path
143+ ) ;
118144 }
119145}
120146
@@ -167,7 +193,10 @@ fn test_encode_with_reserve_dtb() {
167193 let reparsed = Fdt :: from_bytes ( & encoded) . unwrap ( ) ;
168194
169195 // 验证保留区被正确编码
170- assert_eq ! ( original. memory_reservations. len( ) , reparsed. memory_reservations. len( ) ) ;
196+ assert_eq ! (
197+ original. memory_reservations. len( ) ,
198+ reparsed. memory_reservations. len( )
199+ ) ;
171200}
172201
173202/// 测试节点属性完整性
@@ -180,10 +209,16 @@ fn test_encode_properties_integrity() {
180209 let node = fdt. node_mut ( root_id) . unwrap ( ) ;
181210
182211 // u32 属性
183- node. set_property ( crate :: Property :: new ( "prop-u32" , 0x12345678u32 . to_be_bytes ( ) . to_vec ( ) ) ) ;
212+ node. set_property ( crate :: Property :: new (
213+ "prop-u32" ,
214+ 0x12345678u32 . to_be_bytes ( ) . to_vec ( ) ,
215+ ) ) ;
184216
185217 // u64 属性
186- node. set_property ( crate :: Property :: new ( "prop-u64" , 0x1234567890ABCDEFu64 . to_be_bytes ( ) . to_vec ( ) ) ) ;
218+ node. set_property ( crate :: Property :: new (
219+ "prop-u64" ,
220+ 0x1234567890ABCDEFu64 . to_be_bytes ( ) . to_vec ( ) ,
221+ ) ) ;
187222
188223 // 字符串属性
189224 node. set_property ( crate :: Property :: new ( "prop-string" , {
@@ -201,8 +236,8 @@ fn test_encode_properties_integrity() {
201236 // reg 属性
202237 {
203238 let v = vec ! [
204- 0x00 , 0x10 , 0x00 , 0x00 , 0x00 , 0x20 , 0x00 , 0x00 ,
205- 0x00 , 0x30 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 , 0x00 ,
239+ 0x00 , 0x10 , 0x00 , 0x00 , 0x00 , 0x20 , 0x00 , 0x00 , 0x00 , 0x30 , 0x00 , 0x00 , 0x00 , 0x40 ,
240+ 0x00 , 0x00 ,
206241 ] ;
207242 node. set_property ( crate :: Property :: new ( "reg" , v) ) ;
208243 }
0 commit comments