diff --git a/firmware/qemu/write_output.sh b/firmware/qemu/write_output.sh new file mode 100755 index 00000000..db6cd175 --- /dev/null +++ b/firmware/qemu/write_output.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +bins=("assert" "assert-eq" "assert-ne" "bitflags" "dbg" "hints" "hints_inner" "log" "panic" "panic_info" "timestamp" "unwrap") + +echo "Generating output ..." + +for value in "${bins[@]}"; do + command="DEFMT_LOG=trace cargo -q run --features no-decode --manifest-path ../../qemu-run/Cargo.toml ../target/thumbv7m-none-eabi/debug/$value > ~/defmt/xtask/output_files/$value.out" + echo "$command" + eval "$command" +done diff --git a/xtask/output_files/assert-eq.out b/xtask/output_files/assert-eq.out new file mode 100644 index 00000000..aa969dfb Binary files /dev/null and b/xtask/output_files/assert-eq.out differ diff --git a/xtask/output_files/assert-ne.out b/xtask/output_files/assert-ne.out new file mode 100644 index 00000000..11b1cc43 Binary files /dev/null and b/xtask/output_files/assert-ne.out differ diff --git a/xtask/output_files/assert.out b/xtask/output_files/assert.out new file mode 100644 index 00000000..d31fa133 Binary files /dev/null and b/xtask/output_files/assert.out differ diff --git a/xtask/output_files/bitflags.out b/xtask/output_files/bitflags.out new file mode 100644 index 00000000..fbe68839 Binary files /dev/null and b/xtask/output_files/bitflags.out differ diff --git a/xtask/output_files/dbg.out b/xtask/output_files/dbg.out new file mode 100644 index 00000000..e8d9a008 Binary files /dev/null and b/xtask/output_files/dbg.out differ diff --git a/xtask/output_files/hints.out b/xtask/output_files/hints.out new file mode 100644 index 00000000..9efe9565 Binary files /dev/null and b/xtask/output_files/hints.out differ diff --git a/xtask/output_files/hints_inner.out b/xtask/output_files/hints_inner.out new file mode 100644 index 00000000..e69de29b diff --git a/xtask/output_files/panic.out b/xtask/output_files/panic.out new file mode 100644 index 00000000..670bb1f5 Binary files /dev/null and b/xtask/output_files/panic.out differ diff --git a/xtask/output_files/panic_info.out b/xtask/output_files/panic_info.out new file mode 100644 index 00000000..b9ee21cb Binary files /dev/null and b/xtask/output_files/panic_info.out differ diff --git a/xtask/output_files/timestamp.out b/xtask/output_files/timestamp.out new file mode 100644 index 00000000..386c9bbf Binary files /dev/null and b/xtask/output_files/timestamp.out differ diff --git a/xtask/output_files/unwrap.out b/xtask/output_files/unwrap.out new file mode 100644 index 00000000..fcc079bc Binary files /dev/null and b/xtask/output_files/unwrap.out differ diff --git a/xtask/snapshot_elfs/assert b/xtask/snapshot_elfs/assert new file mode 100755 index 00000000..7a081402 Binary files /dev/null and b/xtask/snapshot_elfs/assert differ diff --git a/xtask/snapshot_elfs/assert-eq b/xtask/snapshot_elfs/assert-eq new file mode 100755 index 00000000..40e0511d Binary files /dev/null and b/xtask/snapshot_elfs/assert-eq differ diff --git a/xtask/snapshot_elfs/assert-ne b/xtask/snapshot_elfs/assert-ne new file mode 100755 index 00000000..122058a2 Binary files /dev/null and b/xtask/snapshot_elfs/assert-ne differ diff --git a/xtask/snapshot_elfs/bitflags b/xtask/snapshot_elfs/bitflags new file mode 100755 index 00000000..140f1da3 Binary files /dev/null and b/xtask/snapshot_elfs/bitflags differ diff --git a/xtask/snapshot_elfs/dbg b/xtask/snapshot_elfs/dbg new file mode 100755 index 00000000..e6c645bb Binary files /dev/null and b/xtask/snapshot_elfs/dbg differ diff --git a/xtask/snapshot_elfs/hints b/xtask/snapshot_elfs/hints new file mode 100755 index 00000000..ef9d4185 Binary files /dev/null and b/xtask/snapshot_elfs/hints differ diff --git a/xtask/snapshot_elfs/hints_inner b/xtask/snapshot_elfs/hints_inner new file mode 100755 index 00000000..471950e8 Binary files /dev/null and b/xtask/snapshot_elfs/hints_inner differ diff --git a/xtask/snapshot_elfs/panic b/xtask/snapshot_elfs/panic new file mode 100755 index 00000000..0cbd826b Binary files /dev/null and b/xtask/snapshot_elfs/panic differ diff --git a/xtask/snapshot_elfs/panic_info b/xtask/snapshot_elfs/panic_info new file mode 100755 index 00000000..e2ed9b94 Binary files /dev/null and b/xtask/snapshot_elfs/panic_info differ diff --git a/xtask/snapshot_elfs/timestamp b/xtask/snapshot_elfs/timestamp new file mode 100755 index 00000000..a2075127 Binary files /dev/null and b/xtask/snapshot_elfs/timestamp differ diff --git a/xtask/snapshot_elfs/unwrap b/xtask/snapshot_elfs/unwrap new file mode 100755 index 00000000..1cd19ee5 Binary files /dev/null and b/xtask/snapshot_elfs/unwrap differ diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 33e88fbc..f6601d5d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -50,7 +50,10 @@ enum TestCommand { /// Runs a single snapshot test in Debug mode single: Option, }, - TestPrintSnapshot, + TestPrintSnapshot { + /// Runs a single snapshot test in Debug mode + single: Option, + }, } fn main() -> anyhow::Result<()> { @@ -80,7 +83,7 @@ fn main() -> anyhow::Result<()> { test_book(); test_lint(); } - TestCommand::TestPrintSnapshot => test_print_snapshot("log"), + TestCommand::TestPrintSnapshot { single } => test_print_snapshot(single), _ => unreachable!("get handled in outer `match`"), } } diff --git a/xtask/src/print_snapshot.rs b/xtask/src/print_snapshot.rs index 31878cab..c29da4d3 100644 --- a/xtask/src/print_snapshot.rs +++ b/xtask/src/print_snapshot.rs @@ -1,59 +1,73 @@ use crate::do_test; +use crate::snapshot::{all_snapshot_tests, Snapshot}; use crate::utils::{load_expected_output, run_capturing_stdout}; use anyhow::{anyhow, Context}; use colored::Colorize; use similar::{ChangeTag, TextDiff}; use std::process::{Command, Stdio}; -pub fn test_print_snapshot(name: &str) { - do_test( - || { - println!("{}", name.bold()); - - let frame_path = format!("xtask/output_files/{}.out", name); - let elf_path = format!("xtask/snapshot_elfs/{}", name); - - let frames = Command::new("cat") - .arg(frame_path) - .stdout(Stdio::piped()) - .spawn() - .unwrap(); - - let actual = run_capturing_stdout( - Command::new("defmt-print") - .arg("-e") - .arg(elf_path) - .arg("--log-format") - .arg("{L:4} {s}") - .stdin(Stdio::from(frames.stdout.unwrap())), - ) - .with_context(|| name.to_string())?; - - let expected = load_expected_output(name, false)?; - let diff = TextDiff::from_lines(&expected, &actual); - - // if anything isn't ChangeTag::Equal, print it and turn on error flag - let mut actual_matches_expected = true; - for op in diff.ops() { - for change in diff.iter_changes(op) { - let styled_change = match change.tag() { - ChangeTag::Delete => Some(("-".bold().red(), change.to_string().red())), - ChangeTag::Insert => Some(("+".bold().green(), change.to_string().green())), - ChangeTag::Equal => None, - }; - if let Some((sign, change)) = styled_change { - actual_matches_expected = false; - eprint!("{sign}{change}"); - } - } - } +pub fn test_print_snapshot(snapshot: Option) { + match snapshot { + None => test_all_print_snapshots(), + Some(snapshot) => { + do_test( + || test_single_print_snapshot(snapshot.name()), + "qemu/snapshot_print", + ); + } + } +} - if actual_matches_expected { - Ok(()) - } else { - Err(anyhow!("{}", name)) - } - }, - "qemu/print_snapshot", +pub fn test_all_print_snapshots() { + for test in all_snapshot_tests() { + do_test(|| test_single_print_snapshot(test), "qemu/snapshot_print"); + } +} + +pub fn test_single_print_snapshot(name: &str) -> anyhow::Result<()> { + println!("{}", name.bold()); + + let frame_path = format!("xtask/output_files/{}.out", name); + let elf_path = format!("xtask/snapshot_elfs/{}", name); + + let frames = Command::new("cat") + .arg(frame_path) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + + let actual = run_capturing_stdout( + Command::new("defmt-print") + .arg("-e") + .arg(elf_path) + .arg("--log-format") + .arg("{L:4} {s}") + .stdin(Stdio::from(frames.stdout.unwrap())), ) + .with_context(|| name.to_string())?; + + let expected = load_expected_output(name, false)?; + let diff = TextDiff::from_lines(&expected, &actual); + + // if anything isn't ChangeTag::Equal, print it and turn on error flag + let mut actual_matches_expected = true; + for op in diff.ops() { + for change in diff.iter_changes(op) { + let styled_change = match change.tag() { + ChangeTag::Delete => Some(("-".bold().red(), change.to_string().red())), + ChangeTag::Insert => Some(("+".bold().green(), change.to_string().green())), + ChangeTag::Equal => None, + }; + if let Some((sign, change)) = styled_change { + actual_matches_expected = false; + eprint!("{sign}{change}"); + } + } + } + + if actual_matches_expected { + Ok(()) + } else { + Err(anyhow!("{}", name)) + } }