Skip to content

Commit 41ca1e9

Browse files
committed
feat: 优化代码格式,调整多个测试文件中的打印语句和属性设置的格式
1 parent 00c81fb commit 41ca1e9

File tree

7 files changed

+81
-38
lines changed

7 files changed

+81
-38
lines changed

fdt-edit/src/fdt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use alloc::{
1313
vec::Vec,
1414
};
1515

16-
use crate::{FdtData, FdtEncoder, FdtError, Node, NodeId, NodeType, NodeTypeMut, NodeView, Phandle};
16+
use crate::{
17+
FdtData, FdtEncoder, FdtError, Node, NodeId, NodeType, NodeTypeMut, NodeView, Phandle,
18+
};
1719

1820
pub use fdt_raw::MemoryReservation;
1921

fdt-edit/tests/clock.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ fn test_clock_output_names() {
3434
if let NodeType::Clock(clock) = node {
3535
let names = clock.clock_output_names();
3636
if !names.is_empty() {
37-
println!(
38-
"Clock {} has output names: {:?}",
39-
clock.path(),
40-
names
41-
);
37+
println!("Clock {} has output names: {:?}", clock.path(), names);
4238

4339
// Test output_name method
4440
if let Some(first_name) = clock.output_name(0) {
@@ -59,11 +55,7 @@ fn test_fixed_clock() {
5955
if let NodeType::Clock(clock) = node {
6056
let clock_type = clock.clock_type();
6157
if let fdt_edit::ClockType::Fixed(fixed) = clock_type {
62-
println!(
63-
"Fixed clock: {} freq={}Hz",
64-
clock.path(),
65-
fixed.frequency
66-
);
58+
println!("Fixed clock: {} freq={}Hz", clock.path(), fixed.frequency);
6759

6860
// Fixed clock should have a frequency
6961
assert!(

fdt-edit/tests/encode.rs

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

fdt-edit/tests/pci.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::sync::Once;
44

55
use dtb_file::*;
6-
use fdt_edit::{Fdt, NodeType, PciSpace, PciRange};
6+
use fdt_edit::{Fdt, NodeType, PciRange, PciSpace};
77

88
fn init_logging() {
99
static INIT: Once = Once::new();
@@ -45,11 +45,7 @@ fn test_pci_ranges() {
4545
for node in fdt.all_nodes() {
4646
if let NodeType::Pci(pci) = node {
4747
if let Some(ranges) = pci.ranges() {
48-
println!(
49-
"PCI {} has {} ranges:",
50-
pci.path(),
51-
ranges.len()
52-
);
48+
println!("PCI {} has {} ranges:", pci.path(), ranges.len());
5349

5450
for range in &ranges {
5551
let space_name = match range.space {
@@ -60,7 +56,11 @@ fn test_pci_ranges() {
6056

6157
println!(
6258
" {}: bus={:#x} cpu={:#x} size={:#x} prefetch={}",
63-
space_name, range.bus_address, range.cpu_address, range.size, range.prefetchable
59+
space_name,
60+
range.bus_address,
61+
range.cpu_address,
62+
range.size,
63+
range.prefetchable
6464
);
6565
}
6666

fdt-edit/tests/range.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ fn test_reg_address_translation() {
1515

1616
let reg = &regs[0];
1717
assert_eq!(reg.address, 0xfe215040, "CPU address should be 0xfe215040");
18-
assert_eq!(reg.child_bus_address, 0x7e215040, "bus address should be 0x7e215040");
18+
assert_eq!(
19+
reg.child_bus_address, 0x7e215040,
20+
"bus address should be 0x7e215040"
21+
);
1922
assert_eq!(reg.size, Some(0x40), "size should be 0x40");
2023
}
2124

@@ -74,6 +77,9 @@ fn test_set_regs_roundtrip() {
7477
};
7578

7679
assert_eq!(roundtrip_reg.address, original_reg.address);
77-
assert_eq!(roundtrip_reg.child_bus_address, original_reg.child_bus_address);
80+
assert_eq!(
81+
roundtrip_reg.child_bus_address,
82+
original_reg.child_bus_address
83+
);
7884
assert_eq!(roundtrip_reg.size, original_reg.size);
7985
}

fdt-edit/tests/rebuild.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ fn test_rebuild_single(case: &DtbTestCase) {
5959

6060
// 1. 获取原始 DTB 数据
6161
let raw_data = (case.loader)();
62-
let original = Fdt::from_bytes(&raw_data)
63-
.unwrap_or_else(|_| panic!("Failed to parse {}", case.name));
62+
let original =
63+
Fdt::from_bytes(&raw_data).unwrap_or_else(|_| panic!("Failed to parse {}", case.name));
6464

6565
// 2. 编码
6666
let encoded = original.encode();
@@ -118,7 +118,9 @@ fn test_rebuild_single(case: &DtbTestCase) {
118118
assert!(
119119
diff_status.success(),
120120
"DTS files differ for {}: run 'diff {} {}' to see details",
121-
case.name, orig_dts_path, enc_dts_path
121+
case.name,
122+
orig_dts_path,
123+
enc_dts_path
122124
);
123125

124126
println!("Rebuild test PASSED: {}", case.name);

fdt-raw/tests/node.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,10 @@ fn test_find_children_by_path_leaf() {
816816
let children: Vec<_> = fdt.find_children_by_path("/chosen").collect();
817817
info!(
818818
"Children of /chosen: {:?}",
819-
children.iter().map(|n: &fdt_raw::Node| n.name()).collect::<Vec<_>>()
819+
children
820+
.iter()
821+
.map(|n: &fdt_raw::Node| n.name())
822+
.collect::<Vec<_>>()
820823
);
821824

822825
// Even if it has children, verify they are all at the correct level
@@ -835,7 +838,10 @@ fn test_find_children_by_path_nonexistent() {
835838

836839
// Non-existent path should return empty iterator
837840
let result: Vec<_> = fdt.find_children_by_path("/nonexistent/path").collect();
838-
assert!(result.is_empty(), "Non-existent path should return empty iterator");
841+
assert!(
842+
result.is_empty(),
843+
"Non-existent path should return empty iterator"
844+
);
839845
}
840846

841847
#[test]

0 commit comments

Comments
 (0)