-
-
Notifications
You must be signed in to change notification settings - Fork 104
Add print snapshot tests #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
BenFordTytherington
wants to merge
5
commits into
knurling-rs:main
Choose a base branch
from
BenFordTytherington:add-print-snapshot-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af20dd8
Add no-decode option to qemu-run
BenFordTytherington 9ef417c
Add framework for snapshot print tests
BenFordTytherington ebbeee4
Add format arg to test runner
BenFordTytherington 264f1e4
Add other ELFs and .out files
BenFordTytherington 07b65f5
Switch to File::open() instead of spawning cat to avoid waiting on sp…
BenFordTytherington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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
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.
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 hidden or 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 hidden or 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,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(snapshot: Option<Snapshot>) { | ||
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 = 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)) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathanpallant Clippy refers to the
Command
in line 33.I think it is correct without
.wait
, because it pipes the output fromcat
intodefmt-print
. So we do not want to wait until cat exited before executingrun_capturing_stdout
.Iiuc the pipe also makes sure cat does not exit before we execute
run_capturing_stdout
.So we just need to allow it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could also bypass the issue by not spawning
cat
and instead doingstd::fs::read()
on the file and passing the bytes to the stdin of thedefmt-print
process.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, that sounds simpler actually.