MCPcopy Index your code
hub / github.com/cloud-hypervisor/cloud-hypervisor / test_device_tree

Function test_device_tree

vmm/src/device_tree.rs:159–272  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

157
158 #[test]
159 fn test_device_tree() {
160 // Check new()
161 let mut device_tree = DeviceTree::new();
162 assert_eq!(device_tree.0.len(), 0);
163
164 // Check insert()
165 let id = String::from("id1");
166 device_tree.insert(id.clone(), DeviceNode::new(id.clone(), None));
167 assert_eq!(device_tree.0.len(), 1);
168 let node = device_tree.0.get(&id);
169 assert!(node.is_some());
170 let node = node.unwrap();
171 assert_eq!(node.id, id);
172
173 // Check get()
174 let id2 = String::from("id2");
175 assert!(device_tree.get(&id).is_some());
176 assert!(device_tree.get(&id2).is_none());
177
178 // Check get_mut()
179 let node = device_tree.get_mut(&id).unwrap();
180 node.id.clone_from(&id2);
181 let node = device_tree.0.get(&id).unwrap();
182 assert_eq!(node.id, id2);
183
184 // Check remove()
185 let node = device_tree.remove(&id).unwrap();
186 assert_eq!(node.id, id2);
187 assert_eq!(device_tree.0.len(), 0);
188
189 // Check iter()
190 let disk_id = String::from("disk0");
191 let net_id = String::from("net0");
192 let rng_id = String::from("rng0");
193 let device_list = vec![
194 (disk_id.clone(), device_node!(disk_id)),
195 (net_id.clone(), device_node!(net_id)),
196 (rng_id.clone(), device_node!(rng_id)),
197 ];
198 device_tree.0.extend(device_list);
199 for (id, node) in device_tree.iter() {
200 if id == &disk_id {
201 assert_eq!(node.id, disk_id);
202 } else if id == &net_id {
203 assert_eq!(node.id, net_id);
204 } else if id == &rng_id {
205 assert_eq!(node.id, rng_id);
206 } else {
207 unreachable!()
208 }
209 }
210
211 // Check breadth_first_traversal() based on the following hierarchy
212 //
213 // 0
214 // | \
215 // 1 2
216 // | | \

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
iterMethod · 0.80
insertMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
get_mutMethod · 0.45
removeMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected