-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
du: Fix overlapping input arguments #9211
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
Open
KCeple77
wants to merge
6
commits into
uutils:main
Choose a base branch
from
KCeple77:kiki_du_duplicates_fix
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f88ead5
du: Fix wrong output sizes when a subdirectory is included with its p…
KCeple77 acaf953
tests/uutests: Add empty fixture constructor for TestScenario
KCeple77 263ee36
tests/du: test overlapping input arguments
KCeple77 3cfdc8e
tests/du: du_summary_total_mega_duplicates - keep only linux test
KCeple77 9a078c1
tests/uutests: util: Add fill_bytes function to AtPath class
KCeple77 6f23a14
tests/du: du_summary_total_mega_duplicates cross-platform fix
KCeple77 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
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ use nix::pty::OpenptyResult; | |
| #[cfg(unix)] | ||
| use nix::sys; | ||
| use pretty_assertions::assert_eq; | ||
| use rand::Rng; | ||
| #[cfg(unix)] | ||
| use rlimit::setrlimit; | ||
| use std::borrow::Cow; | ||
|
|
@@ -1039,6 +1040,17 @@ impl AtPath { | |
| .unwrap_or_else(|e| panic!("Couldn't write {name}: {e}")); | ||
| } | ||
|
|
||
| pub fn fill_bytes(&self, name: &str, size_bytes: usize, use_rng: bool) { | ||
| let mut f = OpenOptions::new() | ||
| .create(true) | ||
| .write(true) | ||
| .truncate(true) | ||
| .append(false) | ||
| .open(self.plus(name)) | ||
| .unwrap(); | ||
| fill_file_rand(&mut f, size_bytes, use_rng).unwrap(); | ||
| } | ||
|
|
||
| pub fn append(&self, name: impl AsRef<Path>, contents: &str) { | ||
| let name = name.as_ref(); | ||
| log_info("write(append)", self.plus_as_string(name)); | ||
|
|
@@ -1342,32 +1354,44 @@ pub struct TestScenario { | |
| } | ||
|
|
||
| impl TestScenario { | ||
| /// Using a standard fixture | ||
| pub fn new<T>(util_name: T) -> Self | ||
| where | ||
| T: AsRef<str>, | ||
| { | ||
| let tmpd = Rc::new(TempDir::new().unwrap()); | ||
| println!("bin: {:?}", get_tests_binary!()); | ||
| let ts = Self { | ||
| bin_path: PathBuf::from(get_tests_binary!()), | ||
| util_name: util_name.as_ref().into(), | ||
| fixtures: AtPath::new(tmpd.as_ref().path()), | ||
| tmpd, | ||
| #[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))] | ||
| tmp_fs_mountpoint: None, | ||
| }; | ||
| let ts = Self::new_fresh(&util_name); | ||
|
|
||
| let mut fixture_path_builder = env::current_dir().unwrap(); | ||
| fixture_path_builder.push(TESTS_DIR); | ||
| fixture_path_builder.push(FIXTURES_DIR); | ||
| fixture_path_builder.push(util_name.as_ref()); | ||
|
|
||
| if let Ok(m) = fs::metadata(&fixture_path_builder) { | ||
| if m.is_dir() { | ||
| recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap(); | ||
| } | ||
| } | ||
|
|
||
| ts | ||
| } | ||
|
|
||
| /// Using an empty fixture | ||
| pub fn new_fresh<T>(util_name: T) -> Self | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it okay if I move those utility functions locally to du tests file? |
||
| where | ||
| T: AsRef<str>, | ||
| { | ||
| let tmpd = Rc::new(TempDir::new().unwrap()); | ||
| println!("bin: {:?}", get_tests_binary!()); | ||
| Self { | ||
| bin_path: PathBuf::from(get_tests_binary!()), | ||
| util_name: util_name.as_ref().into(), | ||
| fixtures: AtPath::new(tmpd.as_ref().path()), | ||
| tmpd, | ||
| #[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))] | ||
| tmp_fs_mountpoint: None, | ||
| } | ||
| } | ||
|
|
||
| /// Returns builder for invoking the target uutils binary. Paths given are | ||
| /// treated relative to the environment's unique temporary test directory. | ||
| pub fn ucmd(&self) -> UCommand { | ||
|
|
@@ -2865,6 +2889,44 @@ pub fn vec_of_size(n: usize) -> Vec<u8> { | |
| result | ||
| } | ||
|
|
||
| pub fn fill_file_rand( | ||
| file: &mut std::fs::File, | ||
| size_bytes: usize, | ||
| use_rng: bool, | ||
| ) -> io::Result<()> { | ||
| const CHUNK_SIZE: usize = 64 * 1024; // 64 kiB | ||
| let mut writer = BufWriter::new(file); | ||
| let mut written: usize = 0; | ||
| let mut to_write_len: usize; | ||
| let mut tx_buf = [b'a'; CHUNK_SIZE]; | ||
| let mut tx_slice: &mut [u8]; | ||
|
|
||
| if use_rng { | ||
| let mut rng = rand::rng(); | ||
|
|
||
| while written < size_bytes { | ||
| to_write_len = (size_bytes - written).min(CHUNK_SIZE); | ||
| tx_slice = &mut tx_buf[..to_write_len]; | ||
|
|
||
| rng.fill(tx_slice); | ||
|
|
||
| writer.write_all(tx_slice)?; | ||
| written += to_write_len; | ||
| } | ||
| } else { | ||
| while written < size_bytes { | ||
| to_write_len = (size_bytes - written).min(CHUNK_SIZE); | ||
| tx_slice = &mut tx_buf[..to_write_len]; | ||
|
|
||
| writer.write_all(tx_slice)?; | ||
| written += to_write_len; | ||
| } | ||
| } | ||
|
|
||
| writer.flush()?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn whoami() -> String { | ||
| // Apparently some CI environments have configuration issues, e.g. with 'whoami' and 'id'. | ||
| // | ||
|
|
||
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.
i don't think we need to extend uutests for this.
could you please find another way? thanks
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.
Is it okay if I move those utility functions to du tests file?