-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Other examples which don't require features are now in the xtask dir - Added new functions to better align with how the current snapshot tests work
- Loading branch information
1 parent
ebbeee4
commit 942dea3
Showing
25 changed files
with
79 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Snapshot>) { | ||
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)) | ||
} | ||
} |