use super::super::super::*;
#[test]
#[cfg(feature = "presentar-tui")]
fn test_f121_to_tree_node_hierarchy() {
let mut graph = ExecutionGraph::new();
let layer_id = graph.push_scope(ExecutionNode::Layer { index: 0 });
graph.push_scope(ExecutionNode::Brick {
id: BrickId::RmsNorm,
timing_ns: 50_000,
elements: 4096,
});
graph.record_kernel_launch("rmsnorm_kernel", 0x1234, (16, 1, 1), (256, 1, 1), 1024);
graph.pop_scope(); graph.pop_scope();
let tree = graph.to_tree_node();
assert_eq!(tree.label, "Layer 0", "F121: Root is Layer");
assert_eq!(tree.children.len(), 1, "F121: Layer has 1 child (brick)");
let brick = &tree.children[0];
assert_eq!(brick.label, "RmsNorm", "F121: Brick label");
assert!(brick.info.as_ref().is_some_and(|i| i.contains("50.0µs")), "F121: Brick has timing");
assert_eq!(brick.children.len(), 1, "F121: Brick has 1 child (kernel)");
let kernel = &brick.children[0];
assert_eq!(kernel.label, "rmsnorm_kernel", "F121: Kernel label");
assert!(
kernel.info.as_ref().is_some_and(|i| i.contains("smem=1024B")),
"F121: Kernel has shared mem"
);
assert_eq!(tree.depth(), 3, "F121: Tree depth is 3 (layer->brick->kernel)");
assert_eq!(tree.count_nodes(), 3, "F121: Tree has 3 nodes");
let _ = layer_id;
}
#[test]
#[cfg(feature = "presentar-tui")]
fn test_f122_to_tree_node_multiple_roots() {
let mut graph = ExecutionGraph::new();
graph.add_node(ExecutionNode::Layer { index: 0 });
graph.add_node(ExecutionNode::Layer { index: 1 });
let tree = graph.to_tree_node();
assert_eq!(tree.label, "Execution Graph", "F122: Synthetic root label");
assert_eq!(tree.children.len(), 2, "F122: Two children (two layers)");
assert_eq!(tree.children[0].label, "Layer 0", "F122: First child");
assert_eq!(tree.children[1].label, "Layer 1", "F122: Second child");
}
#[test]
#[cfg(feature = "presentar-tui")]
fn test_f123_to_tree_node_empty() {
let graph = ExecutionGraph::new();
let tree = graph.to_tree_node();
assert_eq!(tree.label, "Empty Graph", "F123: Empty graph label");
assert!(tree.children.is_empty(), "F123: No children");
}
#[test]
fn test_f124_to_ascii_tree_hierarchy() {
let mut graph = ExecutionGraph::new();
graph.push_scope(ExecutionNode::Layer { index: 0 });
graph.push_scope(ExecutionNode::Brick {
id: BrickId::RmsNorm,
timing_ns: 50_000,
elements: 4096,
});
graph.record_kernel_launch("rmsnorm_kernel", 0x1234, (16, 1, 1), (256, 1, 1), 1024);
graph.pop_scope(); graph.pop_scope();
let tree = graph.to_ascii_tree();
assert!(tree.contains("Layer 0"), "F124: Contains Layer 0");
assert!(tree.contains("RmsNorm"), "F124: Contains RmsNorm");
assert!(tree.contains("50.0µs"), "F124: Contains timing");
assert!(tree.contains("rmsnorm_kernel"), "F124: Contains kernel");
assert!(tree.contains("smem=1024B"), "F124: Contains shared mem");
assert!(tree.contains("├──") || tree.contains("└──"), "F124: Has tree connectors");
}
#[test]
fn test_f125_to_ascii_tree_multiple_roots() {
let mut graph = ExecutionGraph::new();
graph.add_node(ExecutionNode::Layer { index: 0 });
graph.add_node(ExecutionNode::Layer { index: 1 });
let tree = graph.to_ascii_tree();
assert!(tree.starts_with("Execution Graph"), "F125: Synthetic root");
assert!(tree.contains("Layer 0"), "F125: Contains Layer 0");
assert!(tree.contains("Layer 1"), "F125: Contains Layer 1");
}
#[test]
fn test_f126_to_ascii_tree_empty() {
let graph = ExecutionGraph::new();
let tree = graph.to_ascii_tree();
assert_eq!(tree, "(empty graph)", "F126: Empty graph output");
}
#[test]
fn test_f127_to_ascii_tree_snapshot() {
let mut graph = ExecutionGraph::new();
graph.push_scope(ExecutionNode::Layer { index: 0 });
graph.push_scope(ExecutionNode::Brick {
id: BrickId::QkvProjection,
timing_ns: 200_000,
elements: 4096,
});
graph.record_kernel_launch("batched_gemv", 0xABCD, (32, 1, 1), (256, 1, 1), 4096);
graph.pop_scope();
graph.pop_scope();
let tree = graph.to_ascii_tree();
let expected = "\
Layer 0
└── QkvProjection 200.0µs (4096 elem)
└── batched_gemv <<<32,256,1>>> smem=4096B";
assert_eq!(tree, expected, "F127: Snapshot matches expected output");
}