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/qemu-run/Cargo.toml b/qemu-run/Cargo.toml index 2d9a60de..c8f102b9 100644 --- a/qemu-run/Cargo.toml +++ b/qemu-run/Cargo.toml @@ -9,3 +9,6 @@ version = "0.0.0" [dependencies] anyhow = "1" defmt-decoder = { version = "=0.4.0", path = "../decoder" } + +[features] +no-decode = [] \ No newline at end of file diff --git a/qemu-run/src/main.rs b/qemu-run/src/main.rs index 5ea0c98f..54b4b4ad 100644 --- a/qemu-run/src/main.rs +++ b/qemu-run/src/main.rs @@ -5,7 +5,7 @@ use std::{ env, fs, - io::Read as _, + io::{self, Read as _, Write}, process::{self, Command, Stdio}, }; @@ -70,8 +70,12 @@ fn notmain() -> Result, anyhow::Error> { let exit_code; loop { let n = stdout.read(&mut readbuf)?; - decoder.received(&readbuf[..n]); - decode(&mut *decoder)?; + if cfg!(feature = "no-decode") { + io::stdout().write_all(&readbuf[..n])?; + } else { + decoder.received(&readbuf[..n]); + decode(&mut *decoder)?; + } if let Some(status) = child.0.try_wait()? { exit_code = status.code(); 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..30e233c4 Binary files /dev/null and b/xtask/output_files/hints_inner.out differ diff --git a/xtask/output_files/log.out b/xtask/output_files/log.out new file mode 100644 index 00000000..c909b06d Binary files /dev/null and b/xtask/output_files/log.out differ diff --git a/xtask/output_files/net.out b/xtask/output_files/net.out new file mode 100644 index 00000000..637e421d Binary files /dev/null and b/xtask/output_files/net.out differ 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..e44a3b46 Binary files /dev/null and b/xtask/snapshot_elfs/hints_inner differ diff --git a/xtask/snapshot_elfs/log b/xtask/snapshot_elfs/log new file mode 100755 index 00000000..036b959d Binary files /dev/null and b/xtask/snapshot_elfs/log differ diff --git a/xtask/snapshot_elfs/net b/xtask/snapshot_elfs/net new file mode 100755 index 00000000..2dab1afc Binary files /dev/null and b/xtask/snapshot_elfs/net 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..ade61ae1 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 75b7a589..f6601d5d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,4 +1,5 @@ mod backcompat; +mod print_snapshot; mod snapshot; mod targets; mod utils; @@ -9,6 +10,7 @@ use anyhow::anyhow; use clap::{Parser, Subcommand}; use utils::rustc_is_msrv; +use crate::print_snapshot::test_print_snapshot; use crate::{ snapshot::{test_snapshot, Snapshot}, utils::{run_capturing_stdout, run_command}, @@ -48,6 +50,10 @@ enum TestCommand { /// Runs a single snapshot test in Debug mode single: Option, }, + TestPrintSnapshot { + /// Runs a single snapshot test in Debug mode + single: Option, + }, } fn main() -> anyhow::Result<()> { @@ -77,6 +83,7 @@ fn main() -> anyhow::Result<()> { test_book(); test_lint(); } + 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 new file mode 100644 index 00000000..e0212dae --- /dev/null +++ b/xtask/src/print_snapshot.rs @@ -0,0 +1,69 @@ +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(snapshot: Option) { + match snapshot { + None => test_all_print_snapshots(), + Some(snapshot) => { + do_test( + || test_single_print_snapshot(snapshot.name()), + "qemu/snapshot_print", + ); + } + } +} + +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 = std::fs::File::open(frame_path)?; + + 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)), + ) + .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)) + } +}