-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(fuzz) - add test progress #7914
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a3e7d97
feat(forge) - add test progress
grandizzy d479bd0
Code cleanup
grandizzy c6f92fd
Invariant progress bar cleanup
grandizzy 0672dff
Display number of threads and shrink run counter
grandizzy 0a338f2
Add progress for regular fuzz tests too
grandizzy fd21f0b
Cleanup code, use rayon collect
grandizzy ddbeabd
Merge remote-tracking branch 'origin' into test-progress
grandizzy 38e5343
Merge remote-tracking branch 'origin' into test-progress
grandizzy efe5a22
Merge remote-tracking branch 'origin' into test-progress
grandizzy 6233ae6
Merge remote-tracking branch 'origin' into test-progress
grandizzy 7aaafc8
Changes after review. Cleanup
grandizzy 77e85ff
Merge branch 'master' into test-progress
grandizzy 42cae1f
Fix clippy
grandizzy fedd8f6
Merge branch 'master' into test-progress
grandizzy 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -50,3 +50,4 @@ parking_lot = "0.12" | |
proptest = "1" | ||
thiserror = "1" | ||
tracing = "0.1" | ||
indicatif = "0.17" |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use indicatif::{MultiProgress, ProgressBar}; | ||
use parking_lot::Mutex; | ||
use std::{collections::HashMap, sync::Arc, time::Duration}; | ||
|
||
/// State of [ProgressBar]s displayed for the given test run. | ||
/// Shows progress of all test suites matching filter. | ||
/// For each test within the test suite an individual progress bar is displayed. | ||
/// When a test suite completes, their progress is removed from overall progress and result summary | ||
/// is displayed. | ||
#[derive(Debug)] | ||
pub struct TestsProgressState { | ||
/// Main [MultiProgress] instance showing progress for all test suites. | ||
multi: MultiProgress, | ||
/// Progress bar counting completed / remaining test suites. | ||
overall_progress: ProgressBar, | ||
/// Individual test suites progress. | ||
suites_progress: HashMap<String, ProgressBar>, | ||
} | ||
|
||
impl TestsProgressState { | ||
// Creates overall tests progress state. | ||
pub fn new(suites_len: usize, threads_no: usize) -> Self { | ||
let multi = MultiProgress::new(); | ||
let overall_progress = multi.add(ProgressBar::new(suites_len as u64)); | ||
overall_progress.set_style( | ||
indicatif::ProgressStyle::with_template("{bar:40.cyan/blue} {pos:>7}/{len:7} {msg}") | ||
.unwrap() | ||
.progress_chars("##-"), | ||
); | ||
overall_progress.set_message(format!("completed (with {} threads)", threads_no as u64)); | ||
Self { multi, overall_progress, suites_progress: HashMap::default() } | ||
} | ||
|
||
/// Creates new test suite progress and add it to overall progress. | ||
pub fn start_suite_progress(&mut self, suite_name: &String) { | ||
let suite_progress = self.multi.add(ProgressBar::new_spinner()); | ||
suite_progress.set_style( | ||
indicatif::ProgressStyle::with_template("{spinner} {wide_msg:.bold.dim}") | ||
.unwrap() | ||
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "), | ||
); | ||
suite_progress.set_message(format!("{suite_name} ")); | ||
suite_progress.enable_steady_tick(Duration::from_millis(100)); | ||
self.suites_progress.insert(suite_name.to_owned(), suite_progress); | ||
} | ||
|
||
/// Prints suite result summary and removes it from overall progress. | ||
pub fn end_suite_progress(&mut self, suite_name: &String, result_summary: String) { | ||
if let Some(suite_progress) = self.suites_progress.remove(suite_name) { | ||
self.multi.suspend(|| { | ||
println!("{suite_name}\n ↪ {result_summary}"); | ||
}); | ||
suite_progress.finish_and_clear(); | ||
// Increment test progress bar to reflect completed test suite. | ||
self.overall_progress.inc(1); | ||
} | ||
} | ||
|
||
/// Creates progress entry for fuzz tests. | ||
/// Set the prefix and total number of runs. Message is updated during execution with current | ||
/// phase. Test progress is placed under test suite progress entry so all tests within suite | ||
/// are grouped. | ||
pub fn start_fuzz_progress( | ||
&mut self, | ||
suite_name: &str, | ||
test_name: &String, | ||
runs: u32, | ||
) -> Option<ProgressBar> { | ||
if let Some(suite_progress) = self.suites_progress.get(suite_name) { | ||
let fuzz_progress = | ||
self.multi.insert_after(suite_progress, ProgressBar::new(runs as u64)); | ||
fuzz_progress.set_style( | ||
indicatif::ProgressStyle::with_template( | ||
" ↪ {prefix:.bold.dim}: [{pos}/{len}]{msg} Runs", | ||
) | ||
.unwrap() | ||
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "), | ||
); | ||
fuzz_progress.set_prefix(test_name.to_string()); | ||
Some(fuzz_progress) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Removes overall test progress. | ||
pub fn clear(&mut self) { | ||
self.multi.clear().unwrap(); | ||
} | ||
} | ||
|
||
/// Clonable wrapper around [TestsProgressState]. | ||
#[derive(Debug, Clone)] | ||
pub struct TestsProgress { | ||
pub inner: Arc<Mutex<TestsProgressState>>, | ||
} | ||
|
||
impl TestsProgress { | ||
pub fn new(suites_len: usize, threads_no: usize) -> Self { | ||
Self { inner: Arc::new(Mutex::new(TestsProgressState::new(suites_len, threads_no))) } | ||
} | ||
} | ||
|
||
/// Helper function for creating fuzz test progress bar. | ||
pub fn start_fuzz_progress( | ||
tests_progress: Option<&TestsProgress>, | ||
suite_name: &str, | ||
test_name: &String, | ||
runs: u32, | ||
) -> Option<ProgressBar> { | ||
if let Some(progress) = tests_progress { | ||
progress.inner.lock().start_fuzz_progress(suite_name, test_name, runs) | ||
} else { | ||
None | ||
} | ||
} |
Oops, something went wrong.
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.
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.
ok with this for now, but I think we want to have one single par_iter here and also handle all output in between progress bars